Why Loop Detectors Miss Most Reasoning Stalls (and a Token Budget Beats Them)
· code
In How Quantized Reasoning Models Fail to Stop, I separated two ways low-bit reasoning models run out a 16,384-token cap in llama.cpp: verbatim repetition loops, and non-verbatim stalls where the model keeps re-checking math it has already solved. Here I tested whether an online 12-gram CUSUM loop detector can catch and rescue those stalls better than a plain reasoning-token cutoff that closes </think> and forces \boxed{}.
Short version:
- My pre-registered four-test Holm-Bonferroni family came back null (0 of 4 hypotheses rejected at α = 0.05). A paired check at matched token spend showed why.
- Even without a repetition penalty, 12-gram CUSUM missed nearly two-thirds of stalls. On post-hoc ternary
Qwen3.6-35B-A3B, the loop detector caught only 6 of 17 capped runs (35.3%) and moved accuracy from 18/36 to 19/36. - At the same average prefix spend (~8,872 tokens), a plain token cutoff at 14,173 tokens solved 25/36. It left all 18 uncapped solved runs intact (0/18 false kills), moved solves from 18/36 to 25/36 (7 to 0 discordant over baseline, p = 0.015625), and beat the loop detector 6 to 0 on discordant problems (two-sided McNemar p = 0.03125).
- When verbatim repeats aren’t there, an n-gram detector is blind. Adding
presence_penalty = 1.5cutQwen3.6’s CUSUM recall to 1 of 13 caps (7.7%), and native-ternaryTernary-Bonsai-2-2Btriggered CUSUM on 0 of 23 caps. Token budgets moved solves from 20 to 23 and 21 to 26 (+3 and +5, short of my pre-registered +6 bar). - The single graded “false kill” across all three cohorts was a grader formatting miss. On one uncapped
Bonsai 2Bproblem (problem 245), baseline matched gold-13x+3while the earlier cutoff boxed3 - 13x, which our string-matching grader rejected for polynomial term order.
A bug that pointed to the right baseline
Before running this study, I built an overnight prototype of sequential 12-gram CUSUM halting with a greedy \boxed{} wrap-up and had to throw its results out the next morning. Two bugs had slipped into the detector:
- Window self-overlap. The detector scanned 300-word windows at a 100-word stride, but updated its set of
seen12-grams at the end of each window instead of keepingseenstrictly behind the current window’s start. Every step after the first overlapped the previous window by 200 words, creating a built-in revisit rate of 189/289 (0.654) against a drift threshold of 0.35. Even on 10,000 completely unique words, it guaranteed a deterministic abort around word 4,400. - Scanning past
</think>. It ran over the whole response instead of stopping at</think>, firing inside the final answer write-up on two runs.
Fixing seen to lag the current window and slicing before </think> dropped false triggers on 10,000 unique words to zero. Replaying the fixed detector on saved Seed-2 trajectories also gave 0% false triggers on uncapped solved runs.
Comparing two earlier presence_penalty = 1.5 runs then gave away what had actually helped. On saved Seed-2 trajectories, the fixed 12-gram detector caught only 1 of 15 caps (6.7%). On the retracted Seed-3 run, the buggy detector’s accidental ~4,400-word </think>\nFinal Answer: \boxed{ cutoff had rescued 8 of 15 caps, lifting accuracy from 18/36 to 26/36. The presence penalty suppressed verbatim 12-gram repeats without stopping algebraic wheel-spinning, and a plain token cutoff was doing the rescue.
Setup
I froze the hypotheses, thresholds, and stopping rules before generating any test-seed runs. Everything ran on stock llama.cpp build b12600 (29b52d398) on one RTX 5060 Ti 16 GB inside a read-only bwrap sandbox, pinned to 8 physical Zen 3 cores (0–7):
- Server flags:
-ngl 99 -fa on --load-mode none --jinja -np 1 -c 20480 -ub 512 --no-cache-prompt --cache-ram 0(plus-ncmoe 0onQwen3.6-35B-A3B). Every/completionresponse was checked forcache_n == 0, and full raw text plus integer token IDs were saved for every run (2.32 eval GPU-hours; 2.33 wall hours under a 4.50 GPU-hour cap). - Qwen3.6, unpenalized (n = 36, fresh Seed 4):
Qwen3.6-35B-A3B-russellwmy-ternary-experts-Q2_0.gguf(post-hoc calibrated ternary experts) atT = 0.6, top_p = 0.95, top_k = 20, min_p = 0.0,presence_penalty = 0.0,effort = "low". Uses the 25 Seed-1 capped problems plus 11 Seed-1 uncapped-solved controls from my earlierMATH-500Seed-1 run. - Qwen3.6, presence penalty 1.5 (n = 36, fresh Seed 4): the same 36 problems and per-problem seeds (
4 * 100000 + i), addingpresence_penalty = 1.5, repeat_last_n = 20480, repeat_penalty = 1.0, frequency_penalty = 0.0. - Bonsai 2B, unpenalized (n = 44, fresh Seed 2):
prism-ml/Ternary-Bonsai-2-2B-gguf(Q2_0trained native ternary, reva6032a50) atT = 0.6, top_p = 0.95, top_k = 20, min_p = 0.0,presence_penalty = 0.0, seed2 * 100000 + i(effort = "xhigh"is ignored by its 2B Jinja template, verified via/apply-templateto open<think>\ncleanly). On an earlier 100-problem Seed-1MATH-500run, this model hit the cap on 32/100 problems with zero verbatim loops; this 44-problem set pairs all 32 of those capped problems with 12 randomly sampled uncapped-solved controls.
Because each cohort ran one request at a time with prompt caching off and recorded every generated token ID, all three stopping arms share the exact same generated token prefix on every problem:
- Baseline (16k): generates up to 16,384 tokens and grades the last
\boxed{}after</think>(verified per model as a single special token) with our frozenMATHstring-normalization grader (v2). - 12-gram CUSUM + wrap-up: runs Page’s one-sided CUSUM over 300-word windows at a 100-word stride after 3,000 words (
ngram_n = 12, win_words = 300, stride_words = 100, min_words = 3000, ref_k = 0.35, h_thresh = 4.00), strictly before</think>. When it triggers, the harness binary-searches the exact token index via/detokenize, appends 31 wrap-up tokens (\n\nOkay, I have thought about this long enough. Let me stop here and write the final answer now.\n</think>\nFinal Answer: \boxed{), decodes up to 128 greedy tokens (temperature = 0.0), and grades the first balanced\boxed{...}. If CUSUM never triggers, this arm is identical to Baseline. - Token budget + wrap-up: cuts off reasoning at one uniform integer cap across the cohort whenever a run is still inside
<think>past that cap, appending the same 31-token wrap-up and up to 128 greedy tokens. On unpenalizedQwen3.6, the cap (14,173 tokens) was solved offline to match CUSUM’s cohort prefix-token total (0.8947 of baseline tokens). Because CUSUM fired fewer than 3 times in the other two cohorts, the pre-registered transfer rule clamped that ratio at 0.88, setting caps of 13,527 tokens on penalizedQwen3.6and 13,909 tokens onBonsai 2B.
Caveats:
- Stall-enriched problem sets, one fresh seed per cohort. Both problem sets (25+11 and 32+12) were built around Seed-1 16k stalls to fit inside 4.50 GPU-hours. Cap rates and token savings here are conditional on hard, stall-heavy subsets, not full
MATH-500rates. - Shared Qwen
<think>templates and prior ID inspection. BothQwen3.6-35B-A3B(hybrid Gated DeltaNet MoE) andTernary-Bonsai-2-2B(qwen3-derived dense 2B) use Qwen-family<think>...</think>templates, so these results do not automatically generalize to non-<think>reasoning formats without testing. The CUSUM thresholds (ref_k = 0.35, h_thresh = 4.0, min_words = 3000) were frozen before Seed 4 without re-tuning, but the 36Qwen3.6problem IDs had been inspected on Seed 2;Bonsai 2Bon Seed 2 had zero involvement in threshold selection. - Offline budget calibration and uncached wrap-up timing. Solving the token cap across a finished batch gives the budget arm cohort-level calibration that single-request serving has to approximate with a fixed
--reasoning-budget(such as 13,000–14,000) picked on validation data. Also,--no-cache-promptre-prefills the truncated prompt on each wrap-up instead of appending 31 tokens to a live KV cache, so GPU-hours here are higher than in normal serving.
Results
Cohorts are evaluated separately and never pooled across model families.
| Cohort | n | Baseline solved [95% CI] | CUSUM solved [95% CI] | Budget solved [95% CI] | Capped runs (CUSUM caught) |
|---|---|---|---|---|---|
| Qwen3.6, unpenalized | 36 | 18 [34.5, 65.5]% | 19 [37.0, 68.0]% | 25 [53.1, 82.0]% | 17 (6 caught, 35.3%) |
| Qwen3.6, penalty 1.5 | 36 | 20 [39.6, 70.5]% | 20 [39.6, 70.5]% | 23 [47.6, 77.5]% | 13 (1 caught, 7.7%) |
| Bonsai 2B, unpenalized | 44 | 21 [33.8, 62.1]% | 21 [33.8, 62.1]% | 26 [44.4, 72.3]% | 23 (0 caught, 0.0%) |
Token spend, false kills on uncapped baseline solves (with one-sided 95% Clopper-Pearson upper bounds), and exact paired McNemar counts:
| Cohort | Budget cap | Mean tokens (Base / CUSUM / Budget) | Uncapped false kills (CUSUM / Budget) | Budget vs Base (wins/losses, 2s p) | Budget vs CUSUM (wins/losses, 1s / 2s p) |
|---|---|---|---|---|---|
| Qwen3.6, unpenalized | 14,173 | 9,916.0 / 8,873.0 / 8,874.6 | 0/18 / 0/18 (≤ 15.33%) | 7/0 (0.015625) | 6/0 (0.015625 / 0.03125) |
| Qwen3.6, penalty 1.5 | 13,527 | 9,310.1 / 9,099.1 / 8,194.9 | 0/20 / 0/20 (≤ 13.91%) | 3/0 (0.25) | 3/0 (0.125 / 0.25) |
| Bonsai 2B, unpenalized | 13,909 | 11,422.1 / 11,422.1 / 10,118.8 | 0/21 (≤ 13.29%) / 1/21 (4.76%, ≤ 20.67%) | 6/1 (0.125) | 6/1 (0.0625 / 0.125) |
(CUSUM vs Baseline discordant counts were 1/0, 0/0, and 0/0, all two-sided p = 1.0. CUSUM cut total tokens by 10.52% [p = 0.0856], 2.27% [p = 0.883], and 0.0% [p = 1.0]; the budget arm cut total tokens by 10.50%, 11.98%, and 11.41%. Cohort eval times were 0.9363, 0.9377, and 0.4447 GPU-hours.)
Why all four pre-registered primary tests missed
I pre-registered four one-sided tests under step-down Holm-Bonferroni at α = 0.05 (sorted thresholds 0.0125, 0.0167, 0.025, and 0.05):
- Drop in CUSUM recall under
presence_penalty = 1.5(rank 1/4): Conditional stall recall fell from 6/17 (35.3%) unpenalized to 1/13 (7.7%) penalized, clearing the +25 percentage-point practical bar (+27.60 points; 11 shared caps with 2/0 discordant triggers). On the studentized paired regime-swap permutation test (100,000 draws), Z = 1.7713 gave p = 0.0254, missing the 0.0125 first-step Holm cutoff and stopping step-down. - Bonsai 2B budget salvage (rank 2/4): The budget arm beat CUSUM 26/44 to 21/44 (6/1 discordant, +5 net solves against a pre-registered +6 floor, one-sided McNemar p = 0.0625 > 0.0167). On Seed 2,
Bonsai 2Bsolved 21/44 at baseline and under CUSUM (both above the[8, 17]80% prediction interval) and 26/44 under the token budget (above[14, 25]), accounting for all 3 misses among the 13 pre-data intervals and leaving 23 baseline caps instead of 32 to rescue. - Unpenalized Qwen3.6 CUSUM token savings above a 5% null (rank 3/4): CUSUM cleared every practical and safety bar (10.52% ≥ 10.0% token savings, 19 ≥ 17 solved, 0/18 false kills, net savings +19,701.15 tokens beyond 0.95 × baseline), but because it caught only 6 of 17 capped runs (leaving most of the 36 runs untouched), the paired sign-flip test gave p = 0.0856 > 0.025.
- Penalized Qwen3.6 budget salvage (rank 4/4): The budget arm beat CUSUM 23/36 to 20/36 (3/0 discordant, +3 short of +6, one-sided p = 0.125 > 0.05).
What the iso-token check and grader check showed
Outside the Holm family, I pre-registered a direct head-to-head comparison between CUSUM and the matched token budget inside unpenalized Qwen3.6, where the 14,173-token cap matched CUSUM’s cohort prefix spend (8,871.9 vs 8,872.1 mean prefix tokens; 8,874.6 vs 8,873.0 total tokens with wrap-ups):
- 12-gram CUSUM caught the 6 heavy verbatim repeaters among the 17 capped runs, rescuing 1 of them (18 to 19), and let the other 11 capped runs (64.7%)—non-verbatim or slower-repeating stalls—burn all 16,384 tokens with no final answer.
- The 14,173-token budget left all 18 uncapped solved runs intact (0/18 false kills) and lifted solves from 18/36 to 25/36 (7/0 discordant over baseline, p = 0.015625), beating CUSUM 25/36 to 19/36 (6/0 discordant, descriptive two-sided p = 0.03125) at the same average token cost.
Checking the single uncapped false kill on Bonsai 2B (problem 245, 1/21 = 4.76%) showed a grader formatting quirk rather than a broken answer: baseline finished uncapped and matched gold -13x+3, while the 13,909-token budget cutoff stepped in during <think> and boxed 3 - 13x, which v2 rejected for polynomial term order.
Running a pure-Python check for polynomial term order, unparenthesized tuples, and ordinal unit suffixes across all 116 rows (348 arm outputs, keeping frozen v2 as the primary record) turned up 7 v2 false negatives in total: Bonsai 2B problem 245 (3 - 13x vs -13x+3), unpenalized Qwen3.6 problem 379 (12^{\mathrm{th}} grade vs 12 on CUSUM and Budget) and problem 60 (6, 31, -1 vs (6,31,-1) on Budget), and penalized Qwen3.6 problem 379 (12th\ grade vs 12 on all three arms). With those counted, uncapped false kills drop to 0 across all three cohorts (0/18, 0/21, and 0/21; one-sided 95% upper bounds ≤ 13.29%–15.33%), unpenalized Qwen3.6 moves to 18 / 20 / 27 (Budget vs CUSUM 7/0, two-sided p = 0.015625), penalized Qwen3.6 moves to 21 / 21 / 24, and Bonsai 2B moves to 21 / 21 / 27 (6/0, one-sided p = 0.015625 > 0.0125 at Holm step 1, so the primary Holm verdict stays null).
Prior work
- Sequential change detection and budget-cap termination: Page (1954), “Continuous Inspection Schemes” (
Biometrika41:100–115), introduced one-sided CUSUM charts. arXiv:2606.02011 studies commit-on-loop reasoning loop termination. s1 (arXiv:2501.19393) andllama.cpp’s--reasoning-budgetand--reasoning-budget-messageflags implement fixed token-budget wrap-ups. Luis Leal (When Budget Forcing Fails: Forced “Wait” Extensions Add Little Beyond the Token Cap and Run-to-Run Noise,arXiv:2612.02436) audits 410k traces across 10 open models and showss1’s headline scaling curve comes from the truncation cap rather than forced"Wait"extensions (+0.67 percentage points[-0.67, +2.00]null, 0/42 significant ins1’s released files). Boesgaard Lorup (Delivered Sooner: Learned Brevity Travels With a Reasoning Model’s Feed-Forward Weights,arXiv:2612.01699) uses forced</think>readouts every 2k tokens between denseQwen3.5-9Band brevity-trainedConcise-9B(n = 768) to show that answers stabilize at the same depth (367/512 vs 366/512 available by 8k) while brevity training delivers them sooner (232 vs 144 delivered). - Static
</think>-expert quantization (RTAQ): Choi, Kim, Yun & Han (2026), “RTAQ: Reasoning Termination-Aware Quantization for Mixture-of-Experts Architecture” (arXiv:2611.37751), show that near-2-bit MoE (Qwen3.6-35B-A3B) errors are dominated by non-terminated traces whose accuracy once</think>appears stays close to full precision, and trace</think>emission to roughly 2% of routed experts. Keeping those experts at higher precision during quantization cuts non-termination substantially without eliminating all unclosed traces.RTAQacts statically when quantizing MoE weights, so it does not apply to already-quantized GGUFs, penalty-induced paraphrastic stalls, or dense native-ternary models without routed experts (Ternary-Bonsai-2-2B), making it complementary to decode-time stopping.
What this post adds:
- A pre-registered within-trajectory comparison (16k baseline vs window-lagged 12-gram CUSUM vs prefix-matched token budget) on stock
llama.cppGGUFs across post-hoc ternary MoE (Qwen3.6-35B-A3B,presence_penalty0.0 and 1.5) and dense native ternary (Ternary-Bonsai-2-2B), with saved token IDs and zero prompt-cache reuse. - A post-mortem of how 200-word sliding-window overlap turns an n-gram CUSUM detector into an accidental ~4,400-word token timer (
189/289 = 0.654 > 0.35). - A paired iso-token check on unpenalized
Qwen3.6(8,871.9 vs 8,872.1 mean prefix tokens) showing that frozen 12-gram CUSUM missed 11 of 17 capped runs (64.7%) while a uniform 14,173-token cutoff beat it 25/36 to 19/36 with 0/18 false kills, plus offline-calibrated cutoffs (13,527 and 13,909) on the two non-verbatim cohorts (0/20 and 1/21 primaryv2false kills; 0 across all three after accounting for3 - 13xvs-13x+3and unit suffixes).
Takeaways
- Start with
--reasoning-budgetand--reasoning-budget-messagebefore building a text loop detector. Even on unpenalized post-hoc ternaryQwen3.6-35B-A3B, 11 of 17 capped runs never tripped 12-gram CUSUM, while late token cutoffs (14,173, 13,527, and 13,909) lifted solves across all three cohorts (18 → 25, 20 → 23, and 21 → 26; discordant 7/0, 3/0, and 6/1 vs baseline) with 0/18, 0/20, and 1/21 primaryv2false kills (0 across all three after polynomial term-order and unit-suffix checks; one-sided 95% upper bounds ≤ 13.29%–15.33%). - Repetition penalties hide surface loops without fixing stalls. Setting
presence_penalty = 1.5cutQwen3.6’s 12-gram CUSUM triggers from 6/17 (35.3%) to 1/13 (7.7%), yet 13 of 36 runs still hit the 16,384-token cap. - Test sequential loop detectors against a 10,000-unique-word synthetic stream and an iso-token budget baseline. Without both checks, a window-overlap bug looks just like a working stall detector because the accidental token cutoff rescues answers on its own.