Repository navigation
refactor(infra): run core restart sentinel I/O in workers - #163364
Conversation
Move core restart sentinel writes and reads into the shared-state workers, preserve commit admission and revision ownership, and recheck producer and delivery liveness after settlement. Keep installed updater and migration kernels unchanged; no schema or state-format changes.
|
🦞👀 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: needs maintainer review before merge. Reviewed October 2, 2026, 5:49 AM ET / 09:49 UTC (Revision 6). ClawSweeper reviewWhat this changesMoves saved restart-notification reads and writes into existing SQLite workers while preserving config acknowledgement, update handoff, and recovery ordering. Merge readiness✅ Ready for maintainer review The PR remains useful because current main still executes core restart-notification SQL on the calling thread. No actionable introduced defect remains, and the final-head published-driver result resolves the previous proof blocker. Priority: P2 Review scores
Verification
How this fits togetherRestart notifications preserve config, chat-restart, and update outcomes across Gateway restarts. Producers save them in shared SQLite state; startup recovery consumes them after recording durable notification and continuation work. flowchart TD
A[Config and restart requests] --> C[Restart notification owner]
B[Update campaigns] --> C
C --> D[Worker admission and revision checks]
D --> E[Shared SQLite state]
E --> F[Startup recovery]
F --> G[Durable notices and continuations]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +197, Tests +568. Total +765 across 27 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep one sentinel kernel behind the existing workers, preserving revision ownership, live producer admission, durable settlement, and installed-updater compatibility. Do we have a high-confidence way to reproduce the issue? Yes, by source inspection: current main directly executes synchronous sentinel SQL inside promise-returning APIs. The supplied boundary regression records the before-fix failure; this read-only review did not execute it. Is this the best way to solve the issue? Yes. Extending the existing writer and read-worker registries preserves the authoritative kernel and avoids introducing a competing storage owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against aa31aeefb745. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (5 earlier review cycles)
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
…63364) * refactor(infra): run restart sentinel operations in workers Move core restart sentinel writes and reads into the shared-state workers, preserve commit admission and revision ownership, and recheck producer and delivery liveness after settlement. Keep installed updater and migration kernels unchanged; no schema or state-format changes. * test(infra): retain real logger methods in sentinel fixture * fix(infra): fence campaign sentinel writes at commit admission * test(infra): adapt sentinel consumers to worker completion
Related: #162446
What Problem This Solves
Core restart-sentinel APIs returned promises while executing SQLite on the Gateway thread during config acknowledgements, chat restarts, update handoff, and post-readiness recovery. This is a maintainer-requested cutover to the existing async storage boundary.
Why This Change Was Made
Core writes now use typed handler-table operations in the shared-state writer registry. Current-row, revision-snapshot, and install-receipt reads extend the existing typed read-only worker registry alongside diagnostic reads. The broker and connection lifecycle remain unchanged.
The existing synchronous kernel still owns atomic
current/revision-floorupdates and guarded deletion. Named failure/finalization operations replace the private callback rewrite path. Finalization retains its original database admission across reads and root discovery, and verifies the revision again before updating the notification and install receipt in one transaction. Producer authority is checked at transaction and commit admission. Callers recheck campaign or shutdown ownership after awaited settlement.User Impact
The Gateway awaits core sentinel I/O in workers. Config acknowledgement, chat restart, and managed update transfer retain their persistence ordering. A retired campaign cannot publish or clear its successor, and stopped recovery leaves durable delivery work queued.
Inventory measured with
node scripts/database-worker-inventory.mjs --jsonon pinned base212a6b81d58d01624e787b097db01bb6bb5ef58cand the candidate:src/infra/restart-sentinel.tssrc/infra/restart-sentinel-store.tsAll eleven selected core sites execute through worker paths. The five kernel sites remain classified as mixed: the shared row reader also serves the excluded update-report receipt workflow, migrations, and the sealed updater helper. No inventory classification or generated inventory document was changed. The new writer module has one W transaction site.
Production TypeScript delta against merged main
a6dce59e1ca97363636bf9342e05af1bf643be09: +412 / -215 / net +197 across this lane, excluding tests and test support. The increase supplies typed dispatch, worker admission, and read routing; the host rewrite implementation is removed. The PR changes 27 files.Evidence
The boundary regression failed on the pinned base with
caller-thread SQLatwriteRestartSentinel. It now passes while host database-open and transaction functions throw, exercising actual worker persistence, reads, and consumption. It also proves existing-only reads do not create a database.239 focused tests passed. New coverage includes live revocation at transaction and commit admission, consumed revision floors, database-target preservation, deferred config acknowledgement, replacement campaigns, and shutdown during sentinel consumption. Existing coverage proves newer acknowledgements survive cancellation, update handoff waits for persistence, and legacy reader dispatch remains synchronous.
Each row ran with
OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS=1800000 pnpm test <file> --maxWorkers=1:src/infra/restart-sentinel.update-result.test.tssrc/infra/restart-sentinel.test.tssrc/infra/restart-sentinel-format.test.tssrc/infra/update-startup-campaign-run.test.tssrc/gateway/server-methods/config.shared-auth.test.tssrc/gateway/server-methods/update-run-campaign.test.tssrc/gateway/server-restart-sentinel.state-context.test.tsThe unchanged sibling files below passed 62 tests in 660.32 s total:
OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS=1800000 pnpm test \ src/auto-reply/reply/commands-session-restart.test.ts \ src/gateway/server-methods/update-handoff-failure.test.ts \ src/gateway/server-startup-restart-sentinel.test.ts \ src/state/openclaw-state-read.worker.test.ts \ src/state/openclaw-state-read.quarantine-cleanup.test.ts \ src/state/openclaw-state-db-read-connection.cache.test.ts --maxWorkers=1Wall times include worker-cache validation and transformation on a heavily loaded host. Persistence fixtures reuse suite-level workers; separate database lifetimes remain where physical identity, migration custody, shutdown, and durable delivery ownership are the contract under test. Those lifecycle suites require real workers and SQLite. Formatting assertions were moved unchanged into their own file. CI seconds are not available yet.
Additional validation:
node scripts/check-changed.mjs --base a4ad0b67b100308b25dae459f79b52d8b40fbdc5— passed, including core typechecking, all 27 test-typecheck shards, core/script lint, export scans, and repository guards.pnpm build qaRuntime— passed; this is the Gateway setup's supported runtime build. A full release declaration build was stopped before switching to this profile.pnpm check:database-worker-ratchet --base 212a6b81d58d01624e787b097db01bb6bb5ef58c— passed.pnpm check:madge-import-cycles— zero cycles; runtime import-cycle guard also passed.node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.infra.json --incrementaland targetednode scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json src/infra/restart-sentinel.test.ts— passed after the logger-fixture correction.git diff --check— passed.Initial validation exposed a combined-contract import cycle, lazy ledger setup missing from the reused fixture, a threaded test lane without the host broker, and an incomplete logger mock. These were corrected. Worker compilation also correctly refused concurrent build/lint namespace changes; final behavioral validation ran serially after those operations completed. The initial implementation validation used isolated tests; published-driver update proof is recorded below.
Landing repairs and validation
Final candidate:
71f9b49e869dc27e29e5c5bdd5a7adce1225176a. Behavior proof, P2 review, targeted lint, affected typechecks, and repository guards passed. The final-head published-driver update cell passed. CI retains one independently reproduced main failure, recorded below for the explicitly approved native admin exception.The P2 branch review and ClawSweeper both identified the same durable campaign race: a foreground update could retire while its worker write was queued, leaving a stale notification despite suppressing the in-memory publication.
update.runnow passes current campaign authority into the existing transaction and commit admission checks. Real-worker regressions failed on the prior implementation at both boundaries and pass with the guard; an existing positive campaign case also verifies the actual persisted row. Fresh Codex review of the repairs is scoped-clean through P2.CI run 36978870518 exposed three PR-caused test integration failures. The two CLI sentinel consumers needed the existing forked host-broker lane. A real persistence case needed to move out of the deliberately worker-free startup suite. The startup update suite assumed a fake-timer tick completed worker-backed install discovery; its early assertion left a deferred probe unreleased and stalled cleanup. That suite now awaits the existing injected scheduler clock and explicit operation-entry signals, preserving real persistence and all assertions. Its unchanged mock setup moved into a sibling support module to satisfy the line-count ratchet.
Repair validation (overlapping runs, not additive coverage):
--maxWorkers=1, including the CLI consumers, worker-free startup, sentinel startup, campaign RPC, and both core sentinel suites.update-failure-report-transport,update-run-reader,update-startup): 92 tests passed, 292.09 s wall with the original concurrency.update-startup.test.ts --maxWorkers=1: 55 tests passed, 333.40 s wall, including 106.85 s compiled-worker preparation. The lifecycle suite retains real workers because cancellation, durable receipts, and post-settlement publication are its contracts.The moved startup-sentinel file passed 4 cases (9.61 s summed case time), the retained worker-free startup file passed 84 (25.84 s), and the campaign file passed 30 (59.95 s) before its positive persistence strengthening. These case totals are distinct from invocation wall time above. Per-file CI timing artifacts are not published; the local case and wall measurements are above, and the final update-cell duration is recorded below.
Main was integrated with a merge commit after a real routing-map conflict; both independent watch mappings were retained. This includes upstream Windows declaration-fixture fix
0a188c4f038f05a04af5d9cac2f0695c54cd229e. Its missingrecord-coerceexport failure was independently observed in main run 36979748808, before any sentinel code was reached. The repaired branch also exposed 17 mechanical startup-fixture lint errors; all were corrected and targeted typed lint passed.The merged dispatcher crossed the local 700-line lint limit. Its existing journal status and authority branches now use the existing registry-read helper, retaining the same admitted database and unchanged kernels. This move adds no production lines overall and changes no schema, authority, or transaction contract. Post-merge proof passed 107 tests in 215.44 s across sentinel, campaign, restart-recovery, and read-worker suites. The dispatch move passed 36 existing journal/read-worker tests in 64.62 s. Core typechecking, affected test-type graphs, targeted core/script lint, and the runtime import-cycle check passed. Before integration, all 27 test-type graphs and the pre-lint changed-file guards completed successfully; the broad lint invocation was stopped after CI identified the now-corrected fixture errors.
A second real conflict arose when main landed the diagnostic and config worker migrations. Integration now extends main's
stateReadRegistrywith sentinel operations, carries both read result/command contracts, and retains all writer and test registrations. The branch-privateprepareRegisteredStateReadbridge was removed. The final composition passed 60 tests across sentinel, diagnostic, config-snapshot, and legacy read-worker suites in 107.18 s, targeted typed lint, core typechecking, a zero-cycle import check, and fresh P2 review. No schemas, persistence bytes, or authority checks changed during integration.The intermediate repaired head
9f99d108also passed the selected published-driver update cell (job 110766741312, 429 s): published 2026.9.7, updater exit 0, durable run succeeded/finished, readiness 200, correct serving version, and cleanup exit 0. This remains prior-head evidence after integration.The original head's selected published-driver update cell passed using published 2026.9.7: managed update exit 0, durable run succeeded/finished, replacement service readiness 200, serving version verified, and service cleanup exit 0. This is prior-head evidence; the final-head result is recorded below.
Final-head update proof and inherited CI failure
The selected published-driver update cell passed on head
71f9b49e869dc27e29e5c5bdd5a7adce1225176a. Published 2026.9.7 performed a managed update to CI merge candidatebbb65251f83bf7988fb184ab94b9c2bbf6e26caa(package SHA-2562d6cda79fc8f1fe06070700b322982b4b5db3fa2a55b01a7d71953f3bdecadb5). The updater exited 0 in 556.002 s; durable completion was succeeded/finished, managed service replacement passed, readiness returned 200, the serving version matched, and cleanup exited 0. The complete cell took 661 s, including a 612 s update step.CI attempt 1 has one failed leaf: Windows Node shard 3. The source and compiled TUI provider-hook cases in
test/scripts/vitest-worker-artifacts.test.tsstill expect the old authentication-error sentence after main'sd0b48d63efb88ac4f9f5eb447a39ea95cb2b0542changed that wording. A clean checkout of the exact tested main parent5ec7d7f3b0ce443563d0e1e6f2c4122c3b6aac75, with its own frozen dependency install, reproduced both identical failures using the existing tests (2 failed, 33 skipped, 66.42 s wall). The assertion executes before provider preparation or any sentinel/SQLite flow. All 13 causal fixture/formatter inputs are byte-identical between that main parent and the tested PR merge, and were unchanged in checked main0614328f729e36addaaa02d72d114054ca6c9a27.The remaining selected CI jobs, including security-fast, passed; no jobs were cancelled. The aggregate CI gate failed only because of that Windows leaf. Native landing retained this failure and the independent main proof under the explicitly authorized pre-existing-failure exception; it is not reported as green CI. No workflow rerun was requested.
Compatibility Retained
No public SDK API changed and no async/sync aliases were added. No exports were deleted; the private
rewriteRestartSentinelcallback path was removed.readRestartSentinelRowSync,readRestartSentinelSnapshotSync, andwriteRestartSentinelRowSyncremain available to the legacy migration/maintenance owner.readRestartSentinelRowSyncandwriteRestartSentinelRowIfRevisionSyncretain the sealed updater-helper subprocess contract.readRestartSentinelRowForKeySyncremains shared with the excluded update-failure-report receipt owner. That owner's runtime SQL is remaining debt, not a new compatibility exception.Update Behavior
No schema version, state format, retention, durability, config, or permission change. Existing sentinel keys, typed columns, payload bytes, revision-floor semantics, and install receipts are preserved. Installed drivers and the sealed helper keep their native contracts; old drivers are unaffected. The frozen released 2026.9.4 recovery-reader cases pass. Candidate-side callers still await accepted persistence before acknowledgement, restart emission, or handoff.
Overlap Census
No competing core sentinel worker cutover was found. Adjacent #144764, #121050, and #161513 affect untouched config-producer, test, migration, or report-receipt files. Main's #162874 update-target validation cleanup was merged without conflicts; its hunks are separate from sentinel persistence.
Merged through the native workflow as
d8b18a62a3c61adb4247064f2ad93d6ea8d9df54. The retained parent audit records intervening main movement fromaa31aeefb745aba23a8393ea50ddb26251132c31to actual parentca0159f1c2ea5087df217430fc608815268ea180; the native workflow verified the exact attempted head and retained its qualified CI result.