[PR #2140] [CLOSED] [Engine] serve: honour llama-server's thinking_budget_tokens (a llama.cpp client's thinking budget was silently ignored) #3878

Closed
opened 2026-11-07 15:31:23 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/2140
Author: @xrip
Created: 10/12/2026
Status: ❌ Closed

Base: main ← Head: pr/thinking-budget-alias


📝 Commits (1)

  • b394c6f serve: thinking_budget_tokens (llama.cpp's name) is the same thinking budget as reasoning_budget_tokens

📊 Changes

3 files changed (+18 additions, -5 deletions)

View changed files

📝 docs/DETAILS.md (+2 -1)
📝 serve/server.py (+5 -4)
📝 serve/test_server.py (+11 -0)

📄 Description

Problem and result

A client written for llama-server sends its thinking budget as thinking_budget_tokens. Strata's server reads only reasoning_budget_tokens, so it ignores that field: the request runs with no thinking budget at all, and nothing is logged or reported. llama-server reads both names (tools/server/server-common.cpp takes reasoning_budget_tokens and falls back to thinking_budget_tokens), and its Anthropic adapter (server-chat.cpp) writes the second one, so any client built against llama-server can hit this.

How it showed up: the pi coding agent's llama.cpp provider (pi-llama-cpp) sends thinking_budget_tokens (8,192 at pi's default level). During an automatic compaction (a 109,013-token history, answer capped at 26,214 tokens) the model thought until the cap and never wrote the summary. pi sent the same request again five times, about 250 s each (21 minutes), without compacting.

  • Before: thinking_budget_tokens: N is ignored, and the thinking runs until max_tokens or the end of the context.
  • After: it is the same budget as reasoning_budget_tokens: N. The thinking is wrapped up at N tokens, and reasoning_budget_tokens wins when both are set.

Fixes #2141 (re-tested on 0.2.0-beta there: still present).

Approach

Service.reasoning_budget() reads reasoning_budget_tokens and, when it is absent, thinking_budget_tokens, as llama-server does. The validation is unchanged (a whole number; 0 means no budget), and the config default still applies when neither field is given.

  • serve/server.py: 4 lines in reasoning_budget().
  • serve/test_server.py: test_llama_cpp_thinking_budget_tokens_is_the_same_budget. The alias wraps the thinking up at the same point, and reasoning_budget_tokens takes precedence when both are set.
  • docs/DETAILS.md: the alias is named in the thinking-budget paragraph.

The engine is not touched; there are no compatibility effects for clients that send reasoning_budget_tokens.

Validation

Passed:

  • Rebased onto 0.2.0-beta (f57c0adc) as b394c6fc. python -m pytest -q serve/test_server.py: 339 passed, 3 skipped, 444 subtests passed (Windows 11, Python 3.14).
  • The new test against 0.2.0-beta's own serve/server.py (this change taken out) fails: the thought comes back whole instead of cut at 20 tokens. With the change it passes.
  • In daily use on my box (2x CMP 50HX, Ubuntu 24.04.4) since 2026-10-12, in my fork, which is now on 0.2.0-beta (342185bd) with this change.

Failed: none observed.

Not run: this exact branch against a GPU engine (the change is in request parsing; the test uses the server's stub engine).

Limits

Only the name is added; the budget's behaviour is the existing one.


🔄 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/2140 **Author:** [@xrip](https://github.com/xrip) **Created:** 10/12/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/thinking-budget-alias` --- ### 📝 Commits (1) - [`b394c6f`](https://github.com/Niko1221/Strata/commit/b394c6fcb27f927ade867fd74391f5bf288d51fe) serve: thinking_budget_tokens (llama.cpp's name) is the same thinking budget as reasoning_budget_tokens ### 📊 Changes **3 files changed** (+18 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `docs/DETAILS.md` (+2 -1) 📝 `serve/server.py` (+5 -4) 📝 `serve/test_server.py` (+11 -0) </details> ### 📄 Description ## Problem and result A client written for llama-server sends its thinking budget as `thinking_budget_tokens`. Strata's server reads only `reasoning_budget_tokens`, so it ignores that field: **the request runs with no thinking budget at all**, and nothing is logged or reported. llama-server reads both names (`tools/server/server-common.cpp` takes `reasoning_budget_tokens` and falls back to `thinking_budget_tokens`), and its Anthropic adapter (`server-chat.cpp`) writes the second one, so any client built against llama-server can hit this. How it showed up: the pi coding agent's llama.cpp provider ([pi-llama-cpp](https://github.com/gsanhueza/pi-llama-cpp)) sends `thinking_budget_tokens` (8,192 at pi's default level). During an automatic compaction (a 109,013-token history, answer capped at 26,214 tokens) the model thought until the cap and never wrote the summary. pi sent the same request again five times, about 250 s each (21 minutes), without compacting. - **Before:** `thinking_budget_tokens: N` is ignored, and the thinking runs until `max_tokens` or the end of the context. - **After:** it is the same budget as `reasoning_budget_tokens: N`. The thinking is wrapped up at N tokens, and `reasoning_budget_tokens` wins when both are set. ## Related discussion Fixes #2141 (re-tested on 0.2.0-beta there: still present). ## Approach `Service.reasoning_budget()` reads `reasoning_budget_tokens` and, when it is absent, `thinking_budget_tokens`, as llama-server does. The validation is unchanged (a whole number; 0 means no budget), and the config default still applies when neither field is given. - `serve/server.py`: 4 lines in `reasoning_budget()`. - `serve/test_server.py`: `test_llama_cpp_thinking_budget_tokens_is_the_same_budget`. The alias wraps the thinking up at the same point, and `reasoning_budget_tokens` takes precedence when both are set. - `docs/DETAILS.md`: the alias is named in the thinking-budget paragraph. The engine is not touched; there are no compatibility effects for clients that send `reasoning_budget_tokens`. ## Validation **Passed:** - Rebased onto 0.2.0-beta (`f57c0adc`) as `b394c6fc`. `python -m pytest -q serve/test_server.py`: 339 passed, 3 skipped, 444 subtests passed (Windows 11, Python 3.14). - The new test against 0.2.0-beta's own `serve/server.py` (this change taken out) fails: the thought comes back whole instead of cut at 20 tokens. With the change it passes. - In daily use on my box (2x CMP 50HX, Ubuntu 24.04.4) since 2026-10-12, in my fork, which is now on 0.2.0-beta (`342185bd`) with this change. **Failed:** none observed. **Not run:** this exact branch against a GPU engine (the change is in request parsing; the test uses the server's stub engine). ## Limits Only the name is added; the budget's behaviour is the existing one. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:31:23 +07:00
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#3878
No description provided.