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#4499
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/3207
Author: @47Hunter47
Created: 10/19/2026
Status: ❌ Closed
Base:
main← Head:f-2731-guard📝 Commits (9)
629037bserve: a reply that ends inside its thinking with no answer is continued (#1814)890e9f9serve: report a reply that ended inside its thinking, guard or no guard (#1814)0b4b970serve: put the tag back into the reasoning before the close, and test it (#1814)a68d71eserve: this test file waits for the sampler its servers start (#1814)1b08d6eserve: the #1814 report is opt-in too, so a default server is unchanged041b2c3serve: the token that ended the turn is given back as text (#1178)dc0a378serve: the #1814 total on /metrics/prometheus too, and the help says what it countseebea06serve: the length-cut test turns 0.1.45 answer room off (#1814)e606835serve: the guard on the Responses dialect too, measured with a mock engine (#1814)📊 Changes
7 files changed (+744 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(+334 -0)➕
serve/test_literal_think_guard_responses.py(+195 -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. This is the work #1840 carried (closed in the tracker reset), rebased onto
mainand extended by one test commit.Problem and result
A reply that ends inside its thinking with no answer comes back empty, and nothing says why:
finish_reasonisstop,contentis empty, the reasoning stops mid-sentence. I retested the end on a stockv0.2.0-betacheckout (3d1fb480, engine built from that source,/props.build_inforeportsStrata 0.1.45.3), RTX 3090, Qwen3.8-Flash-Next IQ3_XXS, 250K context,--kv int8, sampling 1.0/0.95/20,reasoning_budget_tokens16384:With
reasoning_close_retry: truethe replies stop being empty (0 of 8) but are stubs: 9, 10, 12 and 80 characters on #1178's input, because the close happens exactly where the closing tag would start.With this change, behind one opt-in flag: 0 of 14 empty over two batteries of the same two prompts. The marker's text goes back into the reply as ordinary text where the model was writing it (2 of 3 trigger-prompt runs contain the exact 10-character marker text, which is what that prompt asks for), the thought continues from there (the code-fence prompt answers in full, 1120 and 1211 characters), and the end is reported: one log line,
totals.ended_inside_thinking, and"ended_inside_thinking": truebesidechoices.Related discussion
#1814 (the shape this fixes), #1178 (the turn-side case, covered here), #2731 (my retest of this end on 0.2.0-beta, reopened with the numbers above), #1840 (the same work before the tracker reset), #1053 and #123 (the close this falls back to), #931 (the plain spans the write-back uses), #728 (the loop this deliberately does not touch).
Approach
In this pack's tokenizer the token that ends the turn is a type-3 control token (id 248046, matched only with
parse_special) and the closing thinking tag is a type-4 token (id 248069). The turn ends on the control token itself, so no character of any marker reaches the stream, and a turn that ended there on purpose looks exactly the same - which is also why the parser cannot catch it.Behind
"literal_think_guard": trueinstrata-<model>.json(orSTRATA_LITERAL_THINK_GUARD=1), like #1053'sreasoning_close_retry:totals.ended_inside_thinkingexposed asstrata:totals_ended_inside_thinking_totalon both/metrics/prometheusand/metricswithAccept: text/plain, and"ended_inside_thinking": truebesidechoicesand in the stream's last chunk.plainspans (#931's mechanism), in the reply and in the next pass's prompt. With the real pack tokenizer: encoding the marker withparse_special=Trueis the single control token 248046, while the same string markedplainis 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); a thought that repeats whole passages is #728's loop, not a marker it mentions, and goes to the close.LITERAL_THINK_RETRIES).The write-back runs before
reasoning_close_retry's close, so a server with both on keeps the thought that was writing the marker. With the flag off a default server is unchanged: no log line, no counter, no response field, and unit checks cover the field and the counter being absent.Validation
Passed:
python -m unittest serve.test_literal_think_guard serve.test_prometheus- 27 tests, OK (this head791e7b0e, Ubuntu, RTX 3090).python -m unittest discover -s serve -t . -p "test_*.py"- 902 tests, 14 skipped, the failures listed below.Portable monitor clientandMinimal serving runtime, green.ended_inside_thinking: trueon the 7 runs that ended inside.v0.2.0-betatag without the change: 5 of 8 empty (the table above), and 0 of 8 empty but 9-80 character stubs withreasoning_close_retry: true.Failed:
test_keepawake.KeepAwakeTests.test_service_holds_for_the_whole_request_including_early_close- every full run on this machine, and the same on a detachedv0.2.0-betaworktree (881 tests, 1 failure, that test).test_responses.NoLeakedSampler.test_server_close_ends_the_sampler- 2 of 3 full runs here. It passes alone (3 of 3) and right after this PR's own module, and it also fails on older trees of this suite on this machine, so I read it as the thread-racy sampler counting this suite already has, not this patch. I did not fix it here.Not run:
Limits
/metricsis what an operator sees.max_tokens, but 0.1.45's answer room caps the thinking at 3/4 ofmax_tokensand wraps it up and answers before the cut is reached. The test turns the answer room off so the turn is the one that was recorded.History
#1840 carried this work and was closed in the tracker reset. The branch is 8 commits (the 7 of #1840 plus the test adaptation above); the diff is +549/-2 in 6 files, the stat #1840 reported plus that test commit. The first push was based on the
v0.2.0-betatag and both fork workflows went red on it: the tag'stools/minimal_server_smoke.pysummary regex predatesfcca2ccband rejectsOK (skipped=N), and the monitor client smoke wants the packaging preflight that landed after the tag. Rebasing ontomainfixed both without touching the diff.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.