Skip to content

fix(gateway): preserve active work during recovered Node restarts - #153435

Merged
steipete merged 2 commits into
mainfrom
upd/recovery-wrapper-restart-grace
Sep 20, 2026
Merged

steipete merged 2 commits into
mainfrom
upd/recovery-wrapper-restart-grace

Conversation

@steipete

Copy link
Copy Markdown
Contributor

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 before pnpm openclaw gateway restart --preserve-definition --json; responses were released fifteen seconds after observed native stop.

Observation Recorded main baseline 9440a90e6b4 Candidate eee281d29d14
Twelve original connections All cut unfinished at +2.018–2.019s All completed at +15.011s; zero unfinished closes
Native stop SIGKILL status 9 at +2.030s Successful stopped job at +16.263s
Three original agent runs Cancelled Succeeded, with original completion transcripts
Original subagent Failed Succeeded; registry terminal/ok and original transcript
Eight original cron receipts/tasks Interrupted/failed All original receipts ok and tasks succeeded
Restart CLI Exit 0 in 17.167s Exit 0 in 31.705s
Authenticated replacement 23.114s from command start 31.733s, with changed boot identity

Original-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.4 updated to the final 2026.9.5 tarball 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 event JOB_TYPE=restart. The captured record has canonical stopped MESSAGE_ID=9d1aaa27d60140bd96365438aad20286, the exact service unit, and JOB_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:

extensions/l948-lint-canary.ts:2:7: error eslint(no-unused-vars): Variable 'l948UnusedCanary' is declared but never used.
exit=1

Removing the deliberate declaration passed with exit=0; the temporary file was then deleted. The real substitute command passed with exit=0:

node_modules/.bin/oxlint --tsconfig test/tsconfig/tsconfig.extensions.test.json extensions

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.

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.
@clawsweeper

clawsweeper Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime cli CLI command changes scripts Repository scripts commands Command implementations docker Docker and sandbox tooling size: XL maintainer Maintainer-authored PR labels Sep 20, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 20, 2026
@clawsweeper

clawsweeper Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 20, 2026, 1:01 AM ET / 05:01 UTC (Revision 2).

ClawSweeper review

What this changes

The 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
Reviewed head: eee281d29d1438a13cb832255ec9f37d77d4b24f

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent repair with strong Linux production-path evidence and no actionable code findings; macOS acceptance remains outstanding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The supplied final-head systemd observations exercise Node recovery, the production restart command, serving-owner intent, and original-work completion after a 15-second hold. Published-driver upgrade evidence supplements this; native launchd remains a separate platform-validation gap.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The supplied final-head systemd observations exercise Node recovery, the production restart command, serving-owner intent, and original-work completion after a 15-second hold. Published-driver upgrade evidence supplements this; native launchd remains a separate platform-validation gap.
Evidence reviewed 9 items Current main still has the defect: The fetched main revision retains a one-second initial grace followed by force-kill escalation, independently supporting the reported approximately two-second interruption.
Latest release remains affected: The v2026.9.5 source also retains the one-second launcher grace; this repair is not established as shipped.
Introduced shutdown behavior: The launcher selects the existing service budget for Unix foreground Gateway commands, reserving two seconds for escalation. The launchd service budget remains 20 seconds; only the launcher's waiting behavior changes.
Findings None None.
Security None None.

How this fits together

The 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]
Loading

Before merge

  • Resolve merge risk (P1) - The recovered macOS launcher now waits substantially longer before escalation, but native launchd completion and child cleanup within the existing 20-second service limit remain unverified.
  • Complete next step (P2) - Add native launchd evidence for recovered-child drain and managed restart completion within the existing 20-second limit, or narrow the macOS scope.
Agent review details

Security

None.

PR surface

Source -85, Tests +527, Docs +9, Config +3, Other +254. Total +708 across 38 files.

View PR surface stats
Area Files Added Removed Net
Source 10 243 328 -85
Tests 16 565 38 +527
Docs 1 9 0 +9
Config 1 3 0 +3
Generated 0 0 0 0
Other 10 288 34 +254
Total 38 1108 400 +708

Review metrics

Metric Value Why it matters
Launcher escalation Initial grace: 1s → 328s on Linux; 1s → 18s under recognized launchd Native service limits remain unchanged, making supervisor completion the important platform contract.
Production versus regression coverage Production/tooling net +172 lines; tests/support net +527 lines Production growth supports shared startup helpers and transactional owner selection; added coverage exercises drain and ownership failures.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #146956
Summary: This PR is a candidate fix for the launcher shutdown defect; the other open implementation overlaps but does not establish supersession.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Verify the launchd lifecycle (recommended)
    Provide native macOS evidence that the recovered serving child drains and the managed restart completes within the existing service deadline.
  2. Defer macOS behavior
    Narrow the behavior and documentation to the demonstrated Linux repair until launchd acceptance is available.

Technical review

Best 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.

Labels

Label justifications:

  • P1: Routine managed restarts can interrupt admitted agent, subagent, and cron work in affected installations.
  • merge-risk: 🚨 availability: The longer macOS launcher lifetime needs native confirmation that launchd restart and child cleanup remain bounded.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The supplied final-head systemd observations exercise Node recovery, the production restart command, serving-owner intent, and original-work completion after a 15-second hold. Published-driver upgrade evidence supplements this; native launchd remains a separate platform-validation gap.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied final-head systemd observations exercise Node recovery, the production restart command, serving-owner intent, and original-work completion after a 15-second hold. Published-driver upgrade evidence supplements this; native launchd remains a separate platform-validation gap.

Evidence

What I checked:

  • Current main still has the defect: The fetched main revision retains a one-second initial grace followed by force-kill escalation, independently supporting the reported approximately two-second interruption. (node-runtime-recovery.mjs:69, e7f5b8f57a9b)
  • Latest release remains affected: The v2026.9.5 source also retains the one-second launcher grace; this repair is not established as shipped. (node-runtime-recovery.mjs:68, ec9c1a13db89)
  • Introduced shutdown behavior: The launcher selects the existing service budget for Unix foreground Gateway commands, reserving two seconds for escalation. The launchd service budget remains 20 seconds; only the launcher's waiting behavior changes. (node-runtime-recovery.mjs:46, eee281d29d14)
  • Live ownership and compatibility: Restart preparation uses the installed-service environment, resolves a live matching supervisor inside the admitted SQLite transaction, and rechecks update authority before writing. The existing PID API, record format, exact-PID consumption, and native-PID fallback remain intact. (src/infra/restart-intent.ts:80, eee281d29d14)
  • Regression coverage: Read the real-child drain regression and SQLite lifecycle tests, including replacement before write admission, unrelated/dead/unknown owners, and revoked authority preventing both intent writes and native restart. These tests were inspected, not executed during this read-only review. (src/cli/daemon-cli/lifecycle.restart-intent.test.ts:171, eee281d29d14)
  • Recorded production-path evidence: The complete supplied body, source revision 29cc5bd48a78eea8a15133f363b16ace64e46875e2d622d842b9b05c6ac15e69, records real systemd and Node recovery at this head: twelve original requests completed after approximately 15 seconds, original agent/subagent/cron outcomes succeeded, and the replacement authenticated. It also records published-driver upgrade proof and explicitly excludes native launchd verification. The linked Crabbox portal could not be opened by the reviewer; the assessment preserves the supplied observations without claiming independent artifact inspection. (eee281d29d14)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • RomneyDa: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Provide native launchd restart evidence or narrow the macOS behavior and documentation.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-20T04:53:03.376Z sha eee281d :: blocked before merge. :: none

@steipete
steipete marked this pull request as ready for review September 20, 2026 04:55
@steipete
steipete merged commit 2ce0573 into main Sep 20, 2026
298 checks passed
@steipete
steipete deleted the upd/recovery-wrapper-restart-grace branch September 20, 2026 05:41
steipete added a commit that referenced this pull request Sep 20, 2026
…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
@steipete

Copy link
Copy Markdown
Contributor Author

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 main by #153510 (84eb4be8f8ffbd9107ef910c1c4d7081eef5edcc). Restart admission now verifies the service command and the serving-process identity before recording intent or signaling, the launcher-PID fallback is removed, and published 2026.9.4 Gateways that only carry lock-file identity are admitted when that identity verifies against the live process. Both ship together in the release after 2026.9.5.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 21, 2026
…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.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 21, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes commands Command implementations docker Docker and sandbox tooling docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant