mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #5512] [Engine] serve: skip the thinking block on prompts that ask for a short direct answer (opt-in) #5484
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#5484
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/5512
Author: @rwkeyes
Created: 11/7/2026
Status: 🔄 Open
Base:
main← Head:serve/thinking-skip-for-short-direct-answers📝 Commits (1)
18eb0fbserve: skip the thinking block on prompts that ask for a short direct answer📊 Changes
4 files changed (+658 additions, -0 deletions)
View changed files
➕
serve/prompt_kind.py(+251 -0)📝
serve/server.py(+90 -0)➕
serve/test_prompt_kind.py(+167 -0)➕
serve/test_thinking_policy.py(+150 -0)📄 Description
Problem and result
A Chat Completions request that asks for a short answer at a small
max_tokenscan spend the wholebudget inside
reasoning_contentand returncontent: ""withfinish_reason: "length"— thecaller gets a successful turn with nothing in it. This is #5039, and it still reproduces on
v0.2.12(146df3c4) for a non-DeepSeek family, because the small-cap wrap-up is gated tofamily == "deepseek41".Before (release
146df3c4, Arc Pro B70, Qwen3.8-Flash-Next coder IQ1_M, six extraction prompts,temperature 0, one at a time):After (
--thinking-policy on, same prompts, same hardware):The answers are the values that were asked for. The one prompt that still fails ("the invoice dated
14 March 2023") is a classifier miss, not a policy failure — it is in the table rather than dropped.
The lanes it must not touch were unchanged in the same run: a 3.9 k code prompt at a 160-token
budget (3.01 s TTFT / 3.62 s wall before, 3.03 / 3.64 after — a code prompt keeps its thinking) and
a repeat of a cached 3.9 k prompt (0.198 s / 0.44 s both).
Related discussion
Issue: #5039 — "thinking without a budget eats the whole max_tokens cap … returns content:"" with
finish_reason:"length"". I have added the 0.2.12 reproduction and these numbers there.
#5189 is a draft PR for the same issue and takes the other direction: keep the thinking and
reserve half the cap for the answer (
short_answer_room). This PR instead skips the thinkingentirely for a request that asks for a short direct answer. They are not exclusive; picking one is
a maintainer decision.
Draft on purpose: I am not asking for a merge decision before you say which shape you want. If you
prefer the answer-room direction, I will close this without argument; if the direction is useful but
the scope is wrong, tell me what to cut.
Approach
--thinking-policy off|shadow|on(default off; the same key works in the config as"thinking_policy"):enable_thinking = falsebefore the prompt is rendered, so the template and the parser agree(they read the same kwargs object).
It never overrides a client:
enable_thinking: false, a top-levelreasoning_effort, an effortinside
reasoning/chat_template_kwargs, or anoutput_config/thinkingbody all leave therequest exactly as sent. A code prompt always keeps its thinking — a bug report or a design question
is where the thinking earns its tokens.
Two things a reviewer should look at closely:
_effort_from_shared(2 lines at the existingfill_sharedsite). The server fillsreq["reasoning_effort"]from shared settings or the config'sreasoning_effort. Without markingthat as the server's value, the policy reads it as a client choice and silently never fires.
There is a test for exactly that case.
serve/prompt_kind.pyis a regex classifier over the last user turn (extraction, formatting,translation and "reply with only …" raise the score;
explain/why/plan/compareand arithmeticlower it; fenced code, error text, diffs and code instructions exclude a prompt). No model, no
extra request, plain Python. It is the largest part of the diff and the part most worth arguing
with.
GET /v1/statusgains{"thinking": {"mode", "direct", "reason", "applied", "shadowed"}}so thecounters are visible without a new endpoint.
One commit on top of
146df3c4;git apply --checkverified on a fresh worktree of the tag.Server-side Python only — no engine source, no protocol, no on-disk format changes.
Validation
Passed:
python -m unittest discover -s serve -p 'test_*.py'at18eb0fb: 1514 tests, 611 s, 17skipped, 1 failure. The failure is
test_server.test_hip_ordinal('0,1' != '1,0') and it failsidentically on an unpatched
146df3c4worktree — the release's own mismatch, not this change.Full log kept.
python -m pytest -q serve/test_thinking_policy.py serve/test_prompt_kind.py: 30 passed(0.17 s). Cases cover: direct vs reasoning prompts, code prompts keeping thinking, client overrides
of every kind accepted above, the server-filled effort, shadow mode, a classifier exception, and the
default-off path.
Qwen3.8-Flash-Next-GSQ-RCO-CoderIQ1_M pack, engine 0.1.58 SYCL build (
bmg-g31AOT) — the release's own engine binary, sincethis change touches no engine code. Server started from this branch at
18eb0fb, then the sixextraction prompts at
max_tokens=24and96, plus the two control lanes, via a stdlib probe(streaming,
temperature 0). Numbers in "Problem and result" above.Failed: none observed. (The single suite failure is pre-existing and named above.)
Not run:
so no backend is implicated; I am flagging it rather than implying coverage.
prepare()is shared by/v1/messagesand/v1/responses, so they take the same path, but I did not run them.the B70. One GPU, one model, one pack.
Limits
and can mislabel others; when it does, the request loses a thinking block it would have used. That
is the cost of the approach, and it is why the flag defaults to off.
the client's to spend); it only stops the server from asking for a scratchpad the request did not
want.
shadowmode is there so a deployment can measure its own traffic mix before turning it on — therate of
directlabels on real traffic is the number to look at first.AI assistance was used for diagnosis, implementation and the measurement runs. Every number above
comes from a run on the hardware named; the commands and the raw JSON are available if useful.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.