Skip to content

Keep the SQLite cache usable when a snapshot save fails - #450

Merged
ProfSynapse merged 3 commits into
mainfrom
fix/cache-startup-save-recovery
Nov 23, 2026
Merged

ProfSynapse merged 3 commits into
mainfrom
fix/cache-startup-save-recovery

Conversation

@ProfSynapse

Copy link
Copy Markdown
Owner

Summary

Fixes #448.

Verification

  • Full Jest suite on the branch with 7,247 passing tests and 125 skipped.
  • Two clean plugin reloads in the dedicated Obsidian test vault. With a disposable 1.2 MB cache, injected export failures exercised fresh and migrated startup, corrupt-cache recovery, startup hydration, and manual rebuild. Obsidian reported no uncaught errors.
  • TypeScript, ESLint, and the mobile import check passed.

Gustavo Cunha Prazeres and others added 3 commits November 23, 2026 09:57
initialize() awaited two saves without protection: after creating a fresh
database and after applying schema migrations to an existing one. When the
full export does not fit in the WASM heap, sqlite3_js_db_export throws an
SQLite3Error ("Database serialization failed with code SQLITE_NOMEM"),
initialize() rethrows it, and the storage adapter stays failed for the whole
session; every restart repeats the same export and fails the same way.

- Both saves go through saveDuringInitialize(), which marks the database
  dirty first (the migrator writes through the raw handle, so nothing else
  would) and logs instead of rethrowing. Auto-save and close() retry.
- isAllocationFailure() recognises the SQLITE_NOMEM export failure as well
  as the RangeError of a JS-side copy, so the existing exponential back-off
  also applies to it instead of re-exporting on every tick. resultCode is
  the generic SQLITE_ERROR for this throw, so the message is what carries it.

Tests cover both init paths, the retry after a failed init save, the back-off
after SQLITE_NOMEM at init and at runtime, and the adapter staying query-ready.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 082766a)
Route recovered cache snapshots through startup save handling and let manual rebuild discard the old cache after its active blob write settles. Finish hydration when replay succeeds and only the final snapshot save fails.
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.

SQLiteCacheManager.initialize() fails for the whole session when a save inside it hits SQLITE_NOMEM (no back-off for the export error)

1 participant