Repository navigation
fix(sqlite): prevent WAL split-brain cleanup corruption - #132844
Conversation
Co-authored-by: Vito Cappello <[email protected]>
Worked on by: - @VACInc Co-authored-by: VACInc <[email protected]> OpenClaw-Publication: 3e783eee-3a6a-40ed-95ec-29a64b9b5f73
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 29, 2026, 4:39 PM ET / 20:39 UTC. ClawSweeper reviewWhat this changesThe PR replaces stale SQLite-handle cleanup after a Linux WAL/SHM identity mismatch with a fatal process stop, preserving the replacement database family for a clean restart. Warning SQLite table change This PR modifies persisted SQLite tables in Regression provenancePossible regression — probable (reviewed change; failure trace). No predecessor PR is attributed. Merge readinessThis PR remains necessary: current main still closes the stale SQLite handle after a verified WAL-sidecar mismatch. The introduced fail-stop path removes that cleanup route and is technically coherent, but its process-wide restart behavior needs maintainer acceptance before merge. Priority: P0 Review scores
Verification
How this fits togetherSQLite WAL maintenance periodically compares an open database connection’s sidecar descriptors with the directory-visible files. It protects the Gateway shared-state database and other timed, path-backed SQLite owners before checkpointing or orderly cleanup can run. flowchart LR
A[Open SQLite connection] --> B[WAL maintenance timer]
B --> C[Descriptor and sidecar identity check]
C -->|Match| D[Checkpoint maintenance]
C -->|Mismatch| E[Fatal diagnostic]
E --> F[Immediate process stop]
F --> G[Supervisor restart]
G --> H[Directory-visible database family]
Decision needed
Why: The patch removes a data-corruption path, but it intentionally changes the operator-visible outcome to a fatal restart for a generic persistence helper. Before merge
Agent review detailsSecurityNone. PR surfaceSource -1, Tests +96. Total +95 across 5 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Adopt one fail-stop invariant for verified sidecar mismatches, with maintainer-confirmed process-wide restart semantics instead of any stale-handle cleanup path. Do we have a high-confidence way to reproduce the issue? Yes: the Linux child-process regression creates the stale and replacement WAL families in the relevant order and distinguishes the old orderly-close behavior from fatal containment. It was inspected but not executed in this read-only review. Is this the best way to solve the issue? Yes, contingent on maintainer acceptance of the process-wide restart policy: terminating before SQLite cleanup is the narrowest source-backed way to preserve the verified mismatch invariant. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against f9b3bcccdba3. LabelsLabel 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
|
|
ClawSweeper follow-up:
This applies the sole Rank-up move. No merge or automerge is requested. |
|
Additional P0 clean-host sanity proof (no code changes):
This exercised real Linux processes and real SQLite files: stale writer A retained the detached WAL family, replacement writer B committed through the directory-visible family, A received the production self- The clean host reported a running systemd user manager. I did not install or mutate a service for this proof; supervisor behavior remains owned by OpenClaw's generated |
|
Land-ready verification for exact head
Observed behavior: stale writer A self-terminated without SQLite cleanup, replacement writer B remained authoritative, and a fresh reopen returned |
|
Merged via squash.
|
) * fix(sqlite): fail-stop on WAL split brain Co-authored-by: Vito Cappello <[email protected]> * fix(sqlite): prevent WAL split-brain cleanup corruption Worked on by: - @VACInc Co-authored-by: VACInc <[email protected]> OpenClaw-Publication: 3e783eee-3a6a-40ed-95ec-29a64b9b5f73 --------- Co-authored-by: roboclaw-bot <[email protected]> Co-authored-by: Vito Cappello <[email protected]> Co-authored-by: VACInc <[email protected]>
Closes #132363
What Problem This Solves
Fixes an issue where a Linux Gateway that detected a replaced SQLite WAL/SHM family would close its stale connection, allowing SQLite's last-close cleanup to checkpoint stale pages into the main database or remove the replacement sidecars.
Why This Change Was Made
A verified descriptor/path identity mismatch is now a terminal process boundary. OpenClaw writes a synchronous fatal diagnostic containing the sidecar identity details, then self-terminates with
SIGKILLso Node exit hooks and SQLite destructors cannot run. The managed service supervisor can restart a clean process against the directory-visible database family.The obsolete callback-driven cache eviction path is removed. No schema, protocol, configuration, retry, or timeout surface changes.
User Impact
Operators get a brief, explicit Gateway restart instead of risking persistent shared-state corruption and offline database reconstruction. A repeated external sidecar replacement remains visible as a restart loop requiring investigation rather than silently damaging data.
Evidence
main: all four WAL/SHM unlink-or-replacement containment cases failed because the process did not hard-stop; the process-level replacement-family test observed the stale connection closing.node scripts/run-vitest.mjs src/infra/sqlite-wal.test.ts— 53 passed.node scripts/run-vitest.mjs src/state/openclaw-state-db.test.ts— 177 passed.node scripts/check-changed.mjs -- src/infra/sqlite-wal.ts src/infra/sqlite-wal.test.ts src/state/openclaw-state-db-open.ts src/state/openclaw-state-db.ts src/state/openclaw-state-db.test.ts— passed.PRAGMA integrity_check = okwith exactly the authoritative rows.AI-assisted; implementation and lifecycle behavior reviewed and understood.
Worked on by
View the OpenClaw team session