fix(retry): move a recorded continuation forward before its delivery (#21379)

## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - When a run cannot resume, the server records a continuation for the
task and delivers it later as a new run
> - #21378 made a person's Retry deliver a recorded, undelivered
continuation as the one run, with its workspace isolation
> - #21373 added the `move_forward` Retry action, which does nothing
when the observed run is not queued or running
> - Together, a `move_forward` request before delivery returned "already
moved on" and started no work
> - That state can last a long time when the agent has a deep queue, and
it is when a person wants to move the task forward
> - This pull request accepts the request when the task has a recorded,
undelivered continuation
> - The benefit is one action that moves waiting work forward in each
state, with one run and the recorded isolation

## Linked Issues or Issue Description

**What happened?**

A task has a continuation that is recorded but not delivered. The latest
run is the failed source run. A Retry request with `retryAction:
"move_forward"` returns `accepted: false, alreadyMovedOn: true`. No run
starts.

**Expected behavior**

The request is accepted. Wake admission delivers the recorded
continuation as the one run for the task. The run keeps the recorded
isolation. A later delivery pass creates no second run.

**Steps to reproduce**

1. Record a fresh continuation for a task and do not run the delivery
pass.
2. Call `requestTaskRetry` with `observedRunId` set to the source run
and `retryAction: "move_forward"`.
3. The receipt says `alreadyMovedOn: true`.

Refs #21373, #21378, #21348.

## What Changed

- `admitTaskRetry` in `server/src/services/task-retry.ts` does not
return `alreadyMovedOn` when `undeliveredContinuation` finds a recorded,
undelivered continuation for the task. The check runs under the task row
lock.
- A new test in `fresh-continuation-retry-delivery.test.ts` covers the
three record kinds: `fresh_isolated_workspace`, `writer_ended` and
native.
- The presentation code is unchanged. The interface does not offer the
action in this state yet.

## Verification

- The new test failed before the change for the three kinds (`expected {
requestId: null, … } to match object { accepted: true }`).
- `npx vitest run
src/services/fresh-continuation-retry-delivery.test.ts`: 15 of 15
passed.
- `npx vitest run src/services/task-retry.test.ts`: 117 of 117 passed.
- `npx vitest run src/__tests__/recovery-wake-herd.test.ts -t move`: 2
of 2 passed. The case where the run ended and no continuation is pending
still returns `alreadyMovedOn`.
- `npx tsc --noEmit -p .` in `server/`: no errors.

## Risks

Low risk. The change adds one read under a lock that the function
already holds. The read runs only for a `move_forward` request when the
observed run is not queued or running. A request without a pending
continuation behaves as before.

## Model Used

Claude Fable 5.2 (`claude-fable-5-2`), 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
- [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 Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
DottaandClaude Fable 5.2 authored and GitHub committed 2026-11-13 07:31:16 -06:00
1 parent ed16a5b1a8
commit 39ef43a73e
2 files changed
+15 -1

No files matched your search

@@ -134,6 +134,18 @@ suite("a person's Retry while a continuation waits for delivery", () => {
expect((await taskRuns(f)).map(row => row.id)).toEqual([run.id]);
}, 60_000);
it.each(KINDS)("moves a recorded continuation forward as the one run when delivery has not happened yet (%s)", async kind => {
const f = await pendingContinuation(kind);
await occupySlot();
const receipt = await requestTaskRetry({ db, companyId, issueId: f.issueId, actorId: userId, observedRunId: f.runId,
idempotencyKey: randomUUID(), actorSource: "local_implicit", retryAction: "move_forward" });
expect(receipt).toMatchObject({ accepted: true });
await heartbeatService(db).resumeTaskRetry(companyId, receipt.requestId!);
const run = await expectSingleContinuationRun(f, receipt.requestId!);
await deliver();
expect((await taskRuns(f)).map(row => row.id)).toEqual([run.id]);
}, 60_000);
it.each(KINDS)("answers a Retry saved before delivery with the delivered continuation, never a second run (%s)", async kind => {
const f = await pendingContinuation(kind);
await occupySlot();
+3 -1
View File
@@ -23,6 +23,7 @@ import { hasRequiredWorkspaceRecovery } from "./workspace-restore-recovery-state
import { deferredChatInputPredicate, resumeDeferredChatWake, unadmittedChatWakeupCondition } from "./durable-chat-wakeup.js";
import { notifyDeferredExecutionWork } from "./deferred-execution-notifications.js";
import { hasPendingRunCleanup } from "./execution-blocker.js";
import { undeliveredContinuation } from "./fresh-continuation-retry-fold.js";
import { PersistedExecutionWaitRefusal } from "./deferred-execution-wait.js";
import { rearmExhaustedNativeFinalization } from "./native-runtime/exhausted-finalization-retry.js";
import { NativeChatReviewPresentationContentionError } from "./native-runtime/native-chat-review-presentation.js";
@@ -319,7 +320,8 @@ function admitTaskRetry(input: TaskRetryRequest) {
latest.agentId !== issue.assigneeAgentId || input.observedRunId !== latest.id) {
return { requestId: null, accepted: false, stale: true, observedRunId: latest?.id ?? null, chatActionId: undefined };
}
if (input.retryAction === "move_forward" && !["queued", "running"].includes(latest.status))
if (input.retryAction === "move_forward" && !["queued", "running"].includes(latest.status) &&
!(await undeliveredContinuation(tx, { companyId: issue.companyId, issueId: issue.id })))
return { requestId: null, accepted: false, stale: false, alreadyMovedOn: true, observedRunId: latest.id, chatActionId: undefined };
let active = (await tx.select().from(agentWakeupRequests).where(and(
eq(agentWakeupRequests.companyId, issue.companyId), eq(agentWakeupRequests.agentId, issue.assigneeAgentId),