Repository navigation
fix: recover subagent shutdown notices after upgrades - #201706
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 Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs maintainer review before merge. What this changesThis PR restores delivery of pending subagent shutdown errors that older Gateways persisted as quiet cancellations. Example: A completion-required child was interrupted with “Gateway stopped” before upgrading.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR is worth merging: it repairs a concrete upgrade recovery gap, and no actionable correctness or security findings remain. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherGateway startup restores persisted subagent runs, repairs their metadata through the registry mutation owner, and leaves requester admission and completion delivery to existing recovery. flowchart TD
A[Persisted subagent runs] --> B[Registry restore]
B --> C[Legacy shutdown repair]
C --> D[Existing durable mutation owner]
D --> E[Requester recovery admission]
E --> F[Completion delivery]
Technical reviewBest possible solution: Merge the focused startup repair through the existing registry owner while preserving intentional cancellation, delivered outcomes, and requester admission. Do we have a high-confidence way to reproduce the issue? Source confirms the historical writer shape and missing main restoration path; supplied differential evidence reports the identical legacy-input regression failing on the pinned base and passing on this head. Is this the best way to solve the issue? The smallest complete fix is to normalize the proven legacy record in the existing startup metadata transaction; the patch does this without adding another recovery owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against ebbd85cb6e7f. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +33, Tests +209, Docs +4, Other +39. Total +285 across 5 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. 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)
Reviewed November 19, 2026, 3:52 AM ET / 08:52 UTC (Revision 2). |
|
Addressing the one open item on final head
The restart test crosses actual Gateway subprocess boundaries: public chat.send starts the main-lane exec, stop/start retains and repairs the historical input, and chat.history plus atomic removal receipts verify delivery. The model is a deterministic HTTP fixture; the agent, exec tool, Gateway processes, persistence and requester delivery are real. This is not an in-process Gateway mock. A diagnostic-only replay of those same two cases passed (58.39 s Vitest), with this synthetic runtime output: The logging instrumentation was removed afterward and the committed test bytes verified unchanged. The identical committed legacy-input regression is red on base The repository's published-upgrade survivor passed from npm stable The PR body also now contains the complete interleaved A/A/B owner wall, CPU and allocation measurements, including the first worker startup/commit cost and the APFS limitation. Exact-head CI run 44482002367 is green. No announcement ownership guards changed. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
Use the existing retained run association so accepted user replies survive provider backoff. Update the inherited parent restart assertion from #201706 to require the restored child completion instead of a duplicate generic resume.
* fix(gateway): keep interrupted automation with its scheduler * fix(gateway): retain steered work between backend attempts Use the existing retained run association so accepted user replies survive provider backoff. Update the inherited parent restart assertion from #201706 to require the restored child completion instead of a duplicate generic resume.
…resume 🌊's ruling on upstream openclaw#201544 keeps its delivery path: a graceful shutdown completes a live child with the error "Gateway stopped", and the requester receives that outcome after startup. Restart-terminal-custody cases 1 and 3 still asserted the fork's earlier quiet kill (subagent-killed, intentional_non_delivery) and were red at e7de8c3 on that assertion. Both cases now run startup end to end through the real announce flow: the shutdown, a new lifecycle, the root resume, and three sweeps. They record what each requester receives at the delivery seam. Case 1 has one live delegate. The root gets exactly one input, GATEWAY_RESTART_RESUME_TEXT, which names no child and claims no completion. The requester gets exactly one outcome for that child, and its rendered text is pinned in full ("status: failed: Gateway stopped", "session_id: unknown", "(no output)"). The row ends delivered, never as a success. Case 3 adds an unreached sibling. It still gets no notice in this commit, and both custody receipts stay inspectable. O3's no-second-outcome case is unchanged and green. The delegate rows now carry requesterAgentId, as spawn always records it. Restart completion recovery admits a pending child only by that field. Without it the stopped child's outcome was never re-admitted in this fixture. Negative control: with the pre-openclaw#201544 quiet-kill shutdown restored (markSubagentRunTerminated with suppressTaskDelivery), case 1 is red ("expected 'subagent-killed' to be 'subagent-error'"). Case 3 stays green there because upstream openclaw#201706's restore repair re-owes the quiet-kill row on boot. Item 4 of this lane handles that repair. Refs openclaw#129388 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e a deploy 🌊's ruling on upstream openclaw#201544, item 4: before any deploy, audit the target's older pending quiet-kill rows and prevent a surprise late delivery from restore. Verify the migration on fixtures first. The hazard: before openclaw#201544 a graceful shutdown ended a live child with markSubagentRunTerminated(reason "Gateway stopped", suppressTaskDelivery). That left delivery pending as a quiet kill. On its first boot, upstream openclaw#201706's restore (subagent-registry-restore- metadata.ts) re-owes every such row that is still pending, whenever the restart that wrote it happened. A probe of the pre-merge fork head bc7e568 confirms that those rows match the predicate as its shutdown writes them and still match after its next activation. What later boots do to them depends on the seat, so each owner has to count their own. The predicate restore uses is now exported as isUnrepairedShutdownQuietKill, unchanged; restore itself calls it. It is the one definition, so the audit cannot drift from restore. This is the only upstream-owned change in this commit and is a candidate upstream contribution. Operator surface, offline, beside fence-status and interrupt-fenced: - openclaw continuations shutdown-notices [--json]: read-only. It is refused while a Gateway owns the state and reads through an artifact-preserving snapshot. It lists every row restore would re-owe (the predicate, minus rows whose child authority restore skips) with runId, child, requester, delegate or plain, and endedAt. It prints no task text. - openclaw continuations settle-shutdown-notices --ended-before <time>: runs under exclusive local state ownership. First it writes a backup with each row exactly as stored plus what the settle will write (<stateDir>/backups/subagent-shutdown-notices/, 0600, fsynced). Then it closes each row that ended before the cutoff as an intentional non-delivery: delivery not_required, disposition intentional_non_delivery, suppressCompletionDelivery. It compares and swaps on the stored payload, never deletes a row, and starts no turn. Rows at or after the cutoff are kept, so the deploy's own stop is still delivered. - settle-shutdown-notices --undo <backup>: puts back each row that is still exactly as the settle wrote it. Pins, on fixtures written by the pre-openclaw#201544 shutdown call itself, booted through this build's real restore, root resume and announce flow (subagent-registry.shutdown-notices): 1. The count names the three re-owed rows, not the explicit Stop. On an unsettled seat the week-old rows are delivered late: the hazard. 2. After a settle with a cutoff between them, the requester receives only the root resume input and the deploy restart's one stopped delegate. The settled runs are neither deleted nor delivered. Each stays reachable by run id as ended by "Gateway stopped" with delivery not_required. 3. The undo restores the rows byte for byte, and restore then re-owes them as before. The CLI case pins the receipts, the untouched store bytes for the count, and the refusals (no instruction, an unparseable time). The restart custody suites share their registry world through subagent-registry.restart-custody.test-support.ts. The worker inventory classifies the settle as a CLI one-shot (T3) and is regenerated. Refs openclaw#129388 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…201757) * fix(gateway): keep interrupted automation with its scheduler * fix(gateway): retain steered work between backend attempts Use the existing retained run association so accepted user replies survive provider backoff. Update the inherited parent restart assertion from openclaw#201706 to require the restored child completion instead of a duplicate generic resume.
(cherry picked from commit d54f706) Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit 473d88a1cb978d95d0eca93c7f217302fda42db1) (cherry picked from commit d8d9e2c498ce079774fc7efafa4fa4f34157c240)
* fix(gateway): keep interrupted automation with its scheduler * fix(gateway): retain steered work between backend attempts Use the existing retained run association so accepted user replies survive provider backoff. Update the inherited parent restart assertion from #201706 to require the restored child completion instead of a duplicate generic resume. (cherry picked from commit cb04fef) Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit 2324999c64c047bc97813153e345d35cdf26be2b) (cherry picked from commit 1d8de7fa3709981f7b6fcfd176d79f0277f9112d)
What Problem This Solves
Upgrading from a Gateway that recorded shutdown-interrupted subagents as quiet kills can leave their required completions pending forever. The shutdown correction in #201544 fixes new writes, but startup still treats the older persisted records as intentional cancellation.
User Impact
Requesters receive the retained “Gateway stopped” error after restart. Explicit Stop and already delivered outcomes remain closed.
Why This Change Was Made
The existing startup metadata owner repairs the exact old shutdown record before cancellation reconciliation can retire it. The existing requester recovery path still admits delivery under current authority. No schema, runtime configuration, cache, or announcement ownership guard changes.
Production grows by 33 lines for the upgrade repair. Reusing the restoration transaction keeps this at one owner without another scan or recovery mechanism.
Evidence
The real-Gateway test starts a completion-required child, continues it on its main lane into a long-running exec tool, stops the process, and checks the retained outcome, requester reply, and atomic delivery/removal receipts after restart. The upgrade case restores the old writer's observed persisted input between the real processes. It fails on the exact main parent at the missing requester reply and passes with this repair. A separate differential using the previous shutdown writer also reproduced the missing reply.
Current-main shutdown already passed the main-lane reproduction before this change. This PR repairs the proven upgrade-state gap; it does not claim attribution of an individual production incident without the predecessor process build or removal receipt. The separately reported abort after sessions_yield remains unproven and is outside this change.
The two final Gateway cases pass (41.418 s total test bodies), and all three native restoration cases pass. The identical upgrade regression fails on main parent
11b65598aa4d6at the missing requester reply. Independent Codex review found no actionable P0–P2 issues.pnpm check:changedpassed on the final tree. Exact-head CI run 44482002367 is green. The latest-stable published-upgrade survivor and diagnostic runtime replay also passed; the numbered review response records the evidence.Synthetic owner measurements
No production data was used. The fixture contains 10,800 sessions, 5,545 populated transcripts / 322,437 events, a 56.04 GiB agent database, 4,300 retained runs, and 62,000 workspace files totaling 1.116 GB. The host uses Node 24.22.1 and APFS; these are not btrfs measurements. Text filling stopped after the physical DB exceeded the target; the summary records the actual populated count.
Five interleaved fresh processes per A1/A2/B and cohort, six trials each; wall/CPU measured separately from V8 allocation sampling. Warm values are medians of five process medians. Imports, fixture reset and compact hydration are outside the timed owner; its actual worker transaction is included.
The first interrupted repair includes the source harness's first worker startup/commit: 2,972 ms wall / 2,527 ms CPU / 11,772,216 sampled bytes, versus base A/A 6.39/6.45 ms wall and 24.39/24.44 ms CPU because base performs no repair. Already-repaired cold controls remain 6.38–6.50 ms. This is a correctness repair with a one-time write cost, not a startup speedup. Process CPU includes worker threads; allocation sampling covers the main thread only. Healthy-control CPU increased about 3.5% versus the A/A midpoint; wall stayed within A/A variation and sampled allocation increased about 0.4%.
Stored-data compatibility
The repository's published-upgrade survivor passed from npm stable
[email protected]through its actual updater to the candidate tarball built from this exact head (SHA-2566a1ee747ca32b815dd639a4f5b3d846faac8febc279dc01fed7c685f8b89d80a). Thebasescenario verified configuration and session/workspace state preservation, completed Doctor, then started the installed Gateway and passed health/readiness/RPC checks. Summary:status=passed,updateOutcome=success,candidateInstallMode=updater,failure=null; scenario 389 s, startup 14 s, health/readiness/status 1 s each. The container used Node 24.22.0; the focused restart tests and measurements used Node 24.22.1. The stable-upgrade smoke complements the explicit Stop/delivered registry controls above; it does not claim a live external model turn. The first attempt stopped before installation because my diagnostic logging dirtied the checkout during plugin packaging; the clean serial attempt passed without bypassing the guard.The diagnostic replay of both real-Gateway cases passed (58.39 s Vitest). Each recorded the requester receiving
Gateway stopped, the reply appearing in its transcript, and the durable delivered-before-removal check passing. Diagnostic logging was removed afterward and the committed test bytes verified unchanged.