Skip to content

fix(agents): resume interrupted turns without a recognized abort string - #114121

Merged
steipete merged 1 commit into
mainfrom
claude/session-resume-interruption-f57fd7
Jul 26, 2026
Merged

steipete merged 1 commit into
mainfrom
claude/session-resume-interruption-f57fd7

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

An ordinary gateway restart could leave a main session showing the terminal
notice instead of resuming:

I was interrupted by a gateway restart and couldn't safely resume the previous
turn. Please send that last request again and I'll pick it up cleanly.

Restart recovery classifies the transcript tail before resuming. An interrupted
turn is persisted as an assistant message with stopReason: "aborted", but
isRestartAbortAssistantMessage in
src/agents/main-session-restart-recovery-resume-policy.ts additionally required
errorMessage to be one of three exact strings:

  • Request was aborted
  • This operation was aborted
  • agent run aborted for restart

Production writes several other abort details on that same tail. The worker
inference adapter persists Worker inference aborted. and
Worker inference aborted before start.
(src/worker/inference-stream.runtime.ts:246, :262), and
terminalErrorMessage copies whatever cancel message the transport reported
(src/worker/inference-stream.runtime.ts:195). A tail carrying any of those fell
through every resume branch to transcript tail is not resumable, so the user
was asked to re-send a request the gateway could have continued on its own.

Why This Change Was Made

Every row that reaches recoverStore was mid-run when the process went down:
mark_interrupted is dispatched only from the restart/startup-orphan paths in
src/agents/main-session-restart-recovery-marking.ts, and the entry must still be
running with abortedLastRun === true. In that context stopReason: "aborted"
is the interruption, so matching on the abort string was a leaky proxy for a
fact the stop reason already carries.

isRestartAbortAssistantMessage now treats any aborted tail as the restart
abort and keeps the allowlist for stopReason: "error", where the error may be a
genuine provider failure rather than lifecycle noise.

The safety machinery downstream is unchanged and does the real work:

  • A dangling tool call in the aborted tail still goes through
    classifyDanglingToolCalls, so anything outside the audited replay-safe
    allowlist resumes with forceRestartSafeTools; the continuation can inspect
    and report, never silently re-execute an ambiguous side effect.
  • Partial streamed text stays in the transcript and the message beneath it
    decides resume safety.
  • Code Mode control calls keep their stricter replay-safe checkpoint gating.
  • Unknown before_agent_reply outcomes, unknown terminal delivery outcomes,
    stale approval-pending tails, missing message-tool authority, and empty
    transcripts all still fail closed with the notice.

User Impact

A gateway restart during a turn now resumes best-effort in the common case
instead of asking the user to send the request again. Side-effect safety is
unchanged: ambiguous tool calls resume restricted to restart-safe tools, and
genuinely unsafe tails still get the notice.

docs/gateway/restart-recovery.md describes the aborted-tail behavior and
narrows the "unsafe tail" example to a provider failure or stale approval.

Evidence

  • node scripts/run-vitest.mjs src/agents/main-session-restart-recovery.test.ts
    — 137 passed. Adds a table covering aborted tails persisted with no abort
    string, with a worker abort string, and with a dangling side-effecting call
    (asserting forceRestartSafeTools); removes the two aborted rows from the
    "does not resume" table that encoded the old behavior.
  • node scripts/run-vitest.mjs src/agents/main-session-recovery-state.test.ts src/agents/main-session-recovery-store.test.ts src/agents/agent-command-restart-recovery.test.ts src/agents/agent-command-recovery-owner.test.ts
    — 97 passed.
  • node scripts/run-vitest.mjs src/gateway/server.chat.gateway-server-chat-b.test.ts
    — 89 passed.
  • node scripts/check-changed.mjs — exit 0 (delegated to Blacksmith Testbox
    tbx_01kyfec215qvz6tvh7ce6hbyqw, 5m12s).
  • Autoreview (Codex gpt-5.6-sol, xhigh): clean, no accepted/actionable
    findings.

Three notice-delivery tests used an aborted tail purely as a convenient
"unresumable" fixture; they now use a shared unresumableAssistantMessage()
provider-failure shape so they keep proving notice mechanics rather than resume
classification.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling labels Jul 26, 2026
@steipete
steipete marked this pull request as ready for review July 26, 2026 14:55
@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Jul 26, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. labels Jul 26, 2026
@clawsweeper

clawsweeper Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 26, 2026, 10:59 AM ET / 14:59 UTC.

ClawSweeper review

What this changes

The PR changes gateway restart recovery so an assistant transcript tail marked aborted can resume regardless of its recorded abort-message text, while error tails still require an allowlisted restart-abort message.

Merge readiness

⛔ Blocked until real behavior proof from a real setup is added - 4 items remain

Keep this PR open for maintainer review: the patch is a focused repair to interrupted-session recovery and its targeted coverage is well aligned, but the supplied evidence is test/CI-only rather than direct after-fix restart evidence. The protected maintainer label also requires explicit maintainer handling rather than automated cleanup.

Priority: P2
Reviewed head: 1b2c200c7860bc06fa67b204f21a5607a8f8194a
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch is focused and safety-aware with strong targeted test intent, but direct runtime proof of the altered restart path is still required before merge.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: The PR provides focused tests, delegated checks, and CI results, but no redacted after-fix runtime trace showing a persisted non-allowlisted abort detail through an actual gateway restart and safe continuation. Add terminal output, logs, or a recording and redact private endpoints, identifiers, and credentials; updating the PR body should trigger a fresh review automatically, or a maintainer can request @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The PR provides focused tests, delegated checks, and CI results, but no redacted after-fix runtime trace showing a persisted non-allowlisted abort detail through an actual gateway restart and safe continuation. Add terminal output, logs, or a recording and redact private endpoints, identifiers, and credentials; updating the PR body should trigger a fresh review automatically, or a maintainer can request @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 4 items Changed recovery classification: The branch changes the restart-tail predicate so stopReason: "aborted" returns resumable without inspecting errorMessage; only stopReason: "error" retains the recognized restart-abort message allowlist.
Focused safety coverage: The PR adds cases for an aborted tail with no abort string, a worker abort string, and an aborted tail with a side-effecting dangling call that must set forceRestartSafeTools; it also moves notice-delivery fixtures to a provider-failure shape.
User-facing contract update: The documentation now distinguishes resumable aborted tails from genuinely unsafe provider-failure or stale-approval tails, matching the proposed classifier behavior.
Findings None None.
Security None None.

How this fits together

When a gateway restarts, main-session recovery examines a persisted interrupted transcript and either resumes the agent or posts a resend notice. The changed classifier determines that branch, while downstream logic restricts unresolved tool calls before continuation.

flowchart LR
  A[Gateway restart] --> B[Persisted interrupted session]
  B --> C[Transcript-tail classifier]
  C --> D{Safe to resume?}
  D -->|Yes| E[Recovery continuation]
  E --> F[Dangling-tool safeguards]
  D -->|No| G[Resend notice]
Loading

Decision needed

Question Recommendation
Should this protected maintainer-labeled restart-recovery change merge after direct runtime evidence confirms the persisted-abort invariant and tool restrictions? Request restart evidence: Ask for a redacted terminal/log or recording that shows an interrupted worker-abort tail, a gateway restart, successful continuation, and restricted handling of any dangling side-effecting tool call.

Why: The implementation changes persisted-session recovery semantics, and the available evidence is strong test coverage but not an observed after-fix gateway restart. The protected label requires explicit maintainer handling.

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The PR provides focused tests, delegated checks, and CI results, but no redacted after-fix runtime trace showing a persisted non-allowlisted abort detail through an actual gateway restart and safe continuation. Add terminal output, logs, or a recording and redact private endpoints, identifiers, and credentials; updating the PR body should trigger a fresh review automatically, or a maintainer can request @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve merge risk (P1) - The patch deliberately broadens which persisted interrupted turns resume. Before merge, a real restart trace should confirm that a worker/provider abort detail reaches recovery as described and that a dangling side-effecting call remains restricted rather than replayed.
  • Complete next step (P2) - A maintainer must review this protected restart-recovery semantic change after the contributor supplies direct runtime proof; there is no narrow automated repair to perform.
Agent review details

Security

None.

PR surface

Source +10, Tests +29, Docs +6. Total +45 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 12 2 +10
Tests 1 63 34 +29
Docs 1 10 4 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 85 40 +45

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep the narrow aborted-tail classifier change if a redacted real gateway-restart run confirms safe continuation and the existing dangling-tool restrictions; retain the fail-closed provider-error and stale-approval paths.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep the narrow aborted-tail classifier change if a redacted real gateway-restart run confirms safe continuation and the existing dangling-tool restrictions; retain the fail-closed provider-error and stale-approval paths.

Do we have a high-confidence way to reproduce the issue?

No independent high-confidence live reproduction is included. The source and focused tests provide a clear reproducible path: persist a running session with an aborted assistant tail using a non-allowlisted worker/provider abort detail, then restart recovery should resume it under existing tool safeguards.

Is this the best way to solve the issue?

Unclear pending direct restart evidence. Treating stopReason: "aborted" as the authoritative lifecycle fact appears narrower and more maintainable than matching transport strings, provided only restart-interrupted rows can reach this classifier as the PR states.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 2b7b0f244095.

Labels

Label changes:

  • add P2: The PR repairs a bounded but user-visible agent-session recovery flow; the reported impact is a resend notice after ordinary gateway restarts rather than a system-wide outage.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR provides focused tests, delegated checks, and CI results, but no redacted after-fix runtime trace showing a persisted non-allowlisted abort detail through an actual gateway restart and safe continuation. Add terminal output, logs, or a recording and redact private endpoints, identifiers, and credentials; updating the PR body should trigger a fresh review automatically, or a maintainer can request @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Label justifications:

  • P2: The PR repairs a bounded but user-visible agent-session recovery flow; the reported impact is a resend notice after ordinary gateway restarts rather than a system-wide outage.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR provides focused tests, delegated checks, and CI results, but no redacted after-fix runtime trace showing a persisted non-allowlisted abort detail through an actual gateway restart and safe continuation. Add terminal output, logs, or a recording and redact private endpoints, identifiers, and credentials; updating the PR body should trigger a fresh review automatically, or a maintainer can request @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

Likely related people:

  • steipete: Authored the current focused change and its recovery-safety test coverage; the available review context does not provide enough merged-history provenance to identify a stronger long-term owner. (role: recent area contributor; confidence: low; commits: 1b2c200c7860; files: src/agents/main-session-restart-recovery-resume-policy.ts, src/agents/main-session-restart-recovery.test.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Add a redacted real restart trace showing a persisted worker/provider abort detail resumes after gateway restart.
  • Include or show a dangling side-effecting tool-call case remaining restricted to restart-safe tools in that runtime evidence.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete

Copy link
Copy Markdown
Contributor Author

Addressing the two rank-up moves before landing.

Which shipped surfaces actually persist a non-allowlisted abort detail

The strongest checkable answer to "does this matter at runtime?" is naming the
code that writes those tails, so the claim can be verified without trusting a
trace:

  • partial.errorMessage = "Worker inference aborted." —
    src/worker/inference-stream.runtime.ts:248,
    written alongside partial.stopReason = "aborted" at :247.
  • "Worker inference aborted before start." — same file, :264 with
    stopReason = "aborted" at :263.
  • "Worker inference result exceeds the transcript message limit." — :212,
    which explicitly preserves stopReason: "aborted" at :211.
  • terminalErrorMessage copies whatever cancel message the transport reported
    into errorMessage while setting stopReason: "aborted" —
    :195.

That adapter is production-wired through
src/worker/worker.runtime.ts:107,
so any worker-environment deployment restarted mid-turn persists a tail that the
old three-string allowlist rejected. The default in-process path aborts with
createAgentRunRestartAbortError() (agent run aborted for restart), which was
already allowlisted — so this fix is scoped to worker-environment and
oversized-message aborts rather than to every restart, and I'd rather state that
narrowly than overclaim it.

Why the runtime trace is a follow-up, not part of this PR

The existing restart scenarios
(qa/scenarios/runtime/gateway-restart-inflight-run.yaml,
gateway-restart-multi-live.yaml) drive the Code Mode wait checkpoint branch
of resolveMainSessionResumePolicy, which this change does not touch — they
would pass identically before and after, so running them proves absence of
regression, not the new path.

Producing the trace you're asking for needs a new QA scenario that restarts a
worker-environment turn at the moment the worker persists its own abort string,
plus a second one holding a dangling side-effecting call. That is a real
scenario-authoring task against live QA infrastructure, and it is a larger piece
of work than the 12-line predicate change it would be attached to. I'm treating
it as a follow-up rather than growing this PR's scope.

What is proven here in the meantime: the three aborted-tail shapes (no abort
string, worker abort string, dangling side-effecting call) are covered by the
added table in src/agents/main-session-restart-recovery.test.ts, and the
dangling-call case asserts forceRestartSafeTools: true — the restriction runs
through the unchanged classifyDanglingToolCalls allowlist, so the safety
contract this PR relies on is the one already shipped and tested.

@steipete
steipete merged commit 01f8bd9 into main Jul 26, 2026
230 of 238 checks passed
@steipete
steipete deleted the claude/session-resume-interruption-f57fd7 branch July 26, 2026 15:10
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant