Skip to content

The open-source app everyone uses to manage agents at work

fix(github): allow review publication to finish before tool timeout (#16275)

Dotta6cb6ac3b8e40
diff --git a/doc/connections/GITHUB-REVIEW-BOT.md b/doc/connections/GITHUB-REVIEW-BOT.md
index 414b14f096..c059e0208d 100644
--- a/doc/connections/GITHUB-REVIEW-BOT.md
+++ b/doc/connections/GITHUB-REVIEW-BOT.md
@@ -188,6 +188,12 @@ old runs cannot publish over the latest head. One current summary is updated in
place, with history and task/run links retained. Stable finding keys prevent
duplicate inline comments on repeated reviews.
+GitHub bot tools allow up to 60 seconds by default for their provider requests
+and publication receipts. An explicit shorter tool deadline still applies.
+The assessment and publication intent are saved before publication. A timeout
+does not cancel that durable publication or prove that GitHub rejected it;
+check the review's publication links before starting another review.
+
The check's **Details** link opens its Paperclip task on the current instance
hostname, or the connector's Reviews page when no task has been created yet.
diff --git a/server/src/__tests__/chat-channels.integration.test.ts b/server/src/__tests__/chat-channels.integration.test.ts
index 6ff16ab4fb..e08849a867 100644
--- a/server/src/__tests__/chat-channels.integration.test.ts
+++ b/server/src/__tests__/chat-channels.integration.test.ts
@@ -2536,8 +2536,14 @@ describeEmbeddedPostgres("chat channel control-plane integration", () => {
expect(f.wakeup).toHaveBeenCalledTimes(wakeCount);
expect(await readIssueCommentsByIssueId(f.conversation.issueId!)).toHaveLength(1);
});
- async function toolReplyFixture(threadId = "github:paperclipai/paperclip:issue:418") {
+ async function toolReplyFixture(threadId = "github:paperclipai/paperclip:issue:418", reportOnly = false) {
const f = await reviewBotFixture();
+ if (reportOnly) {
+ const config = await f.management.configuration(f.endpoint.id, "owner-user");
+ await f.management.saveConfiguration(f.endpoint.id, { expectedRevision: config.revision,
+ configuration: { ...config.configuration, defaults: { ...config.configuration.defaults, ratingThreshold: null } },
+ }, "owner-user");
+ }
const thread = makeThread({ channelId: "paperclipai/paperclip", id: threadId }).thread;
await deliverMessage({ callbacks: f.callbacks, endpointId: f.endpoint.id, provider: "github", thread,
trigger: "mention", message: makeMessage({ id: "41801", text: "Are you there?", userId: "42", userName: "octocat", mentioned: true }) });
@@ -2549,6 +2555,56 @@ describeEmbeddedPostgres("chat channel control-plane integration", () => {
const session = { companyId: f.companyId, agentId: f.assignedAgentId, issueId: conversation.issueId, runId: run.id };
return { ...f, conversation, run, session };
}
+ it.each([
+ { label: "returns the confirmed GitHub assessment when publication takes longer than ten seconds", delayMs: 11_000, timeoutMs: undefined },
+ { label: "preserves an explicit shorter GitHub tool deadline and reconciles without duplicate publication", delayMs: 200, timeoutMs: 50 },
+ ])("$label", async ({ delayMs, timeoutMs }) => {
+ const f = await toolReplyFixture("github:paperclipai/paperclip:418", true);
+ const head = "b".repeat(40);
+ const checks: Record<string, unknown>[] = [];
+ f.setSupplementalProviderFetch(async (input, init) => {
+ const url = String(input);
+ if (url.endsWith("/pulls/418")) return Response.json({ number: 418, state: "open", draft: false,
+ head: { sha: head }, base: { sha: "a".repeat(40), ref: "master" }, user: { id: 42, login: "octocat", type: "User" }, labels: [] });
+ if (url.includes("/files?")) return Response.json([{ filename: "src/math.ts", status: "modified", patch: "@@ -1 +1 @@\n-old\n+new" }]);
+ if (url.includes("/check-runs?")) return Response.json({ check_runs: [] });
+ if (url.includes("/check-runs") && init?.method) {
+ checks.push(JSON.parse(String(init.body)));
+ return Response.json({ id: 419, html_url: "https://github.com/checks/419" });
+ }
+ if (url.includes("/issues/comments/") && init?.method === "PATCH") {
+ await new Promise(resolve => setTimeout(resolve, delayMs));
+ }
+ return undefined;
+ });
+ vi.stubGlobal("fetch", f.providerFetch);
+ onTestFinished(() => { vi.unstubAllGlobals(); });
+ const { createToolGatewayService } = await import("../services/tool-gateway.js");
+ const gateway = createToolGatewayService(db);
+ const session = await gateway.createSession({ companyId: f.companyId, agentId: f.assignedAgentId, runId: f.run.id });
+ const tools = await githubBotToolsForSession(db, f.session);
+ const tool = tools.find(tool => tool.upstreamToolName === "submit_review")!;
+ await githubChatReviewService(db, f.providerFetch).execute(f.session, "begin_review", { reviewedCommit: head });
+ const assessment = { reviewedCommit: head, score: 5, complete: true, summary: "Looks good", rationale: "Reviewed the changed file",
+ coverage: { reviewedPaths: ["src/math.ts"], omittedPaths: [], limitations: [] }, findings: [] };
+ const result = await gateway.executeTool({ sessionToken: session.token, tool: tool.name, parameters: assessment, timeoutMs })
+ .then(value => ({ value }), error => ({ error }));
+ await expect.poll(async () => {
+ const [action] = await db.select().from(chatActions).where(and(eq(chatActions.endpointId, f.endpoint.id), eq(chatActions.kind, "github_review_publication")));
+ return action?.status;
+ }, { timeout: 15_000 }).toBe("processed");
+ expect(f.responseComments.size).toBe(1);
+ expect(f.responseWrites.map(write => write.method)).toEqual(["POST", "PATCH"]);
+ expect(checks).toContainEqual(expect.objectContaining({ conclusion: "neutral", status: "completed" }));
+ if (timeoutMs === undefined) {
+ expect(result).toMatchObject({ value: { status: "completed", result: { data: { status: "processed", score: 5, conclusion: "neutral" } } } });
+ } else {
+ expect(result).toMatchObject({ error: { status: 504, reasonCode: "tool_timeout" } });
+ }
+ const writes = f.responseWrites.length;
+ await gateway.executeTool({ sessionToken: session.token, tool: tool.name, parameters: assessment });
+ expect(f.responseWrites).toHaveLength(writes);
+ }, 40_000);
it("does not post a GitHub working comment when the scheduler declines the request", async () => {
const f = await reviewBotFixture();
f.wakeup.mockImplementation(async (agentId, opts) => {
diff --git a/server/src/services/tool-gateway.ts b/server/src/services/tool-gateway.ts
index 550ec59a30..b6382677fe 100644
--- a/server/src/services/tool-gateway.ts
+++ b/server/src/services/tool-gateway.ts
@@ -209,6 +209,7 @@ export function isConnectionGrantAudienceAllowed(
// `tool_timeout` even though the approval succeeded. Give approved executions
// the full permitted headroom instead.
const APPROVED_EXECUTION_TIMEOUT_MS = 60_000;
+const GITHUB_BOT_TOOL_TIMEOUT_MS = 60_000;
const ACTION_REQUEST_EXECUTION_POLL_MS = 25;
// Approval execution performs live target, signature, managed-argument, and
// issue-state checks before provider dispatch. Give that preparation a
@@ -732,8 +733,10 @@ function gatewaySessionFromRow(
};
}
-function timeoutMs(value: number | undefined) {
- if (!Number.isFinite(value)) return DEFAULT_TOOL_TIMEOUT_MS;
+function timeoutMs(value: number | undefined, tool?: ToolGatewayDescriptor) {
+ if (!Number.isFinite(value)) return tool?.providerType === "paperclip_github_chat"
+ ? GITHUB_BOT_TOOL_TIMEOUT_MS
+ : DEFAULT_TOOL_TIMEOUT_MS;
return Math.max(
1,
Math.min(60_000, Math.floor(value ?? DEFAULT_TOOL_TIMEOUT_MS)),
@@ -7270,7 +7273,7 @@ export function createToolGatewayService(
const startedAt = Date.now();
try {
- const executionTimeoutMs = timeoutMs(args.timeoutMs);
+ const executionTimeoutMs = timeoutMs(args.timeoutMs, args.tool);
const connectedMcpExecution =
(args.tool.providerType === "mcp_remote_http" || args.tool.providerType === "provider_rest")
? await executeRemoteHttpTool(
@@ -10624,7 +10627,7 @@ export function createToolGatewayService(
});
try {
- const executionTimeoutMs = timeoutMs(input.timeoutMs);
+ const executionTimeoutMs = timeoutMs(input.timeoutMs, tool);
if (
tool.providerType === "paperclip_plugin" &&
(!session.agentId || !session.runId)