Skip to content

fix(gateway): resume interrupted turns after restarts instead of asking users to re-send - #112562

Merged
steipete merged 1 commit into
mainfrom
claude/gateway-restart-interruption-8193b0
Jul 22, 2026
Merged

steipete merged 1 commit into
mainfrom
claude/gateway-restart-interruption-8193b0

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Every gateway restart — dev-watch rebuilds, auto-updates, openclaw gateway restart — that caught a main session mid-turn ended with the canned channel message:

"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."

The Discord #maintainers archive shows this notice fired on Jul 11, 12, 15 (three times), and 16, and a maintainer asked the obvious question: if the agent can send that message, why can't it just resume?

Restart recovery (resolveMainSessionResumePolicy) already resumes cleanly when the transcript tail is a user turn, tool result, or an empty provider abort artifact. But the two most common real interruption shapes failed to "transcript tail is not resumable" and produced the notice:

  1. Partial streamed output — when the provider surfaces the restart abort as an error stream event, the aborted assistant message persists with its accumulated partial blocks (packages/agent-core/src/agent-loop.ts "done"/"error" path). The empty-content-only artifact check rejected it.
  2. A tool call interrupted mid-execution — the assistant toolUse message persisted, the tool result never did. This tail only resumed when the turn was already a restart-safe recovery turn.

There was also a latent recognition gap: the gateway's own restart abort reason ("agent run aborted for restart" from createAgentRunRestartAbortError) was not in the accepted abort-artifact strings, so even an empty abort tail could miss the strip depending on which abort path won.

Why This Change Was Made

The notice demanded a manual re-send, and that manual re-send runs the same continuation on the same transcript with the same missing information — the human adds no safety, only latency. The recovery machinery for a safe automatic version already exists (recovery continuation prompt, dangling tool-call stripping before the provider payload, restart-safe tool catalog restriction, delivery receipts); the policy just never used it for these shapes.

Changes in src/agents/main-session-restart-recovery.ts:

  • Restart abort tails are recognized by stop reason + the three known abort messages (now including "agent run aborted for restart"), regardless of partial content. A tail without tool calls is stripped as lifecycle noise (partial text stays in the transcript for the continuation) and the message beneath decides resume safety, exactly as before.
  • Dangling tool calls — whether in an aborted tail or a pending toolUse tail — are classified against the audited replay-safe allowlist (tool-replay-safety.ts): all-replay-safe calls resume with full tools; anything side-effecting resumes under forceRestartSafeTools, so the recovery turn can inspect state and reply contextually but can never silently re-execute an ambiguous side effect. Code Mode control calls are excluded and keep their stricter replay-safe checkpoint gating.

Fail-closed behavior is unchanged for: unknown terminal delivery receipts (terminal-pending), before_agent_reply hook states, non-replay-safe Code Mode waits, stale approval-pending tails, completed-but-undelivered assistant output, and hook-safety dispatch gates. Truly unrecoverable sessions still get the notice.

User Impact

Sessions interrupted by a gateway restart mid-answer or mid-tool-call now continue automatically instead of dead-ending with "please send that last request again". For interrupted side-effecting tools the agent replies with what it can verify instead of a canned notice, and asks before re-running anything ambiguous.

Evidence

  • Focused suite: node scripts/run-vitest.mjs src/agents/main-session-restart-recovery.test.ts → 132 passed (new coverage: partial streamed answer resumes; restart-reason abort artifact resumes; side-effecting dangling call resumes restricted, in both aborted and pending-toolUse tails; replay-safe dangling call resumes unrestricted; existing fail-closed suites unchanged).
  • Sibling suites: main-session-recovery-state.test.ts, main-session-recovery-store.test.ts → 25 passed.
  • pnpm check:changed (delegated Testbox) green: https://github.com/openclaw/openclaw/actions/runs/29896926646
  • oxfmt/oxlint clean on touched files.
  • Codex autoreview (gpt-5.6-sol, xhigh): two P1 findings raised and fixed across iterations (side-effect replay hazard → restart-safe restriction; aborted tails carrying tool calls → same classification), final pass clean: "patch is correct".

…ng users to re-send

Gateway restarts (rebuilds, auto-updates) frequently killed main sessions
mid-turn and recovery gave up with the user-facing "couldn't safely resume"
notice for the two most common interruption shapes:

- partial streamed assistant output persisted by a provider abort event
- a tool call interrupted mid-execution (no result persisted)

Both now resume through the existing recovery continuation. Dangling tool
calls are classified against the audited replay-safe allowlist: replay-safe
calls resume with full tools, side-effecting calls keep the restart-safe
tool restriction so an ambiguous side effect is never silently re-executed.
The gateway's own restart abort reason ("agent run aborted for restart")
is now also recognized as a restart abort artifact.

Fail-closed behavior is unchanged for unknown terminal delivery receipts,
before_agent_reply hook states, non-replay-safe Code Mode waits, stale
approval-pending tails, and completed-but-undelivered output.
@steipete
steipete marked this pull request as ready for review July 22, 2026 06:45
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Jul 22, 2026
@clawsweeper

clawsweeper Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: fix(gateway): resume interrupted turns after restarts instead of asking users to re-send This is item 1/1 in the current shard. Shard 0/1.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

@steipete
steipete merged commit 6402e53 into main Jul 22, 2026
195 of 203 checks passed
@steipete
steipete deleted the claude/gateway-restart-interruption-8193b0 branch July 22, 2026 07:46
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 23, 2026
…ng users to re-send (openclaw#112562)

Gateway restarts (rebuilds, auto-updates) frequently killed main sessions
mid-turn and recovery gave up with the user-facing "couldn't safely resume"
notice for the two most common interruption shapes:

- partial streamed assistant output persisted by a provider abort event
- a tool call interrupted mid-execution (no result persisted)

Both now resume through the existing recovery continuation. Dangling tool
calls are classified against the audited replay-safe allowlist: replay-safe
calls resume with full tools, side-effecting calls keep the restart-safe
tool restriction so an ambiguous side effect is never silently re-executed.
The gateway's own restart abort reason ("agent run aborted for restart")
is now also recognized as a restart abort artifact.

Fail-closed behavior is unchanged for unknown terminal delivery receipts,
before_agent_reply hook states, non-replay-safe Code Mode waits, stale
approval-pending tails, and completed-but-undelivered output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant