mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #1814] Model writing a literal </think> emits the special token: quoted tag ends the reasoning mid-sentence and the turn stops (finish_reason=stop) #717
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#717
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 @danirebollo on GitHub (Oct 10, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/1814
Follow-up on the output side of #537. On 0.1.41 (Qwen3.8-Flash-Next IQ3_XXS, 2×3090), a long agent session about parsing had 4 turns in a row cut after 100–200 tokens with finish_reason: stop, right after a backtick in the reasoning.
What I changed in serve/ (patch attached):
Only the model's own end-of-thinking token closes the thinking. Service.run() now tells the parser when it is that token, so a the model writes with ordinary text tokens stays reasoning text.A special / token that can't be a real marker is swapped for the tag's text tokens, and generation continues. That covers the answer, and quoted or mid-line tags in the thinking. It reuses the #123 continuation path.If the model stops right after opening an inline code span in its thinking, the tag is written as text and generation continues.
It's capped at 64 swaps per reply, behind a literal_think_guard flag (on by default), with 12 new tests.
What worked for me: asking the model to write the tag, repeating answer: 42 and a tool result containing the tag now all give full reasoning and a correct answer. A prompt that returned no answer 2/6 times returned 0/3. Decode speed is unchanged (120.3 vs 120.4 tok/s).
@47Hunter47 commented on GitHub (Oct 10, 2026):
I reproduced this on an RTX 3090 with Qwen3.8-Flash-Next IQ3_XXS on 0.1.41 and dumped the raw turns with
STRATA_DEBUG=1. The fix is in PR #1840.What the raw text shows
The tag is not being swapped for text tokens, and it is not being quoted: the model is about to write its closing thinking tag and the turn-end token comes instead.
finish_reasonisstop, the reasoning ends mid-sentence, nothing is produced as content, and the client gets an empty reply. In the other turns I dumped the cut lands on a backtick instead (...Some models output reasoning in \``) or on`` or ```, i.e. wherever the model reaches for the tag. That matches your "right after a backtick" observation.I kept five raw turns in the PR as
serve/fixtures/literal_think_specimens.json(no-answer,answered,length-cut).How often
STRATA_PREFILL_CPU_SHAREon and offIt is not deterministic on my machine: the same prompt answers normally on one pass and ends with nothing on the next, and the prompt has to make the model reach for the tag (asking it to show, parse or quote the tag). Your 2/6 and 0/3 numbers fit that.
Why the parser cannot catch it on its own
In this tokenizer the tag is not a special token - it is eight ordinary text tokens (
<,/,t,h,i,n,k,>), and the token that ends the turn is the ordinary end-of-turn token. So a turn that stops inside its thinking is byte-for-byte indistinguishable from a turn that stops inside its thinking: nothing in the stream says "I meant that". That is also why the #537 work on the input side does not cover it (there the prompt carries a literal tag and can be marked before it is rendered; here it is the model's own output).What I did
Service.run()continues the reply when it ends withfinish_reason == "stop"inside the thinking with no answer: the thinking is closed the way #123's wrap-up closes it (REASONING_CLOSE) and the next pass's prompt is the one that produced the reply plus what it generated plus that close, so the engine continues from the prefix it already holds.parser.state == "content"is the same end from the other side (the tag was written as text, the parser took it as the marker and nothing followed): there the tag goes back into the reasoning text first, so the client still sees everything the model wrote.It is #1053's continuation, so opt-in the same way:
"literal_think_guard": trueinstrata-<model>.json, orSTRATA_LITERAL_THINK_GUARD=1, capped atLITERAL_THINK_RETRIES = 2continuations per reply, with aliteral_think_retriescounter in the request status/trace. I left the default off because #1053 is off by default and this appends the close to the prompt, which should stay a deliberate choice.serve/test_literal_think_guard.pyreplays the five dumped turns through a mock engine; the fullservesuite is at 604 tests with the only failure being the flaky telemetry(_loop)thread count intest_responses.py(it fails the same way on this checkout without the change).One more symptom, same family
While testing I also saw turns that ended with
finish_reason == "length"and up to a few thousand characters of reasoning text incontent(the reasoning ran to the token budget after the parser had taken a literal tag as the marker). That is a second, quieter version of the same confusion - the client gets reasoning where the answer belongs - and it is not what this PR addresses. If you want it handled too, I can look at whether the same guard should reopen the thinking on alengthend as well, or whether the answer parser should refuse content that is only reasoning.@47Hunter47 commented on GitHub (Oct 10, 2026):
A quick follow-up on my comment above: I split the work into two layers in PR #1840, so the fix is not optional any more.
totals.ended_inside_thinking(/metrics'totals_ended_inside_thinking_total), and"ended_inside_thinking": truebesidechoicesin the response (and in the stream's last chunk). If you are getting an empty reply, the response itself now says the turn ended inside the thinking, so a client can decide to retry instead of showing nothing. It changes no output, so it needs no switch."literal_think_guard": true, orSTRATA_LITERAL_THINK_GUARD=1) closes the thinking and lets the model answer, capped at two continuations per reply.serve/fixtures/literal_think_specimens.jsonin that PR holds five raw turns from my machine (no-answer/answered/length-cut), andserve/test_literal_think_guard.pyreplays them through a mock engine, so the behaviour is pinned to the real text rather than to my summary of it.@47Hunter47 commented on GitHub (Oct 12, 2026):
Fresh numbers on the current build, since my branch in #1840 is now synced with main.
Setup: RTX 3090, Qwen3.8-Flash-Next IQ3_XXS, 0.1.43 (engine rebuilt for it), 250K context,
--kv int8,literal_think_guardon.The trigger prompt asks the model to show exactly how the closing thinking tag looks. Four runs:
ended_inside_thinking: true, the journal has the line, and/metricsreadtotals.ended_inside_thinking= 2 (strata:totals_ended_inside_thinking_totalin/metrics/prometheus).So the dead end you reported still happens on 0.1.43, and with the flag off those two runs are exactly the empty reply from your report.
I also found the same family elsewhere while looking: #1178 (a special token written in the thinking), #1526 (a quoted tag, which the maintainer fixed as a rule in 0.1.42) and #2026 (v0.1.43, reached from the string
</tool_call>). Same end, different strings, so the guard keys on the end itself rather than on the tag.@Niko1221 commented on GitHub (Oct 13, 2026):
Thanks for the report. To keep the tracker current we are closing issues older than three days: 0.1.44 is out with a long list of fixes, and many older reports are covered by it or by 0.1.43.1.
If this still happens on 0.1.44, please leave a comment here with your engine log (and the version line it prints), and we will reopen it. A new issue that links this one works too.
@47Hunter47 commented on GitHub (Oct 14, 2026):
I re-ran this on a stock 0.1.44, so this shape is not covered by the release:
v0.1.44(ed4773eb) — the tag's ownserve/, no local patches;literal_think_guarddoes not exist there, so none of my code is in the path.build_info=Strata 0.1.44, engine 0.1.44, RTX 3090, Qwen3.8-Flash-Next IQ3_XXS, 250K context,--kv int8, sampling 1.0/0.95/20, thinking budget 16384.The minimal input from #1178 (
Qwen 聊天模板里,助手回合的结束标记是什么?请原样写出,例如 "标记"。), 8 runs,max_tokens4000, temperature 1.0: 8 of 8 came back with an emptycontentandfinish_reason: stop(86 to 255 tokens generated). One turn, as the engine log prints it:89 tokens out of a 3000-token thinking budget, ended with
stop: no budget cut and no length cut — the raw text stops where the model was about to write<|im_end|>and nothing reachescontent.The prompt from #1814 ("In a markdown code fence, show exactly how the closing thinking tag looks..."), 10 runs: 3 empty, same shape (the reasoning ends on
Could be something like ",the closing tag for thought: `,they likely mean a tag like <|im_end|>).On that tree
/metricshas noended_inside_thinking, so an empty reply carries no sign of why it is empty. That is what #1840 adds, both layers behindliteral_think_guard: with it on, the same two prompts came back 0 empty of 8 on the same box, and each end is reported (the response field, the journal line,/metrics).So the class is still there on 0.1.44 as it ships, and the fix for it is the review of #1840.
@47Hunter47 commented on GitHub (Oct 16, 2026):
Re-reported with the engine log the close comment asked for: #2731 — the same end still reproduces on a stock checkout of
v0.1.44.1(reasoning_close_retryoff, 4 of 4 runs empty for the #1178 input).@nghia1930mmm-cmd commented on GitHub (Oct 16, 2026):
Là sao?
Trên 16 tháng 10, 2026 12:14:25 GMT+07:00, Mert @.***> đã viết: