Repository navigation
fix(agents): reconcile interrupted subagents at startup - #166846
Conversation
Settle restored interruptions after requester ownership transfer through the existing recovery coordinator and sweep overlap guard. Respect the Gateway crash-loop recovery pause and retry through scheduled maintenance, preserving owner checks after preparation. Share restart outcome guidance between main-session recovery and retained native-child follow-ups without duplicating failure diagnostics. Preserve parent delivery retries across lifecycle consolidation and use the active collector capacity fence in the restored FIFO fixture.
|
🦞👀 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. Reviewed October 7, 2026, 9:03 PM ET / October 8, 2026, 01:03 UTC (Revision 2). ClawSweeper reviewWhat this changesThe branch reconciles interrupted subagents during Gateway startup and gives native-child continuations shared guidance to verify uncertain tool outcomes. Example: The Gateway restarts while two shell subagents run
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR remains useful: current main still waits for scheduled interruption reconciliation. The repaired head has sufficient real-Gateway proof, preserves recovery ownership, and has no actionable review findings. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe Gateway’s subagent registry restores saved child runs and informs their parent sessions when execution was interrupted. Parents then decide whether to continue retained children or assign replacement work. flowchart TD
A[Gateway restart] --> B[Restore saved child runs]
B --> C[Restore requester ownership]
C --> D[Shared recovery coordinator]
D --> E{Recovery paused or owner changed?}
E -->|Yes| F[Scheduled retry]
E -->|No| G[Settle interruption and inform parent]
G --> H[Parent reconciles unfinished work]
F --> D
Technical reviewBest possible solution: Keep startup and periodic reconciliation under the existing recovery coordinator, with parents controlling child continuation and uncertain effects verified before retry. Do we have a high-confidence way to reproduce the issue? Yes: current-main activation lacks the interruption pass, and the supplied real-provider SIGKILL/restart scenario demonstrates the resulting delay. This read-only review did not execute it. Is this the best way to solve the issue? Yes: invoking the existing guarded coordinator after requester restoration is a narrow repair, and sharing the interruption guidance avoids competing prompt behavior. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 5ffec9b0ad85. Provenance checked
TestingProof path: shipped entry point. Added test files: 11. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +34, Tests +186, Docs +7. Total +227 across 20 files. 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 (1 earlier review cycle)
|
|
Merged via squash.
|
) * fix(agents): reconcile interrupted subagents at startup Settle restored interruptions after requester ownership transfer through the existing recovery coordinator and sweep overlap guard. Respect the Gateway crash-loop recovery pause and retry through scheduled maintenance, preserving owner checks after preparation. Share restart outcome guidance between main-session recovery and retained native-child follow-ups without duplicating failure diagnostics. Preserve parent delivery retries across lifecycle consolidation and use the active collector capacity fence in the restored FIFO fixture. * fix(agents): restore recovery runtime fixture type import
Startup interruption recovery can return while detached cleanup still owns the retired receipt. A microtask yield lets the test's explicit sweep race that cleanup and report a correctly rejected stale recovery write. Await the existing fixture settlement barrier before both sweeps. Preserve all cases and assertions, including the newer session restart marker and retired receipt removal. No production behavior changes. Follow-up to #166846.
Startup interruption recovery can return while detached cleanup still owns the retired receipt. A microtask yield lets the test's explicit sweep race that cleanup and report a correctly rejected stale recovery write. Await the existing fixture settlement barrier before both sweeps. Preserve all cases and assertions, including the newer session restart marker and retired receipt removal. No production behavior changes. Follow-up to openclaw#166846.
The restart matrix starts a manual sweep while activation can still be settling interrupted subagents. Join the existing fixture settlement barrier before the sweep; preserve every assertion and all production guards. Test-only: one line added. Startup recovery introduced by 89b6b48 (#166846) supplies the overlapping work; 70637ed repaired two sibling cases but missed this matrix. This is source-supported attribution, not a bisected first-bad commit. Validation: the exact changed file passed 33/33 in CI runs 38275924955 and 38279325004. The focused local file passed 33/33 on composition b3c4dcb (1202.38s Vitest / 1343.45s wrapper), with a clean final checkout and no owned survivors. Codex scoped review found no actionable issue. V9 build, types, lint, dependencies, topology, contracts and baseline ratchets passed; its SDK API-report job timed out. These are composition-level results, not whole-head certification of this single commit.
The restart matrix starts a manual sweep while activation can still be settling interrupted subagents. Join the existing fixture settlement barrier before the sweep; preserve every assertion and all production guards. Test-only: one line added. Startup recovery introduced by 6fdb7d2 (openclaw#166846) supplies the overlapping work; 1ef9fbf repaired two sibling cases but missed this matrix. This is source-supported attribution, not a bisected first-bad commit. Validation: the exact changed file passed 33/33 in CI runs 38275924955 and 38279325004. The focused local file passed 33/33 on composition b3c4dcb (1202.38s Vitest / 1343.45s wrapper), with a clean final checkout and no owned survivors. Codex scoped review found no actionable issue. V9 build, types, lint, dependencies, topology, contracts and baseline ratchets passed; its SDK API-report job timed out. These are composition-level results, not whole-head certification of this single commit.
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).
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)
What Problem This Solves
When the Gateway restarts while a parent session is waiting on subagents, the interrupted children are only reconciled by the subagent registry's periodic sweep, not at startup. The parent therefore waits for that maintenance pass before it learns its children were interrupted and can finish the task. In a stability-campaign crash test on main (parent launches two 20-second shell subagents, Gateway SIGKILLed while both run, then restarted), children were next active 46 s after the restarted Gateway became healthy, and the parent's final answer arrived at 93 s.
User Impact
Why This Change Was Made
Registry activation already restored requester ownership but left interrupted runs to periodic maintenance. Activation now runs one interruption-only pass through the existing guarded recovery coordinator right after ownership is restored (
subagent-registry-restore.ts). The coordinator is the single owner of the eligibility check, which moved out of the sweeper, so the startup pass and periodic sweeps share one gate. It respects the crash-loop pause and rechecks ownership after awaiting preparation. The periodic sweep remains the retry backstop. The restart-recovery note lives in one shared module (restart-recovery-prompt.ts), reused by main-session recovery and bysessions_sendfollow-ups to interrupted native children. It is distinct from the recovered-child failure diagnostics main already preserves (#166454). Prompt snapshot token delta is 0.Evidence
Live crash test (dev Gateways from main 905a74d and this head, fresh state, real OpenAI provider; parent spawns two
sleep 20; echo …subagents, SIGKILL while both run, restart; times from the restarted Gateway becoming healthy):Tests: 1,370 passed across 52 non-E2E files covering recovery, lifecycle, announce, requester wakes, raw owners, collectors, cancellation, persistence, and prompts (restart/announce/prompt set 506 s; remaining registry set 590 s). With production rolled back, the four startup regressions, both prompt regressions, and the breaker-pause regression fail. A deterministic FIFO fixture deadlock exposed during the rebase was repaired by removing a redundant admission suspension; capacity-ordering assertions are intact. Types, lint, format, and the import-cycle check pass. Autoreview is clean through P2.
Production +52/-18, tests/support +205/-20, docs +6/-1 (
docs/gateway/restart-recovery.md).Landing validation: initial CI run 37708125808 found a missing
GatewayRecoveryRuntimetype import in the updated sweeper fixture. Commitd9798f6746312606c0736ecc555c6cdad0036450restores that import; the agent/session test typecheck now passes locally. The original head passed 119 focused startup/ownership/prompt tests across three files (204.10 s wall), and the repaired fixture passed all 33 sweeper recovery tests (48.11 s wall). Independent review found no actionable P0–P2 findings in the original change or the one-line repair. CI and ClawSweeper are being checked against the repaired head before landing.