Skip to content

fix(sqlite): prevent snapshot starvation under writes - #113708

Merged
vincentkoc merged 1 commit into
mainfrom
fix/sqlite-snapshot-pinned-read
Jul 25, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
fix/sqlite-snapshot-pinned-read

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Jul 25, 2026 •

Copy link
Copy Markdown
Member

Related: #113306

What Problem This Solves

Fixes an issue where SQLite snapshots could make no progress under sustained concurrent WAL writes. Node's stepped online backup restarts when another connection changes the source, so a busy OpenClaw state database could keep the snapshot process scanning the same early pages indefinitely.

Why This Change Was Made

The source connection now opens and activates one explicit read transaction before integrity validation and online backup. Validation and copied bytes therefore come from the same SQLite snapshot, and the transaction is rolled back before the source connection closes.

This follows the existing pinned-read pattern in the read-only SQLite location helper instead of changing backup batch size or adding a retry budget.

User Impact

Snapshot and backup operations remain consistent and complete under active WAL write load instead of starving. Concurrent WAL writers can continue while OpenClaw copies a stable read state, and the published snapshot still receives the existing integrity, index, foreign-key, compaction, and durability checks.

Evidence

  • ARM64 symptom: the default reliability profile spent more than 1 hour 45 minutes repeatedly reading the first approximately 2 MB of a 20.7 MB source while the writer continued.
  • Dependency proof: Node v24.18.0's BackupJob repeatedly calls sqlite3_backup_step; SQLite documents that external source writes restart the backup.
  • Live hypothesis proof: adding BEGIN plus PRAGMA schema_version copied the same 5,045-page, 20,664,320-byte source in 18 ms while the writer remained active.
  • Regression: src/infra/sqlite-snapshot.test.ts injects a WAL commit immediately before backup and proves the snapshot contains only the transaction-pinned state.
  • Focused Testbox: tbx_01kycrts2k0qa02ctx1armvmz1, 30 passed / 2 platform skips.
  • Fresh exact-head pnpm check:changed: tbx_01kycsj0z236xv1wsrp24s99sq, passed in 4m52s.
  • Autoreview: clean, no accepted/actionable findings, confidence 0.94.
  • Linux ARM64 VM (cbx_fb95c4edd52c, Apple Virtualization, Node 24.15.0): full default profile passed in 51.4s with 25 concurrent restores, 57,312 writer rows, crash recovery, publication/restore/repository interruption, unsafe-index repair, VACUUM interruption, compaction, and post-compaction restore all verified.
  • ARM64 peak WAL was 17,987,952 bytes against the 536,870,912-byte limit; final 4,096-row state hash was 784f055fe46aa3314615b5d5461425f787170b26e7b2fc7347d434a3252a5cb1.
  • Direct AWS ARM64 was attempted on two fresh c7g.8xlarge leases, but the broker withdrew SSH before code execution on both; no application result is inferred from those infrastructure failures.

@vincentkoc vincentkoc self-assigned this Jul 25, 2026
@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Jul 25, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review July 25, 2026 14:22
@vincentkoc
vincentkoc merged commit 2169478 into main Jul 25, 2026
193 of 197 checks passed
@vincentkoc
vincentkoc deleted the fix/sqlite-snapshot-pinned-read branch July 25, 2026 14:31
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant