Files
PaperClipAI/server/src/services/execution-projection.test.ts
T
DottaandClaude Opus 5.5 a65644d1e1 fix(retry): continue an accepted connected Retry from recovered saved work when its chat replay is refused later (#21080)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Tasks from a connected chat (for example GitHub pull request
reviews) show Retry when a run fails
> - A person's Retry on such a task first asks the chat retry owner to
repeat the exact failed chat request. #21038 made a refusal at the click
continue the task from saved work instead
> - The chat owner can also defer its source check (a busy identity,
endpoint, or agent row lock) and refuse it a few seconds later. Then the
route has already answered 202, and the task Retry receipt was marked
failed with no run
> - The task stayed blocked, and its execution blocker told the person
to send a message, while the interruption projection still offered Retry
> - This pull request makes that late refusal take the same board
continuation as a refusal at the click, and makes the blocker offer
Retry for recovered saved work
> - The benefit is that an accepted Retry always starts work, and the
two projections agree

## Linked Issues or Issue Description

No public issue exists. This is the bug description, in the fields of
`.github/ISSUE_TEMPLATE/bug_report.yml`.

**What happened?**

On a hosted deploy, about 20 blocked tasks of one busy GitHub review
agent (`paperclip_runner`, native remote runs) did not restart after
Retry. `POST /api/issues/:id/retry` returned 202 with `accepted: true`,
a `chatActionId`, and `presentation.state: retry_scheduled`. No run was
created. The task Retry receipt changed to `failed` 5 to 10 seconds
later, and the task stayed blocked. The activity record of each click
(`chat.failed_run_retry_requested`) has `sourceAuthorizationPending:
true`, so the chat owner deferred its source check at the click. No chat
wake row was written, so the chat replay ended before admission. The
last run failed with `native_continuation_requires_reconciliation` /
`runner_remote_process_identity_unavailable`. Its saved work was
recovered (`workspaceRecovery.status: recovered`, remote lease destroyed
with a termination receipt). The projections disagreed: `interruption`
had `canRetry: true`, but `executionBlocker` had `canRetry: false` and
`nextAction: "Saved work recovered. Send a message to continue."`.

Root cause: when the chat retry action settles `failed`,
`releaseUnadmittedTaskRetryInput` in
`server/src/services/chat-channels/task-retry-input.ts` marked the
linked task Retry receipt `failed`. #21038 added a board-continuation
fallback only for a refusal inside the click transaction. A refusal
after a deferred source check (for example 8 lock-busy attempts on the
agent row, about 7 seconds) had no fallback. Separately,
`getExecutionBlocker` hid Retry for every chat-bound task (`canRetry &&
!chatBinding`), and `workspaceRecoveryDisplay` always said "Send a
message to continue" for recovered work.

**Expected behavior**

A Retry that is accepted starts work. If the exact chat replay is
refused after the click, the person's Retry continues the task from its
recovered saved work. The execution blocker and the interruption both
offer Retry, and neither tells the person to send a message to unblock a
failed run.

**Steps to reproduce**

1. Bind a task to a GitHub chat conversation. Make its latest native run
fail with `native_continuation_requires_reconciliation` and recover its
saved work.
2. Hold the chat identity advisory lock while you click Retry, so the
source check is deferred (`sourceAuthorizationPending: true`).
3. Hold a row lock on the agent while the chat retry processes, so the
deferred check fails 8 times.
4. The route returned 202. The chat action settles `failed`, the task
Retry receipt changes to `failed`, and no run starts.

**Paperclip version or commit**

`master` at a8580160 (the deployed revision). Reproduced on f30005440b.

**Deployment mode**

Hosted (cloud) instance with Daytona remote sandboxes and a GitHub chat
connection.

**Agent adapter(s) involved**

`paperclip_runner` (native remote runs). The fix is in core Retry code
and is not adapter-specific.

## What Changed

- `server/src/services/task-retry.ts`: new `settleRefusedTaskChatRetry`.
When a chat retry action settles `failed`, the linked task Retry receipt
becomes an ordinary board continuation if all of these are true: it is a
person's Retry (or an automatic Retry that the same person's click has
joined), its source run is still the latest run and its saved work is
recovered (system recovery `complete`, workspace recovery `recovered`),
the clicking person still has task access, the chat wake has no run, and
no saved or unadmitted chat input remains. Any other refusal still
settles the receipt as failed, so the existing source-edited, revoked,
and identity-expiry outcomes do not change. A paused agent does not fail
the receipt: it stays deferred and starts when dispatch allows. The
receipt drops `chatActionId`, stays `deferred_issue_execution`, notifies
the deferred-receipt worker, and records
`issue.retry_continued_from_saved_work`. Otherwise the receipt is failed
as before. `reconcileTaskChatRetryReceipts` uses the same check, so a
crash before settlement is also covered. Its failed write matches the
chat binding it read, so a stale pass cannot fail a receipt that
settlement already converted.
- The task Retry intent now records `initiatedBy` for an automatic
Retry, so an automatic Retry keeps the exact-replay requirement after
the click too.
- `server/src/services/chat-channels/task-retry-input.ts`:
`releaseUnadmittedTaskRetryInput` calls the task owner's settlement
instead of failing the receipt directly.
- `server/src/services/execution-blocker.ts` and
`workspace-recovery-receipt.ts`: for a failed or timed-out run whose
saved work is recovered, the blocker offers Retry also on a chat-bound
task. The text follows actual Retry eligibility: "Saved work recovered.
Retry continues from it." when Retry is offered, "Saved work recovered."
when it is not (for example cleanup quarantine), and "Send a message to
continue" only for a stopped run. Only the task blocker decides Retry.
The run-level projection (`execution-projection.ts`) has no task
context, so it says "Saved work recovered." and never claims Retry.
`execution-projection.ts` uses the same text.
- `ui/src/lib/activity-format.ts`: labels for the new activity.
- `doc/execution-semantics.md`: the late-refusal rule.
- Tests: a new real-service case in
`server/src/__tests__/chat-channels.integration.test.ts` that reproduces
the hosted state (remote saved workspace, destroyed lease receipt,
recovered recovery action, deferred source check, refused replay), for a
person's Retry and for an automatic Retry. A gate case per continuation
condition (unrecovered workspace and revoked access settle failed; a
paused agent stays deferred and runs after resume), a stale-reconcile
race case, and a joined-click case. Two existing text expectations are
updated.

## Verification

- Red before the fix: with only the source changes removed, the new test
fails on the projection (`canRetry: false`, "Send a message to
continue."). With only the Retry settlement removed, it fails with the
receipt `status: "failed"` and no run.
- Green after the fix: `npx vitest run
src/__tests__/chat-channels.integration.test.ts -t "continues an
accepted GitHub task Retry from recovered saved work"` passes 2/2. The
person's Retry starts one queued run that resumes the preserved
workspace, and the automatic Retry still settles as failed.
- Focused suites pass: `task-retry`, `execution-projection`,
`execution-projection-recovery`, `workspace-recovery-retry-copyback`,
`chat-failed-run-retry-boundary`, `workspace-recovery-admission`,
`remote-workspace-recovery-receipt-fallback` (372/372), and other
recovery, blocker and continuation suites.
- `npx tsc --noEmit -p server/tsconfig.json` passes.
- Staging was read with GET requests only. No POST was sent.

## Risks

- Behavior change: a person's Retry on a connected task that the chat
owner refuses after the click now starts a board continuation. It is the
same continuation #21038 already uses for a refusal at the click, with
the clicking person's authority, and dispatch keeps every normal gate.
- Receipts that already failed on staging stay failed. The next click on
those tasks takes the fixed path. No migration.
- The blocker now reports `canRetry: true` for chat-bound tasks only
when the failed run's saved work is verifiably recovered.

> For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and
discuss it in `#dev` before opening the PR. Feature PRs that overlap
with planned core work may need to be redirected — check the roadmap
first. See `CONTRIBUTING.md`.

## Model Used

- Claude Opus 5.5 (claude-opus-5-5), Anthropic, with tool use and code
execution in Claude Code.

## 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>
2026-11-12 07:57:42 -06:00

371 lines
18 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { projectExecution } from "./execution-projection.js";
import { startTaskDrain, stopTaskDrain } from "./task-admission.js";
import { resetStartupRecoveryStateForTests, setStartupRecoveryPhase } from "../startup-recovery-state.js";
type Run = Parameters<typeof projectExecution>[0];
type Coordinator = NonNullable<Parameters<typeof projectExecution>[1]>;
const now = new Date("2026-09-08T12:00:00Z");
const run = (values: Partial<Run> = {}) =>
({
status: "running",
runtimeMode: "native",
errorCode: null,
nextAction: null,
lastUsefulActionAt: now,
lastOutputAt: null,
startedAt: now,
scheduledRetryAt: null,
scheduledRetryAttempt: 1,
retryOfRunId: null,
executionControlDeadlineAt: null,
...values,
}) as Run;
const coordinator = (values: Partial<Coordinator> = {}) =>
({
phase: "observed",
attempt: 1,
failureCode: null,
failureDetail: {},
nextAttemptAt: null,
leaseExpiresAt: new Date(now.getTime() + 30_000),
controlDeadlineAt: null,
...values,
}) as Coordinator;
const project = (
r = run(),
c: Coordinator | undefined = coordinator(),
pending: { kind: string }[] = [],
) => projectExecution(r, c, pending, undefined, now);
describe("execution truth projection", () => {
it.each(["contained", "ordinary", "wrong-source", "continued"] as const)("projects controller containment without inventing queued work: %s", state => {
const stopped = run({ id: "old", status: "failed" });
const action = { status: "resolved" as const, cause: "native_restart_recovery_blocked", nextAction: "Inspect the original owner",
evidence: { reason: "controller_process_space_unverified", continuationDelivery: "not_requested",
executionReconciliation: { runId: state === "wrong-source" ? "another-run" : "old", providerStopped: true,
...(state === "ordinary" ? {} : { controllerStopped: true, controllerAuthorityDigest: "a".repeat(64) }) },
...(state === "continued" ? { explicitUserContinuation: { previousRunId: "old", runId: "new" } } : {}),
} };
const projected = projectExecution(stopped, coordinator({ phase: "terminal_failure" }), [], action, now);
expect(projected.phase).toBe(state === "contained" ? "failed" : state === "continued" ? "completed" : "queued");
if (state === "contained") {
expect(projected.label).toBe("Execution contained");
expect(projected.nextAction).toContain("Use Retry");
expect(projected.successorRunId).toBeNull();
}
if (state === "continued") expect(projected.successorRunId).toBe("new");
});
it("offers Stop for every live run, including a long-silent native turn", () => {
const silentSince = new Date(now.getTime() - 35 * 60_000);
const silent = run({ lastUsefulActionAt: silentSince, startedAt: silentSince });
expect(project(silent)).toMatchObject({ phase: "working", canStop: true });
expect(project(run({ runtimeMode: "legacy" }), undefined).canStop).toBe(true);
expect(projectExecution(run({ status: "queued", startedAt: null }), undefined, [], undefined, now).canStop).toBe(true);
for (const status of ["succeeded", "cancelled", "timed_out", "failed"] as const) {
expect(project(run({ status }), undefined).canStop).toBe(false);
}
});
it("shows setup progress without overriding real holds or started work", () => {
const queued = run({ status: "queued", startedAt: null });
const setup = { lifecycleState: "verifying", lifecycleHolds: [], lifecycleError: null };
const projectSetup = (r = queued, agent = setup) => projectExecution(r, undefined, [], undefined, now, undefined, false, agent);
expect(projectSetup()).toMatchObject({ label: "Waiting for agent setup", cause: "agent_setup_pending" });
expect(projectSetup(queued, { ...setup, lifecycleState: "paused" })).toMatchObject({ label: "Queued", cause: null });
expect(projectExecution(queued, undefined, [], undefined, now, undefined, false,
{ ...setup, lifecycleHolds: ["budget"] })).toMatchObject({ label: "Queued", cause: null });
expect(projectSetup(run({ status: "queued", startedAt: now }))).toMatchObject({ label: "Queued", cause: null });
expect(projectSetup(run({ status: "running" })).label).toBe("Confirming execution");
});
it("shows maintenance only for admission that has not started", () => {
startTaskDrain();
try {
expect(projectExecution(run({ status: "queued", startedAt: null }), undefined, [], undefined, now))
.toMatchObject({ phase: "queued", label: "Waiting for maintenance", cause: "task_drain" });
expect(project().phase).toBe("working");
} finally { stopTaskDrain(); }
expect(projectExecution(run({ status: "queued", startedAt: null }), undefined, [], undefined, now))
.toMatchObject({ phase: "queued", label: "Queued", cause: null });
});
it.each(["starting", "recovering", "draining"] as const)("names a server restart while it holds queued work: %s", phase => {
setStartupRecoveryPhase(phase);
try {
for (const queued of [run({ status: "queued", startedAt: null }), run({ status: "queued", startedAt: now, retryOfRunId: "prior" })]) {
const projection = projectExecution(queued, undefined, [], undefined, now);
expect(projection).toMatchObject({ phase: "queued", label: "Waiting for server restart", cause: "server_restarting" });
expect(projection.nextAction).toMatch(/starts automatically/);
}
// A live run is not relabelled; restart recovery owns its own state.
expect(project().phase).toBe("working");
} finally { resetStartupRecoveryStateForTests(); }
expect(projectExecution(run({ status: "queued", startedAt: null }), undefined, [], undefined, now))
.toMatchObject({ label: "Queued", cause: null });
});
it("keeps the maintenance hold reason while a restarted server is still recovering", () => {
setStartupRecoveryPhase("recovering");
startTaskDrain();
try {
expect(projectExecution(run({ status: "queued", startedAt: null }), undefined, [], undefined, now))
.toMatchObject({ label: "Waiting for maintenance", cause: "task_drain" });
} finally { stopTaskDrain(); resetStartupRecoveryStateForTests(); }
});
it.each(["queued", "recovering", "blocked", "recovered"] as const)("shows the exact saved workspace recovery state instead of stale repair instructions: %s", status => {
const sourceRunId = "ec036e06-90a3-4b69-81db-a8eab7dbfbac";
const source = run({ id: sourceRunId, status: "failed", errorCode: "native_continuation_requires_reconciliation" });
const action = {
status: "resolved" as const,
cause: "native_continuation_requires_reconciliation",
nextAction: "The original sandbox is retained for workspace repair.",
evidence: {
runId: sourceRunId,
automaticRecovery: { policy: "preserve_without_replay_v1", actionOutcome: "unknown", replay: "blocked" },
continuationDelivery: "invalidated",
workspaceRecovery: {
schema: "paperclip.workspace-recovery.v1", runId: sourceRunId, status,
stage: "saving_receipts", attempt: 1, requestIds: [],
...(status === "blocked" ? { message: "The saved source cannot be read safely." } : {}),
},
},
};
const projected = projectExecution(source, coordinator({ phase: "terminal_failure" }), [], action, now);
expect(projected).toMatchObject({
phase: "recovery_needed", label: "Stopped", cause: action.cause,
nextAction: status === "recovered" ? "Saved work recovered."
: status === "blocked" ? "The saved source cannot be read safely." : "Recovering saved work…",
permittedActions: ["inspect_run"], successorRunId: null,
});
expect(source.status).toBe("failed");
expect(action.evidence.automaticRecovery.replay).toBe("blocked");
if (status === "recovered") {
expect(projectExecution({ ...source, status: "timed_out" }, coordinator({ phase: "terminal_failure" }), [], action, now)
.nextAction).toBe("Saved work recovered.");
expect(projectExecution({ ...source, errorCode: "native_session_cleanup_quarantined" },
coordinator({ phase: "terminal_failure" }), [], action, now).nextAction).toBe("Saved work recovered.");
}
expect(projectExecution(source, undefined, [], { ...action,
evidence: { ...action.evidence, workspaceRecovery: { ...action.evidence.workspaceRecovery,
runId: "5f227d75-b314-4511-bf23-9c615277e69b" } },
}, now).nextAction).toBe(action.nextAction);
});
it("keeps cleanup quarantine visible without a coordinator or recovery row", () => {
const stopped = run({ id: "stopped", status: "failed", errorCode: "native_session_cleanup_quarantined" });
expect(projectExecution(stopped, undefined, [], undefined, now)).toMatchObject({
phase: "recovery_needed", cause: "native_session_cleanup_quarantined", recoveryOwner: "board",
permittedActions: ["inspect_run", "inspect_recovery"],
});
expect(projectExecution(stopped, coordinator({ phase: "retryable_failure" }), [], undefined, now).phase).toBe("recovery_needed");
expect(projectExecution({ ...stopped, finishedAt: now }, coordinator({
phase: "terminal_failure", failureCode: "native_provider_terminal_failed",
}), [], undefined, now)).toMatchObject({ phase: "recovery_needed", recoveryOwner: "board" });
expect(projectExecution({ ...stopped, errorCode: "provider_frame_too_large" }, undefined, [], undefined, now).phase).toBe("failed");
expect(projectExecution(stopped, undefined, [], { status: "resolved", cause: "native_session_cleanup_quarantined", nextAction: "Verify prior execution",
evidence: { executionReconciliation: { providerStopped: true }, continuationRunId: "successor" } }, now))
.toMatchObject({ phase: "completed", successorRunId: "successor", cause: null });
});
it("shows subscription contention as a resource wait without failed provider attempts", () => {
expect(projectExecution(run({ runtimeMode: "legacy", status: "scheduled_retry", scheduledRetryReason: "ai_connection_busy",
scheduledRetryAttempt: 12, contextSnapshot: { failureRetriesBeforeAiConnectionWait: 0 } }), undefined, [], undefined, now))
.toMatchObject({ label: "Waiting for AI subscription", phase: "retry_scheduled", attempt: 1, recoveryOwner: null });
});
it("shows a provider usage limit wait with its reset time", () => {
const scheduledRetryAt = new Date("2026-11-05T13:47:50.375Z");
expect(projectExecution(run({ runtimeMode: "native", status: "scheduled_retry", scheduledRetryReason: "ai_connection_pool_wait",
scheduledRetryAt, scheduledRetryAttempt: 3, contextSnapshot: { wakeReason: "provider_limit_retry", failureRetriesBeforeAiConnectionWait: 0 } }),
undefined, [], undefined, now)).toMatchObject({
label: "Waiting for usage limit reset", phase: "retry_scheduled", attempt: 1, recoveryOwner: null,
nextAction: expect.stringContaining(scheduledRetryAt.toISOString()),
});
});
it("shows a workspace wait without presenting its deferral count as failed attempts", () => {
expect(projectExecution(run({ runtimeMode: "legacy", status: "scheduled_retry", scheduledRetryReason: "workspace_busy",
scheduledRetryAttempt: 12, contextSnapshot: { failureRetriesBeforeWorkspaceWait: 1 } }), undefined, [], undefined, now))
.toMatchObject({ label: "Waiting for workspace", phase: "retry_scheduled", attempt: 2, recoveryOwner: null });
});
it.each([
{ status: "resolved", previousRunId: "old", nextRunId: "next", continued: true },
{ status: "active", previousRunId: "old", nextRunId: "next", continued: false },
{ status: "resolved", previousRunId: "other", nextRunId: "next", continued: false },
{ status: "resolved", previousRunId: "old", nextRunId: "old", continued: false },
{ status: "resolved", previousRunId: "old", nextRunId: null, continued: false },
])("projects the recorded explicit successor without hiding unresolved recovery: $status/$previousRunId/$nextRunId", ({ status, previousRunId, nextRunId, continued }) => {
const source = run({ id: "old", status: "failed", errorCode: "adapter_failed" });
expect(projectExecution(source, coordinator({ phase: "terminal_failure" }), [], {
status,
cause: "native_continuation_requires_reconciliation",
nextAction: "Inspect the stopped execution.",
evidence: {
automaticRecovery: { policy: "preserve_without_replay_v1" },
explicitUserContinuation: { previousRunId, runId: nextRunId },
},
}, now)).toMatchObject(continued ? {
phase: "completed", label: "Continued in another run", successorRunId: "next",
cause: "native_continuation_requires_reconciliation", nextAction: null,
} : { phase: "recovery_needed", successorRunId: null });
expect(source.status).toBe("failed");
});
it("shows a reconciled continuation as queued until its durable delivery is recorded", () => {
const action = {
cause: "native_session_retry_exhausted",
nextAction: "Old recovery action",
status: "resolved" as const,
evidence: {
executionReconciliation: { runId: "old" },
continuationDelivery: "pending",
},
};
expect(
projectExecution(
run({ status: "failed" }),
coordinator({ phase: "terminal_failure" }),
[],
action,
now,
),
).toMatchObject({
phase: "queued",
label: "Continuation queued",
cause: null,
});
expect(
projectExecution(
run({ status: "failed" }),
coordinator({ phase: "terminal_failure" }),
[],
{
...action,
evidence: { ...action.evidence, continuationRunId: "next" },
},
now,
),
).toMatchObject({ phase: "completed", successorRunId: "next" });
expect(
projectExecution(
run({ status: "failed" }),
coordinator({ phase: "terminal_failure" }),
[],
{
...action,
evidence: { ...action.evidence, continuationDelivery: "invalidated" },
},
now,
),
).toMatchObject({ phase: "failed", label: "Continuation cancelled" });
});
it("requires current execution evidence, without treating output silence as failure", () => {
expect(project(run({ lastOutputAt: new Date(0) })).phase).toBe("working");
expect(
project(run(), coordinator({ leaseExpiresAt: new Date(0) })),
).toMatchObject({ phase: "reconnecting", label: "Confirming execution" });
expect(
project(
run({ runtimeMode: "legacy", processPid: process.pid }),
undefined,
).phase,
).toBe("working");
});
it("distinguishes provider work, finalization and timed retry", () => {
expect(
project(
run({ executionControlDeadlineAt: new Date(now.getTime() + 60_000) }),
).phase,
).toBe("finishing");
expect(
project(
run({ status: "failed" }),
coordinator({
phase: "retryable_failure",
nextAttemptAt: new Date(now.getTime() + 30_000),
attempt: 2,
}),
),
).toMatchObject({ phase: "retry_scheduled", attempt: 2, maxAttempts: 3 });
expect(
project(
run({ status: "failed" }),
coordinator({ phase: "retryable_failure", nextAttemptAt: new Date(0) }),
).phase,
).toBe("reconnecting");
});
it("includes the original legacy attempt in the displayed incident budget", () => {
expect(projectExecution(run({ runtimeMode: "legacy", status: "scheduled_retry", scheduledRetryAttempt: 1 }), undefined, [], undefined, now)).toMatchObject({ attempt: 2, maxAttempts: 3 });
});
it("keeps saved governed work in shutdown reconciliation without offering a new attempt", () => {
expect(project(
run({ status: "failed", errorCode: "native_governed_wait_settlement_pending" }),
coordinator({ phase: "retryable_failure", failureCode: "native_governed_wait_settlement_pending",
nextAttemptAt: new Date(now.getTime() + 30_000) }),
)).toMatchObject({ phase: "finishing", label: "Finishing shutdown", permittedActions: ["inspect_run"],
nextAction: "The work and waiting state are saved. Paperclip is confirming shutdown before continuing." });
});
it("shows pending interaction only after productive work has stopped", () => {
expect(
project(run(), coordinator(), [{ kind: "connection_intent" }]).phase,
).toBe("working");
expect(
project(run({ status: "succeeded" }), undefined, [
{ kind: "connection_intent" },
]).phase,
).toBe("waiting_for_access");
expect(
project(run({ status: "succeeded" }), undefined, [
{ kind: "ask_user_questions" },
]).phase,
).toBe("waiting_for_answer");
});
it("retains replacement lineage and exposes operator-owned failures for legacy runs", () => {
expect(
project(
run({ status: "failed" }),
coordinator({
phase: "terminal_failure",
failureDetail: { successorRunId: "replacement" },
}),
),
).toMatchObject({ phase: "completed", successorRunId: "replacement" });
expect(
projectExecution(
run({ runtimeMode: "legacy", status: "failed" }),
undefined,
[],
{
cause: "uncertain_external_action",
nextAction: "Reconcile the email delivery.",
},
now,
),
).toMatchObject({
phase: "recovery_needed",
recoveryOwner: "board",
nextAction: "Reconcile the email delivery.",
});
});
it("bounds recovery checking and surfaces its next action if verification never finishes", () => {
const c = coordinator({
phase: "terminal_failure",
failureCode: "native_provider_terminal_failed",
});
expect(project(run({ status: "failed", finishedAt: now }), c).label).toBe(
"Checking recovery",
);
expect(
project(
run({ status: "failed", finishedAt: new Date(now.getTime() - 60_000) }),
c,
).phase,
).toBe("recovery_needed");
expect(
project(
run({ status: "failed", finishedAt: now }),
coordinator({
...c,
failureDetail: { replacementDenied: "uncertain_provider_action" },
}),
).phase,
).toBe("recovery_needed");
});
});