mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #4939] [Engine] reasoning_loop_recovery "wrap" and "nudge": end a reasoning loop with an answer, not an empty reply #5255
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#5255
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/4939
Author: @nomishbhardwaj
Created: 11/1/2026
Status: 🔄 Open
Base:
main← Head:feat/loop-recovery-wrap-nudge📝 Commits (1)
8a2e4e2[Engine] reasoning_loop_recovery "wrap" and "nudge": end a reasoning loop with an answer, not an empty reply📊 Changes
3 files changed (+171 additions, -7 deletions)
View changed files
📝
docs/DETAILS.md(+1 -1)📝
serve/server.py(+64 -6)➕
serve/test_reasoning_loop_wrap.py(+106 -0)📄 Description
Problem and result
With Qwen3.8-Flash-Next IQ2_XS on one RTX 3090, long chats keep falling into reasoning loops (Open WebUI and an agent
client: whole paragraphs repeated, or numbered lists that keep counting up; one Open WebUI reply thought for 22,229
tokens with 99.2 % of the MTP drafts accepted, then the client sent that loop back as context and it looped again).
The existing guards either never act in time (the thinking budget is far away) or end the reply empty:
"stop"andrepeat_stop_tokensboth return"length"with no answer, which a chat UI shows the same way as the loop."recover"cannot act at medium or low effort (#2906: there is no xhigh sentence to swap).
This adds two opt-in values for
reasoning_loop_recovery:"wrap": when the #728 detector fires, the thinking is closed exactly asreasoning_budget_tokenscloses it(
REASONING_WRAP_UP) and the model answers from what it has."nudge": the first fire continues from the same tokens with temperature raised to at least 1.0 and presencepenalty to at least 1.5 (the two values
"recover"already raises; top_p, top_k and the client's request dict areuntouched), and the detector's window restarts. A second fire wraps.
With either value, a
repeat_stop_tokensrun inside the thinking (for example'4'x 256 on long-digit arithmetic)is handled the same way instead of ending the reply empty. In the answer, and with the existing values, nothing changes.
Defaults are unchanged (off).
Before / after on the reporter's setup (RTX 3090 24 GB, IQ2_XS, CUDA,
--spec 4, sampling 0.3 / 0.95 / 20, effortmedium): three conversations that had looped (two agent turns at ~66K tokens, one Open WebUI turn at ~8K tokens with
27 tools), 6 runs each, replayed with no client-side cut and a 60,000-character cap on the reasoning:
"wrap", 0.1.55"nudge", 0.1.55(
reasoning_close_retry: truewas on in the"wrap"and"nudge"arms; it acted once.)Related discussion
#4402 (loops in long agent sessions; the reporter asks for "a way to end an episode once degeneration starts", and a
later comment for a per-session loop breaker), #728, #2906, #606, #1753. No maintainer agreement on scope yet: it is
opt-in, and I am happy to drop
"nudge"or therepeat_stop_tokenspart, or move it behind another key.Approach
"wrap"reuses the budget's own wrap-up path (wrap = True), so a forced tool call,max_tokensroom and the KVprefix reuse behave as they do for the budget; the log line names the loop instead of the budget.
"nudge"reuses"recover"'s sampling raise but keeps the prompt (prompt + this pass's tokens), so it works at every effort level.The gate allows two fires for
"nudge"and one otherwise, so"stop"and"recover"behave exactly asbefore.
reasoning_recoveries/reasoning_repeat_coveragein/metricscount the new actions too.Validation
Passed:
python -m unittest serve.test_reasoning_loop_wrap serve.test_reasoning_loop_recoveryon this branch (v0.2.9,c62d5e3a+ this commit), Linux x86_64, Python 3.12: 27 tests OK (9 new: wrap answers, wrap never fires on novelreasoning, nudge escapes without a wrap, nudge then wrap, a one-token run in the thinking is wrapped / nudged, a run in
the answer still ends it, off and
"stop"unchanged).python -m unittest discover -s serve -p "test_*.py" -t .: 1,307 tests, 1 failure intest_monitor.Monitor.test_queue_wait_and_loading_are_attributed_separatelyunder load; it passed 3 of 3 when runalone, and the same server.py change passed the whole suite (1,307 OK, 38 skipped) in an earlier run.
--version), IQ2_XS.max_tokens32768) with"nudge"andreasoning_close_retryon, engine 0.1.55: 257/266, 0 empty, vs 253/266 with both off on engine 0.1.52 (exactMcNemar p 0.34, 3 vs 7 discordant, all in the long modular / digit arithmetic categories; two variables changed, so
read it as "no loss", not as a gain). Completion tokens 586,810 -> 434,059. The detector acted on 12 of 266 items, 5
of which were right anyway. 38-task suite 38/38, needles 12/12 to 242K tokens, tool-call set unchanged.
Failed:
Not run:
--parallel/ batch slots (the change is in the single-requestgeneration loop; I did not check the batch path), and
"wrap"on the 266-item suite (only"nudge").Limits
The detector's own limits remain: it needs about 2,000 words of reasoning before it can fire, and repeated useful code
can read as a loop (DETAILS.md already says so). A wrap gives an answer, not a correct one: on items that loop because
the model cannot do the arithmetic the forced answer is often wrong. A conversation whose history already contains a
long loop (as in #4402) still tends to loop again; these values make each such turn end with an answer instead of
running to the budget or ending empty.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.