Repository navigation
fix(agents): preserve subagent work across gateway restarts - #169144
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR preserves interrupted subagent history and parent continuation while preventing cancelled work from restarting. Example: A child spawned with expectsCompletionMessage=false and cleanup="delete" is interrupted after its parent finishes.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Both prior findings are resolved, and no actionable defect remains in the reviewed patch; exact-head CI is still running. Priority: P1 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherGateway shutdown captures session admissions, startup reconciles persisted subagent runs, and requester settlement delivers unfinished work to the current parent owner. flowchart TD
A[Gateway restart] --> B[Session admission capture]
B --> C[Durable recovery markers]
C --> D[Subagent reconciliation]
D --> E[Requester settlement]
E --> F[Original parent continuation]
G[Cancellation or reset] --> B
G --> E
Technical reviewBest possible solution: Preserve parent-owned recovery and pending delivery custody through the existing admission and requester-settlement owners. Do we have a high-confidence way to reproduce the issue? The base source loses structured retryable wait refusals and excludes quiet children from required settlement; the supplied process comparison reports the original scenario failing before repair. Is this the best way to solve the issue? The repair addresses error classification, retained history, continuation ownership, and cancellation at their existing owners without adding a competing replay mechanism. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 8524e7f1cbe2. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +84, Tests +826, Docs +11. Total +921 across 20 files. Added test files: 2. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (5 earlier review cycles)
Reviewed October 11, 2026, 4:32 PM ET / 20:32 UTC (Revision 6). |
9050625 to
9f31eb4
Compare
Carry live terminal and abort facts through session admission handoffs so retained cleanup cannot restart cancelled work. Extend real Gateway recovery proof to cover reset, cancellation before provider dispatch, and repeated restarts.
|
@clawsweeper re-review The prior revocation-proof gap is covered on head
The proof caught and fixed an actual cancellation/restart bug: a terminal cleanup admission could otherwise re-arm the stopped parent. The admission owner now carries the current consumer's terminal and first-abort facts through handoff, with live revalidation at the restart mark. Typed restart interruptions still recover. Hetzner Crabbox |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review Fixed the missing channel reply caller in The previously failing |
|
🦞👀 Re-review progress:
|
Keep completed executions with an outstanding delivery admission eligible for restart recovery. Only settled explicit user cancellation revokes that custody; timeout and restart interruption retain it until release. Preserve the regression coverage for cancellation after recovery planning and adopted admissions, including timeout and pending final delivery.
|
@clawsweeper re-review The pending-final-delivery finding is fixed at the admission owner. A finished execution that still owns final delivery remains restart-recoverable; only settled explicit cancellation ends that custody. Timeout and restart interruption retain recovery, and the live check immediately before marking still rejects released, cancelled, or replaced owners. Hetzner Crabbox The separate ACP lifecycle-start assertion passed on both candidate and unchanged CI main parent |
|
🦞👀 Re-review progress:
|
…#169144) * fix(agents): preserve subagent work across gateway restarts * fix(sessions): preserve cancellation across gateway restarts Carry live terminal and abort facts through session admission handoffs so retained cleanup cannot restart cancelled work. Extend real Gateway recovery proof to cover reset, cancellation before provider dispatch, and repeated restarts. * fix(gateway): retain channel reply restart ownership * fix(sessions): retain restart custody until final delivery Keep completed executions with an outstanding delivery admission eligible for restart recovery. Only settled explicit user cancellation revokes that custody; timeout and restart interruption retain it until release. Preserve the regression coverage for cancellation after recovery planning and adopted admissions, including timeout and pending final delivery.
… (2026.10.5 backport) Restart drain cancels passive agent.wait observations; the wait helper dropped the structured retryable UNAVAILABLE refusal, so the registry invented a child failure and began deletion before recording the restart interruption. Quiet interrupted children are now handed privately back to their original parent, keep their history, and cancelled turns' cleanup leases no longer make them restart-recovery candidates. Backport adaptation (conflicts only, no behavior dropped): - src/agents/run-wait.ts: the branch inlined error normalization in waitForAgentRun via isRecoverableAgentWaitError; replaced it with main's normalizeAgentWaitError(cause), which also honors typed UNAVAILABLE. - src/sessions/session-lifecycle-admission.ts: kept the branch's isSessionWorkAdmissionActive export and its lifecycleGeneration fences on captured owners; isRestartRecoverableAdmission replaces only the bare phase === "acquired" checks in those two restart-capture sites. - session-lifecycle-admission.pending.test.ts: took only the new restart-capture regression; dropped two neighboring main-only tests for captureSessionWorkRunInterruptions, which the branch does not have. Extracted-from: 187a884 Co-authored-by: Peter Steinberger <[email protected]>
The native subagent restart live proof SIGKILLs the Gateway three times in about two minutes. The third unclean boot trips the documented restart-loop breaker (3 unclean boots within 5 minutes, #166238), which pauses restart settlement, including interrupted subagent recovery (#166846), until the unclean window drains. The orphan assertion added with the #169144 backport only waited 30 seconds, so the nonannouncing child was still `running`. Wait up to 360 seconds for the orphan settlement so the proof covers the breaker pause and the automatic resume after its window. Assertions are unchanged. 2026.10.4 passed because it predates the breaker pause, startup subagent reconciliation, and this assertion. Deterministic proof: the quiet-child e2e twin with SIGKILL restarts and an exec-blocked child passes with one prior kill; with two warm-up kills it logs "restart-loop breaker tripped" and the parent continuation never arrives within 60 seconds; with a 400-second wait it settles and passes (338s).
…sters (#175278) The #169144 backport converts a non-announcing child interrupted by a Gateway restart into a private parent continuation only when the captured requester has both a session id and a lifecycle revision. Sessions created implicitly by the `agent` RPC (and other paths that never patch a new session) carry no lifecycle revision, so the orphan settled terminal with no completionTarget or requester settle wake and the parent never received the "Reconcile every listed unfinished child" turn. Every downstream requester identity check already compares the captured revision by equality (absent matches absent, and a reset assigns a new revision), and private spawn only requires a requester session id. Apply the same requirement here. The native live subagent restart proof starts its parents through `agent`, which is why its parent-handoff assertion timed out; the crash-loop breaker only delayed settlement. A quiet-child e2e twin started via `agent` failed with and without the breaker before this change and receives the parent reconcile turn within a second of settlement after it.
…sters (#175278) The #169144 backport converts a non-announcing child interrupted by a Gateway restart into a private parent continuation only when the captured requester has both a session id and a lifecycle revision. Sessions created implicitly by the `agent` RPC (and other paths that never patch a new session) carry no lifecycle revision, so the orphan settled terminal with no completionTarget or requester settle wake and the parent never received the "Reconcile every listed unfinished child" turn. Every downstream requester identity check already compares the captured revision by equality (absent matches absent, and a reset assigns a new revision), and private spawn only requires a requester session id. Apply the same requirement here. The native live subagent restart proof starts its parents through `agent`, which is why its parent-handoff assertion timed out; the crash-loop breaker only delayed settlement. A quiet-child e2e twin started via `agent` failed with and without the breaker before this change and receives the parent reconcile turn within a second of settlement after it. (cherry picked from commit 8d4591a)
…sters (openclaw#175278) The openclaw#169144 backport converts a non-announcing child interrupted by a Gateway restart into a private parent continuation only when the captured requester has both a session id and a lifecycle revision. Sessions created implicitly by the `agent` RPC (and other paths that never patch a new session) carry no lifecycle revision, so the orphan settled terminal with no completionTarget or requester settle wake and the parent never received the "Reconcile every listed unfinished child" turn. Every downstream requester identity check already compares the captured revision by equality (absent matches absent, and a reset assigns a new revision), and private spawn only requires a requester session id. Apply the same requirement here. The native live subagent restart proof starts its parents through `agent`, which is why its parent-handoff assertion timed out; the crash-loop breaker only delayed settlement. A quiet-child e2e twin started via `agent` failed with and without the breaker before this change and receives the parent reconcile turn within a second of settlement after it.
…#169144) * fix(agents): preserve subagent work across gateway restarts * fix(sessions): preserve cancellation across gateway restarts Carry live terminal and abort facts through session admission handoffs so retained cleanup cannot restart cancelled work. Extend real Gateway recovery proof to cover reset, cancellation before provider dispatch, and repeated restarts. * fix(gateway): retain channel reply restart ownership * fix(sessions): retain restart custody until final delivery Keep completed executions with an outstanding delivery admission eligible for restart recovery. Only settled explicit user cancellation revokes that custody; timeout and restart interruption retain it until release. Preserve the regression coverage for cancellation after recovery planning and adopted admissions, including timeout and pending final delivery. (cherry picked from commit 187a884)
First-parent upstream e63e209..0b0c2f2 (93 commits, including openclaw#169144 subagent work across gateway restarts, openclaw#169251 worker write transaction overhead, openclaw#169306 question-answer custody, openclaw#169305 fallback ordering, openclaw#169339 owner-state rechecks, openclaw#169235/openclaw#168887 Solid UI ports). Stops before openclaw#169315 (fp#248, agent schema), which is step 59 on its own. Conflicts: - embedded-agent-runner/run/payloads.ts: upstream gates the assistant-texts branch on !assistantForPayload (an empty canonical terminal stays authoritative); kept our per-hop raw-answer split for earlier continuation signals ahead of it. - session-reset-cleanup.test.ts: upstream's retainEmbeddedSessionPromptState disposable; kept our async clearSessionResetRuntimeState call. - plugin-sdk-surface-report.mts: upstream 3674/2135, ours +11/+4. - config-baseline counts/sha256 and worker-access inventory regenerated on the merged tree (core +17 fork config entries, as before). Auto-merged files that carry continuation overlay (19, incl. attempt-execution, agent-runner-fallback-candidate, session.ts, status-message, stream/update handlers) keep the overlay byte-for-byte. Refs #1475 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The native subagent restart live proof SIGKILLs the Gateway three times in about two minutes. The third unclean boot trips the documented restart-loop breaker (3 unclean boots within 5 minutes, #166238), which pauses restart settlement, including interrupted subagent recovery (#166846), until the unclean window drains. The orphan assertion added with the #169144 backport only waited 30 seconds, so the nonannouncing child was still `running`. Wait up to 360 seconds for the orphan settlement so the proof covers the breaker pause and the automatic resume after its window. Assertions are unchanged. 2026.10.4 passed because it predates the breaker pause, startup subagent reconciliation, and this assertion. Deterministic proof: the quiet-child e2e twin with SIGKILL restarts and an exec-blocked child passes with one prior kill; with two warm-up kills it logs "restart-loop breaker tripped" and the parent continuation never arrives within 60 seconds; with a 400-second wait it settles and passes (338s). (cherry picked from commit 1a4c2a0)
…7319) * fix(test): treat the env-gated Agents API live proof as optional shard evidence test/gateway-agentsapi.live.test.ts (new since 2026.10.4) skips its only case unless OPENCLAW_LIVE_AGENTS_API=1, which the native live test-harness shard never sets, so the shard's no-passing-assertions guard failed it on every 2026.10.5 candidate once the other harness tests went green. Register it in the existing whole-file opt-in map like the other env-gated live proofs. (cherry picked from commit 761ef64) * fix(test): decode the Codex CLI JSON error after plugin uninstall The live Codex npm plugin lane matched the expected post-uninstall error against raw --json stdout, where quotes are escaped, so the correct owner-plugin-not-activatable error never matched. Decode the canonical CLI error message first, as the 2026.10.4 release line does (a9fd56d). (cherry picked from commit e8772a9) * fix(test): scope CLI announcement barrier to parent probe (cherry picked from commit d5c0db7) (cherry picked from commit a48d4a8) * test(live): wait out the crash-loop breaker before the orphan settles The native subagent restart live proof SIGKILLs the Gateway three times in about two minutes. The third unclean boot trips the documented restart-loop breaker (3 unclean boots within 5 minutes, #166238), which pauses restart settlement, including interrupted subagent recovery (#166846), until the unclean window drains. The orphan assertion added with the #169144 backport only waited 30 seconds, so the nonannouncing child was still `running`. Wait up to 360 seconds for the orphan settlement so the proof covers the breaker pause and the automatic resume after its window. Assertions are unchanged. 2026.10.4 passed because it predates the breaker pause, startup subagent reconciliation, and this assertion. Deterministic proof: the quiet-child e2e twin with SIGKILL restarts and an exec-blocked child passes with one prior kill; with two warm-up kills it logs "restart-loop breaker tripped" and the parent continuation never arrives within 60 seconds; with a 400-second wait it settles and passes (338s). (cherry picked from commit 1a4c2a0) * test(qa-lab): skip user-role runtime carriers in visible-child send proof The sessions_send visible-child proof timed out on every 2026.10.5 candidate: its synthetic provider picked the latest user item that lacked the legacy <<<BEGIN_OPENCLAW_INTERNAL_CONTEXT>>> marker as the user prompt. Since #168546 (backport 8d66b94), OpenAI-compatible Responses endpoints, including mock-openai, keep runtime context in a user-role "OpenClaw runtime context:" carrier after the user turn instead of a developer message. The fixture then read that carrier as the prompt, never saw the "send" prompt on turn 2, answered PARENT_READY again, and the test waited for PARENT_DONE until timeout. Captured provider requests: v2026.10.4 sends the turn-2 carrier with role developer; the 10.5 tip sends it with role user. Reverting a293f2e (#168410) left the failure unchanged. Select the prompt with the shared qa-lab isInternalRuntimeContextCarrierText helper, which already accepts current and legacy carrier shapes. (cherry picked from commit d3a06e7) * test(buzz): skip real reconnect backoff in cold-start recovery (cherry picked from commit fa2049a) * fix(release): let the Telegram release lane finish its 25 scenarios The isolated Telegram candidate job hit its 60-minute limit at scenario 24/25 on every 2026.10.5 candidate (about 62 minutes needed at 102-108s per packaged Gateway start). main carries the same Telegram scenario set and job, so raise the job budget to 90 minutes; the calling release-checks job keeps its 210-minute bound. Also carry the 2026.10.4 release-line fixture fix for telegram-prepared-delivery-recovery (8b78670): keep the audit receipt in the shared Gateway workspace and create it up front so the isolated SUT can append without EACCES. main still writes it under the private tempRoot. (cherry picked from commit 3cb49f0, adapted to main's runner anchor) * test(gateway): probe startup readiness on fresh connections The deferred-fleet startup test failed twice in 2026.10.5 FRV #12 with `fetch failed` / `read ECONNRESET`. Its Gateway shares the test process's event loop. A /healthz or /readyz probe could reuse a keep-alive socket that Undici still treated as live; when the request was written and a synchronous main-thread startup stall followed, the server's idle-timer callback ran before the poll phase read the request and destroyed the socket with the request unread, so the kernel reset the connection. main still probes with default keep-alive fetches. Probe with `Connection: close`, matching existing Gateway test probes. Assertions are unchanged. (cherry picked from commit e3c63f2, adapted to main's probe sites) * test(live): expect review effort for Skill Workshop background reviews in the Ultra lane Since #161057 the Skill Workshop counts iterations per session, so Ultra probe sessions trigger a background review after idling. The review runs under its own skill-workshop-review: run and does not inherit the session's thinking level, so the lane's every-request-is-max assertion failed on 2026.10.5 whenever a review reached the provider. On main, #173889 pins review runs to thinkLevel "low" (review-run.ts), which the OpenAI stream wrapper sends as effort "low". Expect that effort for review runs; Ultra runs and their sessions must still be max, and independent heartbeats stay medium. The live file is over the line cap, so the Ultra wire effort policy moves to a sibling helper with its observation type, and the deterministic review cases run in the normal helper suite. (cherry picked from commit ca15213, adapted to main's review thinking level) * test(release): forward-port 2026.10.4-line upgrade-survivor and runtime-smoke harness fixes Release-line harness fixes that 2026.10.1-2026.10.5 carried but main never received: - cron-scheduled-authority: seed the cron authority specimen through the published baseline's own SQLite writer (seedPublishedCronJobs) instead of a raw cron/jobs.json that current candidates treat as a retired pre-July store; drop owner fields for pre-2026.7.1 baselines (usesCronOwnerAtBaseline). The dispatcher passes the package root to seedState, and the scenario now requires a published baseline. - bundled plugin runtime smoke: join deferred read-only update discovery via update.status before the package-manager child watchdog. main still defers install discovery (`<manager> root -g`) until after ready, so it can race the watchdog's no-package-manager-children check. Skips the codex npm plugin live source-reply grep from the release commit: main already probes dynamic-tool-source-reply.ts and dynamic-tools.ts. (cherry picked from commit fcdf0d1, codex grep hunk dropped; cron seed test adapted to main's executable-mode fixture writes)
…nclaw#177319) * fix(test): treat the env-gated Agents API live proof as optional shard evidence test/gateway-agentsapi.live.test.ts (new since 2026.10.4) skips its only case unless OPENCLAW_LIVE_AGENTS_API=1, which the native live test-harness shard never sets, so the shard's no-passing-assertions guard failed it on every 2026.10.5 candidate once the other harness tests went green. Register it in the existing whole-file opt-in map like the other env-gated live proofs. (cherry picked from commit 761ef64) * fix(test): decode the Codex CLI JSON error after plugin uninstall The live Codex npm plugin lane matched the expected post-uninstall error against raw --json stdout, where quotes are escaped, so the correct owner-plugin-not-activatable error never matched. Decode the canonical CLI error message first, as the 2026.10.4 release line does (a9fd56d). (cherry picked from commit e8772a9) * fix(test): scope CLI announcement barrier to parent probe (cherry picked from commit d5c0db7) (cherry picked from commit a48d4a8) * test(live): wait out the crash-loop breaker before the orphan settles The native subagent restart live proof SIGKILLs the Gateway three times in about two minutes. The third unclean boot trips the documented restart-loop breaker (3 unclean boots within 5 minutes, openclaw#166238), which pauses restart settlement, including interrupted subagent recovery (openclaw#166846), until the unclean window drains. The orphan assertion added with the openclaw#169144 backport only waited 30 seconds, so the nonannouncing child was still `running`. Wait up to 360 seconds for the orphan settlement so the proof covers the breaker pause and the automatic resume after its window. Assertions are unchanged. 2026.10.4 passed because it predates the breaker pause, startup subagent reconciliation, and this assertion. Deterministic proof: the quiet-child e2e twin with SIGKILL restarts and an exec-blocked child passes with one prior kill; with two warm-up kills it logs "restart-loop breaker tripped" and the parent continuation never arrives within 60 seconds; with a 400-second wait it settles and passes (338s). (cherry picked from commit 1a4c2a0) * test(qa-lab): skip user-role runtime carriers in visible-child send proof The sessions_send visible-child proof timed out on every 2026.10.5 candidate: its synthetic provider picked the latest user item that lacked the legacy <<<BEGIN_OPENCLAW_INTERNAL_CONTEXT>>> marker as the user prompt. Since openclaw#168546 (backport 8d66b94), OpenAI-compatible Responses endpoints, including mock-openai, keep runtime context in a user-role "OpenClaw runtime context:" carrier after the user turn instead of a developer message. The fixture then read that carrier as the prompt, never saw the "send" prompt on turn 2, answered PARENT_READY again, and the test waited for PARENT_DONE until timeout. Captured provider requests: v2026.10.4 sends the turn-2 carrier with role developer; the 10.5 tip sends it with role user. Reverting a293f2e (openclaw#168410) left the failure unchanged. Select the prompt with the shared qa-lab isInternalRuntimeContextCarrierText helper, which already accepts current and legacy carrier shapes. (cherry picked from commit d3a06e7) * test(buzz): skip real reconnect backoff in cold-start recovery (cherry picked from commit fa2049a) * fix(release): let the Telegram release lane finish its 25 scenarios The isolated Telegram candidate job hit its 60-minute limit at scenario 24/25 on every 2026.10.5 candidate (about 62 minutes needed at 102-108s per packaged Gateway start). main carries the same Telegram scenario set and job, so raise the job budget to 90 minutes; the calling release-checks job keeps its 210-minute bound. Also carry the 2026.10.4 release-line fixture fix for telegram-prepared-delivery-recovery (8b78670): keep the audit receipt in the shared Gateway workspace and create it up front so the isolated SUT can append without EACCES. main still writes it under the private tempRoot. (cherry picked from commit 3cb49f0, adapted to main's runner anchor) * test(gateway): probe startup readiness on fresh connections The deferred-fleet startup test failed twice in 2026.10.5 FRV openclaw#12 with `fetch failed` / `read ECONNRESET`. Its Gateway shares the test process's event loop. A /healthz or /readyz probe could reuse a keep-alive socket that Undici still treated as live; when the request was written and a synchronous main-thread startup stall followed, the server's idle-timer callback ran before the poll phase read the request and destroyed the socket with the request unread, so the kernel reset the connection. main still probes with default keep-alive fetches. Probe with `Connection: close`, matching existing Gateway test probes. Assertions are unchanged. (cherry picked from commit e3c63f2, adapted to main's probe sites) * test(live): expect review effort for Skill Workshop background reviews in the Ultra lane Since openclaw#161057 the Skill Workshop counts iterations per session, so Ultra probe sessions trigger a background review after idling. The review runs under its own skill-workshop-review: run and does not inherit the session's thinking level, so the lane's every-request-is-max assertion failed on 2026.10.5 whenever a review reached the provider. On main, openclaw#173889 pins review runs to thinkLevel "low" (review-run.ts), which the OpenAI stream wrapper sends as effort "low". Expect that effort for review runs; Ultra runs and their sessions must still be max, and independent heartbeats stay medium. The live file is over the line cap, so the Ultra wire effort policy moves to a sibling helper with its observation type, and the deterministic review cases run in the normal helper suite. (cherry picked from commit ca15213, adapted to main's review thinking level) * test(release): forward-port 2026.10.4-line upgrade-survivor and runtime-smoke harness fixes Release-line harness fixes that 2026.10.1-2026.10.5 carried but main never received: - cron-scheduled-authority: seed the cron authority specimen through the published baseline's own SQLite writer (seedPublishedCronJobs) instead of a raw cron/jobs.json that current candidates treat as a retired pre-July store; drop owner fields for pre-2026.7.1 baselines (usesCronOwnerAtBaseline). The dispatcher passes the package root to seedState, and the scenario now requires a published baseline. - bundled plugin runtime smoke: join deferred read-only update discovery via update.status before the package-manager child watchdog. main still defers install discovery (`<manager> root -g`) until after ready, so it can race the watchdog's no-package-manager-children check. Skips the codex npm plugin live source-reply grep from the release commit: main already probes dynamic-tool-source-reply.ts and dynamic-tools.ts. (cherry picked from commit fcdf0d1, codex grep hunk dropped; cron seed test adapted to main's executable-mode fixture writes)
…sters (#175278) The #169144 backport converts a non-announcing child interrupted by a Gateway restart into a private parent continuation only when the captured requester has both a session id and a lifecycle revision. Sessions created implicitly by the `agent` RPC (and other paths that never patch a new session) carry no lifecycle revision, so the orphan settled terminal with no completionTarget or requester settle wake and the parent never received the "Reconcile every listed unfinished child" turn. Every downstream requester identity check already compares the captured revision by equality (absent matches absent, and a reset assigns a new revision), and private spawn only requires a requester session id. Apply the same requirement here. The native live subagent restart proof starts its parents through `agent`, which is why its parent-handoff assertion timed out; the crash-loop breaker only delayed settlement. A quiet-child e2e twin started via `agent` failed with and without the breaker before this change and receives the parent reconcile turn within a second of settlement after it. (cherry picked from commit 8d4591a)
What Problem This Solves
Fixes native subagent work being stranded when a Gateway restart interrupts a turn, including quiet children whose parent has already finished.
User Impact
Interrupted children retain their history and privately hand unfinished work back to their original parent once. Successful quiet children remain quiet. The parent reconciles saved history and uncertain tool effects before continuing; recovery does not blindly replay child commands.
Cancellation and reset still revoke the continuation. A cancelled turn's remaining cleanup lease cannot make the next Gateway restart resume it again. No schema change, new user setting, or operator migration is required. Ambiguous historical failures are not reclassified from their error text.
Why This Change Was Made
Restart drain cancels passive
agent.waitobservations. The shared wait helper discarded the structured retryable refusal, and a retiring lifecycle owner could replace it with an untyped error. The registry then invented a child failure and began deletion before recording the genuine restart interruption. Preserve explicit retryableUNAVAILABLEerrors at these boundaries; actual terminal errors remain terminal.The existing requester-settle owner now carries quiet interrupted children privately, with the captured parent identity, durable batch receipt, and current-owner checks. Nested parent recovery recognizes that custody. Interrupted children keep the history needed for reconciliation even when normal completion would delete it.
The real cancellation regression also exposed a shutdown ownership bug: acquired cleanup admissions were treated as unfinished work after their run had been cancelled. Restart capture now consults the execution owner's existing terminal and abort facts, including after handoff and immediately before marking. It excludes settled explicit cancellation while retaining successful or timed-out executions whose final delivery is still pending, as well as typed restart interruptions.
Production LOC: +84. The growth implements missing continuation and cancellation contracts using existing owners; it adds no dispatcher, retry store, cache, schema, or configuration surface.
Evidence
cbx_f500a39cd475: 397 focused/sibling tests passed (83.29 seconds wrapper time); export collision guard passed; 143 closure/test-plan guards passed (109.02 seconds).cbx_88437d85909a, Node 24.19.0 / pnpm 12.9.0: final owner/startup/restart suites 223 passed, 324.17 seconds wrapper time.node scripts/run-vitest.mjsran the session admission suites and main-session startup, restart, and marking suites.node scripts/run-vitest.mjs --config test/vitest/vitest.e2e.config.ts test/gateway-subagent-restart.e2e.test.ts: 3 passed, 134.000 seconds of test execution. Each case uses realsessions_spawn, a managed restart intent plus SIGTERM, and another restart after continuation settlement. The synthetic provider counts final serialized requests.The same cancellation flow failed before the cleanup-ownership fix: the next shutdown marked an already cancelled parent as interrupted and startup issued its original prompt again.
node scripts/check-changed.mjs --base HEAD^: all preliminary guards, production types, core-test types, and root tooling types passed. It stopped on the unchanged Windows fixture calling removedstopGatewayProcess; current main fixes that in 2695b46dd136. The remaining root E2E/other type partitions passed when run directly through the same native shard owner.Final changed-file lint plan, including the new sibling test: passed, zero warnings/errors. Export-name collision guard: passed. Closure and CI test-plan guards: 143 passed, 115.46 seconds wrapper time.
The full-tree dead-export scan flagged an unchanged, actually used lazy subagent maintenance import. Script/production scans passed; main fixes scanner visibility in a44f088e7b98. No real consumer was removed.
An independently installed, unchanged base checkout reproduced the prior CI terminal-layout timeout in
ui/src/e2e/chat-panel-layout.e2e.test.ts. This PR changes no UI source.Exact-head CI caught a missing channel reply caller: its typed restart reason lives on the reply operation, not the upstream signal. The caller now supplies that reason. Hetzner
cbx_3ef81015fe4f: the previously failingserver-plugins.test.tsand all seven reply-admission sibling suites passed in 139.78 seconds across three Vitest shards; core production types and focused lint passed.The final-delivery correction passed 143 focused tests in 167.12 seconds on Hetzner
cbx_0fd6d568d268, including the actual RPC queued-reply restart regression, ACP completion, plugin reply ownership, admission, and restart-marking suites.Final-candidate real managed restart proof on the same Hetzner lease: 3 passed, 152.498 seconds test execution (553.40 seconds including a clean build and test preparation). It preserves exactly one private continuation, zero post-revocation requests, and zero original-parent replays on another restart.
Core production types and focused lint passed on that final candidate. The separate ACP completion file also passed all 13 cases on unchanged CI main parent
d789eb10a28293751d980bf23406d6597e42a236(121.99 seconds wrapper time). The earlier missing-start-frame failure did not reproduce on either tree; source inspection identifies a possible abort-versus-start-publication fixture race in unchanged code. This PR does not claim to fix it.Final changed-file gate on Hetzner
cbx_5a36f75315a0:node scripts/check-changed.mjs -- docs/gateway/restart-recovery.md src/sessions/session-lifecycle-admission.ts src/sessions/session-lifecycle-admission.pending.test.ts src/agents/main-session-recovery/main-session-restart-recovery-marking.test.ts. All preliminary guards, formatting, core production types, and all 28 core-test type graphs passed (1,644.75 seconds for the core-test graphs). The gate then stopped on the same inherited full-tree dead-export scanner false positive forloadSubagentMaintenanceCandidatesInDatabase, fixed by main commita44f088e7b98. Production and script export scans passed. Focused lint was already green on the identical candidate.Independent review: final candidate, channel reply correction, and final-delivery correction are clean through P2, including the original-parent replay assertion, first-abort precedence, and pending delivery custody.
Final exact-head CI: run 38172242196 passed on
ec4cf17a098f7a5bb2b5c435b0bdc22bca90dcc2, including the aggregate CI/security gate. Fresh exact-head review found no actionable findings and rated proof/patch quality 5/6.All runtime proof uses synthetic provider responses, isolated state, and owned Gateway processes. No production Gateway was touched.