Skip to content

#740 Fix the lower-bound guard's surviving twin in RemoveIterative, and widen IXW-03 to cover it - #766

Merged
nockawa merged 1 commit into
mainfrom
fix-remove-lower-bound-twin
Aug 10, 2026
Merged

nockawa merged 1 commit into
mainfrom
fix-remove-lower-bound-twin

Conversation

@nockawa

@nockawa nockawa commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

PR #745 replaced key < leaf.firstKey with a comparison against the previous leaf's HighKey on the insert side — and left the identical predicate standing in RemoveIterative. Both were written by the same change (#737); one was found wrong, one was fixed.

KeyBelowLeafLowerBound   BTree.Insert.cs: 5    BTree.Remove.cs: 0    BTree.Move.cs: 0
BTree.Remove.cs:610      count > 0 && key < firstKey && previous.IsValid   ← verbatim, until this commit

Why it is wrong

A leaf's first key equals the separator routing to it only until something is removed from the front. After that, the band prevHighKey <= key < firstKey is one the leaf is authoritative for; answering "not authoritative" releases the latch and re-descends to the same leaf.

Why it ships without a red-to-green test — read this part

It is not single-threaded reachable, and I asserted it was before testing it. TryRemoveOlc answers NotFound from the optimistic descent before its count check, so an absent key never arrives at the pessimistic guard. Reaching it needs the descent to find the key, the leaf underfull enough to defer, and a concurrent writer to raise the leaf's first key in between. Concurrency-gated — the #738 class, not #740's.

RemoveAbsentKeyBelowLeafFirstKey_ReportsNotFound is included because the coverage is real and was missing (double-remove across every leaf boundary of a 2,000-key tree, consistency-checked either side) — but it passed before this change as well as after, and its remarks say so in the source. Presenting it as proof would be the same "green means verified" error the assessment condemns. The justification is the invariant, not the test.

Verified against the race harness instead: 4 runs, 41,934 iterations, 0 hangs, 0 crashes, failure counts unchanged from baseline. Full suite 5,116 passed / 5 failed, all known flake band, none in indexing.

IXW-03 did not cover its own twin

The rule written to stop this drift scoped itself to BTree.Insert.cs alone, and shipped that way for a day. Scope now names Remove.cs and Move.cs, plus an explicit gap note: Move.cs performs leaf inserts with no lower-bound guard at all — not a drifted copy but a missing one. Collapsing the five hand-maintained leaf-insert copies onto one authority is #765 step S2.

Assessment: #765.

…nd widen IXW-03 to cover it

PR #745 replaced `key < leaf.firstKey` with a comparison against the previous leaf's HighKey on the insert side, and left the identical predicate standing in RemoveIterative. Both were written by the same change (#737), one was found wrong, one was fixed. BTree.Remove.cs:610 carried `count > 0 && key < firstKey && previous.IsValid` verbatim until this commit, and KeyBelowLeafLowerBound had five uses in BTree.Insert.cs against zero in Remove.cs and zero in Move.cs.

The predicate fails for the same reason it failed on the insert side: a leaf's first key equals the separator routing to it only until something is removed from the front, after which the band prevHighKey <= key < firstKey is one the leaf IS authoritative for. Answering "not authoritative" there releases the latch and re-descends to the same leaf.

It is NOT single-threaded reachable, and the difference from #740 is worth stating because it was asserted the other way before it was tested. TryRemoveOlc answers NotFound from the optimistic descent before its count check, so an absent key never arrives at the pessimistic guard at all. Reaching it needs the descent to FIND the key, the leaf underfull enough to defer to the pessimistic path, and a concurrent writer to raise the leaf's first key above it in between — concurrency-gated, and the #738 class rather than #740's.

That is also why this ships without a red-to-green regression test. RemoveAbsentKeyBelowLeafFirstKey_ReportsNotFound is included because the coverage is real and was missing — double-remove across every leaf boundary of a 2,000-key tree, with a consistency check either side — but it passed before this change as well as after, and its remarks say so. Presenting it as proof of the fix would be the same "green means verified" error the assessment condemns. The justification here is the invariant, not the test.

Verified against the race harness instead: four runs, 41,934 iterations, no hangs, no crashes, failure counts unchanged from baseline. Full suite 5,116 passed with five failures, all in the known flake band and none in indexing.

IXW-03 scoped itself to BTree.Insert.cs alone — the rule written to stop this exact drift did not cover its own twin, and shipped that way for a day. Its scope now names Remove.cs and Move.cs, and it carries an explicit gap note: Move.cs performs leaf inserts with no lower-bound guard at all, which is not a drifted copy but a missing one. Collapsing the five hand-maintained leaf-insert copies onto one authority is the only fix that scales, and it is #765 step S2.
@nockawa
nockawa merged commit 9c01a19 into main Aug 10, 2026
16 checks passed
@nockawa
nockawa deleted the fix-remove-lower-bound-twin branch August 10, 2026 12:19
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