mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-12 22:56:58 +01:00
fix(issues): make every Retry start work or say why (#20283)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - When a task's run fails, the board recovers it with a Retry button, so that button must either start work or say why it did not > - An audit of every Retry-type button found three gaps. The task Retry shown during a scheduled retry's countdown returned "accepted" but changed nothing. A stale Retry looked like success in the Inbox. "Retry now" skipped the task's read and change checks, so a member who cannot see a private task could start its retry > - This pull request makes the task Retry start a scheduled retry immediately, makes every Retry that did not start work say why, and gives "Retry now" the same authorization as the task Retry > - The benefit is that no Retry click silently does nothing ## Linked Issues or Issue Description Refs #19831. The board reported a dead Retry button. A read-only audit of every Retry button confirmed: - **Task Retry during a scheduled retry was a no-op.** `TaskInterruptionPresentation.canRetry` is true in `retry_scheduled`, so `ExecutionBlockerNotice` shows Retry. `requestTaskRetry` treats `scheduled_retry` as busy and inserts a `coalesced` wake pointing at that run. `resumeTaskRetry` reads only `deferred_issue_execution`, and dispatch uses coalesced user wakes only to carry comments. Nothing promoted the run: the API answered 202 `accepted: true` and the countdown did not change. - **A stale Retry looked like success.** `accepted: false, stale: true` comes back as HTTP 200. The Inbox ignored `accepted` and opened the task as if work had started. The task page showed no reason. - **"Retry now" checked less than the task Retry.** It ran only `assertBoard` and `getAccessibleResource`, skipping `assertIssueReadAllowed` and `issue:mutate`. A company member who cannot read a private task could promote that task's scheduled retry. - **"Retry now" said nothing for some outcomes.** It toasted only `promoted` and `gate_suppressed`. ## What Changed - `server/src/services/task-retry.ts`: when the Retry coalesces into the task's latest run and that run is `scheduled_retry` (with no other Retry already active), the receipt returns `scheduledRetryRunId`. - `server/src/routes/issues.ts`: - `POST /issues/:id/retry` then promotes that run through the existing `retryScheduledRetryNow`, the same path "Retry now" uses. It logs `issue.scheduled_retry_retry_now` with `source: "task_retry"` and returns `scheduledRetry: { outcome, message }`. - `POST /issues/:id/scheduled-retry/retry-now` now runs `assertIssueReadAllowed` and `decideIssueAccess("issue:mutate")`, matching `/retry`. A private task the member cannot read now answers 404. - `ui/src/hooks/useTaskRetry.ts`: new `taskRetryNotStartedReason`. When a Retry did not start work (stale, or a scheduled retry that is gate-suppressed, waiting, or gone), the hook returns that reason as its error. `ExecutionBlockerNotice` and `StalledDependencyNotice` already display it. - `ui/src/pages/Inbox.tsx`: a task Retry that did not start work shows the reason in the error toast and does not navigate. - `ui/src/hooks/useRetryNowMutation.ts` and `IssueScheduledRetryCard.tsx`: every "Retry now" outcome now shows its headline and message, including `no_scheduled_retry` on the card. - `ui/src/api/issues.ts`: `retryTask`'s response type includes `scheduledRetry`. ## Verification Red/green (each new test fails against master and passes with this PR): - `server/src/__tests__/issue-scheduled-retry-routes.test.ts`: - "starts a scheduled retry now when the task Retry is clicked during its countdown": 202 with `scheduledRetry.outcome: "promoted"`, the same run becomes `queued`, and no second retry run is created. - "refuses Retry now on a private task the member cannot see, like the task Retry": on master "Retry now" answers 200 `promoted`; now both routes answer 404 and the run stays `scheduled_retry`. - The seed now adds the board user's membership, which the stricter route needs. All 33 tests pass. - `ui/src/hooks/useTaskRetry.test.tsx`: a replaced attempt, a gate-held scheduled retry and a waiting scheduled retry each show their reason; a promoted one shows nothing extra. - `ui/src/pages/Inbox.test.tsx`: an Inbox Retry that did not start work (stale, or gate-held) toasts the reason and does not navigate. - `ui/src/components/IssueScheduledRetryCard.test.tsx`: "explains when there was no scheduled retry left to start". Other Retry buttons: the chat failed-run Retry already reports stopped and failed retries (`agents.test.ts`). Agent lifecycle "Retry now" and cost "Retry accounting" start no task work and already surface their API errors. Regression and static checks: - UI: 7 files, 168 passed. Server: task-retry and scheduled-retry suites, 149 passed. `issue-agent-mutation-ownership-routes.test.ts` passed. - `maintenance-server-routes.test.ts` "assembled maintenance server production wiring" fails identically on master on this Mac (`ensure-build-deps`). - `tsc --noEmit` passes for `server` and `ui/src`. `pnpm check:token-gates` is clean. ## Risks - A task Retry during a scheduled retry now starts the run immediately, through the existing "Retry now" promotion gates (pause, budget, cleanup waits). A gate that holds it is reported, not bypassed. - "Retry now" is stricter: a member without read or change access to the task gets 404 or 403, as on `/retry`. - No schema change. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, via Claude Code with tool use (shell, file edits). ## 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 - [x] 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
fd2e7482c0
commit
ef2b8d5324
11 files changed
+196
-27
No files matched your search
@@ -139,6 +139,8 @@ describeEmbeddedPostgres("issue scheduled retry routes", () => {
|
||||
issuePrefix,
|
||||
requireBoardApprovalForNewAgents: false,
|
||||
});
|
||||
await db.insert(companyMemberships).values({ companyId, principalType: "user", principalId: "board-user",
|
||||
status: "active", membershipRole: "admin" });
|
||||
await db.insert(agents).values({
|
||||
id: agentId,
|
||||
companyId,
|
||||
@@ -664,10 +666,6 @@ describeEmbeddedPostgres("issue scheduled retry routes", () => {
|
||||
|
||||
it.each(["post", "patch"] as const)("keeps a retry's live process and saved work owner when a %s comment arrives", async method => {
|
||||
const f = await seedIssueWithRetry({ retryStatus: "running" });
|
||||
await db.insert(companyMemberships).values({
|
||||
companyId: f.companyId, principalType: "user", principalId: "board-user",
|
||||
membershipRole: "admin", status: "active",
|
||||
});
|
||||
const child = spawn(process.execPath, ["-e", `
|
||||
process.on('message', message => {
|
||||
if (message === 'continue-work') process.send('work-continues');
|
||||
@@ -781,6 +779,60 @@ describeEmbeddedPostgres("issue scheduled retry routes", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("starts a scheduled retry now when the task Retry is clicked during its countdown", async () => {
|
||||
const f = await seedIssueWithRetry();
|
||||
await db.update(heartbeatRuns).set({ createdAt: new Date("2026-05-06T18:00:01.000Z") })
|
||||
.where(eq(heartbeatRuns.id, f.retryRunId));
|
||||
const app = createApp(boardActor(f.companyId));
|
||||
|
||||
const res = await request(app).post(`/api/issues/${f.issueId}/retry`)
|
||||
.send({ idempotencyKey: randomUUID(), observedRunId: f.retryRunId });
|
||||
|
||||
expect(res.status, JSON.stringify(res.body)).toBe(202);
|
||||
expect(res.body).toMatchObject({ accepted: true, scheduledRetry: { outcome: "promoted" } });
|
||||
const [run] = await db.select().from(heartbeatRuns).where(eq(heartbeatRuns.id, f.retryRunId));
|
||||
expect(run!.status).toBe("queued");
|
||||
expect(await db.select().from(heartbeatRuns).where(eq(heartbeatRuns.retryOfRunId, f.sourceRunId))).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("starts the scheduled retry when a saved task Retry is replayed after its promotion was lost", async () => {
|
||||
const f = await seedIssueWithRetry();
|
||||
await db.update(heartbeatRuns).set({ createdAt: new Date("2026-05-06T18:00:01.000Z") })
|
||||
.where(eq(heartbeatRuns.id, f.retryRunId));
|
||||
const app = createApp(boardActor(f.companyId));
|
||||
const body = { idempotencyKey: randomUUID(), observedRunId: f.retryRunId };
|
||||
const first = await request(app).post(`/api/issues/${f.issueId}/retry`).send(body);
|
||||
expect(first.status, JSON.stringify(first.body)).toBe(202);
|
||||
await db.update(heartbeatRuns).set({ status: "scheduled_retry", scheduledRetryAt: new Date(Date.now() + 60 * 60_000) })
|
||||
.where(eq(heartbeatRuns.id, f.retryRunId));
|
||||
|
||||
const replay = await request(app).post(`/api/issues/${f.issueId}/retry`).send(body);
|
||||
|
||||
expect(replay.status, JSON.stringify(replay.body)).toBe(202);
|
||||
expect(replay.body).toMatchObject({ accepted: true, requestId: first.body.requestId, scheduledRetry: { outcome: "promoted" } });
|
||||
const [run] = await db.select().from(heartbeatRuns).where(eq(heartbeatRuns.id, f.retryRunId));
|
||||
expect(run!.status).toBe("queued");
|
||||
});
|
||||
|
||||
it("refuses Retry now on a private task the member cannot see, like the task Retry", async () => {
|
||||
const f = await seedIssueWithRetry();
|
||||
await db.update(issues).set({ visibility: "private", createdByUserId: "task-owner", responsibleUserId: "task-owner" })
|
||||
.where(eq(issues.id, f.issueId));
|
||||
await db.insert(companyMemberships).values({ companyId: f.companyId, principalType: "user", principalId: "other-member",
|
||||
status: "active", membershipRole: "member" });
|
||||
const app = createApp({ ...boardActor(f.companyId), userId: "other-member",
|
||||
memberships: [{ companyId: f.companyId, membershipRole: "member", status: "active" }] });
|
||||
|
||||
const retry = await request(app).post(`/api/issues/${f.issueId}/retry`)
|
||||
.send({ idempotencyKey: randomUUID(), observedRunId: f.retryRunId });
|
||||
const retryNow = await request(app).post(`/api/issues/${f.issueId}/scheduled-retry/retry-now`).send({});
|
||||
|
||||
expect(retry.status, JSON.stringify(retry.body)).toBe(404);
|
||||
expect(retryNow.status, JSON.stringify(retryNow.body)).toBe(404);
|
||||
const [run] = await db.select().from(heartbeatRuns).where(eq(heartbeatRuns.id, f.retryRunId));
|
||||
expect(run!.status).toBe("scheduled_retry");
|
||||
});
|
||||
|
||||
it("promotes the existing scheduled retry and treats duplicate clicks as idempotent", async () => {
|
||||
const { companyId, issueId, retryRunId } = await seedIssueWithRetry();
|
||||
const app = createApp(boardActor(companyId));
|
||||
@@ -855,6 +907,8 @@ describeEmbeddedPostgres("issue scheduled retry routes", () => {
|
||||
issuePrefix: "NONE",
|
||||
requireBoardApprovalForNewAgents: false,
|
||||
});
|
||||
await db.insert(companyMemberships).values({ companyId, principalType: "user", principalId: "board-user",
|
||||
status: "active", membershipRole: "admin" });
|
||||
await db.insert(issues).values({
|
||||
id: issueId,
|
||||
companyId,
|
||||
|
||||
@@ -10107,10 +10107,25 @@ export function issueRoutes(
|
||||
const receipt = await requestTaskRetry({ db, companyId: issue.companyId, issueId: issue.id,
|
||||
...req.body, actorId: getActorInfo(req).actorId, actorSource: req.actor.source,
|
||||
prepareChatRetry: opts.chatRunRetries?.prepareFailedChatRunRetry });
|
||||
res.status(receipt.accepted ? 202 : 200).json({ ...receipt, presentation: await taskInterruptionPresentation(db, issue) });
|
||||
const actor = getActorInfo(req);
|
||||
const scheduledRetryRunId = "scheduledRetryRunId" in receipt ? receipt.scheduledRetryRunId : undefined;
|
||||
const scheduledRetry = scheduledRetryRunId
|
||||
? await heartbeat.retryScheduledRetryNow({ issueId: issue.id, actor: { actorType: actor.actorType, actorId: actor.actorId } })
|
||||
: null;
|
||||
if (scheduledRetry) {
|
||||
await logActivity(db, { companyId: issue.companyId, actorType: actor.actorType, actorId: actor.actorId,
|
||||
action: "issue.scheduled_retry_retry_now", entityType: "issue", entityId: issue.id,
|
||||
agentId: scheduledRetry.scheduledRetry?.agentId ?? issue.assigneeAgentId ?? null,
|
||||
runId: scheduledRetry.scheduledRetry?.runId ?? scheduledRetryRunId ?? null,
|
||||
details: { outcome: scheduledRetry.outcome, message: scheduledRetry.message, source: "task_retry" } });
|
||||
}
|
||||
res.status(receipt.accepted ? 202 : 200).json({ ...receipt,
|
||||
...(scheduledRetry ? { scheduledRetry: { outcome: scheduledRetry.outcome, message: scheduledRetry.message } } : {}),
|
||||
presentation: await taskInterruptionPresentation(db, issue) });
|
||||
// The receipt commits before dispatch. Maintenance redelivers it after a
|
||||
// crash or a lost response; this nudge only reduces perceived latency.
|
||||
if (receipt.chatActionId) void opts.chatRunRetries?.processFailedChatRunRetry(receipt.chatActionId).catch(err =>
|
||||
const chatActionId = "chatActionId" in receipt ? receipt.chatActionId : undefined;
|
||||
if (chatActionId) void opts.chatRunRetries?.processFailedChatRunRetry(chatActionId).catch(err =>
|
||||
logger.warn({ err, issueId: issue.id }, "Connected task Retry remains queued"));
|
||||
else if (receipt.accepted && receipt.requestId) void heartbeat.resumeTaskRetry(issue.companyId, receipt.requestId).catch(err =>
|
||||
logger.warn({ err, issueId: issue.id }, "Task Retry remains queued"));
|
||||
@@ -14012,7 +14027,9 @@ export function issueRoutes(
|
||||
svc.getById(id),
|
||||
"Issue not found",
|
||||
);
|
||||
if (!issue) return;
|
||||
if (!issue || !(await assertIssueReadAllowed(req, res, issue))) return;
|
||||
const decision = await decideIssueAccess(req, issue, "issue:mutate");
|
||||
if (!decision.allowed) throw forbidden(decision.explanation, authorizationDeniedDetails(decision));
|
||||
|
||||
const actor = getActorInfo(req);
|
||||
const result = await heartbeat.retryScheduledRetryNow({
|
||||
|
||||
@@ -268,8 +268,13 @@ function admitTaskRetry(input: TaskRetryRequest) {
|
||||
if (sameRequest.payload?.issueId !== issue.id || sameRequest.requestedByActorId !== input.actorId)
|
||||
throw conflict("This retry request belongs to a different task or user.");
|
||||
const intent = readTaskRetryIntent(sameRequest.payload);
|
||||
const [coalescedRun] = sameRequest.status === "coalesced" && sameRequest.runId
|
||||
? await tx.select({ id: heartbeatRuns.id, status: heartbeatRuns.status }).from(heartbeatRuns)
|
||||
.where(and(eq(heartbeatRuns.companyId, issue.companyId), eq(heartbeatRuns.id, sameRequest.runId)))
|
||||
: [];
|
||||
return { requestId: intent?.canonicalIntentId ?? sameRequest.id, accepted: true, stale: false,
|
||||
observedRunId: intent?.sourceRunId ?? null, chatActionId: intent?.chatActionId };
|
||||
observedRunId: intent?.sourceRunId ?? null, chatActionId: intent?.chatActionId,
|
||||
...(coalescedRun?.status === "scheduled_retry" ? { scheduledRetryRunId: coalescedRun.id } : {}) };
|
||||
}
|
||||
const [latest] = await tx.select().from(heartbeatRuns).where(and(eq(heartbeatRuns.companyId, issue.companyId),
|
||||
or(eq(heartbeatRuns.issueId, issue.id), eq(heartbeatRuns.nativeIssueId, issue.id),
|
||||
@@ -277,7 +282,7 @@ function admitTaskRetry(input: TaskRetryRequest) {
|
||||
.orderBy(desc(heartbeatRuns.createdAt), desc(heartbeatRuns.id)).limit(1);
|
||||
if (["done", "cancelled"].includes(issue.status) || !issue.assigneeAgentId || !latest ||
|
||||
latest.agentId !== issue.assigneeAgentId || input.observedRunId !== latest.id) {
|
||||
return { requestId: null, accepted: false, stale: true, observedRunId: latest?.id ?? null };
|
||||
return { requestId: null, accepted: false, stale: true, observedRunId: latest?.id ?? null, chatActionId: undefined };
|
||||
}
|
||||
let active = (await tx.select().from(agentWakeupRequests).where(and(
|
||||
eq(agentWakeupRequests.companyId, issue.companyId), eq(agentWakeupRequests.agentId, issue.assigneeAgentId),
|
||||
@@ -430,7 +435,8 @@ function admitTaskRetry(input: TaskRetryRequest) {
|
||||
...(replacedRequestId ? { replacedRequestId } : {}),
|
||||
...(restartRecovery ? { initiatedBy: "restart_recovery", onBehalfOfUserId: input.actorId } : {}) } });
|
||||
return { requestId: active?.id ?? id, accepted: true, stale: false, observedRunId: latest.id,
|
||||
chatActionId: intent.chatActionId };
|
||||
chatActionId: intent.chatActionId,
|
||||
...(!active && latest.status === "scheduled_retry" ? { scheduledRetryRunId: latest.id } : {}) };
|
||||
}, { companyId: input.companyId });
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user