Skip to content

fix(update): hash SQLite lock bytes as zeros so Windows exclusion cannot fail verification - #205668

Merged
RomneyDa merged 2 commits into
mainfrom
openclaw/plaid-krill-33520a
Nov 26, 2026
Merged

RomneyDa merged 2 commits into
mainfrom
openclaw/plaid-krill-33520a

Conversation

@tideclaw-bot

Copy link
Copy Markdown
Collaborator

Problem

Windows updates whose agent or state database is larger than 1 GiB fail post-install Doctor with:

SQLite migration publication could not be verified: SQLite read-only worker EBUSY: resource busy or locked, read (code=EBUSY)

This is the recurring Windows variant in #197083 (2026.11.6 → 11.7 → 11.8 → 11.9 → 11.10). The reporter's main agent database is about 5 GB.

Root cause: updateSqliteMigrationSteps (update-doctor-migration-attribution.ts) keeps PRAGMA locking_mode=EXCLUSIVE on the source while it reads the post-migration generation. SQLite's lock bytes sit at offset 1 GiB: the pending byte, the reserved byte and the 510-byte shared range. On POSIX those locks are advisory. On Windows, LockFileEx locks are mandatory, so any other handle that reads [0x40000000, 0x40000200) gets ERROR_LOCK_VIOLATION. Node reports that as EBUSY ... read, and the main-database hash in fingerprintFile (sqlite-file-generation.ts) fails there. Databases under 1 GiB have no lock-byte page, which is why this only hits large installs.

Small -shm reads are not the cause: Windows SQLite locks -shm at offset 120 and above, and the WAL-index header read covers only bytes 0–95. The earlier forced-lock experiment had to inject a lock there by hand.

Fix

SQLite never stores content in the lock-byte page. The main-database digest now hashes those 512 bytes as zeros instead of reading them. SQLite never writes that page, and backups and VACUUM skip it, so it always reads back as zeros. The digest therefore matches a full read, and existing captures and receipts stay valid. The WAL and journal are still hashed in full because they have no lock bytes and a WAL can hold real frame data at that offset.

Accepted edge case: if another tool wrote nonzero bytes into the lock page, they now hash as zeros. That page is not database content, so this does not hide a database change.

Evidence

  • Regression test hashes SQLite's lock bytes as the zeros SQLite leaves. On base it fails with a different digest; with the fix it passes.
  • Real Windows proof on Windows 11 ARM64 (Node 24.22.3), using a 1.15 GB WAL database. The real readUpdateDatabaseGeneration was bundled from base and from this branch. A second process held the same native exclusion the migration owner takes (PRAGMA schema_version, then locking_mode=EXCLUSIVE; BEGIN EXCLUSIVE; ROLLBACK):
    • base, unlocked: generation ok
    • base, under the exclusive owner: EBUSY: resource busy or locked, read (matches the field reports)
    • fix, unlocked: the same generation as base (11003e4d…), so digests are compatible
    • fix, under the exclusive owner: generation ok (b33cfc60…). That is exactly the unlocked read's empty-reader alternate, and the content digest is identical (e96fafa8…), so the existing admission accepts it.
  • A raw mechanism check on the same VM: reads at offset 0 and right after the lock range succeed under EXCLUSIVE; the 512 lock bytes return EBUSY. A last-connection close checkpoint caused 41,320 EBUSY reads of those bytes in 592 ms.
  • node scripts/run-vitest.mjs on update-database-generations, update-doctor-migration-wal-rebuild, update-database-backup-engine and sqlite-snapshot tests: 139 passed, 2 skipped. pnpm tsgo:core, oxlint, format check and git diff --check all pass.
  • Test cost: the new test hashes about 2 GiB of a sparse file and takes about 1.6 s of test time locally.

Not covered: a full managed Windows openclaw update with a database larger than 1 GiB. The proof above runs the production generation reader under the production lock sequence, not the whole updater. Private-copy paths (copySourceFile) still read the whole file, but the failing post-migration read uses the drained, copy-free path after truncateSqliteWal.

Refs #197083

Worked on by

tideclaw-bot and others added 2 commits November 26, 2026 01:18
…not fail verification

On Windows, SQLite's byte-range locks at 1 GiB are mandatory. While the update
migration owner retains EXCLUSIVE on a database larger than 1 GiB, the post-migration
generation read failed with EBUSY. SQLite stores no content in those 512 bytes, so the
main-database digest now hashes them as the zeros SQLite leaves, matching a full read.

Refs #197083

Co-authored-by: RomneyDa <[email protected]>
…not fail verification

Worked on by:
- @RomneyDa

Co-authored-by: RomneyDa <[email protected]>
OpenClaw-Publication: 2a84fae0-c618-43f3-881b-f5bc9ca55842
@clawsweeper

clawsweeper Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@tideclaw-bot

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. impact:crash-loop Crash, hang, restart loop, or process-level availability failure. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 26, 2026
@clawsweeper

clawsweeper Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR hashes SQLite’s 512 lock bytes as zeros when computing main-database generations, while continuing to hash WAL and journal files completely.

Example: A Windows process reads a 1.15 GB SQLite database while another SQLite connection retains EXCLUSIVE locking.

  • Before: The reported base generation read fails with EBUSY at the lock-byte range.
  • After: The reported fixed generation read succeeds with the same content digest and an accepted empty-reader generation alternate.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The implementation is focused and has meaningful native Windows boundary evidence, but required upgrade proof remains incomplete.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: Windows updates can activate the new version but leave Doctor maintenance unfinished when generation verification reads mandatory SQLite lock bytes in a database larger than 1 GiB.
Reason: This maintainer-authored repair addresses a recurring update failure with a narrow change; the broader linked issue has additional causes.

Merge readiness

✅ Ready for maintainer review

Keep this PR: it addresses a concrete Windows update failure still present on main, and review found no actionable code defect.

Reviewed head: 485f077b13d7377852dac97a533f77d1bace068d

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Provide a redacted managed Windows upgrade from v2026.11.10 to the fixed build with a database larger than 1 GiB, showing Doctor completion and existing settings and data intact.
Agent review details

How this fits together

Doctor retains native SQLite exclusion during migration, then asks an isolated worker to verify database generations used for publication and recovery attribution.

flowchart TD
A[Installed Doctor] --> B[Migration owner]
B --> C[Retained SQLite exclusion]
B --> D[Generation worker]
D --> E[Database and sidecar hashes]
E --> F[Publication receipt]
Loading

Technical review

Best possible solution:

Retain the focused database-hashing repair within the existing generation and snapshot-verification owners.

Do we have a high-confidence way to reproduce the issue?

Current source exposes the full-file read under retained native exclusion, and the PR reports a matching Windows base/fix reproduction; this review executed no target code.

Is this the best way to solve the issue?

Normalizing only SQLite’s unused lock range addresses the failing read without releasing migration exclusion, swallowing EBUSY, or weakening WAL and journal verification.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 2cb81bbb38a1.

Provenance checked

  • Full-file generation hashing and snapshot verification changes intended behavior with a stated reason (5d33b69: Recovery verification moved to identity and content so harmless timestamp drift would not reject unchanged files; the shared snapshot hasher retained independent byte checks.)
  • Observation-scoped digest reuse keeps the original intent (556c807: Reduce repeated large-file reads while retaining fresh hashing for recent or imprecise metadata and preserving private-image verification.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Main still performs the failing full read: Current main passes the main database through the ordinary full-file hasher; the PR adds lock-range normalization only for the database and retains ordinary hashing for sidecars. (src/infra/sqlite-file-generation.ts:104, 2cb81bbb38a1)
  • Production lock lifetime matches the proposed mechanism: The migration owner acquires EXCLUSIVE locking, checkpoints the WAL, and reads the postimage generation before releasing its exclusion. (src/infra/update-doctor-migration-attribution.ts:317, 485f077b13d7)
  • Focused regression preserves an independent digest expectation: The added test hashes a sparse file before changing its lock bytes, then checks that the generation digest still equals that original full-file digest; existing small-file tests do not exercise this range. (src/infra/update-database-generations.test.ts:318, 485f077b13d7)
  • Windows boundary evidence and its declared limit: The PR body reports base failure and fixed success using the production generation reader on Windows 11 ARM64 with native SQLite exclusion, but explicitly excludes a full managed Windows update. (485f077b13d7)
  • Related reports establish value without proving every occurrence: WG-Mojo documents repeated official Windows update failures through 2026.11.10 in [Bug]: Post-install Doctor WAL publication verification leaves 11.3 update partially finalized #197083 (comment); those reports identify generation verification but do not establish the exact busy file or lock holder.
  • Documented tradeoff preserves the existing owners: The maintainer-authored PR explicitly accepts ignoring nonzero bytes written by a foreign tool into SQLite’s unused lock range; identity checks, mutation verification, native admission, and recovery authority remain in their existing owners. (src/infra/sqlite-file-generation.ts:86, 485f077b13d7)

Likely related people:

  • Peter Steinberger: Raw commit 556c807 adds src/infra/sqlite-file-generation.ts:28 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 556c8077f82d; files: src/infra/sqlite-file-generation.ts)
  • Vincent Koc: Raw commit 9c87c4e adds src/infra/update-database-generations.test.ts:107 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 9c87c4e82620; files: src/infra/update-database-generations.test.ts)
  • Jason (Json): Raw commit b66471a adds src/infra/sqlite-snapshot-file.ts:43 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: b66471a26d9a; files: src/infra/sqlite-snapshot-file.ts)

PR surface

Source +50, Tests +17. Total +67 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 56 6 +50
Tests 1 17 0 +17
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 73 6 +67

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

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

  • Complete the managed Windows upgrade scenario identified in testingReview.missingE2e.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 25, 2026, 8:24 PM ET / November 26, 2026, 01:24 UTC.

@RomneyDa
RomneyDa merged commit 69b81b5 into main Nov 26, 2026
136 checks passed
@RomneyDa
RomneyDa deleted the openclaw/plaid-krill-33520a branch November 26, 2026 01:48
tideclaw-bot added a commit that referenced this pull request Nov 26, 2026
…not fail verification (#205668)

* fix(update): hash SQLite lock bytes as zeros so Windows exclusion cannot fail verification

On Windows, SQLite's byte-range locks at 1 GiB are mandatory. While the update
migration owner retains EXCLUSIVE on a database larger than 1 GiB, the post-migration
generation read failed with EBUSY. SQLite stores no content in those 512 bytes, so the
main-database digest now hashes them as the zeros SQLite leaves, matching a full read.

Refs #197083

Co-authored-by: RomneyDa <[email protected]>

* fix(update): hash SQLite lock bytes as zeros so Windows exclusion cannot fail verification

Worked on by:
- @RomneyDa

Co-authored-by: RomneyDa <[email protected]>
OpenClaw-Publication: 2a84fae0-c618-43f3-881b-f5bc9ca55842

---------

Co-authored-by: RomneyDa <[email protected]>

Release adaptation for 2026.11.11: added only the lock-bytes regression in update-database-generations.test.ts; the neighboring retained-WAL test belongs to a change not on 2026.11.11.

(cherry picked from commit 69b81b5)
Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
vincentkoc added a commit that referenced this pull request Nov 26, 2026
…irement-rule

* origin/main: (172 commits)
  test(gateway): expect a revoked person's Goal retry to be hidden as not found (#205698)
  fix: keep browser disabled when only hardening relay authentication (#203137)
  fix: recover Linux stream automations after command-anchor crashes (#203149)
  fix(whatsapp): identify voice-note captions as text in delivery receipts (#205381)
  fix(test): unblock restart-auth plugin and worker publication qualification (#205679)
  chore(ui): refresh control ui locales (#205691)
  fix: reduce memory during SQLite usage refresh (#201064)
  fix(plugins): readmit native captures with a dangling host link
  chore(i18n): refresh native locales (#205680)
  fix(update): hash SQLite lock bytes as zeros so Windows exclusion cannot fail verification (#205668)
  fix(skill-workshop): skip the skill diet for skills with Markdown outside support directories (#204881)
  fix(plugins): clarify dated SDK migration notices (#200932)
  fix: keep the resident launcher when reinstalling Gateway (#205655)
  fix: show the whole reply when you reopen a TUI session (#200455)
  test(ui): wait for restored speech player authorization (#199502)
  feat: let agents post approved GitHub comments (#204301)
  fix(agents): honor imageMaxDimensionPx at the provider and CLI image handoffs (#205663)
  chore(ui): refresh control ui locales (#205664)
  fix(google): preserve playback when Google Live splits audio into parts (#205364)
  fix: show named characters in exported session messages (#205362)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 26, 2026
…not fail verification (openclaw#205668)

* fix(update): hash SQLite lock bytes as zeros so Windows exclusion cannot fail verification

On Windows, SQLite's byte-range locks at 1 GiB are mandatory. While the update
migration owner retains EXCLUSIVE on a database larger than 1 GiB, the post-migration
generation read failed with EBUSY. SQLite stores no content in those 512 bytes, so the
main-database digest now hashes them as the zeros SQLite leaves, matching a full read.

Refs openclaw#197083

Co-authored-by: RomneyDa <[email protected]>

* fix(update): hash SQLite lock bytes as zeros so Windows exclusion cannot fail verification

Worked on by:
- @RomneyDa

Co-authored-by: RomneyDa <[email protected]>
OpenClaw-Publication: 2a84fae0-c618-43f3-881b-f5bc9ca55842

---------

Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot added a commit that referenced this pull request Nov 26, 2026
…not fail verification (#205668)

* fix(update): hash SQLite lock bytes as zeros so Windows exclusion cannot fail verification

On Windows, SQLite's byte-range locks at 1 GiB are mandatory. While the update
migration owner retains EXCLUSIVE on a database larger than 1 GiB, the post-migration
generation read failed with EBUSY. SQLite stores no content in those 512 bytes, so the
main-database digest now hashes them as the zeros SQLite leaves, matching a full read.

Refs #197083

Co-authored-by: RomneyDa <[email protected]>

* fix(update): hash SQLite lock bytes as zeros so Windows exclusion cannot fail verification

Worked on by:
- @RomneyDa

Co-authored-by: RomneyDa <[email protected]>
OpenClaw-Publication: 2a84fae0-c618-43f3-881b-f5bc9ca55842

---------

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 69b81b5)
Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

impact:crash-loop Crash, hang, restart loop, or process-level availability failure. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants