Skip to content

fix(storage): add WAL checkpoint on close and fallback for corrupted WAL#1

Merged
herjarsa merged 72 commits into
devfrom
fix/sqlite-wal-crash-on-open
Apr 25, 2026
Merged

fix(storage): add WAL checkpoint on close and fallback for corrupted WAL#1
herjarsa merged 72 commits into
devfrom
fix/sqlite-wal-crash-on-open

Conversation

@herjarsa
Copy link
Copy Markdown
Owner

Summary

Fixes crash on open when SQLite WAL is in inconsistent state from previous crash.

Changes

  • WAL checkpoint before close: Run PRAGMA wal_checkpoint(TRUNCATE) before closing the database to ensure WAL is properly synced and truncated
  • WAL mode fallback: Wrap PRAGMA journal_mode = WAL in try-catch with automatic fallback to DELETE mode if WAL initialization fails

Root Cause

When the app crashes or is killed while WAL mode is active, the WAL file can be left in an inconsistent state. On next startup, PRAGMA journal_mode = WAL would crash instead of handling the corrupted state gracefully.

Testing

  • bun typecheck passes

Closes anomalyco#24287

NN708 and others added 30 commits April 22, 2026 07:19
opencode-agent Bot and others added 29 commits April 23, 2026 16:00
…alyco#23770)

Co-authored-by: rgs_ramp <rgs@ramp.com>
Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
- Checkpoint WAL before closing to prevent corruption on crash
- Wrap PRAGMA journal_mode=WAL in try-catch with fallback to DELETE mode
- Fixes crash on open when WAL is in inconsistent state from previous crash
@herjarsa herjarsa merged commit 8af29c7 into dev Apr 25, 2026
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.

opencode not opening and crashing