fix(storage): durable note catalog with crash recovery - #14
Merged
Conversation
Customer report: a tablet freeze wiped their entire library. Root cause: the note index and all metadata lived solely in AsyncStorage, whose manifest can be lost wholesale when the app dies mid-write. A corrupt index silently became an empty library, and the next note creation overwrote it permanently, even though every note body file survived on disk. - Add a durable catalog (Documents/notes-catalog.json) as the source of truth for notes and folders, written with the same atomic tmp-verify-rename pattern bodies use, mirrored to AsyncStorage, and reconciled on load against body files on disk: any orphaned body is recovered into the library (mirror metadata preferred, stub title as fallback, preview/PDF background restored). Notes pointing at lost folders move to the root instead of vanishing. - Never open an unreadable body as an empty note (autosave would then overwrite the real file): show a recovery screen with retry, back, and an explicit start-blank choice. - Flush pending autosaves on back navigation (previously cancelled, silently dropping the last strokes) with a retry dialog on failure, and on app background (timers do not fire in background). - Skip the metadata update when a body write fails so updatedAt and thumbnail never advance past what actually persisted. - Serialize catalog mutations through a shared promise queue, fixing read-modify-write races between concurrent deletes/moves. Verified: 14 new node tests including reproductions of the corrupt-index and total-manifest-loss scenarios; E2E on iPad simulator recovering seeded notes after deleting the catalog and corrupting the AsyncStorage manifest. Claude-Session: https://claude.ai/code/session_01EEVkk7pkngePErcAAQveCx
Build 8 was prepared on chore/release-1.1-build-8; build 9 supersedes it with the data-durability fix included. Claude-Session: https://claude.ai/code/session_01EEVkk7pkngePErcAAQveCx
markm39
force-pushed
the
fix/durable-note-catalog
branch
from
August 29, 2026 05:25
df64a7e to
4e5da11
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A customer's tablet froze and their entire library appeared deleted. Root cause: note bodies are written durably to disk, but the note index and all metadata lived only in AsyncStorage. On iOS, AsyncStorage keeps small values in a single manifest that can be lost wholesale when the app dies mid-write (freeze, jetsam OOM kill, forced reboot). A corrupt index silently parsed to an empty library, and the next note creation overwrote it permanently — while every note body file sat intact on disk, invisible to the app.
Three adjacent data-loss bugs were found and fixed in the same pass.
Fixes
Documents/notes-catalog.jsonwith the same atomic tmp-verify-rename pattern bodies use, mirrored to AsyncStorage. On load the catalog reconciles against body files on disk: any orphaned body is recovered into the library (real metadata from the mirror when it survived; a 'Recovered note' stub with preview and PDF background otherwise). Notes pointing at lost folders move to the root instead of vanishing. This recovers the affected user's notes on app update.Verification
node --testcases includingREPRO:tests simulating the exact failure (corrupt index after mid-write kill; total manifest loss) — all passhttps://claude.ai/code/session_01EEVkk7pkngePErcAAQveCx