Repository navigation
Description
Summary
PointInTimeAccessor has no retention: cleanup is free to trim the very revisions its snapshot needs, and when that happens a read returns an all-zero component instead of failing. Silent wrong data on a public API.
Three tests assert the guarantee the type's name implies and are quarantined with [Ignore] pointing here. They must go green as part of closing this.
What actually happens
PointInTimeAccessor.Create calls TransactionChain.AllocateTSN(), which is a bare Interlocked.Increment(ref _nextFreeId). It hands out a TSN but registers nothing, so TransactionChain.ComputeNextMinTSN() — which walks the transaction chain to decide how far back revisions must be kept — cannot see the accessor. Any committing writer that runs cleanup may trim below a live snapshot.
Traced on AccessorSeesCorrectVersionedRevision: spawn Value=100, create the PTA (TSN=3), commit an update to 200, read back. The chain at root 1 then holds exactly one entry, TSN=4 — the pre-update revision is gone. WalkChain returns SnapshotInvisible, the caller continues, _locations[slot] stays 0, and EntityRef.Read hands back a zeroed struct.
Not caused by the #629 eligibility flip
Verified by temporarily reverting the flip and re-tracing: the chain is trimmed identically before it. The tests passed anyway for an accidental reason — in the legacy (flat) branch of EntityAccessor.ResolveEntity, CopyLocationsFrom seeds _locations[slot] with the chain ROOT, and on walk failure the code leaves that value in place. Chunk id 1 in the CompRev segment happened to equal chunk id 1 in the content segment, which still held the pre-update value.
So this is a long-standing gap that #629 stopped masking, and the accidental-pass mechanism is itself a second silent-wrong-data path worth removing.
Why P0
- Public API, and the failure mode is wrong data, not an error.
- The name states a guarantee the type does not make, which is exactly what led three tests to assume it.
- Zeroed components are indistinguishable from legitimately-zero data at the call site.
Proposed fix — a retained-TSN watermark, NOT full retention
Cleanup already computes nextMinTSN. Publish it as a global "oldest fully-retained TSN" (monotonic — an interlocked max, not a plain store, since cleanups can complete out of order). A PTA read then costs one Volatile.Read and a compare: if snapshotTSN < watermark, throw snapshot expired.
Deliberately not giving the PTA real retention. Retention means chains stop being trimmed while a snapshot is live, and RevisionChainReader.TryWalkSingleEntryOptimistic — the lock-free fast path for every Versioned read in the engine — is predicated on chains being one entry long (claude/design/Revision/02-mvcc-visibility.md §3.2). That would hand any caller a way to silently degrade MVCC read performance engine-wide by holding an accessor too long, or leaking one. Fail-fast is the cheaper and safer contract.
Scope
- Publish the retained-TSN watermark from the cleanup path (interlocked max).
- Check it on the PTA Versioned read path; throw a typed snapshot expired error.
- Decide throw vs. an
IsSnapshotValidprobe — throwing changes a public failure mode and needs an explicit call. - Fix the legacy walk-failure path that leaves the chain root in
_locations[slot]and reads it as a content chunk id (or confirm it dies with the flat path). - Un-
[Ignore]AccessorSeesCorrectVersionedRevision,TwoAccessorsAtDifferentTSNs_SeeDifferentSnapshots,MultipleAccessorsConcurrently_IndependentSnapshotsand adapt them to the enforced contract. - Add coverage for an expired snapshot raising rather than returning zeros.
- Update
claude/design/Revision/02-mvcc-visibility.mdandclaude/design/Runtime/06-parallel-efficiency.mdwith the stated contract.
Also worth settling here: the name
The snapshot only covers Versioned components. SingleVersion and Transient have no history, so a PTA reads them live — a writer's committed change is visible immediately. "Point in time" was never whole-entity.
SnapshotAccessor, or making Create internal so it is reachable only through the parallel-dispatch path it was designed for, would stop callers reaching for it as a durable snapshot. Pre-alpha, so a clean break is available.
Context
- Design contract: claude/design/Revision/02-mvcc-visibility.md §3.1 — the
skipTimeoutfast path is "Used byPointInTimeAccessor, where the database is known to be quiescent (no concurrent writers)". - Lifecycle: claude/design/Runtime/06-parallel-efficiency.md §2 — attached per parallel-system dispatch, re-attached each tick, cannot write Versioned components.
- Found while completing Index ownership consolidation — retire the per-ComponentTable secondary index #629 (index-ownership consolidation).
Activity
#629 Retire the per-ComponentTable secondary index (PR #680)
#672 Fail an expired PointInTimeAccessor read instead of returning a …
#672 Zero the slot location when a revision-chain walk finds nothing
nockawa commentedon Aug 8, 2026
Fixed in PR #719, taking the fail-fast contract this issue proposed rather than retention, and for the reason stated here: retention would let any caller silently degrade the engine-wide lock-free Versioned read path by holding an accessor too long.
Scope, as filed
TransactionChain.RetainedMinTSN, published fromComputeNextMinTSNitself. One publication point covers every trim site, because every caller computes it in order to trim to it.SnapshotExpiredException(TyphonErrorCode.SnapshotExpired = 1003), carrying both the snapshot TSN and the floor that overtook it.IsSnapshotValidprobe — throw. A probe is only useful to a caller that can do something else instead, and there is nothing else: the snapshot is gone. It would also leave the zeroed read reachable for anyone who forgot to call it, which is the defect._locations[slot]— fixed, and worth restating because it is nastier than the headline bug: that path does not read zeros, it reads whatever occupies that id in the content segment, a wrong value. It is exactly why these tests passed before the Index ownership consolidation — retire the per-ComponentTable secondary index #629 flip.[Ignore]the three tests and adapt them to the enforced contract.claude/design/Revision/02-mvcc-visibility.mdandclaude/design/Runtime/06-parallel-efficiency.md— separate docs PR.One implementation note worth keeping
The check sits in the failure branch of the chain walk, not ahead of the read. A successful read pays nothing at all, not even the watermark load — cheaper than the "one
Volatile.Readand a compare" this issue budgeted for — and it is strictly more precise: a walk that fails for a legitimate reason is left alone unless the snapshot is also demonstrably below the floor.The measurement, which is what made this safe
Before writing the throw I wired a counting probe and ran the full suite. Across 5044 tests there are exactly two revision-chain walk failures, both PTA reads, both below the watermark, and none from a Transaction. Flipping the probe to throw named the blast radius as a single test; the second reported failure was NUnit misattributing a throw across parallel fixtures, and both allocator fixtures pass alone.
That single test is the part worth your attention.
MultipleSnapshotsSequential_MVCCVisibilitywas passing for the wrong reason. It spawnedValue = 0and asserted the older accessor still read0after a mutation — which is precisely what a destroyed snapshot returns. It would have passed whether MVCC isolation held or not. It now spawns7. Same shape as the accidental-pass mechanism this issue already documented for the flat path, one layer up.A new control test pins why the contract is fail-fast and not a limitation of MVCC: a read-only
Transactionkeeps its snapshot across the identical write, through the chain registration the accessor skips.Left for you
The naming question at the end of the issue —
SnapshotAccessor, or makingCreateinternal so it is only reachable through the parallel-dispatch path it was designed for. Both are defensible and both are breaking; the exception now makes the constraint legible at runtime, so it is no longer urgent. Not decided unilaterally.#688 Discover WAL segments through the backend instead of scanning th…
Log2n-io#631 Log2n-io#582 Log2n-io#710 Log2n-io#672 Log2n-io#688 Bug …