Repository navigation
improve(sqlite): harden state lifecycle and snapshots - #104859
Conversation
495f344 to
0eddf6f
Compare
|
Codex review: found issues before merge. Reviewed July 11, 2026, 11:30 PM ET / July 12, 2026, 03:30 UTC. Summary PR surface: Source +968, Tests +2013, Docs +46, Generated +3, Other +1. Total +3031 across 36 files. Reproducibility: yes. The source gives a concrete sequence: the runtime reads rows, another process commits an append, and the later unconditional replacement deletes that append. Review metrics: 2 noteworthy metrics.
Stored data model Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Security Review findings
Review detailsBest possible solution: Move Do we have a high-confidence way to reproduce the issue? Yes. The source gives a concrete sequence: the runtime reads rows, another process commits an append, and the later unconditional replacement deletes that append. Is this the best way to solve the issue? No. The snapshot-aware helper is the correct mechanism, but the actual embedded runtime rewrite still bypasses it; migrating that caller is the narrowest maintainable repair. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against c55ea0b45348. Label changesLabel justifications:
Evidence reviewedPR surface: Source +968, Tests +2013, Docs +46, Generated +3, Other +1. Total +3031 across 36 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
Review history (3 earlier review cycles)
|
850d872 to
70a961a
Compare
4fdb609 to
740d338
Compare
740d338 to
c69753b
Compare
|
Land-ready verification is complete for the SQLite lifecycle hardening. Exact final head: Validation:
Known proof gaps:
|
|
Merged via squash.
|
* fix(sqlite): enable bounded vacuum and hot indexes * fix(sqlite): serialize shared schema upgrades * fix(sessions): reject stale transcript rewrites * fix(sqlite): surface busy checkpoints and refresh registry * fix(backup): verify sqlite snapshots * feat(doctor): compact shared sqlite state * test(sqlite): align hardening helpers * fix(backup): respect plugin sqlite ownership * fix(backup): snapshot plugin sqlite opaquely * fix(doctor): reject mixed sqlite actions * fix(backup): reject unsafe sqlite snapshots * fix(sessions): track unconditional transcript replacements * fix(backup): reject page-aligned sqlite truncation * fix(backup): reject state-root case aliases * docs: refresh sqlite maintenance map * fix(sqlite): register doctor compaction boundary * fix(sqlite): serialize fresh database initialization * fix(sqlite): prove main v5 agent upgrade * perf(sqlite): seek latest transcript messages * test(sessions): align terminal freshness fixtures with SQLite * docs: refresh generated map
Closes #104856
Related: #101290
Related: #83712
What Problem This Solves
Resolves SQLite lifecycle gaps where concurrent schema/session activity, busy WAL checkpoints, bloated freelists, or malformed backup contents could cause stale transcript rewrites, hidden checkpoint failures, unverifiable snapshots, deleted-page data in archives, unbounded state database growth, or first-open lock failures.
Why This Change Was Made
This gives OpenClaw-owned SQLite state one explicit lifecycle: bounded incremental-vacuum defaults and hot indexes, serialized schema mutation and first-open initialization, transaction-time transcript revalidation, fail-closed compact backup snapshots, strict archive verification, and an offline
openclaw doctor --state-sqlite compactcommand with integrity proof.The branch reconciles current main's agent schema v5 transcript-watermark migration with the new index migration as schema v6. Released v5 databases and older v4 databases converge on the canonical v6 schema with their persisted transcript state intact.
Plugin-owned databases remain opaque to core schema interpretation and fail closed when owner capabilities are required for a privacy-safe snapshot. Workspace SQLite files remain ordinary workspace backup content; the compact-snapshot guarantee applies to SQLite databases under the state asset.
AI-assisted: implementation and review used Codex. I reviewed the code, migration boundaries, tests, failure modes, and docs; final scoped autoreview reported no accepted/actionable findings.
User Impact
Operators can explicitly compact shared state, inspect reclaimed bytes and integrity results, and trust state backup verification to reject malformed, mis-scoped, sidecar-contaminated, role-mismatched, truncated, or case-aliased SQLite snapshots. Concurrent processes no longer silently erase newly appended transcript events during destructive rewrites, busy WAL checkpoints are surfaced, and concurrent first opens receive bounded lock retry before schema inspection and WAL activation.
Latest-message reads now seek
(session_id, event_type, seq DESC)directly and avoid a temporary ORDER BY B-tree.Evidence
tbx_01kxa5h62fwx4shyccd0gpgv65: 857 focused tests passed across terminal-session admission, transcript rewrite races, lifecycle freshness, state DB, agent DB, query plans, WAL, transactions, and real session-accessor readers; the generated docs map check also passed.tbx_01kxa5h62fwx4shyccd0gpgv65: exact finalpnpm check:changedpassed in 9m37s.cbx_6d80d4150203, runrun_bb49a88c28c9: the same 229 focused tests passed.quick_checkandintegrity_checkreturnedok.admin_required. Native macOS proof was blocked by unavailable Apple/EC2 Mac capacity. Windows sandbox required a Windows host; other sandbox providers lacked the required runtime/warm pool. These are explicit platform gaps, not claimed passes.Residual Runtime Risk
SQLite documents a rare WAL-reset corruption bug affecting WAL databases through 3.51.2 under concurrent writers/checkpointers, fixed in 3.51.3 and selected backports: https://sqlite.org/wal.html#walreset_bug
OpenClaw currently supports older Node releases that can embed affected SQLite versions. This PR hardens OpenClaw's lifecycle and concurrency behavior but does not claim to patch an upstream embedded-runtime defect. A separate compatibility follow-up should decide and propagate the minimum safe Node/SQLite runtime across engines, installers, CI, docs, and release tooling.