Repository navigation
Description
The integrity scanner (#729) shipped 20 of 47 catalogued checks and performs only lossless repairs. This Feature closes the remainder.
Design: claude/design/Durability/Integrity/09-closing-the-gap.md
Why the gap was mis-framed
08 §4.2 recorded the blocker as "offline system-schema decode". That assumed a decode problem where there is an absence problem:
DBD = new DatabaseDefinitions(); DatabaseEngine.cs:915
ChunkBasedSegment(EpochManager, TStore, int stride) stride is a constructor argument
Component field layout, component size, archetype composition, ClusterSize and chunk stride are not persisted. They are rebuilt at every open from [Component]-annotated CLR structs. The file records segment role (LogicalSegmentHeader.Kind) and segment roots (bootstrap collection.{i}), but nothing about their shape.
What that changes
Re-classifying the 27 missing checks by what each one actually reads:
| Tier | Needs | Checks | Count |
|---|---|---|---|
| 0 | nothing new | MAP-04, ALO-03, IDX-01, WAL-02 |
4 |
| 1 | segment geometry, not schema | CHN-01…06, CLU-01/02/05, MAP-01…03, ALO-01/02/04, IDX-02/05/06/07 |
19 |
| 2 | full user field layout | IDX-03/04, CLU-03/04 |
4 |
Every CHN check reads CompRevStorageHeader fields — engine-defined, compile-time known. The chain payload is schema-shaped, but no CHN check reads payload. 23 of 27 checks need geometry, not schema.
Decision — persist geometry
Four integers per chunk-segment root (stride, cluster size, component count, archetype id), written at Create and read on Load, exactly as Kind already is.
The scanner exists to work when nothing else does. Requiring a matching schema assembly fails precisely the forensic case — assembly lost, version drifted, recovery on a machine that never ran the app. LogicalSegmentHeader already carries Kind so introspection can classify a page without re-deriving ownership from context; stride is the same class of fact, and its absence is why the file cannot describe itself.
Counter, recorded: a second format revision weeks after v6, and Tier 2 still needs the assembly regardless — deferred, not avoided.
Class B excision is three projects, not one
05 §9.4's format precondition shipped as revision 6, so per-slot salvage is unblocked at the format level and waits only on geometry.
| Regime | Authoritative bytes | Missing | Loss |
|---|---|---|---|
| Versioned | the revision chain — separate CRC domain | RebuildClusterFromChains exists; it is not wired to a per-page damage trigger |
none |
| SV, in WAL window | FenceBlock (key + location + value) |
RecoveryDriver reads the location and discards it |
none, in-window |
| SV, outside window | nowhere | name the loss instead | real |
Increments
Sequence G0 → G1 → G10 → G2 → G3; the rest are independent once G1 lands. G0, G1, G2, G10 done; G5 and G7 closed.
- G0 Settle OQ-6a — can a crash-poisoned EntityMap reach disk before
RB-04's loud-fail — done, and it promoted offline-first from preference to requirement: one crash-path open rewrites ~25 pages, so opening the database destroys the evidence the checks read - G1 Persist segment geometry (format revision 7) — done (Integrity G1 — persist segment geometry on the chunk-segment root (format revision 7) #753).
ClusterSizeturned out to be derived andComponentCountwas already onArchetypeR1, so only the stride needed recording - G2 Tier 0 + Tier 1 checks — CHN, CLU, MAP, ALO, IDX structural — done (Integrity G2 — the Tier 0 + Tier 1 checks: CHN, CLU, MAP, ALO, IDX structural #754), 27 of 27 rather than the 23 scoped, because G5 and G7 folded in
- G3 Wire
RebuildClusterFromChainsto a per-page damage trigger — 🔴 blocked on a design contradiction, not on effort (Integrity G3 — wire RebuildClusterFromChains to a per-page damage trigger (lossless Class B, Versioned) #755). Repair-by-opening cannot rebuild derived state for archetypes whose CLR types the repairing process lacks — which is the forensic case, and which G0 made a hard requirement. Needs redesign before code - G4 Orphan-key manifest — name the identities on a lost page (Integrity G4 — orphan-key manifest: name the identities that lived on a lost page #756)
- G5
— closed as unnecessary (Integrity G5 —typhon check --schema <dll>— assembly-backed field decodetyphon check --schema <dll>: assembly-backed field decode for the Tier 2 checks #757).FieldR1is persisted, so all four Tier 2 checks run offline with no assembly - G6 SV in-window salvage from
FenceBlock(Integrity G6 — SingleVersion in-window salvage from the WAL FenceBlock #758) - G7 WAL record-chain walking (
CHK-WAL-02) — done (Integrity G7 — WAL record-chain walking (CHK-WAL-02) #759), subsumed by G2. A segment is a run ofWalFrameHeaderframes and each frame contains CRC-bearing chunks; the first attempt looked one level too far out and reported a false green - G8 Crash-suite integration (the
04-alpha-plan.mdB7 payoff) (Integrity G8 — assert a Deep scan after every chaos cell (the B7 payoff) #760) - G9
allowLoss: string[]— per-code consent (Integrity G9 — per-finding-code consent:allowLoss: string[]instead of one boolean #761) - G10
repair --applyrefuses an unknown format revision (OQ-7) — done (Integrity G10 —repair --applymust refuse a format revision it does not know (OQ-7) #762), shipped as ruleIR-01 - G11 Honour or delete
IntegrityOptions.MemoryBudgetBytes(OQ-1) (Integrity G11 — honour or delete IntegrityOptions.MemoryBudgetBytes (OQ-1) #763) — 🔴 the "folded into G2" plan did not happen: G2 shipped and the property still has exactly one occurrence in the tree, its own declaration - G12 Rule ⟷ check matrix as a build artifact (OQ-4) (Integrity G12 — make the rule ⟷ check matrix a build artifact (OQ-4) #764) — also carries P3's unmet AC from Integrity P3 — check catalogue (cross-structure consistency, traced to rules/) #731
Open questions settled while planning this
| OQ | Outcome |
|---|---|
| OQ-3 | Answered: yes. The UoW registry root is a plain bootstrap int (BK_UowRegistrySPI), reachable offline with no engine state — CHN-01 is unblocked |
| OQ-5a | Answered by construction. VerifyOnOpen() sits in PagedMMF.LoadFile(), below durability, so Spine runs on every open including the crash path, before recovery |
| OQ-7 | Decided: hard refusal on any mismatch (not just newer — no back-compat means the tool knows one revision). check still reads and reports; only apply refuses → G10 |
| OQ-1 · OQ-2 · OQ-4 · OQ-6a | Still open → G11, G5, G12, G0 respectively |
Out of scope, permanently
Freshness versus what was committed. No amount of geometry, schema or salvage distinguishes a database that lost a committed update from one that never received it — that needs a reference copy. It stays ScanLimits.StructuralLimit, printed on every report including a green one.
Status 2026-08-11 — detection is finished, repair is not
Six of twelve increments are closed. Detection is essentially complete: 27 of 27 Tier 0–2 checks run offline, each with a fixture that damages exactly what it detects, on a file that now records its own geometry (revision 7) and refuses a repair tool that does not understand it (IR-01).
Repair is where the remaining work is, and one thing has to be decided before more of it is built. G3 was written as the cheapest genuine repair capability — the primitive already exists, just wire it to a damage trigger. #771 showed that is false, and false in the same way twice over:
Ownership was derived from what the caller registered rather than from what the file records, and the crash path adopted that partial reconstruction wholesale — silently freeing 36 live pages on a plain open-and-close of a healthy database. Fixed in #778 by reading the persisted
ArchetypeR1/ComponentR1pointers instead.The same assumption is still in G3, one layer down: regeneration-by-opening rebuilds derived state only for archetypes whose CLR types the repairing process holds. A repair tool has no schema assembly, and G0 made offline-first a hard requirement rather than a preference.
So G3 needs a design decision, not an implementation, and that decision reshapes G4 and G6 as well — all three assume the repairing process can materialise the archetype it is repairing.
#729 (the parent Feature) and its six phases are closed; this issue carries the remainder. #781 carries two P5 criteria that no increment covered.
Activity
typhon check --schema <dll>: assembly-backed field decode for the Tier 2 checks #757allowLoss: string[]instead of one boolean #761repair --applymust refuse a format revision it does not know (OQ-7) #762#750 Merge main and regenerate the rule-coverage matrix
#750 Close the integrity gap: all 27 cross-structure checks run offli…
#750 A repair plan could never be applied, and a renamed bundle scann…
nockawa commentedon Aug 15, 2026
Two integrity defects fixed in PR #810 (merged). Staying open — this issue's remaining scope (repair, G3, the rest of the gap set) is untouched by that work.
A repair plan could never be applied. The plan fingerprint folded
string.GetHashCode, which .NET randomises per process as hash-flood mitigation, so two scans of byte-identical data produced different fingerprints in different processes. The documented two-step workflow —repair --plan, review it,repair --apply— could not succeed once, and it refused with "the database has changed since this plan was produced", which accuses the database of drifting to explain a defect in the comparison. It was order-dependent too, chaining findings in list order. Now sorted, then FNV-1a over UTF-8 bytes with a separator — the same constructionProfilerSessionMetadataBuilderuses for schema fingerprints, and for the same reasons: sorting makes it order-independent, the byte hash makes it process-independent.A renamed bundle scanned as healthy. The scanner validated the page-0 signature and format revision but not the recorded database name against the bundle directory's stem, which
ManagedPagedMMF.OnFileLoadingcompares on every open. A copied or renamed bundle therefore reported Divergent-but-repairable when no tool could open it at all — and the plan then proposed a repair step that reopens the database. Catalogued as BOO-07 (claude/design/Durability/Integrity/03-checks.md),Fatal+NotRepairablesince the remedy is a filesystem rename and this feature does not move the operator's files. A directory not named*.typhonis reportedAdvisoryinstead — that is what a backup looks like, including the pre-repair copies this feature creates itself, and condemning them would make every backup scan as a broken database.Note the catalogue is now 28 checks, not 27; the counts recorded in
08-implementation-report.mdand09-closing-the-gap.mdare left as the historical record of G2.