epiphany/crates/epiphany-bundle
Levi Neuwirth 68b08adb5e Push 4b tranche 3b-i: the score wire opens schema major 3
ScoreTuningContext gains `smufl` and `overrides` on the canonical wire.
`accidental_extensions` is deliberately STAGED to a later major: under
req:binfmt:frozen-layout a field addition is a major, so freezing a large
subtree whose consumer (the engraver) does not exist yet buys nothing and
risks a major-4 to fix a mis-shaped field. The three shapes 3a ratified
(Cents/CanonicalF64, AnchorPoint, SmuflVersion) stay reversible until
something exercises them.

Scope discovery: no operation payload embeds the tuning context, anywhere.
So the wire reached is the acceleration full-Score snapshot ONLY — the
canonical operation layer is untouched, no payload is born at v3, no frozen
v2 op-payload decoder is needed, and OperationEnvelopeBlock's accept-set
stays at 2 while Snapshot rises to 3. Major 3 is the first data-model bump
under which a chunk role's max does not move in lockstep. The canonical
base embeds no tuning context and stays major 0, byte-identical.

Migration: the live codec becomes v3; the 3-field form is frozen as
enc/dec_tuning_context_v2 and consumed by decode_v2_score (new, with its
byte-exact inverse encode_v2_score) and by the v0/v1 decoders — AND by
encode_v0_score/encode_v1_score, which the contract missed and which would
have silently corrupted the frozen forms through the strict-canonicality
re-encode check.

The frozen bytes are now pinned by a golden, because nothing else pinned
them. The cross-implementation decode corpus covers only the operation and
bundle surfaces — there is no epiphany-core vectors module — so every
existing test round-trips enc against dec and stays green under a
SELF-CONSISTENT reordering: swapping smufl and overrides in both halves
passed the entire workspace suite and 8/8 conformance, silently moving a
permanently frozen layout. schema_major_3_tuning_context_wire_bytes_are_frozen
asserts the exact encoding of the default (48 B) and a loaded (82 B)
context; it kills that swap. The S12 normalization is visible in the
literal: 1.4 stores minor_centi 40 (0x28), 1.12 stores 12.

Gate: fmt clean, clippy 0, 1282 passed / 0 failed, doc 0, conformance 8/8,
requirement labels 6/6 at 212/282/282 (unchanged — no new req: labels).
Mutations verified independently: breaking the v0 reroute kills 6 tests;
the wire-order swap kills the new golden.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-23 17:35:55 -04:00
..
examples A B C D F 2026-06-19 12:42:31 -04:00
src Push 4b tranche 3b-i: the score wire opens schema major 3 2026-07-23 17:35:55 -04:00
tests A B C D F 2026-06-19 12:42:31 -04:00
Cargo.toml Pushes 1+3: fix the MUST-level violations, wire the types-only machinery 2026-07-02 17:10:50 -04:00
DECISIONS.md Text Projection 0.3.0: every production expanded, and one rule for values 2026-07-09 21:55:49 -04:00
README.md Pushes 1+3: fix the MUST-level violations, wire the types-only machinery 2026-07-02 17:10:50 -04:00

README.md

epiphany-bundle

The Epiphany .musc file format, implementing the normative requirements of Chapter 8 (File Format) of the core specification (spec/core_spec.pdf). This is Agent D's crate per spec/QUICKSTART.md. It depends on epiphany-determinism (Agent A) and on nothing else — not on epiphany-core (Agent B) or epiphany-ops (Agent C):

bundles handle bytes, ops handles semantics. A canonical-base snapshot from the bundle's perspective is opaque bytes plus a frontier DVV; only epiphany-ops interprets it. — QUICKSTART

A bundle is a single file: a fixed 64-byte header at offset 0, two 256-byte superblock slots, then a body of immutable, content-addressed chunks. The superblocks are the only mutable on-disk objects. A commit appends new chunks, writes a new manifest chunk, then flips the active superblock by writing the inactive slot and durably flushing it — that flush is the commit point. Because commits only ever append and touch the inactive slot, a crash can never corrupt the active state.

What's here

Area Items Spec
Prelude FixedHeader (64 B, CRC-32C), Superblock/CommitState (256 B, CRC-32C), select_active Ch. 8 §"The Bundle Layout", §"Superblock Selection"
Atomic commit Bundle::create/open/commit, the 7-step protocol, cold-open path Ch. 8 §"The Atomic Write Protocol", §"Streaming Reads"
Content addressing chunk_content_hash/chunk_id, ChunkRef, ChunkKind, CompressionAlgorithm, domain separation Ch. 8 §"Content Hashing", §"Chunks"
Manifest Manifest (canonical_base ≠ acceleration_snapshots), SnapshotRef, BlobRef, ProfileDeclaration, ExtensionDeclaration Ch. 8 §"The Manifest"
Retention RetentionPolicy (first-class), ProfileConstraints Ch. 8 §"Garbage Collection and Retention"
Op blocks pack_operation_blocks (1 MiB soft target), encode_block/decode_block Ch. 8 §"Operation Envelope Blocks"
Storage BlockStore, MemStore, FileStore (real fsync), FaultStore (crash sim) Ch. 8 §"Durable Writes"
Gates fuzz::run_crash_recovery_fuzz, fuzz::exhaustive_crash_check, fuzz::run_manifest_selection_harness QUICKSTART acceptance

The crash-recovery contract (the acceptance gate)

Kill the process between any two syscalls in the commit protocol; reopen; the bundle must be valid in 100% of runs, and must recover to the previous generation when the crash precedes the durable flush. This is the most important single test in the entire prototype. — QUICKSTART, Agent D

Killing a real process between syscalls cannot be made deterministic, so the fuzzer drives the commit against a FaultStore that distinguishes live (page-cache) bytes from durable (survives-a-crash) bytes and can crash after any chosen syscall — optionally tearing the in-flight superblock write, the case the slot CRC must catch. After every simulated crash the bundle is reopened from the durable image and must:

  1. open successfully (never corrupt);
  2. be at the previous generation or the new one, never anything else;
  3. if the commit returned Ok, be at the new generation; and if the crash was clean (the in-flight flush persisted nothing) and the commit did not complete, be at the previous generation — the exact "recover to the previous generation when the crash precedes the durable flush" property. (A torn final flush may at a full prefix legitimately persist the whole superblock — the genuine post-commit case — so the torn branch admits either generation.)
  4. report no integrity anomaly;
  5. have every canonical chunk present and hash-intact.

Two drivers exercise this: a randomized 10,000-iteration sweep, and an exhaustive per-commit sweep that tests every syscall boundary crossed with every tear point (clean, and torn at prefixes around the 252-byte CRC offset and the 256-byte slot size). The second leaves no step of the protocol untested.

The companion manifest_selection gate asserts the Chapter 8 superblock- selection rule across every corruption scenario the QUICKSTART enumerates: slot A corrupt + B valid (and vice versa), both valid at generation+1, both valid at the same generation (equivalent, and divergent), a generation gap > 1, a non-committed slot, a manifest-hash mismatch, and neither valid.

Building and testing

cargo test -p epiphany-bundle                              # unit + the two gates
cargo clippy -p epiphany-bundle --all-targets -- -D warnings
cargo run --release --example fuzz_crash -- 1000000        # extended crash soak

Hand-off criteria (QUICKSTART, Agent D)

  • cargo test clean.
  • Crash-recovery fuzzer passes 10,000 iterations (crash_recovery_fuzz_ten_thousand_iterations, two seeds; extended soak via the example binary; exhaustive per-syscall sweep in exhaustive_sweep_across_base_states_and_commit_shapes).
  • Manifest-selection harness handles every corruption scenario (every_selection_scenario_holds).
  • Real-filesystem fsync round-trip (file_store_real_fsync_round_trip).

Scope boundaries (per QUICKSTART "Don't do these")

v0 writes only uncompressed chunks (compression on the write path is deferred), but reading zstd-compressed chunks and blobs is supported, per the spec's §Compression MUST (the manifest is mandatory-uncompressed regardless, and a compressed manifest is rejected). It carries the text-projection root but does not implement the s-expression projection content, and it preserves extension declarations and chunks but does not evaluate edit barriers — barrier operands (OperationKindTag, ObjectKind, EditBarrier) are owned by Agents C and E. Operation envelopes, snapshots, and causal frontiers are opaque bytes here.

See DECISIONS.md for the prototype byte-layout choices that anticipate the deferred Binary Format companion, and the batched Pass 11 candidates.