Skip to content

fix: read WAL-mode SQLite databases (0.4.1) - #53

Merged
copyleftdev merged 1 commit into
mainfrom
fix/sqlite-wal
Jun 1, 2026
Merged

copyleftdev merged 1 commit into
mainfrom
fix/sqlite-wal

Conversation

@copyleftdev

Copy link
Copy Markdown
Owner

Bug

The SQLite parser failed on WAL-mode databases with failed to parse sqlite input: ... unable to open database file. Found by dogfooding real on-disk .db files (yfinance, GNOME tracker, webkit) — most production databases default to WAL.

Root cause

The parser loads a DB from its main-file byte image via SQLite's read-only deserialize. A WAL-mode database carries read-version 2 in its file header (byte 19); SQLite refuses to open such an image read-only without the -wal companion — which never travels in a byte stream — returning SQLITE_CANTOPEN. Empirically isolated to byte 19: write=2,read=1 reads fine, read=2 fails.

Fix

The main image of a checkpointed WAL database is itself a complete, valid database. The parser now reinterprets it as legacy (read-version 1) on a private copy and reads its checkpointed state. Read-only — the bytes are never written back, and only byte 19 (which gates reads) is touched.

Verification

Four real WAL databases that returned CANTOPEN now read (tkr-tz 34 rows, cookies 1 row, tracker meta.db 7 rows, …); a non-WAL .sqlite still reads; a genuinely non-SQLite .db (GNU dbm) is still honestly rejected (file is not a database).

Gate

proptest + cargo-mutants 0 missed on sqlite.rs (12 mutants, 9 caught, 3 unviable). New test flips a valid fixture's read-version to 2 (simulating WAL) and asserts the parser still reads it.

🤖 Generated with Claude Code

The SQLite parser loads a DB from its main-file byte image via read-only
deserialize. A WAL-mode database carries read-version 2 in its file header
(byte 19), and SQLite refuses to open such an image read-only without the
-wal companion (absent in a byte stream) — failing with "unable to open
database file" (SQLITE_CANTOPEN). The main image of a checkpointed WAL DB is
a complete valid database, so reinterpret it as legacy (read-version 1) on a
private copy and read its checkpointed state. Read-only; bytes never written
back. Byte 18 (write version) does not gate reads, so only byte 19 is touched.

Unblocks the common case: most production .db files (browsers, peewee/yfinance,
many apps) default to WAL. Found by dogfooding real on-disk databases — four
real WAL DBs that returned CANTOPEN now read.

Gate: proptest + cargo-mutants 0-missed on sqlite.rs (12 mutants, 9 caught,
3 unviable). New test simulates a WAL header (flip read-version to 2) and
asserts the parser still reads the checkpointed image.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@copyleftdev, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 37 minutes and 34 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d3801340-f54e-4104-9f32-4ed383861c46

📥 Commits

Reviewing files that changed from the base of the PR and between 5c489d8 and 3bd8184.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • CHANGELOG.md
  • Cargo.toml
  • crates/ax-normalize/src/parsers/sqlite.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/sqlite-wal

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@copyleftdev
copyleftdev merged commit a73eceb into main Jun 1, 2026
2 checks passed
@copyleftdev
copyleftdev deleted the fix/sqlite-wal branch June 1, 2026 05:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant