Repository navigation
fix(gateway): preserve active work during recovered Node restarts - #153435
Conversation
Let Unix Node recovery wrappers respect the existing Gateway stop budget. Share startup-safe command classification and deadline facts, and resolve managed restart intent against the live serving owner in its write transaction with current update authority. Preserve the existing public PID intent API, record format, and Windows behavior. Keep cold lifecycle test preparation outside timed hooks. Inspired by @ly85206559's wrapper-grace approach in #147054; this repair is independently authored from main. Related: #146956. Windows cooperative shutdown remains a follow-up.
Declare receiver-independent restart intent callbacks as arrows and retain typed signal spy handles for lint-safe assertions. Move cold lifecycle imports into test collection so worker preparation cannot consume timed setup hooks.
|
🦞👀 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: blocked before merge. Reviewed September 20, 2026, 1:01 AM ET / 05:01 UTC (Revision 2). ClawSweeper reviewWhat this changesThe PR gives recovered Unix Gateway processes longer to drain, targets restart intent at the serving process, and shares startup helpers across packaging paths. Merge readiness⛔ Blocked before merge - 2 items remain This remains a useful fix: current main and the latest release retain the premature shutdown deadline. Source review found no blocking correctness defect. Priority: P1 Review scores
Verification
How this fits togetherThe Node recovery launcher starts a compatible runtime when the installed runtime cannot run OpenClaw. During managed restarts, it forwards service signals to the Gateway, which owns draining active work and recording recovery outcomes. flowchart TD
A[Restart command] --> B[Installed service metadata]
B --> C[Live owner and restart intent]
A --> D[Native service manager]
D --> E[Node recovery launcher]
E --> F[Serving Gateway]
C --> F
F --> G[Completed work or restart recovery]
Before merge
Agent review detailsSecurityNone. PR surfaceSource -85, Tests +527, Docs +9, Config +3, Other +254. Total +708 across 38 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep draining with the Gateway owner and bounded escalation with its launcher, with native evidence covering each supported supervisor. Do we have a high-confidence way to reproduce the issue? Yes. Current main still escalates recovered children after approximately two seconds; the supplied systemd baseline demonstrates the same failure with active work. This review did not execute target code. Is this the best way to solve the issue? Yes for the repair design: it reuses existing parsing, budgets, storage, and lifecycle ownership rather than adding competing policy. The macOS claim still needs native acceptance evidence. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against e7f5b8f57a9b. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
…mmand (#153510) Require verified native service commands and serving-process identity before recording restart intent or signaling managed Gateways. This fixes the recovery path that could address intent to the launcher PID while the serving child rejected it. Keep restart admission in its existing owner. Use the matching live SQLite owner lease, or narrowly verify the published 2026.9.4 lock when no lease exists, with service-installation, process-tree, state/config, and admission-time identity checks. Preparation failures leave the running Gateway unsignaled; inactive services retain verified start recovery. Preserve the existing intent and lock formats. No new configuration, CLI options, dependencies, or schema changes. Remove the legacy reader when 2026.9.4 leaves the supported upgrade window. Evidence: 15 legacy boundary tests passed; 375 focused tests passed with one existing platform skip; changed-file checks passed; Codex review was scoped-clean at P1. Published 2026.9.4 update and separate legacy/SQLite native restarts passed with real Linux systemd services. Native launchd proof remains a documented gap, covered here by source and boundary tests. The already-current update was a completed no-op, not restart proof. Related: #153435
|
Follow-up landed: the P1 raised in review here (a wrapper-bound restart intent written when service-command inspection failed, so a recovered Node restart could signal the wrong process) is fixed on |
…enclaw#153435) * fix(gateway): preserve work during recovered Node restarts Let Unix Node recovery wrappers respect the existing Gateway stop budget. Share startup-safe command classification and deadline facts, and resolve managed restart intent against the live serving owner in its write transaction with current update authority. Preserve the existing public PID intent API, record format, and Windows behavior. Keep cold lifecycle test preparation outside timed hooks. Inspired by @ly85206559's wrapper-grace approach in openclaw#147054; this repair is independently authored from main. Related: openclaw#146956. Windows cooperative shutdown remains a follow-up. * refactor(gateway): stabilize restart callback and test setup Declare receiver-independent restart intent callbacks as arrows and retain typed signal spy handles for lint-safe assertions. Move cold lifecycle imports into test collection so worker preparation cannot consume timed setup hooks.
…mmand (openclaw#153510) Require verified native service commands and serving-process identity before recording restart intent or signaling managed Gateways. This fixes the recovery path that could address intent to the launcher PID while the serving child rejected it. Keep restart admission in its existing owner. Use the matching live SQLite owner lease, or narrowly verify the published 2026.9.4 lock when no lease exists, with service-installation, process-tree, state/config, and admission-time identity checks. Preparation failures leave the running Gateway unsignaled; inactive services retain verified start recovery. Preserve the existing intent and lock formats. No new configuration, CLI options, dependencies, or schema changes. Remove the legacy reader when 2026.9.4 leaves the supported upgrade window. Evidence: 15 legacy boundary tests passed; 375 focused tests passed with one existing platform skip; changed-file checks passed; Codex review was scoped-clean at P1. Published 2026.9.4 update and separate legacy/SQLite native restarts passed with real Linux systemd services. Native launchd proof remains a documented gap, covered here by source and boundary tests. The already-current update was a completed no-op, not restart proof. Related: openclaw#153435
Related: #146956, #147054
What Problem This Solves
Managed restarts can kill active Gateway work after roughly two seconds when startup has recovered from an unsupported Node version, despite the service's much longer stop budget.
User Impact
Unix Gateways started with the updated launcher can finish admitted work within their existing shutdown budget. Restart intent reaches the serving Gateway even when the service tracks a launcher parent. Updating files cannot change a launcher that is already running. Windows cooperative shutdown remains a follow-up; no new configuration, migration, or dependency is required.
Why This Change Was Made
The launcher shares the CLI's command classification and the service's shutdown-budget constants, leaving the Gateway run loop responsible for draining work. Managed restart preparation resolves the live serving-owner lease inside the existing intent write transaction, using the effective installed-service environment. Exact-PID consumption and update-authority checks remain intact. Inspection problems warn and retain the existing native-PID fallback.
Thanks to @ly85206559 for the original wrapper-grace approach. This implementation is independently authored from current main and keeps the Unix repair separate from the contributor's Windows expansion.
Evidence
The final candidate uses real systemd, Node 24.13.1 recovery to 24.19.0,
KillMode=mixed, a 330-second stop budget, and the real Gateway/RPC/task/subagent/cron owners. Only the loopback model endpoint is synthetic. All twelve requests were held beforepnpm openclaw gateway restart --preserve-definition --json; responses were released fifteen seconds after observed native stop.9440a90e6b4eee281d29d14Original-run no-silent-loss and cooperative drain assertions pass. The serving child explicitly logged
received SIGTERM; restarting. The ninth queued manual cron failed visibly with one job receipt in this cell; broader queued-request durability remains a separate follow-up. Notification and subagent-cleanup admission warnings also remain visible during drain, although the original executions and their durable outcomes succeeded. Native launchd was not exercised; its budget/classification is regression-covered.Real-child and SQLite regressions failed before the fix. Focused validation passed 464 tests before the final admission-race repair, 162 affected tests afterward, 47 lifecycle tests, and the final 64 CLI plus six shutdown tests. These counts overlap. The unchanged launcher/worker-artifact suites passed 231 tests on the preceding reviewed commit; one preexisting opt-in real-Bun case was skipped. The final-head Linux build passed in 273 seconds. Full-diff P1 review and the final four-file follow-up review are clean.
The changed-file follow-up check passed with exit 0. The published-driver/package cell also passed in one attempt: published
2026.9.4updated to the final2026.9.5tarball through its updater, with no recovery step. The candidate then restarted into the fixture's synthetic future package and completed authenticated mock-provider inference. The published first hop intentionally uses--no-restart; the later restart uses the existing 30-second systemd fixture, complementing the separate real 330-second mandatory-Node cell above.Native evidence and audit correction
Baseline native run, candidate native run, and final-head build.
The candidate's native command exited 0. Its outer fixture initially exited 1 because the journal audit demanded
JOB_TYPE=stop, while systemd labels the successful stopped eventJOB_TYPE=restart. The captured record has canonical stoppedMESSAGE_ID=9d1aaa27d60140bd96365438aad20286, the exact service unit, andJOB_RESULT=done. The corrected reader requires this record inside the actual restart interval, so later cleanup cannot satisfy it. The original false audit and unchanged journal are retained. Captured-evidence audit verified the original result/journal/snapshot/build hashes and exits 0; it does not rerun the live cell.All timing relative to native stop uses the first observed transition sampled every 100ms, not exact signal delivery. Replacement runs cannot satisfy original-run completion.
Local nested-checkout lint substitution
The full changed-file check passed all typechecks, guards, and three Knip scans, then hit the campaign's known extension-declaration boundary error through ancestor
node_modules. The prescribed direct extension lint substitute passed across all extensions; no extension source files changed. Its temporary canary proved enforcement:Removing the deliberate declaration passed with
exit=0; the temporary file was then deleted. The real substitute command passed withexit=0:Scripts lint, Stylelint, changed root-test lint, and the import-cycle check passed. The complete core scan exposed unbound callback/spied-method references; the final follow-up repaired those and passed focused canonical lint including the caller. The same follow-up moved two demonstrated cold imports out of timed hooks: 221 seconds of worker preparation now occurs during module collection, with all 64 tests passing and no timeout increases. CI's extension lint remains authoritative.