Repository navigation
Description
Rewritten 2026-08-10. This was filed as "
Add_*race-stress scenarios hang at 10-25% of runs". Both halves of that turned out to be wrong: it is not a hang, and the rate was an artefact of a defective harness. The original framing is preserved in the comments; the body now states what is established.
What actually happens
Under concurrent split pressure, AddOrUpdateCorePessimistic restarts until it exhausts MaxPessimisticRestarts = 10,000 and throws:
System.InvalidOperationException: B+Tree insert made no progress in 10000 pessimistic retries.
The descent keeps reaching a leaf it can neither validate nor modify, which no further retrying
resolves. This is a liveness defect in the tree, not contention (see #695).
at BTree`2.AddOrUpdateCorePessimistic(InsertArguments&) BTree.Insert.cs:620
It presented as a hang because the harness cut each iteration off at a 10-second deadline and labelled that "HANG". It is a bounded burn, not a deadlock.
The experiment that established it
Same build, same 60 s of stress, only the per-iteration deadline changes. A stuck iteration is unaffected by the budget; a merely slow one completes when given room.
| iteration deadline | iterations | DEADLINE records |
outcome |
|---|---|---|---|
| 10 s | 11,694 | 1 | recorded as "hang" |
| 10 s | 19,972 | 2 | recorded as "hang" |
| 300 s | 19,445 | 0 | throws the restart-bound error instead |
Both Add_* scenarios reach the bound and throw once given room. Same event, two labels.
What this rules out
The five hypotheses in the original filing were each looking for a lock cycle, and each was correctly refuted, because there was never one to find. They were refuting the wrong proposition — an artefact of the "HANG" label. Do not re-run them: SMO sibling lock cycle, Sleep(1) amplification in the pessimistic retry loops, restarts introduced by the mode 1 lower-bound guard, a cycle in the leaf chain, page-cache backpressure.
Also note the pessimistic paths use TryWriteLock with full bail-out throughout, so a classic lock-ordering deadlock is excluded by construction.
Relationship to #740
Same defect class — a restart predicate the descent cannot satisfy — and a different instance. #740's band is created by removing a leaf's first key; Add_Splits and Add_Disjoint never call Remove, and the #740 fix was already present in the build that produced the throws above. So a second, insert-only path can also fail to make progress.
Open question
Which restart in AddOrUpdateCorePessimistic fails to progress under concurrent splits. The candidates both return completed=false to the bounded outer loop: the move-right gap check, and the lower-bound guard.
The instrumentation shape that cracked the Remove side is per-exit counters, so a burn names its exit instead of leaving it to inference — see OlcDescentTrace.RemoveBranch* and how RemoveBranchCount sizes the array. The insert side has no equivalent.
Harness repairs — done, PR #746
The instrument had four defects that produce the same signal as a tree bug, all fixed:
- "HANG" was
iterTask.Wait(IterationDeadline)expiring — a 10 s wall clock, not a detected deadlock. NowDEADLINE, with the distinction stated at the site. - That path deliberately leaked the
ManagedPagedMMFwith its file open; atesthost.exefrom a completed run stayed alive holding the test DLL. olcrs_{id:x}restarted from id 0 in every process, so one leak poisoned every later run at the same iteration — three isolated runs failed identically atolcrs_2397, with 33,088 leaked database directories accumulated. Nowolcrs_{ProcessId:x}_{id:x}.- No
[NonParallelizable]while its siblingOlcBTreeStressTestshas it, so it ran as one of four concurrent heavy fixtures underLevelOfParallelism(4)— a configuration that crashed the test host.
On the repaired harness: six runs, 68,123 iterations, no hangs, no crashes, no missing keys in any scenario. Read no rate published before 2026-08-10 as a property of the tree.
Acceptance
- The failing restart is named by a counter, not inferred.
- Root cause stated as a mechanism — met for which loop and why it exits; open for which restart.
- 30 consecutive race-stress runs with no
DEADLINEand no restart-bound throw.
Reproduce
OLC_STRESS_SECONDS=60 OLC_STRESS_ITER_DEADLINE_SECONDS=300 \
dotnet test test/Typhon.Engine.Tests/Typhon.Engine.Tests.csproj -c Release \
--filter "FullyQualifiedName~OlcBTreeRaceStressTests"Related
- B+Tree: remove-then-reinsert of a leaf's first key stalls insert for 10,000 retries then throws — single-threaded, shipped in PR #737 #740 — same defect class, fixed; the regression that exposed the pattern
- OLC B+Tree: merge/unlink writes a garbage chunk id, and a key can survive its Remove #739 — merge/unlink chunk id, reproduces in
Remove_Disjoint - OLC: concurrent inserts can lose keys under contention without throwing #297 / OLC B+Tree: concurrent disjoint-key inserts can lose a key and leave the tree inconsistent #679 — the silent key loss this harness was built to chase
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Estimate
Area
Start date
Target date
Bug status
Product
Projects
- StatusShow more project fieldsDone
Activity
nockawa commentedon Aug 9, 2026
The instrument is defective, and its defects produce this exact signal
Before chasing a sixth hypothesis about the tree, I measured the harness. Four findings, each with its evidence. None of them is a claim that the tree is innocent — they are a claim that nothing reported so far distinguishes a tree defect from the harness's own behaviour.
1. "HANG" is a 10-second wall clock, not a detected deadlock
RunScenarioLoopruns each iteration on a worker and callsiterTask.Wait(IterationDeadline).IterationDeadlinedefaults to 10 seconds (OLC_STRESS_ITER_DEADLINE_SECONDS). Exceeding it records"HANG: scenario body did not complete within 10s".That label detects nothing about locking. A bounded-but-glacial loop reaches it identically to a deadlocked one — and the pessimistic paths permit
MaxPessimisticRestarts = 10,000, measured at 2 m 34 s single-threaded in #740. Meanwhile the deadline is being enforced against a scenario body running underProcessorCount/2CPU-saturating noise threads plus four other scenario loops.Reading that counter as evidence of a lock cycle is what sent the five hypotheses in this issue to be refuted one at a time. Relabelled to
DEADLINE, with the distinction stated at the site.2. The deadline path leaks the database, by design
On that branch the harness deliberately skips cleanup — its own comment says so: "Workers may still be alive — touching the MMF after Dispose() would AV. Skip cleanup; let the orphan workers churn... Memory leak across HANG iters is bounded by the stress duration and acceptable for a diagnostic harness."
It is not bounded by the stress duration. A
testhost.exefrom a completed run was still alive and holding the test DLL long afterdotnet testreported finished — it blocked a rebuild, and had to be killed by PID.3. So one deadline poisons every later run — deterministically
_scenarioIdis a static that restarts at 0 in each test host, and the database name isolcrs_{id:x}. Unique within a process; identical across processes. A leaked locked file therefore sits exactly where the next run will ask for it,EnsureFileDeletedcannot remove a file another process holds, andPagedMMF.LoadFilethrows.Measured: three consecutive isolated runs failed identically, at the same name
olcrs_2397, withIOException: cannot access ... because it is being used by another process. And 33,088 leakedolcrs_*.typhondirectories had accumulated under the test bin.Fixed:
olcrs_{ProcessId:x}_{id:x}. The leak becomes self-contained instead of contagious.4. The fixture was never
[NonParallelizable]The assembly runs
Parallelizable(ParallelScope.Fixtures)atLevelOfParallelism(4).OlcBTreeStressTestscarries[NonParallelizable]; this fixture did not. So a harness that already spawns five scenario tasks plus ~16 noise threads was running as one of four concurrent heavy fixtures.That is not hypothetical: a
Category=Nightlyrun took the test host down, withOlcRaceStress_FourScenariosUnderCpuNoise,ChaosStressTests.UltimateStress_AllSubsystems,SubscriptionStressTests.MultiClient_50Clients_SharedView_AllReceiveDeltasandWalCrashSweepTests.Exhaustive_PageAxis_SingleTxSpawn_N33all in flight. Added[NonParallelizable].What the numbers say now
Six runs of the harness alone, 30 s each,
--blame-hang --blame-hang-timeout 150s --blame-crash:Zero hangs. Zero crashes. All five failures were the
IOExceptionfrom finding 3 — the harness tripping over its own leaked file, not the tree.What is and is not established
Next step
Re-measure on the fixed harness with the leaked directories cleared, and treat any surviving
DEADLINEas a request for stacks rather than an answer —--blame-hangproduces the dump. If deadlines persist with the tree quiescent, the next question is whether they are #740-style bounded burn or a genuine stall, and only the stacks answer that.nockawa commentedon Aug 9, 2026
Root cause: it is not a deadlock. It is a bounded restart burn in the pessimistic insert loop.
The experiment that settles it. Same build, same harness, same 60 s of stress — only
OLC_STRESS_ITER_DEADLINE_SECONDSchanges. If the iteration is stuck, no budget helps. If it is merely slow, a bigger budget lets it finish.DEADLINErecordsAt 300 s the deadlines vanish entirely. The failures do not — they change form:
Both
Add_*scenarios — precisely the two named in this issue's title — reach theMaxPessimisticRestartsbound and throw. Given a 10 s budget the harness cuts them off first and records "HANG". Given 300 s they run to the bound. Same event, two labels.What this settles
AddOrUpdateCorePessimisticrestarts until its bound under concurrent split pressure.Add_Splits/Add_Disjointnever callRemove. The B+Tree: remove-then-reinsert of a leaf's first key stalls insert for 10,000 retries then throws — single-threaded, shipped in PR #737 #740 fix is already in this build. So a second, insert-only path can also spin.What remains
Which restart in
AddOrUpdateCorePessimisticfails to make progress under concurrent splits. The candidates are the move-right gap check and the lower-bound guard, both of which returncompleted=falseto the bounded outer loop. The instrumentation to answer it is the same shape that worked for the Remove side: per-exit counters on the restart branches, so a burn names its exit instead of leaving it to inference.Note the bound is doing exactly what #695 built it for — converting a silent unbounded spin into a loud, diagnosable error. Without it this would still read as an unexplained hang.
Reproduce
#738 Stop the race harness calling slowness a hang, and leaking a loc…
[-]OLC B+Tree: Add_* race-stress scenarios hang at 10-25% of runs[/-][+]OLC B+Tree: concurrent splits drive AddOrUpdateCorePessimistic to its 10,000-restart bound[/+]#740 Fix the lower-bound guard's surviving twin in RemoveIterative, a…
nockawa commentedon Aug 10, 2026
Sharpened again by PR #768 (
839a3902), and one of my earlier claims about it was an instrument artefact.The STUCK I reported was my own bug
The race harness gained a deadline classifier that samples the tree's counters twice, a second apart, and classifies STUCK / SPINNING / RESTARTING / SLOW instead of printing the word "HANG". Its first output looked decisive: 2,861,200
WriteLockFailuresin one second with restarts, fallbacks, splits and entry count all frozen — lock-acquisition livelock, not the restart-bound burn this issue describes.Then I found the classifier was reading counters without first asking whether the iteration was still running. A body that finishes a millisecond after the wall clock expires leaves every counter frozen for the whole sample window, and that reads as "nothing is being attempted". It now checks
iterTask.IsCompletedfirst and reports LATE — a budget too tight for a loaded box — before interpreting anything.Two things followed from fixing that, plus a genuine crash fix in the pessimistic spill path in the same PR:
STUCK disappeared entirely. Across 93,883 iterations the only remaining failures are
DEADLINE/RESTARTING, 2 of them, at a punitive 10-second budget under 32 CPU-saturating noise threads.The 2.86 M/s figure was also partly self-inflicted:⚠️ Spin counts from before and after that change are not comparable: a cheaper iteration fits more of them into the same wait.
Interlocked.Increment(ref _writeLockFailures)sat inside both spin loops, so every spinning thread issued a locked RMW to the same cache line on every iteration — a diagnostic counter generating the cross-core traffic it existed to report. Now tallied locally and published once per acquisition.What this issue is now
Not a deadlock, and no longer a demonstrated livelock either. What remains is a restart storm at a rate of roughly 2 events per 94,000 iterations, under conditions chosen to be hostile.
Suggested next step, cheap: re-run with
OLC_STRESS_ITER_DEADLINE_SECONDS=60instead of 10. A restart storm that resolves in 11 seconds is not a hang, and if those two iterations complete, this closes on the measurement rather than on a fix. The classifier will now sayLATEif that is what they are.S7's original question — build the crabbing fallback from
latch-coupled-smo.md§6 — should stay no until that measurement exists. There is no observed STUCK left to build guaranteed forward progress against, and building it blind is how §6 came to be specified and never written the first time.nockawa commentedon Aug 10, 2026
Stack dump taken. The rewrite in this issue's body was RIGHT — it is a bounded burn, not a deadlock.
Work on branch
feature/739-olc-descent-authority, not yet pushed.First, a correction to something claimed earlier today
A long run produced a
DEADLINE/STUCK— every counter frozen, iteration still alive, at a 300 s deadline — and I read that as contradicting this issue's "bounded burn, not a deadlock" conclusion. It does not. The stacks say the opposite.The stacks
The harness now self-attaches
dotnet-stack reportat the instant it detects a stall (CaptureManagedStacks), because that is the only moment the stacks answer anything and an external watcher would have to guess when. Capture atRemove_Disjointiteration 1,788:AddOrUpdateCorePessimistic→SpinWait.SpinOnce→Thread.SleepRemoveCorePessimistic→SpinWait.SpinOnceCore(running)Task.WaitAll, noise generators28 threads, not one blocked on a lock. No cycle, no wait-forever. Every tree thread is inside the bounded retry loop and four are asleep in it:
SpinWait.SpinOnce()degenerates toThread.Sleep(1), which on a box oversubscribed by the CPU-noise threads stretches far past a millisecond. The counters read zero because the 1-second sample window landed in a sleep convoy.The irony worth recording
Sleep(1)amplification in the pessimistic retry loops is listed in this issue among the five refuted hypotheses. It was correctly refuted as a cause of hanging — and it turns out to be exactly the cause of theSTUCKlabel, which nobody had asked it about. The refutation stands; the mechanism just had a different job.Deadline dependence — useful for anyone reproducing
Across 33 deadline records: at
OLC_STRESS_ITER_DEADLINE_SECONDS=60every record isRESTARTING;STUCKappears only at 300 s. Same defect, sampled in two phases — the burn, then a sleep interval within it. Use 60 s to see the burn, 300 s to see the convoy.Harness defects fixed alongside
deltas over 1sand printed the running total, appending(+n)only when non-zero — so a frozen counter with a large total rendered as heavy activity. It misled the author of the classifier within minutes. Nowtotal(+delta)for every counter including the zeros.STUCKverdict asserted "this is the shape a lock cycle or a wait-forever has" — a guess with no evidence, now refuted by the first dump it produced. The verdict no longer names a cause; it reports that the counters froze and hands over the stacks.That makes three instruments in this cluster that produced a confident wrong reading: the 10-second "HANG" wall clock, the deltas header, and the lock-cycle verdict.
Status: unchanged and correctly diagnosed
AddOrUpdateCorePessimisticburns to its 10,000-retry bound. Rate is stable across today's runs (~2Add_*failures per 240 s run) and unaffected by the IXS-07 descent fix, as expected — that fix is a correctness fix, this is a liveness defect.The answer remains the crabbing fallback with guaranteed forward progress, specified in
design/Indexing/latch-coupled-smo.md§6 and never written (grep -i crab src/finds nothing). Not spin tuning — that would only change how the burn feels.nockawa commentedon Aug 10, 2026
Priority P1 → P2, deliberately parked
Not closed, because it throws a user-visible
InvalidOperationException. Downgraded because:AddOrUpdateCorePessimisticburning to its 10,000-retry bound;design/Indexing/latch-coupled-smo.md§6, which was specified and never written (grep -i crab src/finds nothing). That is a substantial piece of work for a contention profile the product does not target yet.Everything needed to resume is in this issue: the mechanism, the deadline-dependence of the two labels, the five refuted hypotheses (do not re-run them), and the named answer. Picking it back up should not require re-deriving anything.
nockawa commentedon Aug 31, 2026
Root-caused and fixed — PR #873
Not a lock cycle, and not the restart volume. Five hypotheses on this issue hunted a cycle and there was never one; three more died in the branch, all to measurement.
The defect
With an empty descent path —
ctx.Depth == 0, meaning the descent found the root to be a leaf —InsertIterative's Phase 4 builds a new root over the leaf it holds:SetLeft(Root)on one side,Insert(0, promoted)on the other. Both halves assume the held leaf still isRoot. The descent established that; nothing rechecked it.The leaf's own version cannot establish it. It proves the leaf was not modified — not that no level appeared above it — and a tree can grow several levels above a leaf without ever touching it. When it had,
SetLeftattached an internal subtree whilepromotedwas still a leaf, and the new root's two children ended up at different levels, withHeightincremented on top.Caught at the moment of creation rather than inferred. A probe on every Phase 4 root split, flagging any whose two children disagree on leaf-ness, fired on the first run:
One in 7,162 root splits.
Why that is the whole of this issue
Leaves under the promoted side become reachable only through the B-link chain and never by descent. Every writer whose key routes there right-walks onto a full leaf it cannot split — its recorded path belongs to the leaf the descent chose — and restarts until
MaxPessimisticRestartsthrows. The stall was the tree correctly refusing to write into a leaf it could not route to. The liveness symptom had a structural cause, which is why every hypothesis that assumed a lock cycle missed it.The review round then found the guard covered only the
Depth == 0shape: Phase 3 rebindsnodetoctx.PathNodes[ctx.Depth]as it unwinds, so atDepth > 0the same staleness reaches Phase 4 unchecked. Both are closed now.Measured
4-core reproduction of the CI runner (
DOTNET_PROCESSOR_COUNT=4, affinity pinned — the nightly's configuration):Hypotheses refuted, so nobody re-runs them
DescentNodeLocked— 94-98 % of restarts in healthy operation, 0 % of the stall. The dominant counter was not the cause.LeftAncestor/RightAncestorare ancestors of the node and therefore already path-locked.RemoveLeafmerging a neighbour its caller never locked — 0 mismatches in 20 runs.What made it findable
InsertIterativehad seventeen no-progress exits and one counter for all of them — named_optimisticRestarts, while the pessimistic loop did the incrementing. Every record this issue ever produced said a storm happened and nothing about where. Each bail now names itself, the remove path has the same instrument, and theMaxPessimisticRestartsthrow carries the histogram.Also:
SpinWait'sSleep(1)tier was running the retry loop at 64 retries/second, stretching the time to reach the 10,000 bound from under a second to 156 s — past the harness's 10 s deadline. The escalation was hiding the bound that exists to make this failure loud, which is why every record here says DEADLINE and none names the throw.Rule IXW-05 now states the invariant, with a deterministic verifier (6 ms, no sleeps) proven to redden in 19 ms when the guard is removed, plus a
[RuleMutant].#738 The root split that built a new root over a leaf that had stoppe…