[PR #5512] [Engine] serve: skip the thinking block on prompts that ask for a short direct answer (opt-in) #5484

Open
opened 2026-11-08 00:46:55 +07:00 by bsakaguchi · 0 comments
Owner

📋 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)

  • 18eb0fb serve: 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_tokens can spend the whole
budget inside reasoning_content and return content: "" with finish_reason: "length" — the
caller 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 to
family == "deepseek41".

Before (release 146df3c4, Arc Pro B70, Qwen3.8-Flash-Next coder IQ1_M, six extraction prompts,
temperature 0, one at a time):

max_tokens=24   0 of 6 answered   0.72 s median wall   (every reply finish=length, content "")
max_tokens=96   1 of 3 answered   1.38 s median wall   (2 of 3 empty)

After (--thinking-policy on, same prompts, same hardware):

max_tokens=24   5 of 6 answered   0.50 s median wall   ('92.99', 'Paris', 'NOK', 'TCK-77341', '.zst')
max_tokens=96   2 of 3 answered   0.55 s median wall

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).

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 thinking
entirely
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"):

  • off — byte-identical behaviour to the release.
  • shadow — label each request and log what it would do.
  • on — for a request classified as asking for a short direct answer, set
    enable_thinking = false before 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-level reasoning_effort, an effort
inside reasoning / chat_template_kwargs, or an output_config / thinking body all leave the
request 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:

  1. _effort_from_shared (2 lines at the existing fill_shared site). The server fills
    req["reasoning_effort"] from shared settings or the config's reasoning_effort. Without marking
    that 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.
  2. serve/prompt_kind.py is a regex classifier over the last user turn (extraction, formatting,
    translation and "reply with only …" raise the score; explain/why/plan/compare and arithmetic
    lower 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/status gains {"thinking": {"mode", "direct", "reason", "applied", "shadowed"}} so the
counters are visible without a new endpoint.

One commit on top of 146df3c4; git apply --check verified 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' at 18eb0fb: 1514 tests, 611 s, 17
    skipped, 1 failure.
    The failure is test_server.test_hip_ordinal ('0,1' != '1,0') and it fails
    identically on an unpatched 146df3c4 worktree — 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.
  • On hardware, end to end, Ubuntu/KDE host, Arc Pro B70 32 GB, Qwen3.8-Flash-Next-GSQ-RCO-Coder
    IQ1_M pack, engine 0.1.58 SYCL build (bmg-g31 AOT) — the release's own engine binary, since
    this change touches no engine code. Server started from this branch at 18eb0fb, then the six
    extraction prompts at max_tokens=24 and 96, 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:

  • No CUDA, HIP or Metal run, and no engine build of any backend — the engine binary is unchanged,
    so no backend is implicated; I am flagging it rather than implying coverage.
  • Only the Chat Completions API was exercised end to end. prepare() is shared by /v1/messages and
    /v1/responses, so they take the same path, but I did not run them.
  • No accuracy evaluation beyond the six extraction prompts, and no measurement on hardware other than
    the B70. One GPU, one model, one pack.

Limits

  • The classifier is a heuristic. It will miss some short-direct prompts (one of the six above)
    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 policy does not fix the engine side of #5039 (a budget that a client sets explicitly is still
    the client's to spend); it only stops the server from asking for a scratchpad the request did not
    want.
  • shadow mode is there so a deployment can measure its own traffic mix before turning it on — the
    rate of direct labels 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.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/5512 **Author:** [@rwkeyes](https://github.com/rwkeyes) **Created:** 11/7/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `serve/thinking-skip-for-short-direct-answers` --- ### 📝 Commits (1) - [`18eb0fb`](https://github.com/Niko1221/Strata/commit/18eb0fb4db955b3e3265b382ba1ca984dcd17e75) serve: skip the thinking block on prompts that ask for a short direct answer ### 📊 Changes **4 files changed** (+658 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `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) </details> ### 📄 Description ## Problem and result A Chat Completions request that asks for a short answer at a small `max_tokens` can spend the whole budget inside `reasoning_content` and return `content: ""` with `finish_reason: "length"` — the caller 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 to `family == "deepseek41"`. **Before** (release `146df3c4`, Arc Pro B70, Qwen3.8-Flash-Next coder IQ1_M, six extraction prompts, `temperature 0`, one at a time): ``` max_tokens=24 0 of 6 answered 0.72 s median wall (every reply finish=length, content "") max_tokens=96 1 of 3 answered 1.38 s median wall (2 of 3 empty) ``` **After** (`--thinking-policy on`, same prompts, same hardware): ``` max_tokens=24 5 of 6 answered 0.50 s median wall ('92.99', 'Paris', 'NOK', 'TCK-77341', '.zst') max_tokens=96 2 of 3 answered 0.55 s median wall ``` 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 thinking entirely** 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"`): * **off** — byte-identical behaviour to the release. * **shadow** — label each request and log what it *would* do. * **on** — for a request classified as asking for a short direct answer, set `enable_thinking = false` **before** 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-level `reasoning_effort`, an effort inside `reasoning` / `chat_template_kwargs`, or an `output_config` / `thinking` body all leave the request 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: 1. **`_effort_from_shared`** (2 lines at the existing `fill_shared` site). The server fills `req["reasoning_effort"]` from shared settings or the config's `reasoning_effort`. Without marking that 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. 2. **`serve/prompt_kind.py`** is a regex classifier over the last user turn (extraction, formatting, translation and "reply with only …" raise the score; `explain/why/plan/compare` and arithmetic lower 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/status` gains `{"thinking": {"mode", "direct", "reason", "applied", "shadowed"}}` so the counters are visible without a new endpoint. One commit on top of `146df3c4`; `git apply --check` verified 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'` at `18eb0fb`: **1514 tests, 611 s, 17 skipped, 1 failure.** The failure is `test_server.test_hip_ordinal` (`'0,1' != '1,0'`) and it fails identically on an unpatched `146df3c4` worktree — 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. * **On hardware, end to end**, Ubuntu/KDE host, Arc Pro B70 32 GB, `Qwen3.8-Flash-Next-GSQ-RCO-Coder` IQ1_M pack, engine 0.1.58 SYCL build (`bmg-g31` AOT) — the **release's own engine binary**, since this change touches no engine code. Server started from this branch at `18eb0fb`, then the six extraction prompts at `max_tokens=24` and `96`, 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:** * No CUDA, HIP or Metal run, and **no engine build of any backend** — the engine binary is unchanged, so no backend is implicated; I am flagging it rather than implying coverage. * Only the Chat Completions API was exercised end to end. `prepare()` is shared by `/v1/messages` and `/v1/responses`, so they take the same path, but I did not run them. * No accuracy evaluation beyond the six extraction prompts, and no measurement on hardware other than the B70. One GPU, one model, one pack. ## Limits * **The classifier is a heuristic.** It will miss some short-direct prompts (one of the six above) 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 policy does not fix the *engine* side of #5039 (a budget that a client sets explicitly is still the client's to spend); it only stops the server from asking for a scratchpad the request did not want. * `shadow` mode is there so a deployment can measure its own traffic mix before turning it on — the rate of `direct` labels 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#5484
No description provided.