Skip to content

Database as a .typhon bundle directory (rationalize the on-disk file scheme) #450

Description

@nockawa

Problem

A Typhon database is multi-file but is presented as a single file, and the conventions don't agree across surfaces:

  • Data: {name}.bin — generic/vague extension; magic-signed header; in-file checkpoint (no separate file).
  • Lock: {name}.lock.
  • WAL: {segmentId:D16}.wal in a wal/ directory whose default is a bare relative "wal" (cwd-relative — breaks off-cwd), and segments are named by segment id, not DB → two DBs sharing a directory collide.
  • Workbench "marker": {name}.typhon is an empty 0-byte decoy; the real data is the sibling {name}.bin. The Shell doesn't use a marker at all — it strips the extension and writes .bin.

Net: split identity (nice extension is fake), WAL collisions, .bin vagueness, and no ubiquity.

Decision — Option B: a database is a .typhon bundle directory

One path = one database. The extension lives on the directory; everything lives inside with fixed internal names:

game.typhon/
├── data          # primary paged data file (was {name}.bin); magic-signed; in-file checkpoint
├── db.lock       # single-writer lock
└── wal/          # WAL segments — PRIVATE to this DB (collision gone by construction)

Deliverables — ✅ Merged in PR #451 (2026-07-04)

  • PagedMMFOptions / ManagedPagedMMF: open/create the {name}.typhon/ bundle; data + db.lock inside; header validation unchanged
  • WalWriterOptions.WalDirectory defaults to null; the engine derives {bundle}/wal (early in the ctor — see the CRITICAL note in the comment); the bare-"wal" default removed; no caller override needed
  • Recovery scans {bundle}/wal
  • Shell (ShellSession.OpenDatabase) opens/creates a bundle (no .bin hardcode, no marker)
  • Workbench: FileBrowserService shows a .typhon directory as one openable DB row; EngineLifecycle drops the manual WAL-dir override; FixtureDatabase generates bundles; client file filter → ['.typhon']
  • Legacy artifact at the bundle path → typed StorageException(InvalidDatabaseBundle=2008) (+ EnsureFileDeleted clears it)
  • typhon migrate-legacy importer moves a validated legacy .bin into {bundle}/data (magic-checked; refuses if a bundle or non-empty wal/ exists)
  • Full engine hard-reject of the legacy .bin+marker layout on open — still DEFERRED (pre-alpha: a non-bundle path just creates a fresh bundle; migrate-legacy covers the migration path; see design §6 Q4)
  • Tests: create/open/reopen; lock semantics; two DBs in one parent dir don't collide (by construction); crash-recovery from {bundle}/wal with the null default (BundleWalRecoveryTests); legacy-artifact rejection (LegacyBundleArtifactTests)
  • Docs: design doc + engine doc comments; engine overview (03-storage.md), user guide, and doc/feature-set (Storage + Hosting) prose swept to the bundle layout

Related Documents

Parent Epic: #146 (Developer Experience & Adoption)

Activity

  1. self-assigned this
    on Jul 3, 2026
  2. added this to the pre-alpha milestone on Jul 3, 2026
  3. added theissue type on Jul 3, 2026
  4. moved this to Todo in Typhonon Jul 3, 2026
  5. updated Priority, Estimate, Area and Product Engine on Jul 3, 2026
  6. nockawa commented on Jul 3, 2026

    @nockawa
    CollaboratorAuthor

    ✅ Implemented + verified (2026-07-03)

    Core: PagedMMFOptions.BundleDirectory ({dir}/{name}.typhon), data/db.lock inside, EnsureFileDeleted deletes the bundle; PagedMMF creates the dir before lock/data; WalWriterOptions.WalDirectory → null with the engine deriving {bundle}/wal.

    Verification:

    • tsh creates smoketest.typhon/{data, wal/…} (WAL derived inside the bundle) ✅
    • anthill — bundle DB layer works; its ReadsSnapshot<Genetics> crash is pre-existing (confirmed identical on clean main) ✅
    • Workbench 596/609 — the 4 GetPage_* failures are pre-existing (stale v4-layout expectation, confirmed failing on clean main); my 2 regressions (File.Exists on the now-directory path) fixed ✅
    • Engine full suite green on a double consecutive run (the definitive stale-bundle check) — remaining failures are all confirmed parallel-flakes (pass in isolation) ✅

    🔴 Code review caught a CRITICAL durability bug — fixed. The WAL-dir derivation was sequenced after the reopen path reads WalDirectory to gate WalFilesPresentAtOpen → with the new null default, a crash-reopen silently skipped WAL replay (committed data lost). The full suite hid it because every crash fixture sets WalDirectory explicitly. Fix: derive the WAL dir early in the ctor (before InitializeUowRegistry). New BundleWalRecoveryTests (crash + reopen with null WalDirectory, independent providers = a real process restart) fails without the fix, passes with it — verified by reverting.

    Test-harness lesson: any test that hand-rolled Directory.GetFiles(dir).Delete() cleanup left a stale bundle the engine reopened (deterministically broke SingleThreadedParallelFence — 1 entity counted as 3 — and looked like a spatial-migration bug until bisected + baselined). Fixed in ParallelFenceTests/AdaptiveFenceCostTests/TestBase.

    Deferred (noted): typhon migrate importer + explicit legacy-.bin rejection; overview/guide/CLI doc prose. Ready for review + commit (not committed).

  7. moved this from Todo to In Progress in Typhonon Jul 3, 2026
  8. nockawa commented on Jul 4, 2026

    @nockawa
    CollaboratorAuthor

    AC #8 (docs) completed 2026-07-04 — pending review + commit

    The four doc surfaces now describe a Typhon database as a .typhon directory, not a file:

    • Engine overview — claude/overview/03-storage.md gains a bundle-directory note (data / db.lock / wal/ inside), linking the bundle-format design.
    • User guide — doc/guide/06-operating.md: "database file (.typhon)" → "database (a .typhon directory)" (3 spots).
    • Workbench charter — tools/Typhon.Workbench/CLAUDE.md: ".typhon file" → ".typhon database (a directory)"; authority-order line reworded.
    • CLI help — tsh/typhon open command help: "Opens a database file" → "Opens a .typhon database (a directory)".

    Shell builds clean. Still deferred (unchanged): the typhon migrate importer + its CLI help — see the design doc §8b. AC #6's rejection half was already done (legacy-artifact hardening, 2026-07-03).

  9. nockawa commented on Jul 4, 2026

    @nockawa
    CollaboratorAuthor

    Legacy importer (AC #6 importer half) shipped 2026-07-04 — pending review + commit

    tsh migrate-legacy <path>.bin imports a pre-bundle database into a {name}.typhon bundle. Since the v4 data-file format is byte-identical between the legacy .bin and the bundle's inner data (the #450 change was container-only), this is a file move, not a conversion:

    • Validates the .bin carries the "TyphonDatabase" header signature (page-0 scan, offset-independent).
    • Refuses if {name}.typhon already exists, or if a non-empty adjacent wal/ is present (the legacy shared WAL can't be attributed to one DB — the user must cleanly close/checkpoint first; the importer never replays a WAL).
    • Creates {name}.typhon/, moves {name}.bin → {bundle}/data. The .bin filename must be the original database name (the header embeds it; the engine verifies on open).

    Named migrate-legacy because migrate is already the schema-migration verb in tsh; the top-level typhon migrate name awaits the tsh→typhon rename (#435). Implementation: CommandExecutor.ExecuteMigrateLegacy + help entries.

    Verified end-to-end via tsh: seed a real v4 DB → relocate to .bin → migrate-legacy → reopen succeeds (Opened legacydb); plus all three refusal paths (bad magic / target exists / non-empty wal). Shell builds clean.

    With this, AC #6 is fully done (rejection 2026-07-03 + importer 2026-07-04) and AC #8 docs were updated. Design doc §7 (AC #6/#8) + §8b ("Legacy importer") updated.

  10. added a commit that references this issue on Jul 4, 2026
  11. moved this from In Progress to Done in Typhonon Jul 4, 2026
  12. nockawa commented on Jul 4, 2026

    @nockawa
    CollaboratorAuthor

    The one remaining deferred deliverable — the full engine hard-reject of a legacy .bin+marker layout on open — is now tracked separately in #452 (Feature under Epic #146, pre-alpha milestone). Everything else in this issue shipped in PR #451.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Fields

Priority

P2-Medium

Estimate

S

Area

Execution

Start date

None yet

Target date

None yet

Product

Engine

Projects

  • Status
    Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions