8000 fix(browser): store migrated pages on open; keep only live pages (#411, #440) by adityamukho · Pull Request #474 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content

fix(browser): store migrated pages on open; keep only live pages (#411, #440) - #474

Merged
adityamukho merged 1 commit into
v3from
fix/411-440-browser-pages
Oct 7, 2026
Merged

adityamukho merged 1 commit into
v3from
fix/411-440-browser-pages

Conversation

@adityamukho
Copy link
Copy Markdown
Collaborator

Summary

  • browser: BrowserDb.open() does not write migrated pages back to IndexedDB #411 — BrowserDb.open() flushes the pages an open writes, so a v7 IndexedDB store is upgraded to v8 once instead of in memory on every open.
  • BrowserDb: bound page growth via v8 free-list reuse; avoid v7→v8 migration bloat #440 — free pages hold no bytes in BrowserBufferBackend and no keys in IndexedDB. Open drops the whole free list (after a v7 upgrade, the old v7 region). Each commit drops only the ids it newly put on the free list: PageAllocator::finish_free_list now returns them, so the cost stays O(change). The deletes go in the same IndexedDB transaction as the commit's pages and meta page.
  • importGraph() also deletes the replaced database's keys. Before, a reopen loaded them next to the imported pages.
  • exportGraph() writes free pages as zeros, padded to the meta's page_count. A native test checks that a file with all-zero free pages opens, verifies clean and keeps committing, both just migrated and after saves.

Chosen over "migrate into a fresh object store": the same path covers ordinary churn, and no IDB schema bump is needed. Spec: docs/superpowers/specs/2026-10-07-browser-page-reuse-design.md.

Acceptance (#440)

  • After N transacts, buffer and IndexedDB page counts equal page_count − freelist_count, and growth stays under one page per transact (transacts_keep_only_live_pages).
  • After a migrated v7 open, IDB holds exactly the live v8 pages and no v7 region (open_stores_migrated_v7_pages_and_drops_the_v7_region).
  • Crash consistency: IDB transactions are atomic. A commit applied in memory but never flushed reopens at the previous commit and keeps working (unflushed_commit_reopens_at_the_previous_one).
  • Export opens natively (zeroed_free_pages_are_never_read, plus export→import round trip after churn).

Known pre-existing gap (not in this PR)

If an IndexedDB flush fails (quota, abort), the dirty set is already drained and is not restored, so a later flush can miss pages. This is worth its own issue.

Test plan

  • cargo test — 1338 passed, 9 ignored
  • wasm-pack test --headless --firefox --features browser --lib — 32 passed. I checked that the new tests fail with release disabled (4) and with the open-time flush removed (browser: BrowserDb.open() does not write migrated pages back to IndexedDB #411 test)
  • clippy -D warnings: native (--all-features), wasm32-unknown-unknown --features browser, wasm32-wasip1; cargo fmt --check

🤖 Generated with Claude Code

https://claude.ai/code/session_015GgLEs8YozJjYhwPEYgTUn

#440)

BrowserDb.open() now flushes the pages an open writes, so a v7 IndexedDB
store is upgraded to v8 once instead of in memory on every open (#411).

Free pages no longer hold bytes in the buffer or keys in IndexedDB (#440).
Open drops the whole free list (after a v7 upgrade, the old v7 region);
each commit drops the ids it newly put on the free list, which
PageAllocator::finish_free_list now returns, so the cost stays O(change).
The deletes go in the same IndexedDB transaction as the commit's pages
and meta page. importGraph() also deletes the replaced database's keys.
exportGraph() pads free pages with zeros up to the meta's page_count.

Spec: docs/superpowers/specs/2026-10-07-browser-page-reuse-design.md

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015GgLEs8YozJjYhwPEYgTUn
@codecov
codecov Bot commented Oct 7, 2026
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/storage/persistent_facts.rs 66.66% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

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

0