mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-29 06:50:43 +01:00
fix(github): a run that ends without its own reply links the latest response (#23111)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Each GitHub request to a review bot gets a comment that must end in a real reply or an honest, useful notice > - #22798 made the terminal sweep link the latest response on the same pull request when a request's own run did not reply > - A second path settles the same comments: when a run finishes without a GitHub reply, the publication transport calls `failRun` with a fixed notice > - That path never looked for a newer response, so a thread could say "ended without publishing" while the PR already showed a fresh review > - This pull request gives `failRun` the same latest-response link > - The benefit is that both settle paths agree, and readers are pointed at the review instead of a dead-end notice ## Linked Issues or Issue Description Refs #22798, #22672 **Describe the bug** On a pull request the author replied "Fixed in …" on a review bot's inline finding. The bot re-reviewed and updated the PR's main review comment to 5/5, then a second run said no new review was needed. The inline thread settled to "This turn ended without publishing a final response. See the Paperclip task for details." instead of linking the updated review. **Steps to reproduce** 1. An inline request is answered by a run that publishes nothing on GitHub. 2. A response for the same task and PR was published after the request arrived. 3. The publication transport settles the run through `failRun` with the fixed notice. **Expected behavior** The thread says "See the latest response" with a link to it. ## What Changed - `server/src/services/chat-github-response-comments.ts`: for each request of the run, `failRun` looks up the latest response published for the task on the same pull request or issue since the request arrived (`githubLatestTaskResponseUrl`, scoped by base thread) and links it; otherwise it keeps the given notice. - New test in `github-review-response-maintenance.integration.test.ts`: an inline request whose run ends without a reply, with a newer assessment on the same PR, settles with the link. ## Verification - New test fails on master ("ended without publishing") and passes here. - `github-review-response-maintenance`, `github-review-workflow`, `github-retry-and-recovery` integration suites and the response-comment unit tests: 99 passed. Server typecheck is clean. ## Risks - One indexed lookup per request when a run settles without a reply; it reuses the same query and index as the terminal sweep. ## 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 <noreply@anthropic.com>
This commit is contained in:
1 parent
99203b9f95
commit
f78a6f5ae3
5 files changed
+46
-8
No files matched your search
+2
-1
@@ -339,7 +339,8 @@ describeEmbeddedPostgres("chat channels: github review finding threads and fallb
|
||||
const posts = f.runtime.endpoints.get(f.endpoint.id)?.posts ?? [];
|
||||
expect(posts).toHaveLength(0);
|
||||
expect(f.responseWrites).toHaveLength(expected === "none" ? 2 : 1);
|
||||
if (expected === "none") expect(f.responseWrites[1]).toMatchObject({ method: "PATCH", body: expect.stringContaining("stopped before completing this turn") });
|
||||
if (expected === "none") expect(f.responseWrites[1]).toMatchObject({ method: "PATCH", body: expect.stringContaining(
|
||||
scenario === "different_run" ? "See the [latest response](https://github.com/paperclipai/paperclip/issues/418)" : "stopped before completing this turn") });
|
||||
const [fallback] = await db.select().from(chatPublications).where(and(eq(chatPublications.endpointId, f.endpoint.id),
|
||||
eq(chatPublications.idempotencyKey, `run:${f.run.id}:failed:${f.endpoint.id}`)));
|
||||
expect(fallback.state).toBe(expected === "none" ? "published" : "cancelled");
|
||||
|
||||
+25
-2
@@ -129,6 +129,29 @@ describeEmbeddedPostgres("chat channels: github review response maintenance", ()
|
||||
await responses.processPending();
|
||||
expect(f.responseWrites).toHaveLength(writes);
|
||||
});
|
||||
it.each(["in_progress", "blocked"] as const)("links the latest response when a request's run ends without its own reply: %s",
|
||||
async issueStatus => {
|
||||
const f = await toolReplyFixture("github:paperclipai/paperclip:418:rc:4100");
|
||||
await db.update(issues).set({ status: issueStatus }).where(eq(issues.id, f.conversation.issueId!));
|
||||
const [firstId] = [...f.responseComments.keys()];
|
||||
const [main] = await db.insert(chatConversations).values({ companyId: f.companyId, endpointId: f.endpoint.id,
|
||||
issueId: f.conversation.issueId, externalConversationId: "github:paperclipai/paperclip",
|
||||
externalLabel: "paperclipai/paperclip", externalThreadId: "github:paperclipai/paperclip:418" }).returning();
|
||||
await db.insert(chatActions).values({ companyId: f.companyId, endpointId: f.endpoint.id, conversationId: main.id,
|
||||
kind: "github_review_publication", providerActionId: `github_publication:${randomUUID()}`, status: "processed",
|
||||
payload: { operation: "assessment", session: { companyId: f.companyId, issueId: f.conversation.issueId, runId: randomUUID(), agentId: f.assignedAgentId } },
|
||||
result: { summaryUrl: "https://github.com/paperclipai/paperclip/pull/418#issuecomment-1" } });
|
||||
await db.update(heartbeatRuns).set({ status: "succeeded", runtimeMode: "native", nativePhase: "committed", resultJson: {
|
||||
finalizationPhase: "committed", finalizationReasonCode: "completion_claim_policy_accepted",
|
||||
nativeResult: { schema: "paperclip.run_result.v1", reportedWorkDisposition: "done" },
|
||||
presentationDecision: { schema: "paperclip.run_presentation_decision.v1", chosenSource: "none", commentAction: "create" } } })
|
||||
.where(eq(heartbeatRuns.id, f.run.id));
|
||||
await githubResponseCommentService(db, f.providerFetch).failRun({ companyId: f.companyId, endpointId: f.endpoint.id,
|
||||
issueId: f.conversation.issueId!, runId: f.run.id,
|
||||
body: "This turn ended without publishing a final response. See the Paperclip task for details." });
|
||||
expect(f.responseComments.get(firstId)?.body).toContain("See the [latest response](https://github.com/paperclipai/paperclip/pull/418)");
|
||||
expect(f.responseComments.get(firstId)?.body).not.toContain("ended without publishing");
|
||||
});
|
||||
it("links a GitHub thread whose run waited to the response a later run published", async () => {
|
||||
const f = await toolReplyFixture("github:paperclipai/paperclip:418:rc:4100");
|
||||
const [firstId] = [...f.responseComments.keys()];
|
||||
@@ -143,7 +166,7 @@ describeEmbeddedPostgres("chat channels: github review response maintenance", ()
|
||||
externalLabel: "paperclipai/paperclip", externalThreadId: "github:paperclipai/paperclip:4180" }).returning();
|
||||
await db.insert(chatActions).values({ companyId: f.companyId, endpointId: f.endpoint.id, conversationId: other.id,
|
||||
kind: "github_review_publication", providerActionId: `github_publication:${randomUUID()}`, status: "processed",
|
||||
payload: { operation: "comment", session: { companyId: f.companyId, issueId: f.conversation.issueId, runId: f.run.id } },
|
||||
payload: { operation: "comment", session: { companyId: f.companyId, issueId: f.conversation.issueId, runId: randomUUID(), agentId: f.assignedAgentId } },
|
||||
result: { id: "77", url: "https://github.com/paperclipai/paperclip/pull/4180#issuecomment-77" } });
|
||||
await db.update(issues).set({ status: "in_progress" }).where(eq(issues.id, f.conversation.issueId!));
|
||||
await responses.processPending();
|
||||
@@ -176,7 +199,7 @@ describeEmbeddedPostgres("chat channels: github review response maintenance", ()
|
||||
url: "https://github.com/paperclipai/paperclip/pull/418#discussion_r88", digest: "d" } } });
|
||||
await db.insert(chatActions).values({ companyId: f.companyId, endpointId: f.endpoint.id, conversationId: f.conversation.id,
|
||||
kind: "github_review_publication", providerActionId: `github_publication:${randomUUID()}`, status: "processed",
|
||||
payload: { operation: "assessment", reviewId, session: { companyId: f.companyId, issueId: f.conversation.issueId, runId: f.run.id } },
|
||||
payload: { operation: "assessment", reviewId, session: { companyId: f.companyId, issueId: f.conversation.issueId, runId: f.run.id, agentId: f.assignedAgentId } },
|
||||
result: { reviewId, summaryUrl: null } });
|
||||
await db.update(issues).set({ status: "done" }).where(eq(issues.id, f.conversation.issueId!));
|
||||
await responses.processPending();
|
||||
|
||||
@@ -34,6 +34,15 @@ export function settlesFromRequestRun(state: GitHubResponseRunState, issueStatus
|
||||
issueStatus !== "blocked" && !!state.finishedRequestRun;
|
||||
}
|
||||
|
||||
/** The notice that points a request at the latest response its agent published
|
||||
* on the same pull request or issue after the request arrived, if any. */
|
||||
export async function latestResponseNotice(db: Db,
|
||||
input: { companyId: string; endpointId: string; issueId: string; since: Date; threadId: string }) {
|
||||
const url = await githubLatestTaskResponseUrl(db, { companyId: input.companyId, endpointId: input.endpointId,
|
||||
issueId: input.issueId, since: input.since, baseThreadId: baseThreadId(input.threadId) });
|
||||
return url ? `See the [latest response](${url}).` : null;
|
||||
}
|
||||
|
||||
/** `read` is this request's state from a batched page read, if the caller has it. */
|
||||
export async function githubResponseExecution(db: Db, input: GitHubResponseExecutionInput, read?: GitHubResponseRunRead) {
|
||||
const state = read ?? await readGitHubResponseRun(db, input);
|
||||
@@ -55,8 +64,8 @@ export async function githubResponseExecution(db: Db, input: GitHubResponseExecu
|
||||
const presentationPending = !!run && answersRequest && run.nativePresentationPending && reply === "none";
|
||||
const passiveResponseWait = !!run && answersRequest && run.passiveResponseWait && reply === "none";
|
||||
const unanswered = !!run && !presentationPending && reply === "none" && !paused;
|
||||
const latestResponse = unanswered ? await githubLatestTaskResponseUrl(db, { companyId: input.companyId,
|
||||
endpointId: input.endpointId, issueId: input.issueId, since: input.deliveryCreatedAt, baseThreadId: baseThreadId(input.threadId) })
|
||||
const latestResponse = unanswered ? await latestResponseNotice(db, { companyId: input.companyId,
|
||||
endpointId: input.endpointId, issueId: input.issueId, since: input.deliveryCreatedAt, threadId: input.threadId })
|
||||
: null;
|
||||
const taskFinished = ["done", "cancelled"].includes(input.issueStatus);
|
||||
// Precedence: a later published response is more useful to the reader than
|
||||
@@ -71,7 +80,7 @@ export async function githubResponseExecution(db: Db, input: GitHubResponseExecu
|
||||
: run.responsePublicationFailed ? "publish_failed"
|
||||
: run.status === "succeeded" ? "ended" : "stopped";
|
||||
const body = outcome === null || outcome === "waiting" ? undefined
|
||||
: outcome === "link" ? `See the [latest response](${latestResponse}).` : STATUS_TEXT[outcome];
|
||||
: outcome === "link" ? latestResponse! : STATUS_TEXT[outcome];
|
||||
return {
|
||||
body, outcome, paused, reply, running: requestRunning, presentationPending, passiveResponseWait,
|
||||
versionAt: run ? new Date(Math.max(run.updatedAt.getTime(), input.deliveryCreatedAt.getTime()))
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
type Db,
|
||||
} from "@paperclipai/db";
|
||||
import { registerGitHubTerminalResponseWork } from "./chat-channels/github/terminal-response-work.js";
|
||||
import { githubResponseExecution, githubResponseRunColumns as responseRunColumns } from "./chat-channels/github/response-execution.js";
|
||||
import { githubResponseExecution, githubResponseRunColumns as responseRunColumns, latestResponseNotice } from "./chat-channels/github/response-execution.js";
|
||||
import { FINISHED_RUN_STATUSES, finishedRunStatusSql, runBoundToIssue, runWokeForComment } from "./chat-channels/github/response-run-state.js";
|
||||
import { notifyChatResponseAvailability } from "./chat-response-availability.js";
|
||||
import { registerGitHubAcknowledgementWork } from "./chat-channels/github/acknowledgement-work.js";
|
||||
@@ -427,7 +427,10 @@ export function githubResponseCommentService(db: Db, fetchImpl = fetch) {
|
||||
if (isMainPullResponse(source) && current.passiveResponseWait) throw forbidden("GitHub run intentionally yielded without a new response");
|
||||
if (await githubRunReplyState(db, input) !== "none") throw conflict("GitHub reply is still being resolved");
|
||||
};
|
||||
receipt = await acknowledge(link.deliveryId, input.body, assertRun);
|
||||
const source = await context(link.deliveryId);
|
||||
const notice = await latestResponseNotice(db, { companyId: input.companyId,
|
||||
endpointId: input.endpointId, issueId: input.issueId, since: source.delivery.createdAt, threadId: source.conversation.externalThreadId });
|
||||
receipt = await acknowledge(link.deliveryId, notice ?? input.body, assertRun);
|
||||
}
|
||||
if (!receipt) throw forbidden("GitHub failure has no request binding");
|
||||
return receipt;
|
||||
|
||||
@@ -135,6 +135,8 @@ export async function githubLatestTaskResponseUrl(
|
||||
eq(chatActions.status, "processed"),
|
||||
sql`${chatActions.payload}->'session'->>'companyId' = ${input.companyId}`,
|
||||
sql`${chatActions.payload}->'session'->>'issueId' = ${input.issueId}`,
|
||||
sql`${chatActions.payload}->'session'->>'agentId' = (select ${chatEndpoints.assignedAgentId}::text from ${chatEndpoints}
|
||||
where ${chatEndpoints.id} = ${input.endpointId}::uuid and ${chatEndpoints.companyId} = ${input.companyId}::uuid)`,
|
||||
sql`${chatActions.payload}->>'operation' in ('comment', 'formal_review', 'assessment')`,
|
||||
sql`${url} like 'https://github.com/%'`,
|
||||
sql`${chatActions.updatedAt} > ${input.since.toISOString()}::timestamptz`,
|
||||
|
||||
Reference in new issue
Block a user