[GH-ISSUE #613] Thinking budget closes an agent turn's reasoning mid-sentence; the malformed tool call that followed failed the whole request #254

Open
opened 2026-10-29 21:23:21 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @NenadSteric on GitHub (Oct 28, 2026).
Original GitHub issue: https://github.com/mw00/project-maya/issues/613

Version: observed on v1.1.34 (249f9a8), maya-mm3, MiniMax-M3.1-Flash Maya-S, 6x RTX 3090, the setup's config
(thinking_budget not set). v1.1.35 changes none of the code involved: the default (serve/server.py:5013), the
clamp (:2995), parse_tool_call (serve/frontend.py:678) and the error path (serve/server.py:3088-3102).

What happened

A coding agent (pi, OpenAI API, max_tokens 32768, tools on) in a long session:

  1. The default thinking_budget (32768, docs/SETTINGS.md) is clamped to 24,575 by the request's 32K
    max_tokens. In turn 3 the reasoning reached that clamp and was closed in the middle of a sentence:
    ... The upper roof's eave (storyHalf_{i+1}+3.0) vs the lower roof's half-size at that height... The lower roof at
    its ridge is storyHalf_i+0.3 wide; the upper roof's eave is storyHalf_{i+1}+3.0 ≈ storyHalf_i - 1.15 + 3.0 =
    storyHalf_i + 1.85 > story
    
  2. The answer that followed was garbled (0I have enough context to work. Let me check the plan.md and plan.md files in thepagi — actually let me start writing the plan and implementation.), and ~100 tokens later came a tool call
    the parser rejects.
  3. The server ended the request with an error. All 24,677 tokens (634 s of generation) were lost, the client got
    only the error, and the agent stopped:
    [maya] thinking reached its budget (24575 tokens): closed, answering
    [maya] the engine reported an error: malformed tool call: <tool_call>write<arg_key>path</arg_key><arg_value>"PLAN.md"</arg_value>
    [maya] done: 24677 tokens in 634 s (39.1 tok/s) (error, cancel=False), expert cache 99.6% hit
    

With "thinking_budget": 0 and everything else the same, the session ran 65 turns with no malformed call, and two
other sessions on the same server (~325 turns) never reached the budget and had none either. This is one
occurrence. The forced close is the likely trigger, but that is not proven.

The same budget also closed a GLM-5.3-Flash EXL3 turn (v1.1.25, 32K max_tokens) at 24,576 tokens. That answer then
ran to the 32K limit (stop=length); the session recovered.

Three points (your call which are worth changing)

  1. A malformed tool call fails the whole request. A ValueError from the tool-call parser takes the same path
    as an engine ERR line, so the client gets an error instead of what was generated. If the text and the call body
    were returned as the answer's content (finish_reason "stop"), an agent would see the broken call and could retry
    instead of stopping.
  2. The log hides the cause. It says "the engine reported an error", but the server's parser raised it, and it
    keeps only the call's first 80 characters, so the part that failed is lost. Logging the whole body, or at least
    its tail, would show what broke.
  3. The budget applies to API clients that set their own max_tokens. Agent clients send a large cap and expect
    the reasoning to run inside it. The clamp keeps a reply from ending with no answer, but it closes the reasoning
    wherever it is, mid-sentence included. One option: leave the reasoning unbudgeted when the request carries tools,
    or close it only at a line or sentence boundary. The documented setting already turns it off, so this may simply
    be a docs note for agent use.

🤖 Generated with Claude Code

Originally created by @NenadSteric on GitHub (Oct 28, 2026). Original GitHub issue: https://github.com/mw00/project-maya/issues/613 **Version:** observed on v1.1.34 (249f9a8), `maya-mm3`, MiniMax-M3.1-Flash Maya-S, 6x RTX 3090, the setup's config (`thinking_budget` not set). v1.1.35 changes none of the code involved: the default (`serve/server.py:5013`), the clamp (`:2995`), `parse_tool_call` (`serve/frontend.py:678`) and the error path (`serve/server.py:3088-3102`). ### What happened A coding agent (pi, OpenAI API, `max_tokens` 32768, tools on) in a long session: 1. The default `thinking_budget` (32768, `docs/SETTINGS.md`) is clamped to 24,575 by the request's 32K `max_tokens`. In turn 3 the reasoning reached that clamp and was closed **in the middle of a sentence**: ``` ... The upper roof's eave (storyHalf_{i+1}+3.0) vs the lower roof's half-size at that height... The lower roof at its ridge is storyHalf_i+0.3 wide; the upper roof's eave is storyHalf_{i+1}+3.0 ≈ storyHalf_i - 1.15 + 3.0 = storyHalf_i + 1.85 > story ``` 2. The answer that followed was garbled (`0I have enough context to work. Let me check the plan.md and plan.md files in thepagi — actually let me start writing the plan and implementation.`), and ~100 tokens later came a tool call the parser rejects. 3. The server ended the request with an error. All 24,677 tokens (634 s of generation) were lost, the client got only the error, and the agent stopped: ``` [maya] thinking reached its budget (24575 tokens): closed, answering [maya] the engine reported an error: malformed tool call: <tool_call>write<arg_key>path</arg_key><arg_value>"PLAN.md"</arg_value> [maya] done: 24677 tokens in 634 s (39.1 tok/s) (error, cancel=False), expert cache 99.6% hit ``` With `"thinking_budget": 0` and everything else the same, the session ran 65 turns with no malformed call, and two other sessions on the same server (~325 turns) never reached the budget and had none either. This is one occurrence. The forced close is the likely trigger, but that is not proven. The same budget also closed a GLM-5.3-Flash EXL3 turn (v1.1.25, 32K `max_tokens`) at 24,576 tokens. That answer then ran to the 32K limit (`stop=length`); the session recovered. ### Three points (your call which are worth changing) 1. **A malformed tool call fails the whole request.** A `ValueError` from the tool-call parser takes the same path as an engine `ERR` line, so the client gets an error instead of what was generated. If the text and the call body were returned as the answer's content (`finish_reason` "stop"), an agent would see the broken call and could retry instead of stopping. 2. **The log hides the cause.** It says "the engine reported an error", but the server's parser raised it, and it keeps only the call's first 80 characters, so the part that failed is lost. Logging the whole body, or at least its tail, would show what broke. 3. **The budget applies to API clients that set their own `max_tokens`.** Agent clients send a large cap and expect the reasoning to run inside it. The clamp keeps a reply from ending with no answer, but it closes the reasoning wherever it is, mid-sentence included. One option: leave the reasoning unbudgeted when the request carries tools, or close it only at a line or sentence boundary. The documented setting already turns it off, so this may simply be a docs note for agent use. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Owner

@mw00 commented on GitHub (Oct 28, 2026):

Thank you @NenadSteric. v1.1.36 now logs the whole body of a malformed tool call (it was cut at 80 characters), which is what we needed to see what the model wrote at the cut. The part where the thinking budget closes the reasoning mid-sentence is still open; with the full body in the log it can be tackled next. If you can send one of those logged bodies, it would help.

Released in v1.1.36: https://github.com/mw00/project-maya/releases/tag/v1.1.36

<!-- gh-comment-id:6480778545 --> @mw00 commented on GitHub (Oct 28, 2026): Thank you @NenadSteric. v1.1.36 now logs the whole body of a malformed tool call (it was cut at 80 characters), which is what we needed to see what the model wrote at the cut. The part where the thinking budget closes the reasoning mid-sentence is still open; with the full body in the log it can be tackled next. If you can send one of those logged bodies, it would help. Released in **v1.1.36**: https://github.com/mw00/project-maya/releases/tag/v1.1.36
Sign in to join this conversation.
No labels
pull-request
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
mw00/project-maya#254
No description provided.