Repository navigation
fix: allow database rollback after WAL checkpoints - #162599
Conversation
Compare committed database pages and retained WAL commit evidence so exclusive Windows removal probes can checkpoint already-captured frames without blocking package restoration. Preserve later-data and database replacement refusals; accept exact reversals with unchanged bytes and write evidence because they leave no later data to discard.
Remove the in-process snapshot substitute and its path bookkeeping. Raw descriptor closes can drop live SQLite POSIX locks, and the substitute also ignored content-version mode. Keep actual isolated snapshot and content-version worker dispatch in the update command fixtures.
|
🦞👀 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: blocked before merge. Reviewed October 1, 2026, 6:05 AM ET / 10:05 UTC (Revision 2). ClawSweeper reviewWhat this changesThe PR compares committed SQLite content when deciding whether rollback is safe, adds checkpoint regressions, and restores isolated snapshot workers in update test fixtures. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readiness⛔ Blocked before merge - 4 items remain This repair remains necessary, but the prior published-updater compatibility finding is still unfixed. Current main retains the checkpoint-sensitive comparison. Likely related people: steipete (high-confidence routing from merged rollback work). Priority: P1 Review scores
Verification
How this fits togetherThe updater snapshots databases before candidate migrations. Database generation receipts determine whether a failed update can restore those snapshots and then recover the previous package. flowchart TD
A[Installed updater] --> B[Database snapshots and receipts]
B --> C[Candidate Doctor]
C --> D[Compare database generations]
D --> E[Restore databases and package]
D --> F[Preserve state for manual recovery]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +33, Tests +26, Docs +6. Total +65 across 7 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Keep checkpoint-tolerant comparison in the existing generation owner while preserving released receipt semantics and proving safe recovery across the upgrade boundary. Do we have a high-confidence way to reproduce the issue? Yes, from source: a v2026.9.7 updater supplies physical-generation hashes to candidate Doctor, whose changed hash computation makes the direct comparison fail. This review did not execute that upgrade. Is this the best way to solve the issue? No, the shared generation-owner repair is appropriate, but changing its receipt dialect without preserving released callers breaks the upgrade contract. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 564cefeeccef. LabelsLabel changes: No label changes. Label justifications:
EvidenceAcceptance criteria:
What 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 (1 earlier review cycle)
|
|
Landed (squash |
…162599) The update database generation check compared physical fingerprints, so a SQLite checkpoint that merely folded already-captured WAL frames into the main file (on Windows, triggered by the exclusive removal probe) was treated as a later write and rollback was refused with "Databases changed after snapshot capture"; the Windows lifecycle test failed in isolation. The check now compares committed pages plus retained WAL commit evidence: checkpoint-only transitions and exact reversals that leave byte-identical content are admitted (identical content cannot lose data on restore; recorded at the comparer with a regression), while any newer data is still refused. The fixture's unsafe in-process snapshot mock is removed. Refs openclaw#158163
What Problem This Solves
Fixes database and package rollback being refused when SQLite checkpoints already-captured WAL pages during Windows file-removal admission.
Related: #158163. Reproduces the failure reported by hourly run 36827062752.
User Impact
An interrupted update can restore its previous package after a checkpoint-only transition. Newer committed data, database replacement, and changed retained write evidence still refuse restoration. An exact reversal leaving committed bytes and retained write evidence identical is intentionally admitted: it leaves no later data for rollback to discard.
No schema, dependency, configuration, CLI, or service-lifecycle change is included. Auto-merge is off.
Why This Change Was Made
The snapshot/restore owner previously hashed physical database/WAL layout. The Windows exclusive-removal probe uses SQLite's private WAL index; closing it folds the WAL into the main file and can delete the WAL while leaving disk SHM unchanged. The old guard classified that checkpoint as an intervening write and refused database restoration before package restoration began.
The probe remains unchanged because Windows requires its native handle to close before files can be replaced. It is the checkpoint trigger in this reproduced flow; the shared generation owner also needs to tolerate ordinary checkpoints.
The generation owner now checkpoints a verified private copy and hashes committed pages with the original file identity and retained WAL transaction counter/last-frame checksum. SQLite interprets journals and WAL frames. Physical-generation and SHM publication checks still fence capture.
The command fixture incorrectly replaced the isolated snapshot worker with raw in-process copies while native SQLite handles remained live. Closing those descriptors can release SQLite's process-wide POSIX locks. Removing that substitute restores real snapshot/content-version dispatch and deletes its path bookkeeping.
Order dependence
On baseline
40d9ed0924dafa3ef1bf8cf604679e79aa33a3e4, the interruption case fails alone but passes after the complete eleven-case prefix, ending withsettles native Windows task enabled state after update finalization (none). The passing full run captures an empty WAL; isolation captures four frames (16,512 bytes), which the removal probe later checkpoints. Neither selector alone, both selectors, either Windows block, nor the full prefix with either selector omitted masks the failure. No single masking predecessor was established, and cases do not share database files.With the unsafe substitute removed, the old owner also fails in the full file (20 passed, 1 failed). The repaired owner passes the full file and isolation. The owner regression explicitly constructs the WAL/checkpoint transition and does not depend on incidental case ordering.
Evidence
Final head:
8c64cac059357f18bd4271a0b97e4b7d832dc7d3. Linux / Node 24.19.0; leases fetched that exact SHA and ranpnpm install --frozen-lockfile. No local tree sync, tests, or typechecks.node scripts/check-changed.mjs --base 40d9ed0924dafa3ef1bf8cf604679e79aa33a3e4 --head 8c64cac059357f18bd4271a0b97e4b7d832dc7d3The first checker session did not deliver its completion result. Only the checker was rerun with SSH keepalives and streamed output; that run returned exit 0. The passing tests were retained without additional reruns.
The restore tests cover checkpoint admission, newer-data refusal, changed retained commit evidence, and intentional admission after an exclusive writer's exact reversal. Focused restore-file cost was 70.86 s command wall; final repeated runs spent 48.927–57.453 s in its tests. Real multi-database snapshots, exclusions, publication, and update-history preservation require the owner boundary rather than a pure comparer test.
Accepted follow-up: warm snapshot-worker fixture
The maintainer waived the slow-file stop and approved one Windows-file run for this repair. An isolated case launches 72 synchronous snapshot workers, consuming 11.948 s in those calls, with zero content-version workers. Disabling the optional admission cache changed neither the launch count nor the approximately 16.6 s profiled case time.
A shared warm snapshot-worker fixture is explicitly deferred, in the same cost class as #161867 and #162200. This PR does not reinstate the unsafe mock or add retries, sleeps, larger timeouts, skips, or weaker assertions.
Repeated-suite/checker lease: Blacksmith Testbox
tbx_01m3vebh0nn1f9awhh7p2f6s9s, run 36846053529. Windows proof lease:tbx_01m3vd133djpjez0p4ezde3yxe, run 36843590852. All owned leases are stopped.LOC: production +41/-8 (net +33); regression tests +73/-12 and support +2/-37 (combined net +26); docs +8/-2. Production growth reuses the existing private-snapshot owner instead of adding a WAL parser. Windows service behavior is simulated on Linux; no native Windows or published-driver installation test was run in this lane.