Repository navigation
fix: settle native workers in Gateway shutdown ownership order - #188496
Conversation
Cancel pending native snapshot preparations before joining their owner at stop. Keep directory allocation, cleanup, native exit, and accepted write settlement with their existing owners.
|
🦞👀 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. |
|
Codex review: needs maintainer review before merge. What this changesThis PR cancels unfinished native SQLite snapshot preparations before shutdown joins their cleanup. Example: Gateway shutdown begins while a native snapshot copy is stalled.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR fixes a concrete shutdown blocking path still present on current main, with no actionable patch defects found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe snapshot staging owner accepts read preparations and directory allocations, delegates native work, and retains cleanup until requests and temporary directories settle. flowchart TD
A[Gateway shutdown] --> B[Native lifetime owner]
B --> C[Snapshot staging owner]
C --> D[Cancel pending preparations]
D --> E[Native copy child]
E --> F[Join directory cleanup]
F --> B
Technical reviewBest possible solution: Cancel pending disposable preparations through the existing staging owner, then retain normal allocation, cleanup, and accepted-write settlement. Do we have a high-confidence way to reproduce the issue? The current-main shutdown join and existing cancellation channel establish the blocking path, supported by the supplied base-failing native regression; this read-only review ran no target code. Is this the best way to solve the issue? The patch is the smallest complete repair: it requests cancellation before joining and adds no timer, fallback, competing lifecycle owner, or persisted state. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 225af953d1b1. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +10, Tests -1, Docs +3. Total +12 across 3 files. Added test files: 0. View PR surface stats
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 Reviewed October 30, 2026, 12:09 PM ET / 16:09 UTC. |
Use canonical database resource phases and join state close before broker retirement. Remove the competing singleton reset; preserve accepted writes and existing shutdown deadlines.
Keep accepted state lease bindings until canonical resources finish without admitting generic work during drain. Avoid the state-client host-join cycle and retain broker custody on failed cleanup. Unregister the completed one-shot runner fixture resource.
* fix(release): drain shared-state leases before retirement Adapt merged main PR #188496 to the frozen stable broker API. Cancel disposable snapshot reads, fence fresh broker admission, and let canonical shared-state cleanup release accepted leases before retiring actor bindings. (cherry picked from commit 83064b3) Co-authored-by: RomneyDa <[email protected]> * fix(release): restore SQLite build boundary Co-authored-by: RomneyDa <[email protected]> --------- Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: RomneyDa <[email protected]> Co-authored-by: roboclaw-bot <[email protected]>
…ared-state leases (openclaw#188496) Two Team Gateway stops on 2026-10-30 ran to their deadline: at 15:24Z restart.close.global-singleton.openclaw.nativeWorkerLifetimes held 73 s, and at 16:00Z the close stalled with "Shared-state worker is retiring while its actor is in use" until the hard-exit watchdog and systemd SIGKILLed it, which then cost a 111 s database recovery on startup. Snapshot staging shutdown now sends its existing abort to pending native snapshot reads before joining them. Shared-state actor retirement moves into the database lifecycle's after-resources phase so registered resources release their leases first, the competing worker singleton reset is removed, and broker retirement joins canonical state close. Accepted writes and native cleanup still join; no deadlines changed. Close-step tracking for the outer server.close await is a follow-up that needs a run-loop.ts extraction.
|
Is there a maintained published release/backport containing the snapshot-abort and shared-state-owner ordering changes from this PR? I checked the official npm [email protected] archive (registry integrity verified): dist/build-info.json names c0f42f6; the distributed sqlite-snapshot-staging-owner-CqW9sTZt.mjs still joins active preparations without preparation.abort(), and the shared-state owner/broker copies lack the after-resources/beforeSharedStateClose changes. This is executable-artifact inspection, not an inference from merge/publication dates. Current npm tags still point to beta2/latest2026.11.3/extended-stable2026.9.37. We have a long-lived Gateway whose external native-service SIGTERM stop can exceed 330s despite settled inner cleanup logs. I am NOT claiming this PR conclusively explains it: an isolated official-core agent/model/state-worker fixture exits naturally, and Matrix/plugin/long-lived combinations remain under investigation. We are preserving state and update safeguards, not hotpatching or downgrading. A supported published repair target or documented lifecycle workaround would help safely resolve the blocked maintenance path. I also noted the final PR explicitly dropped outer-close observability, so pending-close-steps:none is not being treated as exit proof. Thank you. Nov15 update (public executable artifacts only, no production upgrade): npm now offers core/Matrix2026.11.5-beta.3. Its core tarball passes registry SHA512 integrity; build-info commitc2f4dde2638502fe506e234fb43ac65d8c391072/built2026-11-14T13:59:26.056Z. Manually reading the minified MAIN sqlite-snapshot-staging-owner-aKjz9yAN.mjs, the preparation record still lacks an abort operation and its retained disposer sets closing then joins pending results BEFORE cleanup. Main worker ownerUI8dGdFx and brokerCukTnBL0 remain phase shared-state; the relay bundle has after-resources machinery, which does not establish that main has it. Literal identifier grep alone would be insufficient after minification. Other beta3 final-chat/delivery/memory fixes may still matter; this is not a claim that every possible remedy is absent, or that snapshot disposal conclusively causes our hang. Deployed core remains beta2, safeguards unchanged. Is there a maintained release target or supported live-owner diagnostic/workaround for this main-process ordering path? Nov15 operational discriminator (same beta2, no upgrade/hotpatch): a documented exact-target committed suspension handoff was acknowledged ready/activeCount0 then committed. It passed an identity-free real-systemd fixture with shipped persistent TUI, anonymous loopback model turn, materialized state/workboard and official OTel exporter. On the long-lived real instance, however, the FIRST specific failed span now observed is metadata-retirement: resources remain after its5s grace (5031ms measured rejection, not successful late completion). plugin-metadata/registry reject afterwards; shutdown reports failed in9305ms and skips later close work. While still alive, the kernel reports83FDs/17threads/6worker threads, including two deleted read-only snapshot database+owner pairs and a deleted memory-reindex file. The existing330s native service bound ultimately ended withSIGKILL. We are not treating this as clean exit. Full account/WAL preservation plus native guard inspection allowed safe same-identity recovery; containment remains. A separate identity-free UNIT experiment executes the exact published createStagingOwner function (module SHA256451b7e5050cbbbdf408dea3a193b9a432c5ba882d22530fb03b6823e6c9611a1), with a pending-worker test double that responds to its real MessageChannel abort. Unmodified beta2 retained disposal emits zero aborts and cannot finish until the test externally completes the request. A TEST-ONLY counterfactual retaining preparation.abort and invoking it BEFORE joining active results emits one abort and finishes disposal/pool close without external completion. Installed artifacts are unchanged. This confirms the cancellation dependency in that function, NOT which pending preparation caused the real metadata-retirement failure and NOT a deployed fix. Can a maintained main-process release/backport or supported owner diagnostic be identified for this resource-retirement path? We will not repeat a production stop merely to obtain another330s failure. I can provide the small credential-free unit harness if useful; no crypto identity or state dump is required. |
…es (#200330) * fix(gateway): preserve clean exit while releasing retained state leases Keep cleanup-worker admission open until canonical state lease finalizers finish, while sealing ordinary clients and canceling queued writes immediately. Then close the SQLite host and clear its successful retirement bookkeeping. The retained-lease singleton regression is red on the base; 73 focused tests pass with the fix. A synthetic owner process reproduces exit 1 on the base and 4bce760, and exit 0 with the fix. The current faulty callback ordering comes from 83064b3 (#188496), before the reported release range. Production delta: +3 lines. Codex autoreview: scoped-clean at P0-P2. * style(perf): brace the shutdown measurement abort wait
…es (openclaw#200330) * fix(gateway): preserve clean exit while releasing retained state leases Keep cleanup-worker admission open until canonical state lease finalizers finish, while sealing ordinary clients and canceling queued writes immediately. Then close the SQLite host and clear its successful retirement bookkeeping. The retained-lease singleton regression is red on the base; 73 focused tests pass with the fix. A synthetic owner process reproduces exit 1 on the base and 6199e71, and exit 0 with the fix. The current faulty callback ordering comes from 4807fa9 (openclaw#188496), before the reported release range. Production delta: +3 lines. Codex autoreview: scoped-clean at P0-P2. * style(perf): brace the shutdown measurement abort wait
) Backport 83064b3. Keep accepted writes and native cleanup joined; retire the shared actor only after registered resources release their leases. Co-authored-by: RomneyDa <[email protected]>
…es (#200330) Backport f5d74a5 after #188496. Keep cleanup-worker admission open until retained state lease finalizers finish, then drain the host and discard successful retirement bookkeeping. Regression first: singleton close failed with SQLite worker host is closing, while database close passed. Fixed selected lease, capacity, queued-write, and cleanup checks: 6 passed. Format, staged test-line ratchet, and diff checks passed. Lint/typecheck blocked by linked dependency declaration boundaries. Co-authored-by: RomneyDa <[email protected]>
…es (#200330) * fix(gateway): preserve clean exit while releasing retained state leases Keep cleanup-worker admission open until canonical state lease finalizers finish, while sealing ordinary clients and canceling queued writes immediately. Then close the SQLite host and clear its successful retirement bookkeeping. The retained-lease singleton regression is red on the base; 73 focused tests pass with the fix. A synthetic owner process reproduces exit 1 on the base and 4bce760, and exit 0 with the fix. The current faulty callback ordering comes from 83064b3 (#188496), before the reported release range. Production delta: +3 lines. Codex autoreview: scoped-clean at P0-P2. * style(perf): brace the shutdown measurement abort wait (cherry picked from commit f5d74a5) Co-authored-by: RomneyDa <[email protected]> Release adaptation: none; source change applies to the pinned beta baseline. Follow-up disposition: bounded pinned-main same-path audit recorded in the lane report; cross-lane changes remain parent-owned. (cherry picked from commit afe57940d76947a5931805bce036549abbb6491e)
What Problem This Solves
Fixes Gateway stop retaining unfinished native snapshot reads and retiring shared-state actors before their resource leases settle.
User Impact
Stopping the Gateway cancels disposable snapshot reads and preserves resource and write settlement. Global broker retirement joins canonical shared-state cleanup, whose admission fence refuses fresh leases. Deadlines, configuration, persisted formats, and exit-status policy are unchanged.
Why This Change Was Made
The native-lifetime singleton joins domain owners before the supervisor and broker. Snapshot staging closed admission but awaited its read requests without requesting cancellation. It now sends the existing cancellation message before joining native cleanup; directory allocation still settles normally.
Shared-state retirement also had competing paths: the worker owner closed both as an ordinary database resource and as a separate singleton, while the generic broker independently sealed its clients. The canonical database close now owns resource ordering: shared actors use its existing after-resources phase, the duplicate worker reset is removed, and the broker seals fresh dispatch immediately and joins canonical close before retiring shared actor bindings and native transports. Accepted leases retain their binding until their registered resource releases them; fresh database admission is sealed throughout close. Canonical state client release avoids waiting on the host join that is itself waiting for resource release. Failed cleanup retains broker maps for retry instead of clearing custody.
Follow-up: outer server-close tracking needs a coherent sibling-module extraction of run-loop.ts. Its existing runWithProcessCleanupBudget wrapper propagates the monotonic shutdown deadline through async-local storage to server and service-child cleanup; replacing it with measurement would lose that contract. Adding measurement alongside it grew an already over-cap file from 1273 to 1275 counted lines (cap 700), so the coordinator-directed narrower fix drops that tracking change and its regression. The existing deadlines, coverage, and caps remain intact; pending close steps can still say none while that outer await is held.
The plugin-runtime diagnostic can wrap a later global-singleton timeout; it does not identify a leaking plugin. The first journal also records a separate required session-persistence failure, owned by #188402. The second journal's printed exitCode=0 is an intended outcome, not process exit: retained cleanup and the process lifeline still keep the loop alive, and the hard watchdog can kill it. This PR preserves accepted-write settlement instead of forcing process.exit. The supplied journal cannot uniquely identify every live lease holder or attribute all 73 seconds to snapshot staging.
The existing PluginRuntimeCloseRetainedError classification can treat nested cleanup rejection as retained. Whether to distinguish genuine rejected cleanup from grace-only leftovers is a separate coordinator product decision; this PR leaves that exit-status policy unchanged.
Evidence
Final head
e9bd78d6bb174f7c8ff947f3e1207e4040810c4f: exact-head CI run41095810616 completed successfully. The exact-head watcher returned GREEN with zero pending checks; both required openclaw/ci-gate rows are SUCCESS. Raw rollup retains superseded aliases, which the watcher excludes. No failed job is attributable to the final head.Exact-head CI on 2194bb8 exposed three attributable failures, repaired in the follow-up commit:
checks-node-changed-compact-large-16(partial input staging on global close timed out),checks-node-changed-compact-small-9(capacity waiters slipped through drain), andchecks-node-compact-small-2(one-shot fixture resource was closed twice by sequential canonical/broker drains). The broker now starts its existing admission fence before awaiting canonical close; the fixture unregisters only after successful cleanup, keeping all count and ordering assertions. These were PR regressions, not inherited failures. The failed files plus all affected owner and snapshot suites now pass: 12 files / 117 tests under each runtime (32 unit, 1 tooling, 84 native/process). Targeted state/tooling typechecks and all ratchets also pass. No rerun-only CI recovery was used.A full Node run-loop run passed 155 tests and failed seven: six managed-package setup cases reported “No safe OpenClaw temp root is available”; a later restart-upgrade case timed out with a retained signal owner. The exact failed group reproduces all seven failures and the same signal-owner error with the four affected production owners taken byte-for-byte from main
2eef065f0f89960d0aaebfc64647386715cc9abe(7 failed, 1 passed, 154 skipped). The isolated restart-upgrade case passes on the candidate. These local failures are inherited; no policy or environment guard was bypassed.Focused commands and incident evidence
Supplied production journal, 2026-10-30 UTC, release
5ed4aa23:Additional supplied journal, 2026-10-30 UTC, old release 3c8bd4d, deployment to 562772b: