fix(llm): a reasoning model out of tokens is asked again with a larger budget #457

Merged
sharang merged 1 commits from fix/llm-reasoning-budget into main 2026-10-05 19:09:09 +00:00
Owner

Follow-up to #453, with the cause the platform session found on stage: the batch triage warning ended with an empty answer.

Cause

LlmClient::chat() sends max_tokens: 4096. The model behind LiteLLM (Qwen3.8-27B) reasons first. Once the reasoning uses up the budget, the content is empty or an unclosed <think> block that without_reasoning removes, and the client returned "" without saying why.

Change (llm/client.rs, llm/types.rs)

  • The response now reads finish_reason.
  • An empty answer with finish_reason=length → the same request again, once, with 16384 tokens (logged at info).
  • Still no answer → an error "the model used its whole token budget reasoning and gave no answer (finish_reason=length)" instead of "". #453 then retries the affected findings in smaller chunks, and anything still unanswered stays as reported.
  • This applies to every chat()/chat_with_messages() caller: triage, control judge, code review and help chat. Tool calls are unaffected.

Not done (needs access to the LiteLLM config)

Switching off reasoning for JSON tasks (chat_template_kwargs.enable_thinking=false or /no_think) would be more efficient. Whether LiteLLM passes those parameters through for that model group can only be tested on stage.

Tests

New fake gateway in llm::client::budget_tests:

  • out of tokens at 4096, answers at 16384 → correct answer, requests [4096, 16384];
  • out of tokens both times → error with finish_reason=length, 2 requests;
  • normal answer → exactly 1 request with 4096.

fmt and clippy with the CI flags.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p

Follow-up to #453, with the cause the platform session found on stage: the batch triage warning ended with **an empty answer**. ## Cause `LlmClient::chat()` sends `max_tokens: 4096`. The model behind LiteLLM (Qwen3.8-27B) reasons first. Once the reasoning uses up the budget, the content is empty or an unclosed `<think>` block that `without_reasoning` removes, and the client returned **`""` without saying why**. ## Change (`llm/client.rs`, `llm/types.rs`) - The response now reads `finish_reason`. - **An empty answer with `finish_reason=length`** → the same request again, once, with **16384** tokens (logged at info). - **Still no answer** → an error "the model used its whole token budget reasoning and gave no answer (finish_reason=length)" instead of `""`. #453 then retries the affected findings in smaller chunks, and anything still unanswered stays as reported. - This applies to every `chat()`/`chat_with_messages()` caller: triage, control judge, code review and help chat. Tool calls are unaffected. ## Not done (needs access to the LiteLLM config) Switching off reasoning for JSON tasks (`chat_template_kwargs.enable_thinking=false` or `/no_think`) would be more efficient. Whether LiteLLM passes those parameters through for that model group can only be tested on stage. ## Tests New fake gateway in `llm::client::budget_tests`: - out of tokens at 4096, answers at 16384 → correct answer, requests `[4096, 16384]`; - out of tokens both times → error with `finish_reason=length`, 2 requests; - normal answer → exactly 1 request with 4096. fmt and clippy with the CI flags. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang added 1 commit 2026-10-05 18:19:11 +00:00
fix(llm): a reasoning model out of tokens is asked again with a larger budget
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 8m13s
5345bdbc18
On stage, a batch triage answer came back empty: the reasoning model
(Qwen3.8-27B behind LiteLLM) spent chat()'s 4096 tokens thinking, so the
content was empty or an unclosed <think> block, and the client returned ""
without saying why.

The client now reads finish_reason. An empty answer with
finish_reason=length is sent once more with 16384 tokens; if that gives
no answer either, the call fails with "the model used its whole token
budget reasoning and gave no answer (finish_reason=length)" instead of an
empty string. Covers every chat() and chat_with_messages() caller
(triage, control judge, code review, help chat).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang merged commit 96da28dd3f into main 2026-10-05 19:09:09 +00:00
Sign in to join this conversation.