From 7d850ad65ebe4e0801c89226426d9b371921ce79 Mon Sep 17 00:00:00 2001 From: Dotta <34892728+cryppadotta@users.noreply.github.com> Date: Fri, 27 Nov 2026 12:56:25 +0000 Subject: [PATCH] fix(github): a superseded automatic review finishes instead of asking a person (#23064) 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 > - GitHub review bots run automatic reviews for a specific pull request head > - When the head has moved on, the review tools refuse the stale review and explain why > - That explanation said "an authorized person can request a manual review", so an agent can read it as a blocker owned by a person > - On staging, a review task recovered for an already-merged PR did exactly that: it marked itself blocked and asked the PR author to request a review > - This pull request makes the refusal say the review is no longer needed and that the task should finish as done > - The benefit is that stale or merged-PR reviews close cleanly instead of waiting on a person ## Linked Issues or Issue Description Refs #23049 **Describe the bug** A review-bot task for a PR merged three days earlier was continued by the lost-wait recovery (#23049). Its automatic review targeted the PR's old head. The review tool refused with "no newer automatic review is queued for it. An authorized person can request a manual review", and the agent blocked the task, naming the PR author or a maintainer as owner. **Steps to reproduce** 1. An automatic review request targets head A of a pull request. 2. The pull request moves to head B (or is merged) with no newer automatic review queued. 3. The agent calls a review tool; the refusal tells it a person can request a manual review, and the agent blocks the task. **Expected behavior** The agent finishes the task as done; a merged or closed pull request needs no review, and nothing waits on a person. ## What Changed - `server/src/services/chat-github-reviews.ts`: `supersededAutomaticReview` receives the pull request. For a closed or merged PR the refusal says no review is needed; otherwise it says the review is no longer needed (or that a newer automatic review is queued). In every case it tells the agent to finish the task as done and not to block it or ask anyone to request a review. The error details add `pullRequestClosed`. - Test in `github-review-publications.integration.test.ts` for a closed and an open pull request whose head moved. ## Verification - New test (`tells a superseded automatic review to finish instead of waiting on a person`, closed and open): fails on master (the old message asks for a person), passes here. - `github-review-publications` and `github-review-workflow` integration suites: 39 passed. Server typecheck is clean. - After deploy: a recovered review for a merged PR should finish as done instead of blocking. ## Risks - Wording change for one refusal; the reason code and retryability are unchanged. ## 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 --- ...ub-review-publications.integration.test.ts | 35 +++++++++++++++++++ server/src/services/chat-github-reviews.ts | 30 ++++++++++------ 2 files changed, 55 insertions(+), 10 deletions(-) diff --git a/server/src/__tests__/chat-channels/github-review-publications.integration.test.ts b/server/src/__tests__/chat-channels/github-review-publications.integration.test.ts index e32fab5537e..76a9569b66b 100644 --- a/server/src/__tests__/chat-channels/github-review-publications.integration.test.ts +++ b/server/src/__tests__/chat-channels/github-review-publications.integration.test.ts @@ -18,6 +18,7 @@ vi.mock("@chat-adapter/telegram", async (importOriginal) => { }); import { chatHistoryActionBlocks } from "../helpers/chat-history-proof.js"; import { githubChatReviewService } from "../../services/chat-github-reviews.js"; +import { githubAutomaticReviewEvent } from "../../services/chat-github-events.js"; import { githubResponseCommentService } from "../../services/chat-github-response-comments.js"; import { githubBotToolsForSession } from "../../services/chat-github-tools.js"; import { resolveRunScopedMentionedSkillKeys } from "../../services/heartbeat/run-preparation.js"; @@ -50,6 +51,40 @@ describeEmbeddedPostgres("chat channels: github review publications", () => { } = rev; describe("GitHub agent review publications", () => { + it.each([ + ["closed", "e", "already merged or closed, so no review is needed", "finish the task as done"], + ["closed", "f", "already merged or closed, so no review is needed", "finish the task as done"], + ["open", "e", "this review is no longer needed", "finish the task as done"], + ["queued", "e", "a newer automatic review for that commit is already queued", "leave the task open for the queued review"], + ] as const)("tells a superseded automatic review to stop without waiting on a person: %s, requested head %s", + async (state, requestedHead, reason, ending) => { + const f = await toolReplyFixture("github:paperclipai/paperclip:418"); + const [delivery] = await db.select().from(chatDeliveries).where(eq(chatDeliveries.endpointId, f.endpoint.id)); + const context = githubAutomaticReviewEvent({ action: "opened", repository: { id: 97531, full_name: "paperclipai/paperclip" }, + sender: { id: 42, login: "octocat" }, pull_request: { number: 418, title: "Review", body: "", draft: false, + base: { sha: "a".repeat(40), ref: "master" }, head: { sha: requestedHead.repeat(40) }, user: { id: 42, login: "octocat" }, labels: [] } }, + randomUUID())!; + await db.update(chatDeliveries).set({ normalizedEvent: { ...delivery.normalizedEvent, githubAutomatic: { context } } }) + .where(eq(chatDeliveries.id, delivery.id)); + if (state === "queued") await db.insert(chatDeliveries).values({ companyId: delivery.companyId, endpointId: delivery.endpointId, + conversationId: delivery.conversationId, providerEventId: `newer-${randomUUID()}`, deduplicationKey: `newer-${randomUUID()}`, + eventKind: delivery.eventKind, state: "received", createdAt: new Date(delivery.createdAt.getTime() + 60_000), + normalizedEvent: { ...delivery.normalizedEvent, githubAutomatic: { context: { ...context, headSha: "f".repeat(40) } } } }); + f.setSupplementalProviderFetch(async input => String(input).endsWith("/pulls/418") + ? Response.json({ number: 418, title: "Fix", body: null, state: state === "queued" ? "open" : state, draft: false, head: { sha: "f".repeat(40) }, + base: { sha: "a".repeat(40), ref: "master" }, user: { id: 42, login: "octocat", type: "User" }, labels: [] }) + : undefined); + const error = await githubChatReviewService(db, f.providerFetch).execute(f.session, "read_pull_request", { section: "metadata" }) + .then(() => null, (caught: unknown) => caught as { message: string; details?: Record }); + expect(error?.message).toContain(reason); + expect(error?.message).toContain(ending); + if (state === "queued") expect(error?.message).not.toContain("finish the task as done"); + if (requestedHead === "f") expect(error?.message).not.toContain("older pull request head"); + expect(error?.message).not.toContain("An authorized person can request"); + expect(error?.details).toMatchObject({ reasonCode: "github_review_superseded", pullRequestClosed: state === "closed", + newerReviewQueued: state === "queued" }); + }); + it("loads only the current configured instruction skills, never provider links or another company", async () => { const f = await reviewBotFixture(); const other = await seedCompany(); diff --git a/server/src/services/chat-github-reviews.ts b/server/src/services/chat-github-reviews.ts index 4d35860c46d..791f1075d38 100644 --- a/server/src/services/chat-github-reviews.ts +++ b/server/src/services/chat-github-reviews.ts @@ -337,9 +337,11 @@ export function githubChatReviewService(db: Db, fetchImpl = fetch) { async function supersededAutomaticReview( source: Awaited>, requestedCommit: string, - currentCommit: string, + pull: Pull, ) { - const [newer] = await db + const currentCommit = pull.head.sha; + const closed = pull.state === "closed"; + const [newer] = closed || requestedCommit === currentCommit ? [] : await db .select({ id: chatDeliveries.id }) .from(chatDeliveries) .where( @@ -358,19 +360,27 @@ export function githubChatReviewService(db: Db, fetchImpl = fetch) { ), ) .limit(1); - const next = newer - ? "a newer automatic review for that commit is already queued on this task" - : "no newer automatic review is queued for it. An authorized person can request a manual review"; + const target = requestedCommit === currentCommit + ? `This automatic review was requested for ${requestedCommit.slice(0, 7)}, and ` + : `This automatic review was requested for an older pull request head (${requestedCommit.slice(0, 7)}). ` + + `The pull request now points to ${currentCommit.slice(0, 7)}, and `; + const next = closed + ? "the pull request is already merged or closed, so no review is needed. Stop this review and finish the task as done" + : newer + ? "a newer automatic review for that commit is already queued on this task. Stop this run and leave the task " + + "open for the queued review" + : "no newer automatic review is queued for it, so this review is no longer needed. Stop this review and finish " + + "the task as done"; return conflict( - `This automatic review was requested for an older pull request head (${requestedCommit.slice(0, 7)}). ` + - `The pull request now points to ${currentCommit.slice(0, 7)}, and ${next}. ` + - "Stop this review: do not call review tools again and do not post the review as an ordinary comment.", + `${target}${next}: do not call review tools again, do not post the review as an ordinary comment, ` + + "and do not block the task or ask anyone to request a review.", { reasonCode: "github_review_superseded", retryable: false, requestedCommit, currentCommit, newerReviewQueued: !!newer, + pullRequestClosed: closed, }, ); } @@ -672,8 +682,8 @@ export function githubChatReviewService(db: Db, fetchImpl = fetch) { const pull = await api.request(`/pulls/${source.number}`); const automatic = source.delivery.normalizedEvent.githubAutomatic as { context: GitHubReviewEventContext } | undefined; - if (automatic && automatic.context.headSha !== pull.head.sha) - throw await supersededAutomaticReview(source, automatic.context.headSha, pull.head.sha); + if (automatic && (automatic.context.headSha !== pull.head.sha || pull.state === "closed")) + throw await supersededAutomaticReview(source, automatic.context.headSha, pull); if (name === "read_pull_request") { const parsed = readSchema.parse(input); if (parsed.section === "metadata") {