Skip to content

fix(update): updates fail when another connection opens the state database during a generation read - #193134

Merged
fuller-stack-dev merged 8 commits into
openclaw:mainfrom
fuller-stack-dev:fix/update-wal-reader-index
Nov 5, 2026
Merged

fuller-stack-dev merged 8 commits into
openclaw:mainfrom
fuller-stack-dev:fix/update-wal-reader-index

Conversation

@fuller-stack-dev

@fuller-stack-dev fuller-stack-dev commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Fixes: updates fail with "SQLite WAL commit publication could not be verified" when anything opens or closes the state database during a generation read, even without writing.

User Impact

User impact: an update no longer fails, or loses automatic database restoration, just because another connection opened or closed the state database during a generation read without committing. Real writes during the read still fail the same way they do now.

Why This Change Was Made

readUpdateDatabaseGeneration and readUnchangedUpdateDatabaseGeneration compare the WAL index header (-shm) before and after reading, and refused when it appeared or disappeared. Neither event publishes a commit. A connection that opens a closed WAL database creates an index whose change counter and commit checksum are zero. When the last connection closes, SQLite checkpoints and removes the index, including one that recorded earlier commits.

With no rollback journal and no WAL frames, the read now accepts the index disappearing, and accepts a new index that carries no commit. The database, journal and WAL are already verified byte-for-byte across the read, so neither case can hide a commit. The result is bound to the state after the read, which is exactly what a read a moment later returns. A header that changes and stays, or appears with commit evidence, still refuses. So does any real commit, which fails earlier with "SQLite file generation changed while reading". Fingerprints, emptyReaderAlternate and receipt formats are unchanged. A receipt is not reused across the transition, and the caller reads again.

Evidence

On one Mac, four updates hit this error on state/openclaw.sqlite (Oct 26 twice, Nov 2, Nov 4). On Nov 4 the Gateway had already stopped. The pre-migration backup first lost its write generation ("Database changed during capture"). Then the parent's ledger observation before Doctor failed after 2.2 seconds, and the run ended post-update-failed even though the new Gateway verified healthy.

Real SQLite probes against an unchanged 615 MB WAL database, with a separate process acting during the read, showed the same error when a connection opened or closed mid-read without writing. A real commit mid-read gave "SQLite file generation changed while reading".

The tests in src/infra/update-database-generations.test.ts open or close a real node:sqlite connection at the final stable read and assert the exact generation each case publishes, plus that a second read in the same state agrees. The open, close and receipt cases failed on base a1f99240c836. The last-writer case (a writer commits, checkpoints with TRUNCATE, then closes during the read) failed on the previous head 4c5428ef with this error and passes now with the closed database's generation. A commit during the read still refuses, and so does an index that appears with a nonzero change counter. I mutated the new check to accept any new index and that guard failed, so it does catch overreach.

The whole file passes (47 tests) on e342625e; head 3a112f07 only adds a merge of main's Doctor config change. Before the merges of main, which touched UI, media, process supervisor and Doctor config code, nine generation consumer test files in the infra project passed (243 tests), plus update-command-migrated-schema (21). Format and oxlint pass on the touched files, and the test-line check passes with this PR's allocation set to its net 90 added lines. tsrs on core and on the infra test project shows only the existing packages/ai error that main also has. An independent autoreview (Codex, P0 to P2) found nothing to fix.

This PR doesn't identify which process opened the database on that machine. The read now tolerates any opener or closer that doesn't commit. The stuck-run repair from that failure is #193132. Two follow-ups cover the rest of the Nov 4 run. #193622 keeps the update going when the parent ledger read fails anyway. #193626 stops the backup reporting "Database changed during capture" when a reader opens between its two reads.

…n reads

A database generation read failed with "SQLite WAL commit publication could
not be verified" whenever another connection opened or closed the database
during the read without writing. A native open creates a zero-commit WAL index
and the last close removes it; neither publishes a commit, and the empty-WAL
rule beside it already treats that churn as unchanged content.

Accept only that presence transition: no journal, no WAL frames, and a header
whose change counter and commit checksum are still zero. Header changes,
committed writers' indexes and real commits still refuse.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clawsweeper

clawsweeper Bot commented Nov 5, 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.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 5, 2026
@clawsweeper

clawsweeper Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR allows verified SQLite generation reads to tolerate a WAL index appearing or disappearing without a committed write.

Example: Another connection opens state/openclaw.sqlite during a generation read without writing.

  • Before: The read throws “SQLite WAL commit publication could not be verified.”
  • After: The read publishes the post-read generation while retaining checks for changed database content and commit evidence.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A useful, narrowly scoped repair with real-SQLite regression coverage and no identified code defect; confidence remains limited to the in-process boundary.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the contributor proof gate; supplied real-SQLite regression coverage exercises the generation owner, while the earlier shipped-update confidence improvement remains outstanding.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An update can fail or lose automatic database restoration when another connection opens or closes the database without writing.
Reason: The maintainer-authored direction repairs a reported failure within the existing reader-equivalence contract without adding settings, schemas, or competing ownership.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: current main still rejects harmless WAL-index transitions, and the focused repair introduces no identified correctness defect.

Priority: P2
Reviewed head: 3a112f07d3d5b07ce3cf61cb8159d2f794fa5e84

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: No supplied after-fix trace exercises a shipped update from v2026.11.1 through the reader transition and verifies preserved settings and data.
Agent review details

How this fits together

Update backup and Doctor use the generation owner to turn SQLite file-family observations into fingerprints used for migration admission and automatic restoration checks.

flowchart TD
  A[Update backup and Doctor] --> B[Database generation owner]
  B --> C[SQLite database and sidecars]
  B --> D[Private snapshot validation]
  C --> E[Content and publication checks]
  D --> E
  E --> F[Generation fingerprints]
  F --> G[Migration and restoration checks]
Loading

Technical review

Best possible solution:

Keep the narrow comparison in the existing generation owner while preserving exact fingerprints, receipt fallback, and rejection of real writes.

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

Current main explicitly rejects header presence transitions despite unchanged database-family content, and the supplied real-SQLite regressions target that path with reported baseline failures; this read-only review ran no target code.

Is this the best way to solve the issue?

The shared comparison is the smallest complete repair for transitions during one observation, preserving file verification and existing downstream owners without adding persistent state or configuration.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 29aa438e6502.

Provenance checked

  • WAL publication verification changes intended behavior with a stated reason (d780fdc: Database restoration must refuse uncertain observations and preserve unaccounted writes.)
  • Empty-reader equivalence keeps the original intent (237fdc6: Read-only probes must not invalidate capture when identity, committed content, and write evidence remain equivalent.)
  • Physical receipt reuse keeps the original intent (6c672d4: Reuse a successful observation only after fresh complete physical verification, retaining full observation on stable mismatches.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit d780fdc adds src/infra/update-database-generations.ts:29 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: d780fdc672d3; files: src/infra/update-database-generations.ts)

PR surface

Source +20, Tests +90, Other +5. Total +115 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 22 2 +20
Tests 1 106 16 +90
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 5 0 +5
Total 3 133 18 +115

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.

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +22/−2; tests +106/−16. The production growth centralizes one comparison used by both readers; test growth covers distinct acceptance, write-rejection, and receipt-fallback boundaries.

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: A reported update failure and lost automatic-restoration eligibility have a focused source-backed repair, without evidence of a broadly unusable runtime.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp 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.

  • Add redacted output from a shipped update exercising the reader transition and confirming existing settings and data remain intact.

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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-11-05T02:36:32.814Z sha ed7b4f5 :: needs changes before merge. :: [P3] Remove generated attribution from public PR text and commits
  • reviewed 2026-11-05T17:20:02.499Z sha 3a112f0 :: needs maintainer review before merge. :: none

Reviewed November 5, 2026, 12:25 PM ET / 17:25 UTC (Revision 3).

…es mid-read

A generation read refused when the last connection closed during the read
and removed a WAL index that carried commit evidence, although the database
and WAL were verified unchanged and a read a moment later succeeds. Without
journal data or WAL frames, accept the index disappearing and bind the
closed state. A header that changes, or appears with commit evidence, still
refuses.

Tests assert the exact generation per case, add an appearing committed
header guard, and reuse the mid-read hook for the inline spies.
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 5, 2026
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 5, 2026
@clawsweeper clawsweeper Bot removed the clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. label Nov 5, 2026
@fuller-stack-dev
fuller-stack-dev enabled auto-merge (squash) November 5, 2026 17:30
@fuller-stack-dev
fuller-stack-dev merged commit 50cfa7d into openclaw:main Nov 5, 2026
234 of 236 checks passed
@fuller-stack-dev
fuller-stack-dev deleted the fix/update-wal-reader-index branch November 5, 2026 17:59
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Merged via squash auto-merge.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 6, 2026
…abase during a generation read (openclaw#193134)

* fix(update): accept a reader's zero-commit WAL index during generation reads

A database generation read failed with "SQLite WAL commit publication could
not be verified" whenever another connection opened or closed the database
during the read without writing. A native open creates a zero-commit WAL index
and the last close removes it; neither publishes a commit, and the empty-WAL
rule beside it already treats that churn as unchanged content.

Accept only that presence transition: no journal, no WAL frames, and a header
whose change counter and commit checksum are still zero. Header changes,
committed writers' indexes and real commits still refuse.

* test(update): allocate test lines for WAL reader index coverage

* fix(update): accept a retired WAL index when the last connection closes mid-read

A generation read refused when the last connection closed during the read
and removed a WAL index that carried commit evidence, although the database
and WAL were verified unchanged and a read a moment later succeeds. Without
journal data or WAL frames, accept the index disappearing and bind the
closed state. A header that changes, or appears with commit evidence, still
refuses.

Tests assert the exact generation per case, add an appearing committed
header guard, and reuse the mid-read hook for the inline spies.

* test: set the WAL reader index test-line allocation to its net 90 lines
wangmiao0668000666 pushed a commit to wangmiao0668000666/openclaw that referenced this pull request Nov 6, 2026
…abase during a generation read (openclaw#193134)

* fix(update): accept a reader's zero-commit WAL index during generation reads

A database generation read failed with "SQLite WAL commit publication could
not be verified" whenever another connection opened or closed the database
during the read without writing. A native open creates a zero-commit WAL index
and the last close removes it; neither publishes a commit, and the empty-WAL
rule beside it already treats that churn as unchanged content.

Accept only that presence transition: no journal, no WAL frames, and a header
whose change counter and commit checksum are still zero. Header changes,
committed writers' indexes and real commits still refuse.

* test(update): allocate test lines for WAL reader index coverage

* fix(update): accept a retired WAL index when the last connection closes mid-read

A generation read refused when the last connection closed during the read
and removed a WAL index that carried commit evidence, although the database
and WAL were verified unchanged and a read a moment later succeeds. Without
journal data or WAL frames, accept the index disappearing and bind the
closed state. A header that changes, or appears with commit evidence, still
refuses.

Tests assert the exact generation per case, add an appearing committed
header guard, and reuse the mid-read hook for the inline spies.

* test: set the WAL reader index test-line allocation to its net 90 lines
RomneyDa added a commit that referenced this pull request Nov 16, 2026
…abase during a generation read (#193134)

* fix(update): accept a reader's zero-commit WAL index during generation reads

A database generation read failed with "SQLite WAL commit publication could
not be verified" whenever another connection opened or closed the database
during the read without writing. A native open creates a zero-commit WAL index
and the last close removes it; neither publishes a commit, and the empty-WAL
rule beside it already treats that churn as unchanged content.

Accept only that presence transition: no journal, no WAL frames, and a header
whose change counter and commit checksum are still zero. Header changes,
committed writers' indexes and real commits still refuse.

* test(update): allocate test lines for WAL reader index coverage

* fix(update): accept a retired WAL index when the last connection closes mid-read

A generation read refused when the last connection closed during the read
and removed a WAL index that carried commit evidence, although the database
and WAL were verified unchanged and a read a moment later succeeds. Without
journal data or WAL frames, accept the index disappearing and bind the
closed state. A header that changes, or appears with commit evidence, still
refuses.

Tests assert the exact generation per case, add an appearing committed
header guard, and reuse the mid-read hook for the inline spies.

* test: set the WAL reader index test-line allocation to its net 90 lines

(cherry picked from commit 50cfa7d)

Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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.

1 participant