From 3cd1370141befdb5485578d7e777a1ae26fbf8bb Mon Sep 17 00:00:00 2001 From: Dotta <34892728+cryppadotta@users.noreply.github.com> Date: Mon, 23 Nov 2026 20:35:17 -0600 Subject: [PATCH] fix(github): re-read parked response requests after the settle decision changes (#22710) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Review agents answer GitHub pull requests, and a background sweep settles each request's status comment once its run finishes > - The sweep parks a request it cannot progress yet with a wait key, and a broad rebuild skips it until that key changes > - #22672 changed how requests settle, but requests parked by the older code kept the same key after the deploy > - So the new code never read them: 11 inline "Working on this…" comments stayed open on staging after #22672 deployed > - This pull request puts a decision version at the start of the wait key > - The benefit is that a deploy which changes the settle decision re-reads every parked request once, so old stuck comments settle ## Linked Issues or Issue Description Refs #22672 **Describe the bug** After #22672 deployed to staging, 5 of 16 stuck inline "Working on this…" review comments settled, but 11 did not. Their tasks had no new activity, so their wait keys did not change, and the sweep kept skipping them. **Steps to reproduce** 1. A request is parked by the terminal response sweep with a wait key from older code. 2. Deploy code that changes when such a request settles. 3. Nothing on the task changes, so the key stays the same and the request is never read again. **Expected behavior** A deploy that changes the settle decision re-reads every parked request once. ## What Changed - `GITHUB_TERMINAL_RESPONSE_DECISION_VERSION` ("v2") now starts the terminal sweep's wait key. Keys written before this change never match, so each parked request is read once by the current decision. - New test: requests parked with the old key, whose own run finished before a newer run, are all settled after the sweep starts. ## Verification - `reads requests parked by an older decision once after a deploy`: red without the version (0 of 120 acknowledged), green with it (120 of 120). - `server/src/services/chat-channels/github/` tests: 65 passed. - After deploy: the 11 open "Working on this…" comments on staging-reviewed PRs should settle within a sweep pass. ## Risks - One extra read of every parked request right after deploy (one batched page read per 100 rows, then they park again under the new key). Low risk. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, with tool use and code execution. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [ ] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 --- .../github/terminal-response-work.test.ts | 25 ++++++++++++++++++- .../github/terminal-response-work.ts | 4 ++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/server/src/services/chat-channels/github/terminal-response-work.test.ts b/server/src/services/chat-channels/github/terminal-response-work.test.ts index ebbb0665af5..f5781c0daaf 100644 --- a/server/src/services/chat-channels/github/terminal-response-work.test.ts +++ b/server/src/services/chat-channels/github/terminal-response-work.test.ts @@ -8,7 +8,7 @@ import { createDeliveryWorkCoordinator } from "../../delivery-work-coordinator.j import { DELIVERY_QUEUES, notifyDeliveryWork } from "../../delivery-work-notifications.js"; import { idleWorkSnapshot } from "../../task-admission.js"; import { registerGitHubAcknowledgementWork } from "./acknowledgement-work.js"; -import { registerGitHubTerminalResponseWork } from "./terminal-response-work.js"; +import { GITHUB_TERMINAL_RESPONSE_DECISION_VERSION, registerGitHubTerminalResponseWork } from "./terminal-response-work.js"; import { readGitHubResponseRuns } from "./response-run-state.js"; const support = await getEmbeddedPostgresTestSupport(); @@ -214,6 +214,29 @@ describe.skipIf(!support.supported)("GitHub terminal response sweep backlog", () expect(waiting!.result?.final).not.toBe(true); }, 300_000); + it("reads requests parked by an older decision once after a deploy", async () => { + vi.useFakeTimers({ toFake: ["Date", "setTimeout", "clearTimeout"], shouldAdvanceTime: true }); + const f = await seed(); + const base = Date.UTC(2026, 9, 28); + for (const [index, request] of f.stale.entries()) { + const issueNumber = f.runs.findIndex(run => run.issueId === request.issueId) + 1; + await db.insert(heartbeatRuns).values({ companyId: f.companyId, agentId: f.agentId, + nativeIssueId: request.issueId, issueId: request.issueId, scopeKind: "issue", status: "succeeded", + contextSnapshot: { issueId: request.issueId, wakeCommentId: request.commentId }, + createdAt: new Date(base + issueNumber * 3_600_000 - (index + 1) * 1_000) }); + } + const previous = `v${Number(GITHUB_TERMINAL_RESPONSE_DECISION_VERSION.slice(1)) - 1}|`; + const versioned = new Set(f.stale.filter((_, index) => index % 2 === 0).map(request => request.actionId)); + await db.execute(sql`update ${chatActions} a set result = coalesce(a.result, '{}'::jsonb) || jsonb_build_object('terminalWaitKey', + (case when a.id in (${sql.join([...versioned].map(id => sql`${id}::uuid`), sql`, `)}) then ${previous} else '' end) || (select r.id::text || ':' || r.status || ':' || extract(epoch from r.updated_at)::text from ${heartbeatRuns} r + where r.company_id = a.company_id and r.native_issue_id = c.issue_id order by r.created_at desc, r.id desc limit 1) + || '|' || i.status || '|' || extract(epoch from a.updated_at)::text) + from chat_conversations c, issues i + where c.id = a.conversation_id and i.id = c.issue_id and a.id in (${sql.join(f.stale.map(request => sql`${request.actionId}::uuid`), sql`, `)})`); + await start(); await advance(31_000); + expect(new Set(acknowledged)).toEqual(new Set(f.stale.map(request => request.deliveryId))); + }, 300_000); + it("acknowledges every owed request of a page when one run's requester provenance changed", async () => { vi.useFakeTimers({ toFake: ["Date", "setTimeout", "clearTimeout"], shouldAdvanceTime: true }); const f = await seed("received"); diff --git a/server/src/services/chat-channels/github/terminal-response-work.ts b/server/src/services/chat-channels/github/terminal-response-work.ts index fdbb18d8ef5..0915d04239f 100644 --- a/server/src/services/chat-channels/github/terminal-response-work.ts +++ b/server/src/services/chat-channels/github/terminal-response-work.ts @@ -8,6 +8,7 @@ import { githubResponseExecution } from "./response-execution.js"; import { readGitHubResponseRuns, type GitHubResponseRunRead } from "./response-run-state.js"; import { githubResponseReconstructionIntervalMs, type GitHubResponseSweepScope as Scope } from "./response-sweep-scope.js"; import { HttpError } from "../../../errors.js"; +export const GITHUB_TERMINAL_RESPONSE_DECISION_VERSION = "v2"; type Entry = { id: string; companyId: string; endpointId: string; deliveryId: string; issueId: string; conversationId: string; repositoryId: string | null; number: number | null; dueAt: number }; @@ -48,7 +49,8 @@ export function registerGitHubTerminalResponseWork( // the request's own row changes. Such a request records this key, and a broad // rebuild skips it until one of them changes. A targeted load still reads it. const actionVersion = sql`extract(epoch from ${chatActions.updatedAt})::text`; - const waitKey = sql`coalesce(${latestIssueRun.version}, 'none') || '|' || ${issues.status} || '|' || ${actionVersion}`; + const waitKey = sql`${GITHUB_TERMINAL_RESPONSE_DECISION_VERSION} || '|' || coalesce(${latestIssueRun.version}, 'none') + || '|' || ${issues.status} || '|' || ${actionVersion}`; async function page(scope?: Scope, cursor?: string, actionId?: string) { return db.select({ id: chatActions.id, companyId: chatActions.companyId, endpointId: chatActions.endpointId,