mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
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#3713
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/1840
Author: @47Hunter47
Created: 10/10/2026
Status: ❌ Closed
Base:
main← Head:f-1814-empty-reply📝 Commits (7)
d878296serve: a reply that ends inside its thinking with no answer is continued (#1814)8fc8cefserve: report a reply that ended inside its thinking, guard or no guard (#1814)6ff9c22serve: put the tag back into the reasoning before the close, and test it (#1814)6698858serve: this test file waits for the sampler its servers start (#1814)bf41864serve: the #1814 report is opt-in too, so a default server is unchanged00027bdserve: the token that ended the turn is given back as text (#1178)cf0d002serve: the #1814 total on /metrics/prometheus too, and the help says what it counts📊 Changes
6 files changed (+546 additions, -2 deletions)
View changed files
➕
serve/fixtures/literal_think_specimens.json(+30 -0)📝
serve/frontend.py(+5 -0)📝
serve/prometheus.py(+7 -0)📝
serve/server.py(+149 -2)➕
serve/test_literal_think_guard.py(+331 -0)📝
serve/test_prometheus.py(+24 -0)📄 Description
Fixes #1814. #1178's turn-side case is the same end and is covered by the same flag.
Update to this description (14 Oct): the branch is rebased onto
main(v0.1.44.1,296b59d2) and is now 7 commits, 6 files (+546/−2). The</tool_response>half that used to be a commit here is no longer in this PR: upstream shipped it in 0.1.44 (62185aab, the #2026 follow-up, listed in the 0.1.44 notes as "A literal<tool_call>,<tool_response>or</tool_response>in a message is text (47Hunter47, #2026)"), so the rebase dropped my copy. After the rebase the guard probe on this machine (engine and server 0.1.44.1) is 0 of 4 empty replies, withended_inside_thinking: trueon the run that ended inside its thinking. Everything below about the guard is current; the</tool_response>section is kept for the record, with where it shipped.What I see
The model is about to write its closing thinking tag and the turn-end token comes instead:
finish_reasonisstop, the reasoning stops mid-sentence, no answer is produced, and the client gets an empty reply.Reproduced on 0.1.44 itself, from a stock checkout of the tag
v0.1.44(ed4773eb) — the tag's ownserve/, no local patches (literal_think_guarddoes not exist there),/props.build_info=Strata 0.1.44, engine 0.1.44, RTX 3090 with Qwen3.8-Flash-Next IQ3_XXS, 250K context,--kv int8, sampling 1.0/0.95/20, thinking budget 16384:One of those turns, as the engine log prints it:
89 tokens of a 3000-token thinking budget, ended with
stop: not a budget cut and not a length cut./metricson that tree has noended_inside_thinkingseries, so an empty reply carries no sign of why it is empty.On 0.1.41 the same trigger prompt behaved the same way but not on every run: 6 of 9, then 3 of 5, then 0 of 6. The prompt has to make the model reach for its closing tag, and the cut lands right where the tag would start, or right after a backtick - which matches what danirebollo describes in the issue.
Five real turns are in
serve/fixtures/literal_think_specimens.json(STRATA_DEBUG=1, dumped on this box on 0.1.41): threeno-answer, oneanswered, onelength-cut.Why the parser cannot catch it
In this tokenizer the token that ends the turn,
<|im_end|>, is a type-3 control token (id 248046, matched only withparse_special), and the closing thinking tag</think>is a type-4 token (id 248069, matched either way). The turn ends on that control token itself - the server's stop set - so no character of the marker is emitted, and nothing in the stream says "I meant that": a turn that ends inside its thinking looks exactly like a turn that ended there on purpose. That is also why #537's mark/unmark work (the input side) does not cover it.The fix: the token's text is given back, then the thinking is closed (both behind one opt-in flag)
1. The end is reported (with the flag on, like the continuation):
the reply ended inside its thinking with no answer (N tokens generated)- with the guard on the continuation line follows it, and once its cap is reached the line says sototals.ended_inside_thinking, exposed asstrata:totals_ended_inside_thinking_totalon both/metrics/prometheus(llama.cpp's names) and/metricswithAccept: text/plain(vLLM's). It counts ends inside the thinking, so a reply the guard continues past can count more than once."ended_inside_thinking": truebesidechoicesin the response, and in the stream's last chunk (the same placetimingsgoes)So a client that turned the guard on and got an empty reply is told why it is empty and can retry, and an operator sees the rate. The field is absent on a normal reply.
2. The continuation (
"literal_think_guard": trueinstrata-<model>.json, orSTRATA_LITERAL_THINK_GUARD=1), like #1053 - two moves, in this order:(a) the token that ended the turn is given back as text (#1178, reported by TwoAnts). The turn ends on the control token itself, so the reply stops with the sentence unfinished, and closing the thinking there answers with a stub (the table below). So the guard writes the marker's text back where the model was writing it - as ordinary text (the tokenizer's
plainspans, #931's mechanism) in the reply and in the next pass's prompt - and the thought goes on from there. At the token level, with the real pack tokenizer:encode("<|im_end|>", parse_special=True)is the single control token 248046, whileencode("<|im_end|>", parse_special=True, plain=[(0, 10)])is the same six ordinary text tokens as the unparsed string - which is what makes the next pass carry on instead of stopping at once. Capped per reply (LITERAL_MARKER_WRITES = 2, with aliteral_think_writescounter in the request trace); a thought that repeats whole passages is #728's loop, not a marker it mentions, and goes straight to the close.(b) otherwise the thinking is closed the way #123's wrap-up closes it (
REASONING_CLOSE), so the next pass's prompt is the one that produced the reply plus what it generated plus that close, and the engine continues from the prefix it already holds.parser.state == "content"is the same end from the other side - the model wrote the tag as text, the parser took it as the marker and nothing followed - and there the tag goes back into the reasoning text first (OutputParser.reopen_reasoning()). Capped per reply (LITERAL_THINK_RETRIES = 2) with aliteral_think_retriescounter in the request trace, so a model that keeps doing it cannot loop.Both moves are behind the same switch, like #1053: with the flag off a server behaves exactly as it did before #1814 and before #1178 - no log line, no total, no
/metricsseries, no field on the response - so reporting and continuation are one deliberate choice, and the reporting can stay a proof of concept until it is approved on its own. They work together: whichever fires first setsclose_retried. If you would rather have either on by default, the default is one line (Service.literal_think_guard).Measured with the flag on
Same two prompts, same box, engine and server 0.1.44,
literal_think_guard: true: 0 empty of 8. Every end was reported (ended_inside_thinking: trueon those responses, the journal line,totals.ended_inside_thinking= 15 over the session), and the runs that ended while writing the marker were written back and continued:Why the write-back and not the close alone (#1178's prompt, 4 runs each on 0.1.43, both sets 4/4 ended inside the thinking so the guard fired every run):
</tool_response>: the same token arriving from the prompt (shipped upstream in 0.1.44)This was the second commit here and is not in this PR any more: upstream took it in 0.1.44 (
62185aab), and the 0.1.44 notes credit it. For the record, what it was and what it measured:#2026 marked
</tool_call>- the token that ends a call - as text when it appears in a user, system or tool message.</tool_response>closes a tool result and is the same kind of token here: id 248067 in this pack's tokenizer, type 4, matched by the tokenizer with or withoutparse_special. A prompt quoting it therefore handed the model the real closer, and the turn ended where the reply should start. Six runs per string on this box (IQ3_XXS, 250K context,--kv int8, engine and server 0.1.43.1):</aaa>(not in the vocabulary)</tool_call>(marked since 0.1.43.1)<tool_call><tool_response></tool_response>The pattern was which literal closes a block the template opens -
</tool_call>closes the answer's call block,</tool_response>closes a tool result's block, and the two openers do neither. The one case that must not be marked is a user message that starts with<tool_response>and ends with</tool_response>: the template'smulti_step_toolscan reads it as a wrapped tool result, and marking happens before the template renders, sowrapped_tool_result()gave exactly those messages the set an assistant message keeps. At the token level it came back 4 of 4 after the change,</aaa>unchanged, against 0 of 15 before. All of that is upstream's now.Tests
serve/test_literal_think_guard.py(19 tests) replays the five real turns through a mock engine: everyno-answerspecimen gets the answer with one continuation, the token's text reaches the reply and travels into the next pass asplaintext (not as the control token, which would stop that pass at once), a looping thought gets the close instead of the write-back, the flag-off case carries nothing (no log, no total, no field) and stays empty, the answer the guard reached is reported too, a reply that hit the cap is reported and still empty, ananswered/length-cutspecimen is not touched, a normal reply carries no flag, the flag is off by default, and both caps hold.serve/test_prometheus.pychecks the/metricsseries does not exist until the guard counts.python -m unittest discover -s serve -t . -p "test_*.py"-> 790 tests, 11 skipped, 1 failure:test_keepawake'stest_service_holds_for_the_whole_request_including_early_close(itswait_for(..., t=3.0)races the keepawake thread's release).serve.test_keepawakealone fails the same way on the tagv0.1.44in a clean worktree (6 tests, 1 failure in both trees), so it is not from this change.I have it running on this machine (one 3090, IQ3_XXS, the same config the issue reports) with the flag on.
Scope
It continues an empty reply and reports it; it does not repair the content. When the model reaches for a stop token's text, the reply that comes back after the continuation can still be that marker, or plan text left over from the thinking (measured on my box: 2 of 3 runs answered the marker question correctly, 1 of 3 came back as a stub), so this is the turn-side half. The trigger itself belongs to two other layers: the prompt side (a quoted literal must not reach the model as the real special token -
</tool_call>since 0.1.43.1,</tool_response>since 0.1.44) and the parser side, which is what #1886 is about. Measured split on my box, same prompt: with the flag off, 3 of 3 empty replies; with it on, 0 of 3.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.