Skip to content

PointInTimeAccessor returns zeros instead of failing when its snapshot has been trimmed #672

Closed

Description

@nockawa

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 IsSnapshotValid probe — 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_IndependentSnapshots and adapt them to the enforced contract.
  • Add coverage for an expired snapshot raising rather than returning zeros.
  • Update claude/design/Revision/02-mvcc-visibility.md and claude/design/Runtime/06-parallel-efficiency.md with 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

Activity

  1. self-assigned this
    on Aug 4, 2026
  2. added theissue type on Aug 4, 2026
  3. updated Product Engine, Area MVCC, Priority P0-Critical and Estimate S on Aug 4, 2026
  4. added a commit that references this issue on Aug 5, 2026
  5. moved this to Todo in Typhonon Aug 5, 2026
  6. added 2 commits that reference this issue on Aug 8, 2026
  7. nockawa commented on Aug 8, 2026

    @nockawa
    CollaboratorAuthor

    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

    • Publish the retained-TSN watermark from the cleanup path (interlocked max) — TransactionChain.RetainedMinTSN, published from ComputeNextMinTSN itself. One publication point covers every trim site, because every caller computes it in order to trim to it.
    • Check it on the PTA Versioned read path; throw a typed snapshot expired error — SnapshotExpiredException (TyphonErrorCode.SnapshotExpired = 1003), carrying both the snapshot TSN and the floor that overtook it.
    • Decide throw vs. an IsSnapshotValid probe — 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.
    • Fix the legacy walk-failure path that leaves the chain root in _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.
    • Un-[Ignore] the three tests and adapt them to the enforced contract.
    • Add coverage for an expired snapshot raising rather than returning zeros.
    • Update claude/design/Revision/02-mvcc-visibility.md and claude/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.Read and 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_MVCCVisibility was passing for the wrong reason. It spawned Value = 0 and asserted the older accessor still read 0 after a mutation — which is precisely what a destroyed snapshot returns. It would have passed whether MVCC isolation held or not. It now spawns 7. 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 Transaction keeps 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 making Create internal 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.

  8. moved this from Todo to In Progress in Typhonon Aug 8, 2026
  9. added a commit that references this issue on Aug 8, 2026
  10. moved this from In Progress to Done in Typhonon Aug 8, 2026
  11. added a commit that references this issue on Aug 9, 2026
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

Type

Fields

Priority

P0-Critical

Estimate

S

Area

MVCC

Start date

None yet

Target date

None yet

Bug status

None yet

Product

Engine

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions