Repository navigation
fix(gateway): resume interrupted turns after restarts instead of asking users to re-send - #112562
Merged
Merged
Conversation
…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
marked this pull request as ready for review
July 22, 2026 06:45
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. |
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:The Discord
#maintainersarchive 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:errorstream 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.toolUsemessage 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"fromcreateAgentRunRestartAbortError) 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:"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.toolUsetail — are classified against the audited replay-safe allowlist (tool-replay-safety.ts): all-replay-safe calls resume with full tools; anything side-effecting resumes underforceRestartSafeTools, 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_replyhook 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
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).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