[PR #5218] [Engine] serve: a reasoning loop written as one long hyphen run-on #5349

Open
opened 2026-11-07 16:34:32 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/5218
Author: @e041l4su3qu4u03
Created: 11/4/2026
Status: 🔄 Open

Base: main ← Head: serve-hyphen-runon-guard


📝 Commits (2)

  • b7afb86 serve: a reasoning loop written as one long hyphen run-on
  • d986339 serve: mark the transcript when the degeneracy guard wraps

📊 Changes

3 files changed (+111 additions, -5 deletions)

View changed files

📝 serve/responses.py (+2 -0)
📝 serve/server.py (+86 -4)
📝 serve/test_reasoning_loop_recovery.py (+23 -1)

📄 Description

Problem and result

Before. On long agentic requests, Qwen3.8-Flash-Next degenerates into reasoning where
every word is new but the whole passage circles one sentence pattern. None of the four
existing guards fires:

guard looks for this degeneration
repeat_stop_tokens (#606) one token 256 times in a row every token differs
reasoning_loop_recovery coverage (#728) 12-word passages seen 3x fired in 1 of 5 captured runs
LOOP_TAIL_PERIOD (#1753) a periodic tail, period <= 64 not periodic
repeat_stop_period (#1803) a short phrase, period 2..N not periodic

Measured on 42 runs of one 100,420-token request: 33 degenerate (79%), on all three
local quantizations (IQ3_S 3.4 bpw 5/5, UD-IQ4_XS 4.0 bpw 4/5, NVFP4 4.5 bpw 10/12), so it
is not a quantization artifact. The reply burns max_tokens and returns no answer.

The degeneration has a shape, even though it has no repetition: one run-on of hyphen-joined
words, and almost no sentence ends.

**⇒⇒ two hard new concrete facts landed this-turn tool output block visible
right-now-normal-readable-style-intact-full-result-channel-currently-healthy-
good-readback-mode-too-showing-same-class-real-live-mode-check-cheap-front-
loaded-inline-explicit-steps-instead-betting-hidden-jobs-executed-calls-prove-
hard-data-printing-proof-lines-themselves-visible-appearing-window-soon-as-...

After. With "reasoning_degeneracy": "wrap", the thinking is closed through the
existing reasoning_budget_tokens wrap-up path and the reply answers:

before after
reply time (same 100k request) 68 – 126 s 9 – 46 s
reasoning length 6k – 25k chars ~2.3k chars
degenerate answers 10 / 12 0 / 12
answers produced often none 12 / 12

At 134k / 180k / 252k prompt tokens: 0 / 9 degenerate answers.

#728 (the opt-in recovery this hooks into), #1753 (the periodic-tail check, same class of
blind spot: a run the word split cannot see), #1803, #606. No separate issue: this is a
focused, opt-in fix.

Approach

Two independent signals, then reuse the wrap path — no new state in the happy path, no new
decoding behaviour:

  1. hyphen run-on — longest a-b-c-... chain >= hyphen_chain_chars (default 200).
  2. punctuation density — fewer than degeneracy_punct_per_1k sentence ends
    (。!?!?. + newline) per 1000 characters, once the reasoning is >= 1000 characters.

The second signal is what makes this work for Chinese, which has no spaces: a
whitespace-word metric (mean word length, TTR) cannot be used there at all. Measured:

group sentence ends per 1000 chars
degenerate runs (n=26) 0.3 – 9.3 (median 2.1)
normal English (n=8) 3.7 – 20.8 (median 13.2)
normal Chinese (n=6) 28.5 – 57.3 (median 33.0)

At 6.0: 25/26 degenerate caught, 1/13 normal flagged. Longest hyphen chain: normal 0–56,
degenerate 203–1569.

"reasoning_degeneracy": "wrap",      // off | report | wrap
"hyphen_chain_chars": 200,           // 0 turns that signal off
"degeneracy_punct_per_1k": 6.0       // 0 turns that signal off

report logs the measurement and leaves the reply alone, so an operator can decide from the
numbers; off changes nothing at all. The check is independent of
reasoning_loop_recovery, so either can be used without the other.

Validation

Passed:

  • python -m py_compile serve/server.py — clean, on the patched tree.
  • python -m unittest serve.test_server -v — the repository's own suite, unmodified:
    Ran 359 tests in 149.467s / OK (skipped=3).
  • Detector unit harness (16 assertions, standalone): normal English and normal Chinese stay
    quiet; a hyphen run-on fires; a punctuation-only run-on ("abc def ghi " * 200, no hyphen
    at all) fires; both signals disabled stays quiet; text under 1000 chars is not judged.
  • Live measurement, Strata 0.1.44.1 bundled engine, Windows 11, RTX 4090 24 GB, 125.6 GiB
    RAM, qwen3.8-flash-next-iq3s (ISTA-DASLab GSQ-RCO IQ3_S), --kv int8, 262144 context,
    temperature 1.0 / top_p 0.95 / top_k 20, 242 tools, prompt 100,420 tokens:
    5 runs with the guard, 0 degenerate; the same request without it was degenerate in 10 of
    12 runs. Server log line when it fires:
    [strata] reasoning looks degenerate (hyphen run-on: longest chain 731 chars) at 2048 output tokens; reasoning_degeneracy=wrap

Failed:

  • none observed.

Not run:

  • The 16 assertions are a standalone file, not yet added to serve/test_server.py in this
    PR (I can add them here if you prefer them in the suite).
  • No Linux, AMD (HIP) or Intel (SYCL) run; NVIDIA on Windows only.
  • Only Qwen3.8-Flash-Next; no other architecture exercised.

Limits

A stop-gap, not a cure: the thinking is cut, so a few reasoning steps are lost. Tuned on one
model's degeneration; a language whose run-on does not use hyphens and punctuates normally
would need another signal. A legitimate hyphenated listing longer than 200 characters inside
the reasoning would be cut — the threshold is configurable and report exists for that case.


Nickname: 老哥的小守衛 ("the old fellow's little guard").


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/5218 **Author:** [@e041l4su3qu4u03](https://github.com/e041l4su3qu4u03) **Created:** 11/4/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `serve-hyphen-runon-guard` --- ### 📝 Commits (2) - [`b7afb86`](https://github.com/Niko1221/Strata/commit/b7afb86ab04b87023b438b92aff47fce57027436) serve: a reasoning loop written as one long hyphen run-on - [`d986339`](https://github.com/Niko1221/Strata/commit/d98633929d40cb04f134ffdd550659e2f511cfb9) serve: mark the transcript when the degeneracy guard wraps ### 📊 Changes **3 files changed** (+111 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `serve/responses.py` (+2 -0) 📝 `serve/server.py` (+86 -4) 📝 `serve/test_reasoning_loop_recovery.py` (+23 -1) </details> ### 📄 Description ## Problem and result **Before.** On long agentic requests, `Qwen3.8-Flash-Next` degenerates into reasoning where every word is new but the whole passage circles one sentence pattern. None of the four existing guards fires: | guard | looks for | this degeneration | |---|---|---| | `repeat_stop_tokens` (#606) | one token 256 times in a row | every token differs | | `reasoning_loop_recovery` coverage (#728) | 12-word passages seen 3x | fired in 1 of 5 captured runs | | `LOOP_TAIL_PERIOD` (#1753) | a periodic tail, period <= 64 | not periodic | | `repeat_stop_period` (#1803) | a short phrase, period 2..N | not periodic | Measured on 42 runs of one 100,420-token request: **33 degenerate (79%)**, on all three local quantizations (IQ3_S 3.4 bpw 5/5, UD-IQ4_XS 4.0 bpw 4/5, NVFP4 4.5 bpw 10/12), so it is not a quantization artifact. The reply burns `max_tokens` and returns no answer. The degeneration has a shape, even though it has no repetition: one run-on of hyphen-joined words, and almost no sentence ends. ``` **⇒⇒ two hard new concrete facts landed this-turn tool output block visible right-now-normal-readable-style-intact-full-result-channel-currently-healthy- good-readback-mode-too-showing-same-class-real-live-mode-check-cheap-front- loaded-inline-explicit-steps-instead-betting-hidden-jobs-executed-calls-prove- hard-data-printing-proof-lines-themselves-visible-appearing-window-soon-as-... ``` **After.** With `"reasoning_degeneracy": "wrap"`, the thinking is closed through the existing `reasoning_budget_tokens` wrap-up path and the reply answers: | | before | after | |---|---:|---:| | reply time (same 100k request) | 68 – 126 s | 9 – 46 s | | reasoning length | 6k – 25k chars | ~2.3k chars | | degenerate answers | 10 / 12 | **0 / 12** | | answers produced | often none | 12 / 12 | At 134k / 180k / 252k prompt tokens: **0 / 9** degenerate answers. ## Related discussion #728 (the opt-in recovery this hooks into), #1753 (the periodic-tail check, same *class* of blind spot: a run the word split cannot see), #1803, #606. No separate issue: this is a focused, opt-in fix. ## Approach Two independent signals, then reuse the wrap path — no new state in the happy path, no new decoding behaviour: 1. **hyphen run-on** — longest `a-b-c-...` chain >= `hyphen_chain_chars` (default 200). 2. **punctuation density** — fewer than `degeneracy_punct_per_1k` sentence ends (`。!?!?.` + newline) per 1000 characters, once the reasoning is >= 1000 characters. The second signal is what makes this work for Chinese, which has no spaces: a whitespace-word metric (mean word length, TTR) cannot be used there at all. Measured: | group | sentence ends per 1000 chars | |---|---| | degenerate runs (n=26) | 0.3 – 9.3 (median 2.1) | | normal English (n=8) | 3.7 – 20.8 (median 13.2) | | normal Chinese (n=6) | 28.5 – 57.3 (median 33.0) | At 6.0: 25/26 degenerate caught, 1/13 normal flagged. Longest hyphen chain: normal 0–56, degenerate 203–1569. ```json "reasoning_degeneracy": "wrap", // off | report | wrap "hyphen_chain_chars": 200, // 0 turns that signal off "degeneracy_punct_per_1k": 6.0 // 0 turns that signal off ``` `report` logs the measurement and leaves the reply alone, so an operator can decide from the numbers; `off` changes nothing at all. The check is independent of `reasoning_loop_recovery`, so either can be used without the other. ## Validation **Passed:** - `python -m py_compile serve/server.py` — clean, on the patched tree. - `python -m unittest serve.test_server -v` — the repository's own suite, unmodified: `Ran 359 tests in 149.467s / OK (skipped=3)`. - Detector unit harness (16 assertions, standalone): normal English and normal Chinese stay quiet; a hyphen run-on fires; a punctuation-only run-on (`"abc def ghi " * 200`, no hyphen at all) fires; both signals disabled stays quiet; text under 1000 chars is not judged. - Live measurement, Strata 0.1.44.1 bundled engine, Windows 11, RTX 4090 24 GB, 125.6 GiB RAM, `qwen3.8-flash-next-iq3s` (ISTA-DASLab GSQ-RCO IQ3_S), `--kv int8`, 262144 context, temperature 1.0 / top_p 0.95 / top_k 20, 242 tools, prompt 100,420 tokens: 5 runs with the guard, 0 degenerate; the same request without it was degenerate in 10 of 12 runs. Server log line when it fires: `[strata] reasoning looks degenerate (hyphen run-on: longest chain 731 chars) at 2048 output tokens; reasoning_degeneracy=wrap` **Failed:** - none observed. **Not run:** - The 16 assertions are a standalone file, not yet added to `serve/test_server.py` in this PR (I can add them here if you prefer them in the suite). - No Linux, AMD (HIP) or Intel (SYCL) run; NVIDIA on Windows only. - Only `Qwen3.8-Flash-Next`; no other architecture exercised. ## Limits A stop-gap, not a cure: the thinking is cut, so a few reasoning steps are lost. Tuned on one model's degeneration; a language whose run-on does not use hyphens and punctuates normally would need another signal. A legitimate hyphenated listing longer than 200 characters inside the reasoning would be cut — the threshold is configurable and `report` exists for that case. --- *Nickname: 老哥的小守衛 ("the old fellow's little guard").* --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#5349
No description provided.