Repository navigation
fix(gateway): preserve graceful shutdown when restart intent stalls - #188047
Conversation
Bound restart signal settlement to one second and fall back to normal SIGTERM shutdown so active runs retain resume markers. Cancel late intent admission without detaching native write settlement. Prove suspend/reopen shutdown with an isolated blocked state store and retain worker inspection cancellation coverage. Timed-out optional restart metadata may be lost.
|
🦞👀 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 SummaryThis 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. |
The service environment merge deliberately excludes caller-only state selectors. Declare the fixture-owned state directory in the installed command environment so intent recording and serving-owner refusals exercise the intended database. The same six failures reproduce on the complete base; the corrected fixture passes on base and the bounded-signal implementation. Keep production CLI and SIGTERM behavior unchanged.
|
Codex review: needs maintainer review before merge. What this changesBounds restart-intent signal settlement so stalled storage cannot prevent graceful Gateway shutdown. Example: SIGTERM arrives while a SQLite writer blocks restart-intent consumption.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Regression provenanceRegression provenance — verified: source commit Merge readiness✅ Ready for maintainer review Keep open: this PR repairs a current shutdown failure using the existing lifecycle owners; no actionable introduced defect was found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherGateway process signals enter the run-loop signal owner, which consumes optional restart metadata through the shared SQLite worker before requesting shutdown or restart. flowchart TD
A[Process signal] --> B[Run-loop signal owner]
B --> C[Bounded intent consumption]
C --> D[Shared SQLite worker]
C --> E[Shutdown request]
E --> F[Persist markers and abort runs]
F --> G[Resource cleanup and exit]
Technical reviewBest possible solution: Keep signal waiting bounded in the existing signal owner while the database owner retains dispatched writes and ordinary shutdown persists resume markers. Do we have a high-confidence way to reproduce the issue? Current-main source shows stalled intent settlement reaching force-exit before the shutdown request; the author additionally reports matching base-red/head-green runs, which this read-only review did not execute. Is this the best way to solve the issue? The patch is a focused fix: it bounds optional metadata observation, cancels late admission, and delegates shutdown and native write settlement to their existing owners. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 43af01b15c96. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +9, Tests -1, Docs +7. Total +15 across 7 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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 Reviewed October 29, 2026, 10:52 PM ET / October 30, 2026, 02:52 UTC. |
|
ClawSweeper status: applying reviewed decision. I am applying the reviewed decision for this pull request: fix(gateway): preserve graceful shutdown when restart intent stalls This is item 1/1 in the current shard. Shard 1/1. This transient lease prevents a newer review from overlapping label, comment, or close mutations. Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted. |
…ls (openclaw#188047) The first Team stop on the restart redesign (2026-10-29 20:43Z, release a8ef6aa) closed admission and then logged nothing for 85 s while SIGTERM waited on restart-intent settlement in run-loop-signals.ts. It force-exited before shutdown persisted any resume markers, and systemd SIGKILLed it. After restart there were zero resume inputs, so every running session was lost. - SIGTERM now falls back to ordinary graceful shutdown after 1 s of stalled restart-intent settlement (marker persistence, abort, bounded cleanup) instead of forceExit, and it refuses late intent results. - Shutdown releases worker-environment inspections whose provider ignores cancellation. On Team, 5 crabbox reconcile ops had been retained for 3.6 h. - The CLI daemon lifecycle restart-intent test fixture now supplies the installed service's isolated state directory. Its six failures reproduce on unchanged main; production CLI behavior is unchanged. Proof at exact head 88a8558: - Locally: the run-loop regressions are red on base and green here. A new real-process acceptance case (suspend lease reopened, then SIGTERM) persists the marker and exits 0 in 1.3 s. 992 tests pass across the daemon-cli/gateway-cli/restart-intent suites; targeted typechecks, lint and format pass. - Exact-head CI: 64 jobs succeeded. The only failure, test/gateway-restart-handoff.e2e.test.ts (180 s timeout), is inherited. It times out identically on main fe4fa70, with six SessionEntryChangedDuringReadError before SIGTERM. That is the separate main regression lane K1 is bisecting. Production +9 LOC.
…ls (#188047) The first Team stop on the restart redesign (2026-10-29 20:43Z, release bbde2b8) closed admission and then logged nothing for 85 s while SIGTERM waited on restart-intent settlement in run-loop-signals.ts. It force-exited before shutdown persisted any resume markers, and systemd SIGKILLed it. After restart there were zero resume inputs, so every running session was lost. - SIGTERM now falls back to ordinary graceful shutdown after 1 s of stalled restart-intent settlement (marker persistence, abort, bounded cleanup) instead of forceExit, and it refuses late intent results. - Shutdown releases worker-environment inspections whose provider ignores cancellation. On Team, 5 crabbox reconcile ops had been retained for 3.6 h. - The CLI daemon lifecycle restart-intent test fixture now supplies the installed service's isolated state directory. Its six failures reproduce on unchanged main; production CLI behavior is unchanged. Proof at exact head 88a8558: - Locally: the run-loop regressions are red on base and green here. A new real-process acceptance case (suspend lease reopened, then SIGTERM) persists the marker and exits 0 in 1.3 s. 992 tests pass across the daemon-cli/gateway-cli/restart-intent suites; targeted typechecks, lint and format pass. - Exact-head CI: 64 jobs succeeded. The only failure, test/gateway-restart-handoff.e2e.test.ts (180 s timeout), is inherited. It times out identically on main e04fd21, with six SessionEntryChangedDuringReadError before SIGTERM. That is the separate main regression lane K1 is bisecting. Production +9 LOC. (cherry picked from commit 315380c) Co-authored-by: RomneyDa <[email protected]>
What Problem This Solves
A stalled restart-intent operation could keep SIGTERM in signal settlement until the supervisor cleanup deadline. The settlement timeout then forced exit before ordinary shutdown could persist restart markers or abort active runs. A reversible suspend lease does not seal restart-intent storage; signal storage is sealed by the run loop's close/reset paths.
User Impact
SIGTERM now reaches ordinary graceful shutdown after at most one second waiting for earlier signals, a sealed store, or intent consumption. The shutdown owner can persist resume markers, abort active runs, and perform bounded cleanup. An unavailable intent can lose its optional restart metadata; stopping still proceeds.
Why This Change Was Made
The signal owner bounds its own wait and cancels intent admission. The existing database worker still owns settlement of dispatched native writes, and late results cannot revive a retired signal. SIGINT also keeps its stop request if it times out behind another signal. Existing restart authorization and committed handoff handling remain in their owners.
Worker inspections already cancel on committed drain or service shutdown. The regression extends the existing inspection test through suspend, reopen, and shutdown, including a provider that ignores cancellation. Write-capable provider operations retain their existing settlement owner.
Evidence
The two blocked-intent signal regressions fail on the base (close was never called), then pass with the fix. A real Gateway process, synthetic model stream, real suspend/resume RPCs, and an isolated SQLite writer lock reproduce the stalled consumption. On the base the short-bound fallback never occurs; with the fix the marker is persisted and the process exits successfully in 1.294 seconds on commit
12361a66a6e0262e24fd157101623f9bf8c267e5, below the ten-second acceptance bound.Focused signal ordering, restart-intent, and worker lifetime tests pass. Targeted production, CLI-test, Gateway-test, and e2e typechecks, lint, format, diff whitespace, and both line ratchets pass. Test LOC decreases by one line overall; production changes are net +9 lines, documentation +7. No budgets or baselines change. Fresh isolated review found no actionable P0/P1 defects.
Broader local evidence remains red and is not reported as passing:
No safe OpenClaw temp root, group-writable volume ancestor), followed by a 120-second timeout andA process signal exit owner is already registered. The update-during-close test passes in isolation with the fix.Session entry changed during read, then the expected background reply is absent. The exact-head full file has one pass (new acceptance) and one failure in the same session-setup boundary (expected idle reply absent). This prevents broad replacement/resume acceptance on this host. An exploratory continuation after the new stop case also timed out awaiting the resumed provider request; the new acceptance parameter ends at the requested durable-marker/exit boundary.Full exact-head CI and the merge decision belong to the coordinator; this PR must not auto-merge.
Local commands
Follow-up: daemon CLI restart-intent fixtures
The six
lifecycle.restart-intent.test.tsfailures reproduce on both12361a66and the complete unchanged base5f3afbe. They are caused by the fixture's default installed command returningenvironment: {}after #187901 deliberately stopped inheriting caller state selectors. The tests created their serving owner only in caller-selected state, so intent recording inspected a different isolated database.The fixture now explicitly declares its owned state directory in the installed service command. All 15 daemon restart-intent tests pass with this fixture on both base production and the bounded-signal implementation. Production CLI recording, owner refusals, and SIGTERM cancellation are unchanged by this follow-up. Fresh isolated review found no actionable P0/P1 issues. Total test LOC for this PR is net zero.
Final local validation on
88a8558ac928272768a317bd6abf82fe5457bcefincludes every test file undersrc/cli/daemon-cli/,src/cli/gateway-cli/, andsrc/infra/restart-intent*(68 explicit files). The real-process acceptance passes: marker persisted, exit code 0,shutdownMs=1325. All three targeted test typechecks, lint, format, whitespace and both ratchets pass. Across the exact-head invocations, all 68 requested files were exercised: 67 files passed;run-loop.test.tsretained the same seven baseline failures. Unique per-file case results are 992 passed, seven failed, one skipped. This is an aggregate across invocations, not a passing full-batch result.The shared batch was stopped after its baseline fixture failures leaked the process signal exit owner into later process-owning runtime/timeline tests. The CLI runner shares that process singleton between files; fixture startup waits after registration has already rejected. The remaining six files completed in a fresh process (24 tests passed), and all three runtime-recovery cases also passed together in a separate focused run. The downstream timeouts were not independently rerun on the base; their attribution rests on the baseline-proven owner leak, the matching ownership path, and fresh-process passing results. Timeouts, production custody guards, budgets, and baselines are unchanged.
Follow-up proof artifacts remain in the task worktree:
j1-followup-test-files.txtenumerates all 68 paths;j1-followup-all-tests.command.txtrecords the exact wrapper arguments; the shared-batch, remaining-file, and acceptance logs preserve the results. Full CI remains coordinator-owned.Accepted edge cases and limits
Timed-out restart metadata may be discarded. Already dispatched native writes still settle with the database owner. No new config, schema, retention policy, compatibility path, dependency, or live Gateway mutation is introduced. Historical logs identify the unbounded intent-consumption boundary but cannot identify the exact database job responsible for the incident's long wait.
CI handoff timeout: inherited session-read failure
The
checks-node-changed-7handoff timeout on exact head88a8558ac928272768a317bd6abf82fe5457bcefreproduces on fetched maine04fd211c732b5f3d3e800556bcef1b94ac0864f. Both standard-wrapper Linux arm64 runs usednice -n 5,--maxWorkers=1, separate worker caches, and successful runtime builds. Both finished with one failure at the unchanged 180000 ms timeout (Vitest durations 210.01s and 208.21s).In both runs all six agent turns failed with
SessionEntryChangedDuringReadError: Session entry changed during readbefore SIGTERM. The test waits atprovider.readyfor six held model requests and two exec sessions; restart-intent writing and signaling occur only afterward. The first SIGTERM came from timeout teardown, followed by clean-close receipts within 35ms of the signal fence on head and 30ms on main. This is the same session-read failure signature as the separate restart/resume setup failure, and supplies no evidence of a branch-specific signal/handoff regression.Exact-head CI remains completed red; this is inherited-failure attribution, not a passing handoff proof. The underlying history-read defect and the five-second handoff assertion remain unresolved by these runs. No source change, timeout increase, CI retry, or additional push was made. Full logs and timestamps are preserved in the task's
j1-handoff-classification.mdreport.