Repository navigation
#739 #297 Restore the OLC descent's second parent validation, and share the one descent all write paths use - #769
Merged
Conversation
…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
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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).OptimisticDescendToLeafonly 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 hadkey < 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
BTreeDescentHopAtomicityTestsbumps the parent's version from insideOlcDescentTrace.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
InsertIterativeandRemoveIterativeheld line-for-line identical Phase 1 loops — differing only inargs.Comparervsargs.KeyComparer, the trace opcode, andreturnvsreturn false. Both now callDescendRecordingPath, so IXS-07 reaches every write path by construction instead of being added by hand three times.RemoveCorePessimistic's two fast paths dereferenced cached_linkList/_reverseLinkListunguarded. Those fields are set todefaultby the path that empties the tree, andIsEmpty()at the top is a TOCTOU; a defaultNodeWrapperhas a null_storage. Their OLC twins have always had the guard.deltas over 1sheader that printed running totals, and aSTUCKverdict asserting a lock cycle it had no evidence for (the first dump it produced refuted it: 28 threads, none blocked, four asleep inSpinWait).Verification
PayloadAxes_SurviveACrashandParallelOperations_AreLinearizable, which fail identically on unmodifiedmain. Correction to an earlier version of this description, which called them untracked: both are[Category("Quarantine")]against open issues — ComponentCollection: crash-safety — CC buffer mutations are not WAL-redo-logged (dangling _bufferId after mid-window crash) #389 (ComponentCollectionbuffer mutations are not WAL-redo-logged) and Minimal WAL — P0 leftovers: per-tx ChangeSets (UOW-1) + full-suite CI gate #400 (sharedChangeSetconcurrent-mutation guard). They are excluded from the merge gate by design; they only appeared in my runs because I invokeddotnet testwithout the gate's--filter "Category!=Quarantine".not_removed, nowrong_value.check-rule-scopes,audit-rule-coverage(0 blocking),check-doc-linksall pass.Still open after this
Controlword (flags=0, Start=9, Count=0), i.e. an offset or lifetime defect, not an ordering one. Full analysis on the issue.