mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #1053] A reply that ends inside <think> (no </think>) comes back empty with finish_reason: "stop", and the agent stops — close the thinking and continue once #448
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#448
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?
Originally created by @davidsheridan77-dot on GitHub (Oct 6, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/1053
Summary
With thinking on, Qwen3.8-Flash-Next sometimes writes one sentence of reasoning and then
<|im_end|>, withoutclosing
</think>and without a tool call.OutputParseris still in thereasoningstate, so the whole reply isreasoning_content,contentis empty andfinish_reasonisstop. An agent harness sees an empty turn rightafter a tool result and stops (ours, OpenClaw, then runs a tools-off "finalization" pass, so the model can only
reply that it cannot do the edit).
This is the same family as #804 and #843, but a different shape: there is no
<tool_call>inside the thinking(so #970 / the
rcallstate don't catch it), and no earlier empty turns in the history (fresh session).Strata already has the machinery for this: the #123 thinking-budget wrap-up closes the thinking and continues from
the held prefix. Doing the same once when the model stops inside its thinking fixes it here: 20/20 vs ~15% failures.
Environment
What the model generated
Task: "One of the files in configs/ has debug turned on. Turn it off, then create changelog.md with one line saying
which file you changed." The agent globs, greps (finds
b.conf: debug = true), readsb.conf. The next reply is13 tokens.
STRATA_DEBUG=1(set on the server process — in the config's"env"block it only reaches theengine child, so nothing is printed) shows, identical in all 3 failing runs:
OutputParser(thinking=True).feed(...)on that text gives only areasoningevent — no content, no call.Frequency (same task, fresh session per run)
STRATA_DEBUG=1In run C, after the inserted
</think>the model wrote the correct call both times (tool name and path shortened):(The
<|im_end|>before</think>is only inraw_ids; the continuation prompt isprompt + seg + close, withoutthe stop token.)
A full 24-task agent ladder on the patched server: 24/24, decode 45.0 tok/s (44.7 unpatched) — no regressions seen.
python -m unittest serve.test_server serve.test_responses: same result as unpatched (1 pre-existing error,test_json_schema_text_format, also without the patch).Proposed change
On a stop token while
parser.state == "reasoning"(and nothing held back), append"\n</think>\n\n"and continueonce, the same way the #123 budget wrap-up does. Opt-out:
STRATA_STOP_IN_THINKING=0. Once per reply, so a modelthat stops again after the close ends normally (its text is then
content).Against v0.1.39; on current
mainthe stop-token branch inService.runis unchanged, so it should port directly(there it would also want to skip the
rcallstate).Open questions for you:
/metricscounter like #970'simplicit_reasoning_ends?--batch/parallel).Happy to turn this into a PR against
mainwith a mock-engine test (stop inside thinking → continued; switch off →unchanged; normal answer → untouched; stops twice → closed once).
@justxiami commented on GitHub (Oct 7, 2026):
Data point from a 4×V100 (sm_70) box: both shapes showed up today in the same session with Qwen3.8-Flash-Next IQ3_XXS — the unclosed-thinking shape is not rare, and the literal-marker shape (#537) still reproduces on 0.1.40.1.
Environment
-DCMAKE_CUDA_ARCHITECTURES=70, CUDA 12.8; 4× Tesla V100-SXM2-16GB (NVLink pair mesh),--layer-split 12,24,36 --split-device 1,2,3 --kv int8 --spec 3 --vision --max-context 262144,STRATA_SPEC_COUPLED=1,reasoning_budget_tokens: 8192.serve/server.pyplus local patches (admission #1012, engine death note #997/#890,tool_call_recovery#1172); the output parser is the stockOutputParser.assistant.reasoning_content; template kwargsenable_thinkingandreasoning_effort(nopreserve_thinking).Shape A — the reply ends inside
<think>(this issue)reasoning_content3536 characters,contentempty,finish_reason: "stop"after 1159 generated tokens. The engine-side summary isdone: 1159 tokens in 15 s (stop, cancel=False); the parser was still in thereasoningstate when the model stopped. No<tool_call>anywhere in the turn — same shape you describe (norcallstate to catch it).content138 characters that stop inside a code span, with the remaining 2153 characters inreasoning_content.Shape B — a literal marker in the model's own reasoning (#537, second half)
contentis the reasoning (1969 / 301 / 1300 characters) and ends with a literal</think>.contentstops 138 / 1184 characters in, mid-backtick, and the rest isreasoning_content(2153 / 840 characters).mark_think_literals/unmark_think_literals,serve/frontend.py), the parse side still splits on text (OutputParserstatesreasoning/rcall/content,frontend.py).It is not serve-side truncation
Over the 11.5-hour run of that serve process: 0
lengthfinishes, 0cancel=True, 0thinking budget reached(budget 8192), and every request ends(stop, cancel=False). So the empty turn is the model's own end-of-turn inside the reasoning span, as in your analysis.Suggestion
reasoningstate with no tool call.</think>is quoted or real. Our engine knows the turn's role markers as control tokens, so a token-id boundary (rather than text matching) would remove that ambiguity on the output side too.@eamars commented on GitHub (Oct 7, 2026):
Another data point for the "literal marker in the model's own reasoning" shape (#537, second half): it reproduces on 0.1.39 with a single request, and the leaked replies share a structure that the parser could fix.
Environment
serve/frontend.py(OutputParser,mark_think_literals) is the 0.1.39 code.--kv int8, MTP--spec 4 --spec-min-p 0.5, conversation cache with 16 slots, vision on./v1/chat/completions, non-streaming, one request at a time, thinking on (default effort).Minimal repro: 6/6 seeds
(System: "you are a girl chatting in a group, reply in one or two short sentences". User: "you got freeloaded on compute today, did you know? (by the way, why did a
</think>show up at the end of your last line?)")With seeds 1–6, all six end in
finish_reason: "stop"after 157–396 tokens, and all six have the same shape:reasoning_contentends right where the model quotes the user's question:…上一句末尾怎么冒出来一个contentbegins with the rest of the reasoning (?)" 角色:小满…需要回应…). That reasoning ends in a draft of the reply.</think>, visible incontent, then the reply itself.So
contentlooks like<rest of reasoning ending in draft X>\n</think>\n\n<X>, which client harnesses see as a stray tag plus the reply written twice. The #537 input fix works: the user's</think>reaches the model as text. The model still writes the quote in its reasoning as the single</think>token, and the parser switches channels there.Counts (0.1.39, same setup)
</think>incontent</think>, plain chat, T=0.7thinktool step, then a text reply; reasoning resent asreasoning_content), T=0.2, fixed seed</next_thinking>(not a special token)X\n</think>\n\nX, no quote in the new messageWe also saw this in production. An agent's own leaked line (
X\n</think>\n\nX) was later passed to a summarizer subagent as input, and the summarizer leaked on its first step (2/2).Suggestion: split at the last
</think>In every leaked reply above,
contentcontains a second</think>. Taking the text after the last one gave the clean intended reply in 12/12 text replies. The other 2 were tool-call steps with nothing after the tag, where everything before the call is reasoning anyway. Right nowOutputParserpasses any later</think>through as content text once it is in thecontentstate.A proposal, in the spirit of #1053's "close the thinking and continue":
</think>again after the first one (and no tool call has been emitted since), move everything before the last one intoreasoning_content. This doesn't require deciding which tag was "real". A second end-of-thinking token is enough evidence that the first one was a quote.</think>could at least be held back instead of sent, and clients could be told the boundary moved (for example areasoningdelta repeating the moved span, or a flag in the final chunk).I haven't captured raw token ids. I'm assuming the second visible
</think>is token 248069 rather than the text pieces</,think,>, since that string is one token in this vocabulary. I can rerun withSTRATA_DEBUG=1to confirm if that helps.@Niko1221 commented on GitHub (Oct 7, 2026):
Added in 0.1.40.2 as an opt-in: "reasoning_close_retry": true in strata-.json. When a reply ends on its end-of-turn token still inside with no answer and no tool call, the thinking is closed once and generation continues. Off by default; please try it on your agent and tell us the failure rate before and after.
@davidsheridan77-dot commented on GitHub (Oct 12, 2026):
Thanks for adding
reasoning_close_retry, and to @justxiami and @eamars for the extra data points.Numbers from our setup (single RX 9060 XT 16 GB / gfx1200, Linux, ROCm, Qwen3.8-Flash-Next Q2_0,
--kv int8 --spec 4, a tool-using agent, thinking on, low effort):<think>with empty content and the agent stopped."reasoning_close_retry": true): our 24-task agent ladder passes 24/24, and in about 900 real replies from Oct 8 to Oct 12 the retry fired 0 times. Some logs from that period were lost to restarts, so treat this as "rare", not "zero".We're keeping it on. We'll run a direct A/B next (the same failing step 20 times with the setting off, then 20 times on, on 0.1.40.3) and post the results here soon.