Repository navigation
refactor(sqlite): centralize WAL checkpoint execution - #157263
Conversation
|
Codex review: blocked before merge. Reviewed September 24, 2026, 10:08 AM ET / 14:08 UTC (Revision 4). ClawSweeper reviewWhat this changesThe branch routes runtime and offline SQLite WAL checkpoints through one owner, shares numeric result decoding, and documents that ownership boundary. Merge readiness⛔ Blocked before merge - 3 items remain Current main and the latest release still split checkpoint execution, so this PR remains useful. The pinned patch has no identified correctness defect and fixes the prior SQLite guard finding. The published-updater compatibility proof requested in the prior review remains outstanding. Priority: P3 Review scores
Verification
How this fits togetherOpenClaw uses SQLite write-ahead logs for state databases. Runtime maintenance and offline Doctor or recovery operations checkpoint those logs, then use the result for health reporting or to decide whether offline work may proceed. flowchart LR
A[SQLite state database] --> B[Runtime maintenance]
A --> C[Doctor and recovery]
B --> D[WAL checkpoint owner]
C --> D
D --> E{Checkpoint result}
E --> F[Health status]
E --> G[Proceed or refuse offline work]
Before merge
Agent review detailsSecurityNone. PR surfaceSource -2, Docs +7, Other 0. Total +5 across 7 files. View PR surface stats
Review metricsNone. Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep one SQLite checkpoint execution owner while demonstrating that a shipped updater can activate the candidate and preserve Doctor compaction and duplicate recovery on copied existing state. Do we have a high-confidence way to reproduce the issue? Not applicable: this is an internal ownership refactor. The captured live comparison and existing SQLite entry-point tests address behavioral parity rather than a reported failing bug. Is this the best way to solve the issue? Yes: the existing WAL checkpoint owner is the narrowest home for native checkpoint execution, and the changed callers retain their admission and busy-refusal decisions. The shipped-updater upgrade boundary still needs proof. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 89f9250feaf7. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
b315890 to
15194f8
Compare
15194f8 to
1fce6cc
Compare
|
Merged via squash.
|
* commit '9ccfc7d1bea21e34da48edbd54afd2e1be57db40': (89 commits) fix(exec): avoid gateway stalls during background task writes (#157177) test(cli): isolate preaction title setter state fix(test): synchronize Git backoff cancellation readiness (#157315) fix: validate Codex model references in Docker (#157175) fix(state): tolerate brief WAL coordinator contention (#157121) fix: unblock conversations after recovery preparation fails (#157214) test(telegram): avoid wall-clock pacing in HTTP conformance (#157281) fix: keep independent database work responsive under load (#157230) refactor(sqlite): centralize WAL checkpoint execution (#157263) improve(android): show tool outcomes in collapsed work (#156950) fix: remove tracked release scratch blocking source capture (#157308) test(update): remove legacy probe stream ordering race fix: preserve steering across reconnects and show queued input (#157135) fix(ui): keep typing focus when the GitHub reader opens (#157202) fix(ios): keep screenshot logs outside capture evidence test(codex): await startup teardown in lifecycle fixtures chore(ui): refresh control ui locales (#157311) refactor(memory): deslop memory plugins (#156867) refactor(test): share CLI diagnostics fixture setup (#157201) fix(release): retry notarization submit/wait on transport failures and name the resume command (#157116) ...
WAL checkpoint execution was split between runtime maintenance and Doctor, and duplicate-agent recovery imported its engine operation from the command layer. Centralize native checkpoint execution in the existing sqlite-wal-checkpoint owner. Runtime maintenance retains its admission, health observations, partial-checkpoint reporting, and reader diagnostics. Doctor compaction and duplicate-agent recovery retain strict busy-truncation refusal and their surrounding integrity and authority checks. Remove the Doctor-owned checkpoint export, the recovery layer's reverse import, caller-side checkpoint execution, and the duplicate finite-number parser. The read cache keeps its separate version-gated NOOP freshness probe. This is an internal ownership change. Stored formats, schemas, retention, durability, configuration, SDK contracts, and update behavior are unchanged; existing installations need no migration or operator action.
What Problem This Solves
WAL checkpoint execution is split between runtime maintenance and Doctor, and duplicate-agent recovery imports its engine operation from the command layer. This is the bounded checkpoint-ownership slice of the maintainer-requested storage cleanup.
User Impact
No user-visible behavior changes. Runtime checkpoints preserve partial completion, health observations, errors, reader diagnostics, and maintenance admission. Offline compaction and duplicate recovery still refuse a busy TRUNCATE checkpoint before proceeding.
Existing installations require no configuration changes, migration, schema bump, or operator action on update. Stored bytes, schemas, retention, durability, file identity, authority rechecks, FIFO ordering, uncertain-outcome handling, and MessagePort fences are unchanged. No plugin SDK or public API surface changes.
Why This Change Was Made
The existing
sqlite-wal-checkpoint.tsowner now executes native checkpoints as well as interpreting their outcomes. Its retained runtime owner holds the supplied connection; Doctor and duplicate-agent recovery call its strict offline truncation operation. Callers retain connection lifetime, thread selection, maintenance custody, and transaction boundaries. This introduces no new main-thread database access or asynchronous transaction callback.Deleted the command-owned
checkpointDoctorSqliteFileexport, the migration layer's reverse import from Doctor, caller-side runtime checkpoint execution/error handling, and redundant result assertions. The existing SQLite numeric module now owns the finite-number decoder shared by offline checkpoint and compaction reads. Runtime's stricter three-column decoder remains distinct. The version-gatedNOOPfreshness probe stays with the read cache; it does not perform checkpoint maintenance.Production LOC: +49 / -51 / net -2. Tests: +0 / -0 / net 0. Docs: +7 / -0 / net +7. Assertion-safety baseline maintenance: +1 / -1 / net 0 (exact shrink from 3 to 1).
The broader identity cut was deliberately deferred: current physical identity coalesces aliases, binds first creation, detects replacement, and fences delayed receipts with an incarnation. Role plus agent ID alone cannot replace those relationships. Active broker/admission work also overlaps that cut. Current native backup, vector loading, and WAL policy already have specialized owners; a new aggregate facade would not remove competing ownership.
Evidence
Remote proof uses Blacksmith Testbox lease
tbx_01m39ar17z70c3z6sbgf2n3gkm, run 35979386538. No tests, builds, typechecks, or Gateway processes ran on the local machine.pnpm test src/infra/sqlite-wal src/infra/sqlite-number src/infra/state-migrations.agent-owner-recovery.test.ts src/commands/doctor-sqlite-compact.test.ts src/commands/doctor-state-sqlite-compact.test.ts src/commands/doctor-database-preflight.test.ts src/commands/doctor-state-migrations.test.ts src/state/openclaw-database-preflight --maxWorkers=1— four Vitest shards passed in 276.46 seconds. Dependencies were installed withpnpm install --frozen-lockfilefirst, and synchronized source hashes were verified.node scripts/check-changed.mjs --base d4748c6cc48f6c51ca391df123d1e5fb15418761passed, including all 25 core-test typecheck groups, lint, dead-export and storage guards.pnpm docs:check-linkschecked 14,555 internal links with zero broken links. The runtime-tested checkpoint source, before the final guard annotation, has SHA-2569f9849ca39475d6a5ff0a41e3964f9a26a0e54f2408eb2a7ce6858757199f193; the later rebase did not change any touched SQLite owner.pnpm buildruns passed on Node 24.19.0: baselineaeb32f35468d556c909fbacff3aca550cb01cdd9in 19m 55.6s; candidate00cdc251478b729f4e34bf27d188ab29024c0260in 15m 34.4s. Both reported the same existing Control UI budget warnings (startup JS 363.0 KiB vs 362.6; isolated Mermaid 1555.8 KiB vs 960.0).exact; integrity wasok. No model inference or real user state was involved. The original lease completed during the baseline build, after the tests and changed-file gate had passed. Remaining build/live proof uses replacement Blacksmith leasetbx_01m39hvc7rmajd16tw9k3rsjmk, run 35991648641, with fresh exact checkouts.wal_checkpointexecution is confined to the checkpoint owner; the read cache retains only itsNOOPobservation.this: voidcallback declarations, and the statement-scoped checkpoint-primitive annotation). OAuth attempts failed withrefresh_token_reused; the requested configured direct-API route completed the review.The first changed-file gate required shrinking the assertion-safety baseline after removing casts; that bookkeeping is included. The next gate found two unbound-method declarations; explicit
this: voiddeclarations fixed them, targeted lint passed, and the complete gate then passed. Raw Testbox sync retained stale Git metadata after local rebase, so final gates use exact baseline/candidate worktrees materialized from a Git bundle on the same lease. The local wrapper could not run against the available dependency installation. After a later Testbox bulk-sync timeout, commands used the same owned Testbox SSH route and verified task-only checkouts; neither source trust nor provider changed.The first live probe reached successful baseline backup/restore, integrity, preflight, and restart readback, plus fresh and copied-state candidate boots. Its eight-call candidate burst completed before the shutdown-overlap assertion. All calls succeeded; the probe was corrected to maintain bounded queued load, with the original overlap and acknowledgement assertions retained, then both revisions were rerun.
The live entry points were
pnpm openclaw gateway run --bind loopback --port <isolated-port> --auth token,gateway callforhealth,agents.list,sessions.create,sessions.patch,sessions.list,chat.inject, andchat.history, followed bybackup sqlite create --global/--agent main --repository <private-repository> --json,backup sqlite verify <snapshot> --json,backup sqlite restore <snapshot> --target <fresh-file> --json,database preflight <restored-global> --json,database preflight-agent <restored-agent> --agent-id main --json, anddoctor --state-sqlite compact --json. A task-owned process group joined every Gateway exit before copying or activating restored files. The same stored session ID and complete synthetic message objects were compared on every replay.After the final rebase, the complete live comparison was repeated on the exact published head
15194f898f5853b67b899b017f8422cce9d2ed92against its main baselinef60ad5926e2da357c942f64d4912e741b699c1b3. The supportedpnpm openclaw --versionwrapper built fresh CLI runtime artifacts in 1m 14.6s (baseline) and 1m 35.2s (candidate). Both fresh/copied-state boots, restart readbacks, global/agent snapshot round-trips, integrity checks, andexactpreflights passed again. Each revision retained all four acknowledged writes with 23 outstanding calls at shutdown and 20 expected interrupted reads. This final proof includes the newly landed SQLite rollback change. Hosted CI is attached to head15194f898f5853b67b899b017f8422cce9d2ed92in run 36003761008, completed successfully: 163 jobs, no failures, and requiredopenclaw/ci-gatechecks are successful. GitHub initially created only a zero-jobBuildFailed/startup_failureplaceholder; one close/reopen after confirming mergeability regenerated attachment. The earlier attached run found that the relocated checkpoint statement needed its raw-SQLite primitive annotation. The annotation is bound to that exact call; no file-wide allowance or runtime behavior changed.That earlier CI run also reported an execution-budget timeout in
run-attempt.computer-use.test.ts(completed case; 10.013s elapsed). The fixture's five-second budget starts before connection preparation. On Blacksmith leasetbx_01m39qp7djp8mbepf1za68zw1k(run 36002055640), the exact failing merge382eb95516356de3189ebcd528d20092b23bef29was replayed throughnode --import tsx scripts/ci-run-node-test-shard.mts, using the original ordered 12-file group,OPENCLAW_VITEST_MAX_WORKERS=2, and the same forks/isolation policy: 111/111 tests passed in 130.73s wall. The same file alone passed 2/2 tests in 43.21s wall. No assertions, deadlines, or fixtures were changed.pnpm check:architecturethen passed on the pushed15194f898f5853b67b899b017f8422cce9d2ed92head, including the Kysely guard; hosted CI independently passed the same architecture job. These replays establish non-reproduction, not a fix; the original timeout's cause remains unproven. Correlation and terminal-notification shape were also checked against the sibling Codex source.Follow-ups
All three task-owned Blacksmith leases are confirmed completed/stopped. The branch is clean and pushed. Non-required PR-context/auto-response automation was still queued at closeout; no required checks are pending. This PR remains open and ready for coordinator review, with auto-merge disabled; it has not been merged.