Skip to content

#739 #297 Restore the OLC descent's second parent validation, and share the one descent all write paths use - #769

Merged
nockawa merged 1 commit into
mainfrom
feature/739-olc-descent-authority
Aug 10, 2026
Merged

nockawa merged 1 commit into
mainfrom
feature/739-olc-descent-authority

Conversation

@nockawa

@nockawa nockawa commented Aug 10, 2026 •

Copy link
Copy Markdown
Collaborator

Closes the mechanism behind #297 / #679 (both already closed against this branch — if this is not merged, reopen them).

The defect

OLC makes a parent→child hop atomic with two checks on the same parent version — after the child pointer is read (checkOrRestart), and again after the child's own version is sampled (readUnlockOrRestart). OptimisticDescendToLeaf only ever did the first.

A structure modification completing between them is invisible to both: the parent test has already passed, and the child's version is sampled after the modification, so the child's own later validation compares against a version that never changes again. The descent then answers for a leaf whose separators no longer route the key to it.

RemoveLeaf's borrow-from-right is the producer — it moves a key left, the one direction the B-link right-walk cannot recover from because it can only travel right. That is why all six previously measured events had key < landedLeaf.firstKey.

design/Indexing/latch-coupled-smo.md §2 carried the same inverted ordering, which is where the code got it. Both corrected. Invariant is now rule IXS-07.

Evidence

BTreeDescentHopAtomicityTests bumps the parent's version from inside OlcDescentTrace.RecordStep, which fires exactly in the window, and asserts the descent restarts.

Fails on unmodified main. Passes here. 39 ms. Plus a [RuleMutant] control proving the instrument reads both outcomes. What needed 25,701 harness iterations is now deterministic on one thread.

What is not claimed: the stress rate (1 failure / 106,695 Remove iterations here, 2 / 37,616 on main) is not statistically separable, p ≈ 0.16. The protocol violation is proven and fixed; sufficiency is not proven. Reasoning is in #297.

Also in here

  • One shared descent. InsertIterative and RemoveIterative held line-for-line identical Phase 1 loops — differing only in args.Comparer vs args.KeyComparer, the trace opcode, and return vs return false. Both now call DescendRecordingPath, so IXS-07 reaches every write path by construction instead of being added by hand three times.
  • NRE fix. RemoveCorePessimistic's two fast paths dereferenced cached _linkList / _reverseLinkList unguarded. Those fields are set to default by the path that empties the tree, and IsEmpty() at the top is a TOCTOU; a default NodeWrapper has a null _storage. Their OLC twins have always had the guard.
  • Harness: stack capture on stall, and two lies removed — the deltas over 1s header that printed running totals, and a STUCK verdict asserting a lock cycle it had no evidence for (the first dump it produced refuted it: 28 threads, none blocked, four asleep in SpinWait).
  • Merge/unlink snapshots its chain pointers before the merge. Explicitly not a fix for OLC B+Tree: merge/unlink writes a garbage chunk id, and a key can survive its Remove #739 — the crash survived it unchanged — and the code comment says so. Kept because reading once before mutating is correct on its own terms.

Verification

Still open after this

…re the one descent all write paths use

The OLC protocol makes a parent-to-child hop atomic with two checks on the same parent version: one after the child pointer is read, and one after the child's own version is sampled. OptimisticDescendToLeaf only ever did the first. A structure modification completing between them is invisible to both, because the parent test has already passed and the child's version is sampled after the modification, so the child's own later validation compares against a version that never changes again. The descent then answers for a leaf whose separators no longer route the key to it. RemoveLeaf's borrow-from-right is the producer: it moves a key left, the one direction the B-link right-walk cannot recover from. That is why every one of the six previously measured events had key below the landed leaf's first key. The design doc carried the same inverted ordering in its pseudo-code, which is where the code got it; both are corrected and the invariant is now rule IXS-07.

The race is a 39ms unit test now. BTreeDescentHopAtomicityTests bumps the parent's version from inside OlcDescentTrace.RecordStep, which fires exactly in the window, and asserts the descent restarts. It fails on unmodified main and passes here, with a control test proving the instrument reads both outcomes. What needed 25,701 harness iterations is deterministic on one thread.

InsertIterative and RemoveIterative held line-for-line identical Phase 1 descent loops, differing only in args.Comparer versus args.KeyComparer, the trace opcode, and return versus return false. Both now call one DescendRecordingPath, so IXS-07 reaches every write path by construction rather than being added by hand three times. It deliberately does not sample the leaf's version, because Phase 1.5A needs leafVersion == 0 to tell LOCKED from OBSOLETE and collapsing that is the shape #695 came from.

RemoveCorePessimistic's two fast paths dereferenced the cached _linkList and _reverseLinkList with no validity check. Those fields are not merely stale: the path that empties the tree writes them to default, and IsEmpty at the top of the method is a TOCTOU. A default NodeWrapper carries a null storage reference, which is exactly why IsValid tests it, so GetLatch dereferenced null. Their OLC twins have always had the guard. Fixed, with the pre-dirty and the lock paired into one call so a caller cannot order them apart.

The race harness gained a stack capture on stall detection and lost two lies. Its deltas line was headed "deltas over 1s" and printed running totals, so a frozen counter with a large total read as heavy activity; it now prints total(+delta) for every counter including the zeros. Its STUCK verdict asserted "this is the shape a lock cycle or a wait-forever has" with no evidence, and the first dump it produced refuted that outright: 28 threads, not one blocked on a lock, four asleep in SpinWait inside the bounded retry loop. The verdict now reports what the counters did and hands over the stacks rather than naming a cause.

The merge/unlink branches also snapshot their chain pointers before the merge instead of re-reading them afterwards. This is not the fix for #739 and the comment says so: the crash survived it unchanged, so the pointer was already corrupt when read. Kept because reading once before mutating is correct on its own terms.
@nockawa
nockawa merged commit 8baa671 into main Aug 10, 2026
16 checks passed
@nockawa
nockawa deleted the feature/739-olc-descent-authority branch August 10, 2026 21:39
nockawa added a commit that referenced this pull request Aug 11, 2026
…est engine test sat unrun (#775)

The gate filters the Workbench suite on tools/Typhon.Workbench/** only, so the heaviest page-cache/B+Tree stress case — which lives there — never ran on an engine merge. #765 and #769 executed it zero times; #772 ran it only by touching an SPA file. A green gate was reporting on a test it had skipped.

Moved into Typhon.Engine.Tests and quarantined against #774: reliably red on the gate box, 2 of 2, green locally. shard.py's retry net now covers the Workbench suite too, without softening any verdict.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant