Repository navigation
Description
Summary
Add a Committed durability discipline for SingleVersion-layout components: writes are staged per transaction, made atomic and zero-loss durable at Transaction.Commit via a logical-redo WAL record (the unified SlotRecord with a Committed flag), then published in place to the cluster slot — with read-committed isolation and O(1) rollback, and no revision chain.
It is not a new StorageMode value: it shares the SingleVersion cluster layout (byte-identical) and is selected by a runtime knob (TickFence default ⇄ Commit escalation) on the existing per-UoW durability axis (ADR-005). This closes the ~6× Versioned write gap for the large class of components that need atomicity + zero-loss durability but not snapshot isolation / temporal queries.
Authoritative design doc: claude/design/Ecs/committed-storage-mode.md (rev 3)
WAL-program integration record (decision D7): claude/design/Durability/MinimalWal/05-committed-mode.md
Study (rationale + file:line evidence): claude/scratch/single-version-commit-mode-study.md
Why (3 code-verified facts)
- The 6× is the write path, not reads. Versioned bulk HEAD reads are already 2.6 ns = SV (HEAD-in-cluster, ADR-045 telemetry-lock #3). The gap is COW content-chunk alloc + chain append + GC.
- The WAL slot record already is "logical redo of component bytes → cluster slot." After WAL v2 (Minimal WAL — Durability Redesign (P0 + P1) #399), the unified
SlotRecord/RecordCodecis replayed byRecoveryApplier's slot upsert in LSN order. The Committed write reuses the same wire format + replay; only the trigger (commit vs tick) and a CommittedRecordFlagdiffer. Zero new WAL plumbing. - The runtime DAG already forbids concurrent same-entity write×write and undeclared read×write at
Build()(AC-01/AC-02,rules/runtime-scheduling.md). So read-committed is sufficient for engine-scheduled systems — MVCC snapshot isolation was doing work the scheduler guarantees statically.
Decision (four behaviours, three StorageMode layout values)
| StorageMode (layout) | Discipline (runtime) | For |
|---|---|---|
Transient |
— | scratch; lost on crash |
SingleVersion |
TickFence (default) |
position/velocity/health — ≤1-tick-loss OK, batched WAL, max throughput (kept) |
SingleVersion |
Commit (escalation) |
same layout when a write must be zero-loss + atomic (teleport, pickup), via side-tx |
Versioned |
(always commit-scoped) | economy/progression + temporal + multi-master conflict handlers |
Mandated write path — Variant A (deferred-apply / staging arena). Writes are buffered per-transaction (reusing the Versioned SingleCache read-your-own-writes mechanism); at commit the WAL SlotRecord is appended, then values are published in place to the cluster slot. Variant B (in-place + undo) is rejected: pre-commit in-place writes dirty the page, and the fuzzy checkpoint — gated only by ActiveChunkWriters, released before commit — could persist uncommitted bytes into the data file with no compensating WAL record → unrecoverable phantom data (violates CM-01 / CK-02).
Index timing — aligned with Versioned. The exact secondary B+Tree Move + view notifications happen at commit; spatial R-tree, zone maps and cluster broad-phase AABBs stay fence-batched for all modes (no Committed-specific spatial behaviour — the durability knob must not perturb when a structure reflects a write).
Out of scope (stays Versioned): snapshot isolation, temporal/"AS OF", TAIL indexes, multi-master conflict-rebase.
Acceptance Criteria
- AC-1 — Shared layout, runtime discipline. A
SingleVersioncomponent can be written underTickFence(default) orCommitdiscipline chosen at runtime per tx / side-tx — no layout change, no newStorageModeenum value. - AC-2 — Commit durability. A
Commit-discipline write is recoverable to the exact committed value after a crash (Immediate ⇒ durable atCommit; Deferred/GroupCommit ⇒ durable atuow.Flush()). Crash/recovery test (SimulateHardCrashafter WAL flush, before checkpoint). - AC-3 — Atomicity + rollback. All
Commitwrites become visible together at commit;tx.Rollback()discards the staged values (HEAD was never touched). No partial visibility to a concurrent/subsequent transaction. - AC-4 — Read path unchanged on the hot path. Other transactions read the cluster HEAD slot directly (read-committed), no chain walk. The only added branch is one per-transaction-constant
_tx.Disciplinecheck on the writing tx's own read-your-own-writes path (SingleCache). Bulk iteration stays ≤2.7 ns/entity. - AC-5 — Write path ~SV-class. A
Commitwrite (Variant A staging) is ≤25 ns; commit publish ≤60 ns/component; ≥8× faster than a Versioned write (Zen 4). TheTickFencein-place path (~3 ns) is unregressed. (Measured: write 23.25 ns ✓, 22.6× vs Versioned ✓, TickFence unregressed ✓; publish 65 ns vs ≤60 ns is inconclusive — BDN iteration too short — follow-up to re-measure. See the benchmark comment below.) - AC-6 — No chain allocated. A
Commitwrite allocates zero CompRevTable / content chunks / deferred-cleanup entries. - AC-7 — Recovery reuse. Recovery replays
Commitrecords as ordinarySlotRecords (Committed flag set) throughRecoveryApplier's slot upsert in LSN order, composing with tick-fence records for the same slot (last-writer-wins by LSN). Zero Committed-specific recovery code. - AC-8 — Scheduler safety. A system declaring
ReadsSnapshoton aSingleVersion-layout component is rejected atBuild()(rule CM-04 /runtime-scheduling.mdAC-05). - AC-9 — Versioned & TickFence untouched. No behavioural change to
Versionedor toSingleVersionunder the defaultTickFencediscipline. - AC-10 — Tests + proof. Unit + recovery + scheduler-rejection tests; CM-01 mid-tx page-memory probe; CM-04 Build()-rejection; span-over-staged Debug-assert;
MixedDisciplinecrash-sweep workload; TLA+ Spec S3 green; write/commit benchmarks recorded. All green in the full suite (zero new reds). - AC-11 — Exact-index consistency at commit. After a
Committx commits, an exact secondary B+Tree query reflects the committed value with no false-negative (Movedone at commit, matchingVersioned). Spatial/zone-maps/cluster-AABBs stay fence-batched for all modes. Query-after-commit test.
Key open questions — resolved in design
ReadsSnapshotpolicy → reject atBuild()(CM-04). ✅- Distinct chunk type vs flag → reuse the unified
SlotRecordwith a CommittedRecordFlag(WAL v2); no distinct chunk type. ✅ - WAL volume for multi-write-per-tick → staging coalesces to the last value per slot at commit; one record per slot per commit. ✅
- Detect-only conflict counter → deferred; last-writer-wins only. ✅
Body reconciled 2026-06-25 to match the authoritative rev-3 design doc (Variant A supersedes the original Variant-B mandate per decision D7). Original Variant-B framing preserved in git history of the design doc.
Shipped 2026-06-26 via #401 (engine) + typhon-claude#52 (docs). AC boxes reflect the merged result; AC-5 publish-pass benchmark is inconclusive (re-measure follow-up).
🤖 Generated with Claude Code
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
nockawa commentedon Jun 25, 2026
📌 Post-implementation doc TODO — update
claude/design/Ecs/06-storage-modes.mdOnce the Committed discipline is implemented,
06-storage-modes.mdmust be updated to introduce the durability-discipline axis on theSingleVersionlayout. As written it describes only theTickFencebehaviour, so several statements become false under theCommitdiscipline. Hold the edit until implementation so the doc set doesn't describe an unbuilt feature as present.Add: a "Durability discipline (
TickFence⇄Commit)" section + a sub-matrix (or aCommitcolumn). The new column reads: "SV read path + Versioned commit/durability/index/view semantics, minus the revision chain and snapshot isolation."Statements in
06that areTickFence-only and flip underCommit:CommitSlotRecordsCommitAlso fix one pre-existing imprecision: L38 "Versioned Indexes: Updated at commit" really means "B+Tree at commit, spatial at fence" — relevant because
Commitis intentionally stricter than Versioned on spatial (reconciles fat-AABB escapes at commit; see design doc §Derived-structure maintenance / CM-05).Authoritative spec for the feature:
claude/design/Ecs/committed-storage-mode.md(rev 3).nockawa commentedon Jun 25, 2026
✏️ Correction to the previous comment — spatial stays at the fence (aligned with Versioned)
The prior comment said Commit reconciles spatial-escapes at commit and is "stricter than Versioned on spatial." That was wrong and has been reverted in the design doc (rev 3). Corrected rule:
Commitaligns withVersionedexactly — it's the transactional sibling, and the durability knob must not perturb which derived structures are fresh when (decision #31):CommitandVersioned).Versioned). Spatial is a tick-granular, conservative, derived broad-phase; a not-yet-reconciled fat-AABB escape is an in-memory lag identical across modes — not a per-mode discrepancy, and rebuilt from HEAD on recovery (RB-01).So the
06-storage-modes.mdpost-impl matrix row should read: Indexes (B+Tree) + Views → at commit; spatial → at fence underCommit— not "spatial-escape at commit." And there is no "stricter than Versioned" caveat; the earlier note about that is withdrawn. (The L38 "Versioned indexes at commit" imprecision still stands: it means B+Tree-at-commit, spatial-at-fence — which is now exactly whatCommitdoes too.)Making spatial commit-synchronous would be a separate spatial-subsystem decision affecting all modes (perf cost: per-commit reinserts, losing the batched/parallel AabbRefresh) — out of scope for #392; file its own issue if ever wanted.
nockawa commentedon Jun 25, 2026
Implementation plan — approved 2026-06-25 (core feature + tests)
Scope this pass: core feature + unit/recovery/scheduler tests + CM-01 probe (AC-1..9, AC-11). Deferred to a follow-up: TLA+ Spec S3, the MixedDiscipline crash-sweep workload, and the BDN ≤25/≤60 ns perf gate (the write/commit path is built perf-shaped; only the formal benchmark is deferred). ECS-12 (DirtyBitmap orphaned-array race) is treated as orthogonal — Variant-A staging never
Sets the dirty bit on the write, and the publish-time clear is last-writer-wins-benign per CM-03; ECS-12 stays a separate H-track bug.Authority:
claude/design/Ecs/committed-storage-mode.md(rev 3). Branch:feature/committed-storage-mode.Codebase readiness (verified)
RecordFlags.Committedis defined (RecordFormat.cs:46) and stamped frombatch.CommittedDiscipline(RecordCodec.cs:90-94);RecoveryApplierapplies Committed records as ordinary LSN-ordered slot upserts → AC-7 free, zero new recovery code.CreateSideTransactionexists (TickContext.cs:73,Func<DurabilityMode,Transaction>); per-tx arena_commitBatchArenaexists (Transaction.cs:1630, commit-time-lazy → hoist to first staged write).PrepareClusterVersionedSlot(Transaction.cs:1322-1472) +PublishClusterVersionedSlot(1479-1506).Steps (each mapped to ACs)
DurabilityDisciplineenum +[Component(DefaultDiscipline=)]+ComponentTable.Discipline(AC-1)disciplinethroughCreateQuickTransaction/CreateUnitOfWork/CreateTransaction/CreateSideTransaction→Transaction.Discipline, CM-02 freeze-on-first-write (AC-1)CompRevInfo.StagedOffset+ read-your-own-writes branch on_tx.Discipline(AC-4, AC-6)AddSlotStaged(zero-copy) → APPEND → WAIT → PUBLISH memcpy→HEAD; O(1) rollback; CM-01 probe (AC-2, AC-3, AC-6)Move+ view-notify at commit, mirroringPrepareClusterVersionedSlot; spatial stays at fence (AC-11)Build()rejection ofReadsSnapshoton non-Versioned + new rule AC-05 (AC-8)Deviations flagged at approval
ReadsSnapshoton any non-Versioned (incl.Transient), not onlySingleVersion(neither has MVCC history).DefaultDiscipline=Commitresolution = escalate-on-first-write + freeze + log (open-Q1 "keep + log"); throw a clear CM-02 error if aTickFencewrite already happened.CommitBatchBuilder.AddSlotStaged(offset,len); stagedrefinvalidated by the nextWritein the same tx (documented + Debug-guarded).🤖 Generated with Claude Code
nockawa commentedon Jun 25, 2026
Core implemented + tested — 2026-06-25 (branch
feature/committed-storage-mode)Variant-A (deferred-apply / staging) Committed discipline on the cluster path, regression-free against the full suite (baseline-diffed — every full-suite red is pre-existing or parallel-flakiness; my changes add zero new reds).
Acceptance criteria
DefaultDisciplineescalation (CM-02)CommitDiscipline_*,DefaultDiscipline_Commit_EscalatesTransactionCommitDiscipline_Write_SurvivesHardCrash— required building the clusterRecoveryApplierincrement (the deferred "cluster path")CommitDiscipline_MultiWrite_Atomic,CommitDiscipline_Rollback_DiscardsStagedCommitDiscipline_ReadYourOwnWrites,CommitDiscipline_StagedWrite_NotVisibleBeforeCommitRecordCodec/RecoveryDriverunchangedReadsSnapshot_OnSingleVersionComponent_ThrowsAtBuild;runtime-scheduling.mdAC-05CommitDiscipline_IndexedWrite_FreshAtCommit_NoFenceMixedDisciplinecrash sweepNotable engineering decisions / deviations
RecoveryApplierwas flat-path only. Added a cluster reconstruction path (claim slot → SoA value write →ClusterEntityRecord), mirroring liveFinalizeSpawns. This is the previously-deferred "P2-gated cluster recovery."SingleCacheto avoid colliding with Versioned revision consumers), copied into the WAL batch viaAddSlotat commit. The "stage directly into the batch arena (zero re-copy)" micro-opt is deferred for pointer-safety.ReconcileClusterIndexAndViewsreused by both the Versioned cluster commit and the Committed publish (rationalize = subtract).SingleCachestaging collision (NRE in revision manager) → dedicatedCommitStageddict; CM-04Build()NRE on access-less engine systems → null-Access guard; CM-02 escalation hole on the cluster in-place path →NoteSvInPlaceWrite.Docs updated:
committed-storage-mode.md(status + impl notes),MinimalWal/05-committed-mode.md§1 (index-timing correction),rules/runtime-scheduling.md(AC-05).Ready for review + commit (engine + tests in the main repo; docs in the nested
claude/repo).🤖 Generated with Claude Code
nockawa commentedon Jun 26, 2026
AC-5 / AC-10 benchmark record (Zen 4 — Ryzen 9 7950X, .NET 10, Release)
CommittedDisciplineBenchmarks,OperationsPerInvoke = N = 1000,[SimpleJob(warmup:3, iter:7)],MemoryDiagnoser.Resolve_Only73.76 ns)Resolve_Only(baseline)Write_Sv_TickFenceWrite_Sv_CommitWrite_VersionedCommit_Sv_CommitPublish_OnlyVerdict vs AC-5 targets
Publish_Onlyiteration (57 µs) is too short to measure reliably (Error ±18.7 ns, band ≈ 47–84 ns)Notes
Write_Sv_Commitallocates 104 B/op — the managedDictionary<long,StagedSlot>staging directory (the native staging buffer is off-heap, not counted). Still 3× under Versioned's 288 B, and AC-6 (no revision chain) holds; not allocation-free.Publish_Onlyneeds a longer iteration (e.g. larger N orInvocationCount); recommend a small follow-up to re-measure it in isolation.PRs: engine #401, docs nockawa/typhon-claude#52.
Committed storage discipline + cluster crash durability (closes Log2n…
AntHill demo: fix the ReadsSnapshot<Genetics> schedule error, add an …