mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #5039] [Engine] serve: thinking without a budget eats the whole max_tokens cap (48-1023) and returns content:"" with finish_reason:"length" - the half-cap fix exists for DeepSeek-V4.1 only (Qwen3.8-Flash-Next, 4x V100; 0.1.46.3 and 0.2.9) #2333
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#2333
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 @miaomiaozii on GitHub (Nov 2, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/5039
Summary
With thinking left on and no thinking budget, a Chat Completions request whose
max_tokensisbelow
ANSWER_ROOM_MIN_CAP(1024) can consume the whole budget insidereasoning_contentandreturn
content: ""withfinish_reason: "length". The answer never exists: the streamcarries only
delta.reasoning_contentchunks, then the stop chunk.This is deliberate in today's code -
answer_roomonly closes thinking early frommax_tokens >= 1024up, and the branch that does cap thinking in half below that floor(
DS41_SMALL_CAP_MIN <= max_new < ANSWER_ROOM_MIN_CAP,b4418e30, 2026-10-24) is gated toself.family == "deepseek41". The comment right above it even describes our exact symptom. Theproblem is the consequence for callers: an agent harness or an extraction call that asks for a short
answer (
max_tokens64-512 is the normal range for "answer with one number / one line / one JSONobject") gets an empty turn and no way to tell it apart from a real failure -
completion_tokensequals the cap, so the only signal isfinish_reason: "length".We measured it on both the version we run in production (serve 0.1.46.3 / engine 0.1.46.3) and on
0.2.9 (serve 0.2.9 / engine 0.1.55), plus one hybrid arm (serve 0.2.9 + engine 0.1.46.3), 192
requests in total. It reproduces on all four arms with the same shape, so this is not a 0.2.9
regression and it is a serve-side behaviour, not an engine defect.
Environment
Repro
One request,
max_tokensbelow the cap, thinking on, no budget:Run it 6–10 times per
max_tokensin {64, 180, 512, 1024} withtemperature: 0. Expect:at 64 every run is empty; at 180 some runs are empty; at 512/1024 none are empty.
What we measured (temperature 0, one process restart per arm, 192 requests)
empty= runs whosecontentwas 0 characters. Every arm uses the same prompt and the same requestshape; arms differ only in serve/engine version (the last arm also adds
STRATA_PREFILL_LAYER_MAJOR=1and--vram-reserve-mib 6000- that reserve change was needed to getthe 0.1.55 engine to load on 2× V100 and has no bearing on this behaviour). The first and last rows
were run as two independent passes (9 reps per cell), the middle rows as one pass (3 reps per cell).
The counts below are recomputed from the raw JSON the probe wrote, not read off a log.
max_tokens64thinking_budget_tokens: 96reasoning_effort: lowSTRATA_PREFILL_LAYER_MAJOR=1+--vram-reserve-mib 6000One empty sample, verbatim from the stream:
The same question answered normally costs
completion_tokens152-157 withfinish_reason: "stop"and
content= the 5-character number, so the thinking alone needs ~150-190 tokens for this prompt.That gives a clean shape:
max_tokens: 64, across all fourarms.
reasoning_effort: low.thinking_budget_tokens: 96at cap 180.The hybrid arm (0.2.9 serve + 0.1.46.3 engine) and the production arm (0.1.46.3 serve + 0.1.46.3
engine) give the same picture, which places the behaviour in
serve/and not in the engine build.Two other short questions (a JSON field-extraction ask and a one-sentence definition ask, both in
Chinese) at
max_tokens: 180produced content every time, but the JSON one also regularly ends atfinish_reason: "length"with the object cut off mid-way - the truncated-answer half of this iscommon even when it is not empty.
Where this lives in the code
0.2.9
serve/server.py:The fix we are asking for is already in the tree, gated to one family.
b4418e30(2026-10-24)added the
deepseek41branch above for exactly this symptom - "a short max_tokens ... was spententirely on the thinking, so no text block ever arrived". Our requests fall through both guards:
max_new 180 < 1024skips theanswer_roombranch, andself.family != "deepseek41"skips thehalf-cap branch.
d0e990ba(2026-10-16) is the originalanswer_roomcommit.This also explains why our workaround works: the
#984branch a few lines below (if budget and max_new and max_new > 0:, withANSWER_RESERVE_MIN = 512) only runs when a budget exists, sosending
thinking_budget_tokensputs a 180-token request onto the protected path.0.1.46.3
serve/server.pyhas the sameanswer_roomguard (:204and:4793) and nodeepseek41branch, which is why the control arm reproduces the same table.
So today: thinking without a budget is only protected when
max_tokens >= 1024. A caller askingfor a one-line answer with
max_tokens: 180gets no protection and, when thinking is longer thanthe cap, gets an empty reply with no answer half at all.
Why it matters for us
Our client is an agent/automation harness that asks short, structured questions (numbers, JSON,
one-line summaries) with
max_tokensin the 64–512 range to keep latency and cost bounded. Anempty
contentturn after a tool result is indistinguishable from "the model failed", so theharness either stops or retries the same failing request. We only noticed it because we now hash
and count empty replies per arm — the reply is a valid HTTP 200 with a full usage block.
What works around it today
thinking_budget_tokens: 96withmax_tokens: 180→ 0/24 empty across all four arms. Cheap andeffective, but it forces every caller to size a budget per request, and it also shortens the
thinking (114 completion tokens vs 152-157 unbounded).
max_tokens >= 1024→ 0/24 empty, at the cost of a much larger cap.reasoning_effort: lowdoes not reliably help - 7/24 empty with it (4/9 on the 0.1.46.3control, 3/15 on the 0.2.9 arms), i.e. worse than the same cap without it.
answer_room: falsein the config turns the guard off entirely, so it does not help here.What we would like (pick any)
b4418e30'sdeepseek41branch (cap unbounded thinking at
max_new // 2whenDS41_SMALL_CAP_MIN <= max_new < ANSWER_ROOM_MIN_CAP) is exactly the fix we want forQwen3.8-Flash-Next: either make that branch apply to models that think by default, or add ourfamily to the same condition. The wrap-up machinery it relies on already works for Qwen3.8 on this
model - the
>= 1024branch turns the same prompt into a normal answer every time.lengthcase. #1053 addedreasoning_close_retry(0.1.40.2) for the sibling shape where the model stops inside<think>,and the #123 thinking-budget wrap-up already closes thinking and continues from the held prefix.
Doing the same when
finish_reason == "length"and the parser is still inside thinking with zerocontent would turn these empty turns into answers using the tokens the request already paid for,
and would also cover callers whose own budget is too small.
ANSWER_ROOM_MIN_CAPis a module constant; a config key (and/or aproportional reserve below it, e.g.
max_new - min(512, max_new // 4)) would let callers whodeliberately want today's behaviour keep it.
produced" from a plain truncation: a distinct
finish_reason(or a response field), so a harnesscan retry with a bigger cap instead of treating it as an empty model turn.
Notes
same prompt and the same table shape. The hybrid arm (0.2.9 serve + 0.1.46.3 engine) also
reproduces it, which puts the behaviour in
serve/, not in the engine.<think>,finish_reason: "stop",fixed by
reasoning_close_retry), #1840 (continue a reply that ends inside thinking), #984(
reasoning_budget_tokensignored - which is why ourthinking_budget_tokensworkaround works),#2140 (honour
thinking_budget_tokens), #4035 (finish_reason: "length"after a newline stop),#4949 (Qwen3.8-Flash-Next thinking passes spent on "there is no actual task"), #3981 (HTTP 200 with
empty answers under
--batch 2on Metal - a different cause). None of them covers the shape above:thinking with no budget, a cap below
ANSWER_ROOM_MIN_CAP, andfinish_reason: "length".before/after empty-reply rate; we keep the raw per-request JSON for every arm.
of both matched arms, so the numbers above can be checked line by line.
@miaomiaozii commented on GitHub (Nov 2, 2026):
Full evidence, as promised in the issue: the probe script we ran, and the raw records for the arithmetic cells of the two matched 6-repetition arms (48 requests each).
probe_raw.py (the whole script; run as `TIERS=/probe_raw.py bash run_arm.sh 1 1 8080`)
Raw records - arithmetic cell, both arms, reps=6
0.1.46.3 serve + 0.1.46.3 engine (production control) - file
rawprobe_arm0_072143.json, armarm0, engine?0.2.9 serve + 0.1.55 engine - file
rawprobe_vr029_071653.json, armvr029, engine?Sanitized request shape (the tuned engine arg list is deliberately left out; the only things that matter for this issue are the model, thinking defaults and
max_tokens):@st0aty commented on GitHub (Nov 4, 2026):
Independent reproduction on a different model and GPU, plus a tested patch.
Reproduction
We run Qwen3.8-Flash-Next (GSQ-RCO IQ2_XS, native pack,
--draft dflash2, int8 KV, 262144 context) on a singleRTX 3090, serve 0.2.10 / engine 0.1.56. Thinking on, no budget of the request's own, temperature 0, one
request per
max_tokensvalue:Every completion token went into
reasoning_contentandcontentwas the empty string in all three. A prompt themodel answers without thinking returns content at
max_tokens: 48on the same unit, so the trigger is the thinkingoutliving the cap, not the cap itself. The defect is not specific to the 0.2.9 pair or to V100: this is 0.2.10 on a
consumer card, and it is the same server module.
The cause is the guard the report already names
In 0.2.10 the two guards are the same, and a request below
ANSWER_ROOM_MIN_CAP(1024) with no budget of its ownfalls through both:
max_new >= ANSWER_ROOM_MIN_CAP;DS41_SMALL_CAP_MIN <= max_new < ANSWER_ROOM_MIN_CAP) is still gated onself.family == "deepseek41".So between 48 and 1023 every other family gets no budget at all, which is where the 64 to 512 callers live.
Patch we have tested
Half the cap for every family but DeepSeek-V4.1, with a per-family floor:
DeepSeek-V4.1 keeps 48 and the arithmetic it had, so nothing changes for the family the branch was written for.
Where the floor comes from, measured on the repo's own fake-engine harness with the half rule applied across the
range (
max_tokens48, 64, 96, 128, 144, 160, 176, 192, 208, 256, 512, 1023, a ~1,800-token thinking):The boundary is the wrap-up sentence plus
</think>plus the answer needing to fit in the half that is left, so itmoves with the wrap-up's length: that same sweep with a ~184-token thinking gives the same boundary, and real weights
may shift it again. That is why we put it in a module constant rather than deriving it. A cap below the floor keeps
today's shape rather than being handled wrongly.
Tests: the 300-token case in
test_the_answer_room_has_its_limitsasserted the empty answer, so it was pinning thebug; it now asserts the answer and
finish_reason: stop. Three tests added: every family answers at 192, 256, 300 and1023 with no budget; a cap below the floor keeps the old shape; a request that names its own budget still wins below
the floor. Full
serve.test_server: 362 tests OK.Below 192
The only honest fix there is deciding the thinking where it is chosen, at template time. Flipping it inside the run
leaves token ids built for a thinking reply and the model's
<think>block lands incontent. Two options that wouldwork for a maintainer:
the reply shape for small calls, which is the maintainer's call.
lengthhonestly, but never return an emptycontentthat a client reads as an answer, e.g. a distinctfinish_reasonor an error field a client can act on.Two more measurements, since they bound the blast radius
short-reasoning traffic at
max_tokens: 4096, zero empty replies. So the defect bites callers who ask for shortanswers, exactly the 64 to 512 range in the report, and it is invisible to anything that samples only large caps.
It does not follow that thinking-heavy traffic at 4096 is safe.
reasoning_effort: lowdoes not protect. On a prompt that needs real thinking, through a proxy on the sameengine, temperature 0.6, one draw each:
lowatmax_tokens: 300spent 592 characters of reasoning and returned nocontent,
highdid the same (574). Atmax_tokens: 4096the same prompt atlowanswered, but only after about3,700 tokens of reasoning. Low effort still thinks hard when the prompt needs it, so the cap is the only reliable
lever.
We can open a PR with the patch and the tests against 0.2.10, and run any variant on the 3090 box if you want a second
data point for a specific cap.
@rwkeyes commented on GitHub (Nov 7, 2026):
Adding a 0.2.12 reproduction with numbers, since the report above is from 0.1.46.3 / 0.2.9 and the
same shape is still there at
146df3c4.Environment: Arc Pro B70 32 GB, Ubuntu/KDE, Qwen3.8-Flash-Next GSQ-RCO Coder IQ1_M (native pack,
MTP head), engine 0.1.58 SYCL build (
bmg-g31AOT), Chat Completions, streaming,temperature 0,one request at a time, fresh prompt each request. Six extraction prompts ("reply with only the
date / the total / the city / the currency code / the ticket id / the file extension").
Observed at
146df3c4(release--thinking-policyabsent, i.e. thinking always on):So it is not DeepSeek-specific and not a 0.2.9-only shape: the small-cap wrap-up being gated to
family == "deepseek41"still leaves a Qwen request at a 24-token cap with an empty turn, exactly asthe report says.
completion_tokensequals the cap andfinish_reason: "length"is the only signal,which is what makes it hard for a harness to tell from a real failure.
One possible fix, and its numbers. I opened a draft PR that takes the "do not ask for the
scratchpad in the first place" direction rather than the "reserve half the cap for the answer"
direction of #5189: a request classified as asking for a short direct answer gets
enable_thinking = falsebefore the prompt is rendered, opt-in behind--thinking-policy on(default off,
shadowmode just logs the label). Same six prompts, same hardware:The single miss is "the invoice dated 14 March 2023" (the classifier reads it as prose rather than an
extraction), quoted rather than hidden. A 3.9 k code prompt kept its thinking and was unchanged
(3.01 → 3.03 s TTFT), and a cached-context repeat was unchanged (0.198 s both).
Draft PR: https://github.com/Niko1221/Strata/pull/5512 —
serve/prompt_kind.py(the classifier),~90 lines in
serve/server.py, and two test files (30 cases). It is a draft on purpose: #5189 is adifferent approach to the same issue, and which direction to take is your call — if the answer-room
route is the one you want, say so there and I will close mine.
Full suite on the patched tree: 1514 tests, 611 s, 17 skipped, 1 failure —
test_server.test_hip_ordinal('0,1' != '1,0'), which fails identically on an unpatched146df3c4worktree, so it is pre-existing rather than caused by the change. I have not run CUDA, HIPor Metal, and no engine backend is involved: the change is server-side Python only.
@st0aty commented on GitHub (Nov 7, 2026):
One more data point for this, in case it is useful now that it is on the known-problems list: it still
reproduces on 0.1.58 (0.2.12). Single RTX 3090, driver 615.71.10, Qwen3.8-Flash-Next IQ2_XS, via
/v1/chat/completions, no reasoning budget in the request:Same prompt at 48 tokens on a question the model answers without thinking returns a normal reply, so the
trigger is the thinking outlasting the cap rather than the cap itself.
One thing that may save a round of work if the 48-1023 band is ever touched: the half-cap branch there is
gated to
deepseek41, so other families get no budget at all. Applying half across the whole band fixes 192and above on your harness but leaves 48-176 empty, because half does not leave room for the wrap-up and an
answer. The boundary in my run was between 176 and 192, so a floor around 192 for the non-DeepSeek families
would land properly rather than just moving the empty answer up the range.
I have a small branch with tests for that shape (192/256/300/1023, plus 176 at the boundary and a
request-supplied budget) if you would like it; happy to open a PR, or leave it if you would rather handle the
band your own way. The sub-192 case is a different change (answer without thinking), and that is your call.