Skip to content

Database integrity — cross-structure checks, per-slot salvage, and the geometry the file never recorded #750

Open
6 of 14 issues completed

Description

@nockawa

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.

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 / ComponentR1 pointers 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.

Sub-issues

Sub-issues

6 of 14 Issues completed
Loading 14 sub-issues

Activity

  1. added theissue type on Aug 10, 2026
  2. updated Product Engine, Estimate XL, Area Durability and Priority P1-High on Aug 10, 2026
  3. moved this to Todo in Typhonon Aug 10, 2026
  4. added 2 commits that reference this issue on Aug 11, 2026
  5. moved this from Todo to In Progress in Typhonon Aug 11, 2026
  6. added a commit that references this issue on Aug 15, 2026
  7. nockawa commented on Aug 15, 2026

    @nockawa
    CollaboratorAuthor

    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 construction ProfilerSessionMetadataBuilder uses 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.OnFileLoading compares 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 + NotRepairable since the remedy is a filesystem rename and this feature does not move the operator's files. A directory not named *.typhon is reported Advisory instead — 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.md and 09-closing-the-gap.md are left as the historical record of G2.

  8. moved this from In Progress to Todo in Typhonon Oct 13, 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
      Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions