Skip to content

Database integrity check & repair — typhon check / typhon repair #729

Closed
6 of 6 issues completed
Closed

Description

@nockawa

Why

Typhon is not yet a 100%-reliable database and we cannot wait until it is to run it in production. We need practical tools that close the gap in the meantime: tell me what is wrong with this database, and fix what can be fixed — with an honest account of exactly what was lost.

The gap (assessment, 2026-08-09)

Typhon today has a real, rule-governed repair net (rules/durability.md module RB, the P1.2 net that replaced FPI) — but no diagnosis and no report:

Today
Detection CRC32C per page only — physical. No cross-structure logical check exists anywhere. RB-04 states the limit: "this net detects a torn page ONLY via CRC mismatch", and FPI (which used to mask valid-CRC tears) was deleted in Increment D. The engine has exactly one detector for at-rest damage, with nothing behind it
Repair Real (RB-01..RB-07: rebuild-from-primary, chain scrub, suspect resolution, watermark restore) — but implicit: runs only at open, only on the crash path, cannot be invoked, reports only log lines + internal counters. Outcome is binary: opens, or throws
Reporting None. No answer to "what is damaged / what did I lose"
Layering The only classified full-file walk (~2,072 LOC: StorageMapService, L4Decoder, StructuralMap) lives in Typhon.Workbench, not the engine. Cross-structure verification (~2,169 LOC of oracles) lives in the test project and validates against an external shadow model, so it cannot run on a user's database
Surfaces CLI verbs are ui/new/docs/telemetry/schema. No check, no repair
Backup PIT Backup is designed (7 docs) with zero code and an undecided blocker. Per ADR-014 the WAL is recycled after checkpoint, so there is currently no recovery source older than the last checkpoint

The case is defence in depth, not a live exploit. #579 (unfenced seqlock → valid-CRC torn pages on arm64) is closed — CopyPageWithSeqlock is now arm64-correct end to end. But #579 is itself the argument: a [fatal][silent] P0 that lived in the tree for months and was found by a documentation audit, not by the engine, because nothing in the engine could notice it. A logical checker is the independent second detector that turns that class of discovery from luck into routine.

⚠️ Found while writing this up: RB-04's detection-boundary note (dated 2026-07-28) still presents #579 as live and unmitigated, 9 days after it closed. The rule's structural claim is correct; the annotation needs the fix recorded. Separate doc-accuracy fix.

Scope

Engine-side core in Typhon.Engine, driven by both the CLI and the Workbench.

  • Scan is offline-first — opens the bundle read-only without booting the engine: no recovery, no rebuild, no mutation. This is what lets it diagnose a database that refuses to open (the permanently-unopenable class, e.g. A hard crash makes a SingleVersion archetype with a unique [Index] permanently unopenable #710, N10), which is exactly when it is needed most. Booting also destroys the evidence: the RB net rebuilds the very structures you wanted to inspect before you get a handle. An online (live-engine) scan follows on the same core.
  • Authority model is report → consent → act. Scan is always read-only. Repair executes an explicit, user-approved plan with a written manifest of what will be discarded; destructive steps refuse without an explicit flag.
  • Primary data is ground truth; derived data is suspect — the generalisation of RB-01. Repair regenerates derived structures and never trusts a stale copy of one.
  • Loss is reported, never hidden. RB-07 already establishes the principle in-tree: drop what cannot be represented, count it, report it, and still open.

What the checker structurally CANNOT do

Stated up front because a green report is a licence to trust. A self-consistency checker asks "does this database agree with itself?" — not "does it match what was committed?"

When a recovery gap discards a committed update — the shape #569 had before it was fixed on 2026-08-08 — the database is perfectly self-consistent: cluster slot, chain HEAD, every index entry and occupancy all agree. Every check passes. The value is simply the old one. Same for N2's resurrection. No amount of self-consistency checking finds these — they need an external reference (the un-recycled WAL window, a PIT backup, or app-level invariants). Every report will carry that scope statement explicitly.

Relationship to PIT Backup

This is not gated on PIT Backup, and repair is deliberately not architected around it:

  1. The dependency runs the other way — typhon-backup verify --strict (already in the PIT design) needs exactly this validation.
  2. An unverified backup is a liability: without a checker you cannot know whether a snapshot captured a healthy database, and retention will overwrite the good chain.
  3. It attacks alpha blocker B7 ("the harness cannot falsify most of this") — a self-consistency checker is a general oracle that needs no shadow model, so it can run after every chaos cell.
  4. Splicing pages from a backup into a live database yields a page consistent with an older generation of its neighbours — converting detectable corruption into undetectable corruption. Repair is from-within-the-database and fine-grained; restore is from-backup and wholesale. Backup is the escalation target, referenced by the report ("these N entities are unrecoverable from within this database").

The honest counter-argument: a backup diff is the only thing that catches the silent-staleness class above, so PIT Backup genuinely adds detection power, not just recovery options. It does not change the ordering — the diff needs this feature's decode/compare machinery anyway, and an unverifiable backup cannot serve as ground truth — but the design keeps the door open: IPageSource is abstracted from day one so typhon check --against <backup> is a later additive mode over the same checks.

Phases

Numbers are the execution order. P2 (the format change) moved ahead of checks/report/repair so those are written once against the final primitive instead of built whole-page and reworked. P1 still leads because P2 touches the write path, and there is currently no independent instrument to notice if it goes wrong — build the instrument before changing what it measures.

Settle OQ-6a before P1 starts: whether a crash-path-poisoned EntityMap can reach disk before RB-04's loud-fail. It decides whether offline-first is a preference or the only thing that works, and P1's shape follows from the answer.

Acceptance criteria

  • A corrupted database produces a report naming every damaged structure and, for each, whether it is rebuildable and what is lost if not.
  • A database that fails to open can still be scanned and reported on.
  • Repair never discards primary data without explicit consent, and always emits a loss manifest. — consent half done; naming the lost identities is G4 (Integrity G4 — orphan-key manifest: name the identities that lived on a lost page #756)
  • Scan is provably read-only (byte-identical bundle before/after, asserted in test).
  • Every report states its own detection limits (the silent-staleness class above).
  • The checker runs as an oracle in the crash/chaos suite — no shadow model required. — G8 (Integrity G8 — assert a Deep scan after every chaos cell (the B7 payoff) #760); CrashAssert does not exist
  • Both the CLI and the Workbench drive the same engine core; neither reimplements a check.

Docs

Design series: claude/design/Durability/Integrity/

Assessment source: rules/durability.md (module RB) · research/Durability/epic-411-reassessment/04-alpha-plan.md · design/Durability/PitBackup/

Related: #411 (parent) · #569 (closed 2026-08-08) + N2 — the silent-staleness class a self-consistency checker cannot see · #389 · #712 · #710 (the unopenable class) · #579 (closed — the precedent motivating a second detector)


Closed 2026-08-11 — the remainder moved to #750 and #781

All six phases shipped (#736, plus #772 which completed the check catalogue to 27 of 27). The three acceptance criteria that are not met are each open in exactly one place now, so nothing is tracked twice:

Unmet Where it lives
Loss manifest naming identities, not counts #756 (G4)
Crash-suite oracle (CrashAssert.DatabaseIsSound) #760 (G8)
Durable repair marker · AP-12 idempotence #781 — filed on close, covered by no G-increment

#750 is the continuation Feature and carries the rest.

Sub-issues

Sub-issues

6 of 6 Issues completed
Loading 6 sub-issues

Activity

  1. added theissue type on Aug 9, 2026
  2. updated Product Engine, Area Durability, Estimate XL and Priority P1-High on Aug 9, 2026
  3. moved this to Todo in Typhonon Aug 9, 2026
  4. 1 remaining item

  5. added 11 commits that reference this issue on Aug 9, 2026
  6. moved this from In Progress to Done in Typhonon Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Fields

    Priority

    P1-High

    Estimate

    XL

    Area

    Durability

    Start date

    None yet

    Target date

    None yet

    Product

    Engine

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions