Repository navigation
fix(gateway): wait for lifecycle ownership during restart - #146189
Conversation
A restarted Gateway waits, with a generous bounded budget, for its predecessor to release lifecycle ownership instead of failing immediately and tripping systemd start limits. Share the migration acquisition deadline loop and carry one monotonic deadline through supervised startup. Fixes #146142. Reported by @waynegault (#146142). Coordinator holder identity remains a follow-up pending a persistence design decision.
|
🦞👀 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 12, 2026, 1:37 PM ET / 17:37 UTC (Revision 4). ClawSweeper reviewWhat this changesGateway startup waits for lifecycle ownership under a shared five-minute retry budget, reuses migration polling, and updates systemd restart limits and documentation. Merge readiness⛔ Blocked before merge - 1 item remains This remains a useful, proven fix: reviewed main and v2026.9.4 still fail immediately on lifecycle contention. No blocking correctness or security finding remains. Priority: P1 Review scores
Verification
How this fits togetherThe Gateway startup loop acquires exclusive state ownership before starting the server. Service supervisors launch replacements during restart, so temporary ownership contention can otherwise prevent the replacement from becoming ready. flowchart TD
A[Startup or supervised restart] --> B[Shared retry deadline]
B --> C[Acquire lifecycle ownership]
C -->|Held elsewhere| D[Bounded wait]
D --> C
D -->|Deadline reached| E[Ownership error]
C -->|Acquired| F[State and config locks]
F --> G[Gateway server startup]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +93, Tests +125, Docs +2. Total +220 across 14 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep contention recovery in the existing acquisition owner, preserve exclusive access, and retain published-driver compatibility without adding persistent holder metadata to this fix. Do we have a high-confidence way to reproduce the issue? Yes for the contention failure mechanism: another process holding the lifecycle coordinator makes reviewed main fail immediately. The exact original WSL2 overlap remains unestablished; this read-only review ran no tests. Is this the best way to solve the issue? Yes. Bounded asynchronous acquisition repairs the missing tolerance at its existing owner, and the shared helper preserves migration retry semantics without changing persisted state. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 30577136aa7d. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
Consolidate the two cross-process lifecycle regressions into the existing lock-role suite. Preserve the 700-root typecheck guard and the existing file-size limits.
Remove the obsolete whole-module mock so supervised startup uses the real lifecycle timeout, contention classifier, and error class. The run-loop remains mocked and no locks are acquired by these option tests.
|
Merged via squash.
|
…46189) A restarted Gateway waits, with a generous bounded budget, for its predecessor to release lifecycle ownership instead of failing immediately and tripping systemd's start limit. Share the bounded acquisition loop with startup migrations and carry one monotonic deadline through supervised startup, preserving exclusive ownership and terminal contention errors. Generated systemd units allow ten starts per 300 seconds and retain the five-second restart delay. Existing installed updaters and service units benefit from the candidate-side acquisition fix. No configuration, schema, dependency, or persistent-store recovery change is introduced. Fixes openclaw#146142 Reported by @waynegault (openclaw#146142). Proof: cross-process regression coverage, focused lifecycle and service tests, exact-head CI, Linux systemd restart under injected coordinator contention, and the published [email protected] restart driver against the candidate all passed. The real restart acquired ownership after 3.8 seconds and reached readiness with zero systemd restarts. Coordinator holder identity remains a follow-up pending a persistence decision. The proof does not identify the original WSL2 holder or cover a full npm update.
Fixes #146142
Additional instructions
Maintainer edits: This branch is in
openclaw/openclaw; maintainers with repository write access can update it directly.What Problem This Solves
Fixes an issue where users restarting a supervised Gateway could get an immediate startup failure while another OpenClaw process still held lifecycle ownership. Repeated failed starts could exhaust systemd's start limit and leave the Gateway down.
Reported by @waynegault (#146142).
Why This Change Was Made
Gateway acquisition now waits for lifecycle-coordinator contention under a five-minute monotonic deadline, with backoff from 250 ms to 2 seconds. It logs the initial wait and successful acquisition, and includes the elapsed wait in a terminal ownership error. The deadline loop is shared with the startup-migration lease fix from #120959; migration owner classification and polling cadence stay intact.
Supervised startup recognizes lifecycle contention and passes the same absolute deadline into acquisition, including time spent loading startup code. A healthy port cannot turn coordinator contention into successful startup. Generated systemd units allow ten starts per 300 seconds while retaining the five-second restart delay; both documented unit examples match. Launchd already has throttling without a finite start-limit latch.
The coordinator remains an anonymous SQLite lock. Holder identity is a follow-up pending Peter's persistence design decision. A foreign live owner receives the same bounded wait and still fails if it never releases; the code never steals ownership. Normal restart already releases ownership before handing off in both v2026.9.3 and this branch, so the reporter's exact overlapping process remains unidentified.
User Impact
A restarted Gateway waits, with a generous bounded budget, for its predecessor to release lifecycle ownership instead of failing immediately and tripping systemd's start limit.
The candidate Gateway owns this behavior, so an older installed updater or existing unit can benefit without learning a new handoff marker. The revised systemd limits apply when the service definition is rewritten. No configuration options, dependencies, schemas, or retained-state semantics change.
Evidence
node scripts/check-changed.mjspassed, including production/test typechecks, lint, schema guards, and zero runtime import cycles.git diff --checkpassed.pnpm buildand real systemd restart passed, with candidate source hashes verified. Node 24.19.0 / systemd 255.4. An independent synthetic holder retained the actual coordinator until two seconds after the replacement logged waiting. Readiness succeeded; PID changed;NRestarts=0,Result=success,ExecMainStatus=0, and no failed-start message. The owned service and Testbox were cleaned up.Testbox run, lease
tbx_01m2b60qf71cpz0zhr9p7z153q, wrapper exit 0. Provider cleanup can mark the hosting Actions run cancelled; the proof command itself passed.Production grows by 93 lines for bounded asynchronous acquisition, diagnostics, and deadline propagation; the migration polling loop is shared rather than duplicated. There is no persistent ownership representation change.
CI also exposed an obsolete whole-module lock mock in CLI option coverage. Removing that mock restored the real timeout, contention classifier, and error class; all 94 CLI option/lifecycle tests passed (
node scripts/run-vitest.mjs src/cli/gateway-cli/run.option-collisions.test.ts). No assertions were weakened.The first CI run exposed the infra test-root cap (701 roots versus the existing 700 limit). Both new ownership regressions were consolidated into the existing Gateway lock-role test file, preserving the cap and all assertions. The consolidated Gateway lock-role suite and repository partition/cap suite then passed 29 tests:
Published restart driver × candidate: Exact npm
[email protected]rangateway restart --preserve-definition --jsonagainst the candidate under the same injected contention. It exited 0 withresult=restarted, preserved the unit bytes, and produced a ready successor after a 3.8-second ownership wait withNRestarts=0. Runtime source hashes remained unchanged through the test-only consolidation. Published-driver Testbox run, leasetbx_01m2b6pjepvdw2wj60sgv8hnf9, wrapper exit 0; service, profile, and lease cleaned up. Setup initially hit the released CLI's canonical-path and enabled-unit guards; the final fixture used its supported named-profile layout and normal service enablement.These Linux cells inject contention; they do not establish the original production holder or WSL2-specific behavior. The compatibility cell covers the published restart driver, not a full npm update.
Two unrelated failures were identified in the merged CI revision for head
cafce22616e(maind8312aab8aca):checks-node-compact-small-29:gateway-otherhas 701 roots on that main revision versus 700 on this branch. Main PR fix(gateway): expose missing worker RPC latency diagnostics #145602 /31c8b990cb5cadded the worker-metrics test; this branch changes no Gateway test roots or shard configuration. This is separate from the corrected infra-root increase above.checks-windows-node-test-2:update-managed-service-handoff-database-publication.test.tsexpects “changed during initialization” but receives “file is not a database” on Node 24.21.0. The test and its 265-file static dependency closure, package/lock files, and relevant runner inputs are unchanged by this branch; none of the changed lifecycle acquisition modules is in that closure. The exact Windows cause remains for its owner to investigate.Both existing guards/assertions are retained. Final-head CI passed for
5c6dcc64d0005c6bac5df1d08f4b398b0baf44b4: completed successful run. The earlier failures above are historical; the current check rollup is green.ClawSweeper review
The latest completed review of
5c6dcc64d0005c6bac5df1d08f4b398b0baf44b4found no code or security defects. No code fixups were needed. Skipped: identify the original WSL2 holder and prove a full npm update before merge. The maintainer explicitly approved landing the bounded lifecycle-contention repair with these documented limitations: real Linux cross-process contention and the published 2026.9.3 restart driver prove the changed boundary. Identifying the original holder and adding coordinator holder identity remain follow-ups, with the latter pending a persistence decision.