Skip to content

fix: allow database rollback after WAL checkpoints - #162599

Merged
steipete merged 2 commits into
mainfrom
upd/upd-snapshot-checkpoint-generation
Oct 1, 2026
Merged

steipete merged 2 commits into
mainfrom
upd/upd-snapshot-checkpoint-generation

Conversation

@steipete

@steipete steipete commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

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 with settles 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 ran pnpm install --frozen-lockfile. No local tree sync, tests, or typechecks.

Proof Result
New cases against old generation owner Checkpoint-only and exact-reversal admission fail as intended: 2 failed, 4 passed
Restore + seven owner/direct-import siblings, three runs 111/111 each, 333 total; command walls 226.59 s, 185.03 s, 205.57 s
Windows lifecycle file 21/21; 201.030 s summed test time, 238.94 s command wall
Original isolated Windows interruption case Passed; 15.169 s test time, 22.85 s command wall
node scripts/check-changed.mjs --base 40d9ed0924dafa3ef1bf8cf604679e79aa33a3e4 --head 8c64cac059357f18bd4271a0b97e4b7d832dc7d3 Passed, exit 0; all 27 test typecheck graphs, core typecheck, lint, formatting, dead-export scans, and selected guards
Fresh direct-route Codex P1 review Scoped-clean, with the accepted exact-reversal ruling included

The 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.

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.
@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation cli CLI command changes size: S labels Oct 1, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 1, 2026
@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed October 1, 2026, 6:05 AM ET / 10:05 UTC (Revision 2).

ClawSweeper review

What this changes

The PR compares committed SQLite content when deciding whether rollback is safe, adds checkpoint regressions, and restores isolated snapshot workers in update test fixtures.

Regression provenance

Possible 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
Reviewed head: 8c64cac059357f18bd4271a0b97e4b7d832dc7d3

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused repair and meaningful regressions provide useful signal, but the released-driver compatibility defect blocks readiness.
Proof confidence 🌊 off-meta tidepool Not applicable: The author has verified repository admin access, so ordinary external-contributor proof is exempt. Reported Linux tests exercise the real SQLite generation and restore owners, but do not establish released-driver compatibility or native Windows recovery. The changed restoration receipt contract has insufficient upgrade compatibility evidence independently of that exemption.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The author has verified repository admin access, so ordinary external-contributor proof is exempt. Reported Linux tests exercise the real SQLite generation and restore owners, but do not establish released-driver compatibility or native Windows recovery. The changed restoration receipt contract has insufficient upgrade compatibility evidence independently of that exemption.
Evidence reviewed 10 items Introduced change and merge ownership: The pinned introduced diff replaces the physical-generation hash with a committed-content hash. Raw test-merge parents match the pinned base followed by the exact PR head; its generation-owner change matches the introduced hunk.
Released receipt dialect: v2026.9.7 hashes serialized physical database/WAL/journal generations and the full retained WAL-index header. Its receipts have no generation-format discriminator.
Released updater supplies captured generations: The released package updater passes its database backup sourceGenerations into candidate Doctor as databaseGenerations.
Findings 1 actionable finding [P1] Preserve generation comparisons with published update drivers
Security None None.

How this fits together

The 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]
Loading

Before merge

  • Preserve generation comparisons with published update drivers (P1) - The v2026.9.7 updater captures physical-generation hashes and passes them to candidate Doctor through databaseGenerations. This hunk produces a different hash for the same unchanged database. createUpdateDoctorDatabaseWriteCapture compares those values directly and returns unchanged=false; the released recorder then permanently sets restoreRefusal. A later failure requiring database restoration consequently loses automatic recovery despite no intervening write. Preserve the released receipt dialect for old callers and cover the published-driver × candidate boundary. This prior finding remains unfixed.
  • Resolve merge risk (P1) - Existing v2026.9.7 installations can lose automatic database/package recovery because candidate Doctor treats their unchanged generation receipts as intervening writes; published-driver × candidate compatibility remains unproven.
  • Resolve merge risk (P1) - Linux service simulation does not establish native Windows checkpoint, exclusion, and file-replacement recovery; the platform-specific claim still needs Windows evidence.
  • Complete next step (P2) - Preserve released generation receipt comparisons, demonstrate published-driver × candidate rollback and native Windows recovery, and complete the declared validation gates.

Findings

  • [P1] Preserve generation comparisons with published update drivers — src/infra/update-database-generations.ts:119-125
Agent review details

Security

None.

PR surface

Source +33, Tests +26, Docs +6. Total +65 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 1 41 8 +33
Tests 5 75 49 +26
Docs 1 8 2 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 124 59 +65

Review metrics

Metric Value Why it matters
Receipt compatibility 1 generation hash dialect replaced; 0 format discriminators added These opaque hashes cross the installed-updater/candidate boundary and are compared directly.

Merge-risk options

Maintainer options:

  1. Preserve released receipts (recommended)
    Retain the released generation dialect for old callers and prove v2026.9.7-to-candidate recovery without weakening later-write refusal.
  2. Hold for upgrade and Windows evidence
    Keep the branch open until the mixed-version repair and native Windows recovery behavior are demonstrated.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Preserve generation comparisons and returned receipts for published v2026.9.7 updater callers; add a mixed-version regression covering unchanged state and later-write refusal without resetting captured baselines or weakening sticky refusal.

Technical review

Best 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:

  • [P1] Preserve generation comparisons with published update drivers — src/infra/update-database-generations.ts:119-125
    The v2026.9.7 updater captures physical-generation hashes and passes them to candidate Doctor through databaseGenerations. This hunk produces a different hash for the same unchanged database. createUpdateDoctorDatabaseWriteCapture compares those values directly and returns unchanged=false; the released recorder then permanently sets restoreRefusal. A later failure requiring database restoration consequently loses automatic recovery despite no intervening write. Preserve the released receipt dialect for old callers and cover the published-driver × candidate boundary. This prior finding remains unfixed.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 564cefeeccef.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The item repairs failed-update recovery, and its current patch can disable that recovery for released updater callers.
  • merge-risk: 🚨 compatibility: The changed hash semantics are incompatible with receipts supplied by v2026.9.7, which matching-head tests do not cover.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: The author has verified repository admin access, so ordinary external-contributor proof is exempt. Reported Linux tests exercise the real SQLite generation and restore owners, but do not establish released-driver compatibility or native Windows recovery. The changed restoration receipt contract has insufficient upgrade compatibility evidence independently of that exemption.

Evidence

Acceptance criteria:

  • [P1] pnpm test src/infra/update-database-restore.test.ts --maxWorkers=1.
  • [P1] pnpm test src/commands/doctor-maintenance.database-writes.test.ts src/commands/doctor-maintenance.settlement.test.ts --maxWorkers=1.
  • [P1] pnpm test src/cli/update-cli/update-command-database-rollback.test.ts --maxWorkers=1.
  • [P1] node scripts/check-changed.mjs.
  • [P1] Published v2026.9.7 updater × candidate: unchanged-state recovery and later-write refusal.

What I checked:

  • Introduced change and merge ownership: The pinned introduced diff replaces the physical-generation hash with a committed-content hash. Raw test-merge parents match the pinned base followed by the exact PR head; its generation-owner change matches the introduced hunk. (src/infra/update-database-generations.ts:119, c1f509b33922)
  • Released receipt dialect: v2026.9.7 hashes serialized physical database/WAL/journal generations and the full retained WAL-index header. Its receipts have no generation-format discriminator. (src/infra/update-database-generations.ts:94, c074824a27c9)
  • Released updater supplies captured generations: The released package updater passes its database backup sourceGenerations into candidate Doctor as databaseGenerations. (src/cli/update-cli/update-command-package.ts:377, c074824a27c9)
  • Candidate comparison rejects unchanged released receipts: Candidate Doctor directly compares newly computed generations with supplied hashes during admission and settlement. The changed hash input therefore sets unchanged=false even when an existing database has not changed. (src/infra/update-doctor-result.ts:234, 8c64cac05935)
  • Released recorder makes refusal sticky: The released recorder permanently sets restoreRefusal when writes.unchanged is false. Its database rollback adapter checks that refusal before restoration, so this mismatch can prevent recovery when a later failure requires database rollback. (src/cli/update-cli/update-command-database-receipts.ts:41, c074824a27c9)
  • Current main still needs the central repair: Fetched main still hashes serialized physical generations and the full WAL-index header; it does not contain this checkpoint-tolerant comparison. (src/infra/update-database-generations.ts:94, 564cefeeccef)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Preserve released generation receipts and demonstrate v2026.9.7-to-candidate rollback with unchanged state and later-write refusal.
  • Provide native Windows checkpoint and file-removal recovery evidence.
  • Complete the declared repeated owner/sibling suites and check-changed validation.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-01T09:57:22.490Z sha 8c64cac :: blocked before merge. :: [P1] Preserve generation comparisons with published update drivers

@steipete
steipete marked this pull request as ready for review October 1, 2026 10:56
@steipete
steipete merged commit 0ac1c24 into main Oct 1, 2026
209 of 214 checks passed
@steipete

steipete commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Landed (squash 0ac1c241fba8cb0e255a907e5f23e523ec579a43, head 8c64cac05935): lead review scoped-clean (0.82); lane proof 3× suites (333 tests), Windows 21/21 including the previously isolated failure, check-changed. No failing CI job at merge time (remaining jobs in progress); per the standing rule CI is not re-spent for proof. Fixes the order-dependent update-cli.windows-lifecycle red from hourly 36827062752.

@steipete
steipete deleted the upd/upd-snapshot-checkpoint-generation branch October 1, 2026 11:00
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 2, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes docs Improvements or additions to documentation merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant