Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: re-decide GitHub threads whose agent hand-off was refused

Adam Eivy2504870989f0
diff --git a/server/services/githubNotificationTriage.js b/server/services/githubNotificationTriage.js
index 26389f904f..0f077a2c67 100644
--- a/server/services/githubNotificationTriage.js
+++ b/server/services/githubNotificationTriage.js
@@ -28,10 +28,11 @@ const MAX_THREADS_PER_RUN = 60;
// changed your own PRs and finished threads (now marked done, not just read);
// version 3 leaves a bot's comment on your own PR to the PR workflow; version
// 4 finishes a review request on a merged or closed PR. A thread
-// already handed off keeps its hand-off. One an Assist model sorted is not
+// handed off keeps its hand-off; one whose hand-off was refused (a Private
+// account without agents) is re-decided like any other. One an Assist model sorted is not
// read again, except your own PR: the rule table decides those, so a verdict
// from before the rule existed must not keep one in front of you.
-const REDECIDE_SQL = `(state = 'open' AND NOT (evidence ? 'handoff')
+const REDECIDE_SQL = `(state = 'open' AND decision IS DISTINCT FROM 'handed-off'
AND ((reason = 'author' AND subject_type = 'PullRequest' AND trust = 'yours')
OR (decision = 'suggest-mark-read' AND COALESCE(evidence->>'rule', '') NOT LIKE 'ai-%')
OR (reason = 'review_requested' AND evidence->>'subjectState' IN ('merged', 'closed'))))`;
diff --git a/server/services/githubNotifications.db.test.js b/server/services/githubNotifications.db.test.js
index 4c2c4d40a3..200603118a 100644
--- a/server/services/githubNotifications.db.test.js
+++ b/server/services/githubNotifications.db.test.js
@@ -743,6 +743,16 @@ describe.skipIf(!runDb)('GitHub notifications inbox against Postgres', () => {
await syncAccountNotifications(account.id);
expect((await getNotification(account.id, '1504')).evidence.handoff).toBeUndefined();
expect(addTask).toHaveBeenCalledTimes(1);
+ // A refused hand-off recorded under older rules does not pin the thread:
+ // the version bump re-decides it as finished.
+ await query(
+ `UPDATE github_notifications SET state = 'open', decision = 'suggest-review',
+ evidence = evidence - 'assisted' || '{"rulesVersion":3,"handoff":{"lane":"do-review","skipped":"private-account"}}'::jsonb
+ WHERE account_id = $1 AND thread_id = '1504'`,
+ [account.id],
+ );
+ await syncAccountNotifications(account.id);
+ expect(await getNotification(account.id, '1504')).toMatchObject({ decision: 'suggest-mark-read', state: 'done' });
// A malformed rule is refused at the boundary.
expect(() => updateAccount(account.id, { agentRules: [{ id: 'x', kind: 'review-request', repo: 'not a repo', agent: true }] })).toThrow('Validation failed');
await updateAccount(account.id, { agentRules: [] });