Skip to content

Server: tool calls completed just before the thinking close are returned when no answer follows (#2310) - #2313

Merged
ashhart merged 2 commits into
mainfrom
lead/tool-call-before-close
Nov 6, 2026
Merged

ashhart merged 2 commits into
mainfrom
lead/tool-call-before-close

Conversation

@ashhart

@ashhart ashhart commented Nov 6, 2026

Copy link
Copy Markdown
Owner

Fixes #2310, reported by @AdrianBinDC.

#60 handled a reply that ends inside a think block that never closes, moving a complete tool call there into the answer. But when the call was followed by the think-close token, splitThinkingAt (zig/src/server/reply_text.zig) put everything before the close into reasoning. Tools are parsed only from the answer, so the client got the call's markup in reasoning_content, empty content and no tool_calls. That was seen on Nemotron 3.5 Lightning with thinking on.

  • The fix: at the close, if the answer after it is empty or whitespace, and the reasoning ends with complete tool calls in the model's own format, those trailing calls become the answer (reply_tool_tail.zig).
  • What stays reasoning: a call followed by more reasoning text, or by a non-empty answer. A call the reasoning only mentions isn't made.
  • Streaming: after the close, the trailing calls are held while the answer is still empty, and released only when the reply finishes, so no delta has to be taken back. Whole and streamed replies give the same tool_calls, content and reasoning.
  • MiniMax: the all-format tests found an existing boundary error. Rewriting its complete tool blocks into DSML before the split moved a later close token's byte offset, so the close could show as content. tool_minimax.closeAfterRewrite now maps the offset after the rewrite.

Tests (zig build test-thinking-tail-host):

  • the reporter's shape;
  • a call, the close, then an answer;
  • a mention in the middle of reasoning;
  • two calls before the close;
  • each call format our templates use, whole and streamed.

Checks:

  • with test-server-cpu and test-golden: 13 of 13 steps, 1,161 tests passed and 5 skipped;
  • a plain zig build: 255 of 255;
  • zig fmt --check;
  • no new lean finding.

Keep completed call envelopes at the thinking boundary pending until an empty answer is final. Preserve calls followed by more reasoning or an answer, and remap MiniMax close-token offsets after its existing markup rewrite.

Fixes #2310
@ashhart
ashhart force-pushed the lead/tool-call-before-close branch from 3fde911 to 5888351 Compare November 6, 2026 15:11
@ashhart
ashhart merged commit 5daafaf into main Nov 6, 2026
8 of 11 checks passed
@ashhart

ashhart commented Nov 7, 2026

Copy link
Copy Markdown
Owner Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Finished tool call before a later </think> stays in reasoning_content

1 participant