8000 feat: Minigraf::verify and rebuild_indexes (#373) by adityamukho · Pull Request #458 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content

feat: Minigraf::verify and rebuild_indexes (#373) - #458

Merged
adityamukho merged 1 commit into
v3from
feat/373-verify-rebuild
Oct 6, 2026
Merged

adityamukho merged 1 commit into
v3from
feat/373-verify-rebuild

Conversation

@adityamukho
Copy link
Copy Markdown
Collaborator

Refs #373 (data-integrity; left open per the known-issues process), part of #383.

What

  • Minigraf::verify() -> IntegrityReport — walks every committed page and reports logical damage that page CRCs can't see, one structured error per finding:
    • index content vs EAVT and fact_count (order-independent digest, no per-fact memory) — STG-038
    • keys out of order / outside separator range / page reached twice / node that doesn't decode — STG-039
    • DICT inverse maps or id counters wrong — STG-040; ids with no DICT entry — STG-036
    • leaked, doubly used, or wrongly free pages; free-list count — STG-035
  • Minigraf::rebuild_indexes() — rebuilds EAVT/AEVT/AVET/VAET from an intact index that agrees with another (else the only intact one), re-derives the free list, commits like a checkpoint (pending facts included, WAL deleted). Writes only pages the active meta doesn't reference → crash-safe. No usable source or damaged DICT → STG-041, file untouched.
  • IntegrityReport is #[non_exhaustive], re-exported from the crate root.

Design spec: docs/superpowers/specs/2026-10-06-verify-rebuild-indexes-design.md.

Decisions to review

  • API only, no Datalog/REPL syntax (Datalog stays the query language; SQLite's equivalent is a pragma). Bindings (Python Tier 1) are a follow-up.
  • No on-open sampling: v8 open is O(1) by design and sampling can't find a missing entry.
  • Rebuild memory is O(facts) (bulk build, same as v7 migration); external sort judged not worth it for a repair op.
  • DICT is not rebuildable (only copy of UUIDs/idents) → STG-041.
  • Out of scope: recovering at generation g after STG-033, BrowserDb exposure.

Tests

1248 total (1239 passing, 9 ignored), +10:

  • unit: each damage kind found with its code and repaired by rebuild (verify clean, all facts, indexes exact, space accounted); source choice incl. all-disagree → STG-041 with file unchanged; DICT damage; pending facts committed; crash at every write (clean + torn) and sync of a rebuild → old gen with only old damage, or new gen clean, no fact lost.
  • integration (tests/integrity_test.rs): in-memory, clean file, rebuild commits WAL + deletes it, flip each leaf of a real file → always reported, then repaired or refused (STG-041, file unchanged).

cargo clippy --all-features -- -D warnings clean; wasm32 --features browser builds.

🤖 Generated with Claude Code

https://claude.ai/code/session_015GgLEs8YozJjYhwPEYgTUn

Page checksums catch torn and rotted pages, but not pages that are valid
and say the wrong thing. verify() walks every committed page and reports
one structured error per finding: an index whose facts differ from EAVT
(compared by an order-independent digest, no per-fact memory), keys out
of order or a page reached twice, DICT maps that disagree or ids with no
entry, and leaked or doubly used pages.

rebuild_indexes() rebuilds EAVT, AEVT, AVET and VAET from an intact
index that agrees with another one (or the only intact one), derives the
free list again, and commits like a checkpoint, including pending facts.
It writes only pages the active meta does not reference, so a crash at
any point keeps the previous checkpoint. With no usable source or a
damaged DICT it fails with STG-041 and writes nothing.

New codes STG-038..STG-041. Design:
docs/superpowers/specs/2026-10-06-verify-rebuild-indexes-design.md

Refs #373, #383

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

Codecov Report

❌ Patch coverage is 81.00437% with 87 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/storage/verify.rs 78.79% 67 Missing ⚠️
src/storage/persistent_facts.rs 81.65% 20 Missing ⚠️

📢 Thoughts on this report? Let us know!

@adityamukho
adityamukho merged commit 185196b into v3 Oct 6, 2026
19 checks passed
@adityamukho
adityamukho deleted the feat/373-verify-rebuild branch October 6, 2026 16:57
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