Skip to content

Preserve tool-reply prose in whole responses and warm histories - #650

Merged
ashhart merged 1 commit into
ashhart:mainfrom
akol1:fix/tool-reply-prose
Oct 12, 2026
Merged

ashhart merged 1 commit into
ashhart:mainfrom
akol1:fix/tool-reply-prose

Conversation

@akol1

@akol1 akol1 commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Problem

Whole OpenAI chat-completion replies replace message content with null whenever tool calls are present, discarding accompanying prose. The background warm-history message does the same, including after an otherwise correct streamed reply.

Change

Keep nonempty parsed prose alongside tool calls in both message construction sites; retain null content for tool-only replies. Reuse the existing parsed result without another parse or allocation. Responses and Messages already consume the shared message content and need no production changes.

Regression coverage uses the existing socketpair route harness: prose before/after a legacy tool call, one call with unchanged arguments, returned call ID retained once in background prompts, whole chat/Messages/Responses, legacy SSE, and one-call policy/tool-only boundaries.

Verification

Base: a6aa4782 (upstream main). Zig 0.17.0, macOS arm64.

  • zig build test test-golden native -Dcpu=apple_m1: passed after correcting a test comment annotation.
  • Golden corpus: 309/319 equal, 10 existing known differences, 0 unexpected differences; frozen answers unchanged.
  • Actual HTTP smoke with the existing deterministic server fixture: pinned baseline returned content: null; candidate returned I will look it up. alongside the same single lookup call and arguments. Candidate SSE retained the same prose and single call.
  • Lean checker: 542 inherited findings at the pinned base and candidate; zero added findings.

Limits and publication scope

The HTTP driver is a deterministic engine, not a model-quality benchmark. Three files; production fix is two conditions. No parser/template/DSML/model change, checkpoint fixture, generated binary, or local runtime artifact. Public noreply commit identity; publication trees and outgoing metadata checked for private markers.

@ashhart
ashhart merged commit 463345f into ashhart:main Oct 12, 2026
2 checks passed
@ashhart

ashhart commented Oct 12, 2026

Copy link
Copy Markdown
Owner

Thank you, @akol1. This landed in 1.0.8 as your own commit (fe84f60d1), rebased onto our 1.0.8 work; the only conflict was the CHANGELOG (GitHub's "conflicting" was the same line). Your head commit is merged into the history unchanged (463345f3a), so GitHub shows this PR as merged.

We served it with Nemotron 3.5 Lightning (MLX 4-bit) on an M5 Max, against the same tree without your three PRs. Nemotron only calls tools here with thinking on (on /v1/messages we enabled it with thinking.budget_tokens), and two of our seven weather asks wrote a sentence after the reasoning and before the call:

ask before with this PR
"...tell me in a sentence which city you are checking. Then get the weather for Oslo." chat content: null, Responses [reasoning, function_call], Messages [thinking, tool_use] chat "I am checking the weather for Oslo.", Responses [reasoning, message, function_call], Messages [thinking, text, tool_use]
a system rule to say what you'll do first, then "Weather in Madrid?" the same three "I will now get the current weather for Madrid." in all three

The streamed chat sent those sentences before and after, so whole and streamed replies now agree. The four asks that called with no prose still answer content: null, as before. Every reply was the same tokens on both builds, and drafted, "draft": false and streamed agreed on all 14 chat replies; 17/17 release prompts and 12/12 conversation turns also gave the same tokens.

The warm-history half acts on engines that prefill the next turn in the background, which today is Qwen3.8-27B with its prompt cache on. There (M5 Max, thinking off), a streamed reply wrote "I'll check the current weather in Copenhagen for you." and one call, and the next turn as a streaming client sends it back (the joined prose, the call, a tool result) resumed 346 of its 369 prompt tokens, against 341 before, with the same 16-token reply as a server with the prompt cache off. The gap is small because the 27B already keeps a finished reply's own state, which took the old build to the end of the reply. Its background prefill, though, rendered the turn without the prose, so it never matched a streaming client's history; now it does, and adds the turn's close and the tool turn's opening.

One effect worth knowing: a stored /v1/responses reply now keeps the prose too, so a follow-up through previous_response_id sees the sentence the model wrote, as a streamed one already did.

Keeping it to the two conditions and reusing the parsed result made this a quick one to review.

BobClawblaw pushed a commit to BobClawblaw/TensorFold that referenced this pull request Oct 12, 2026
@ashhart ashhart mentioned this pull request Oct 14, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
The change landed rebased onto the 1.0.8 candidate as 869a3f92b with its author kept; this keeps the PR's head in the history with no change to the tree.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
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.

2 participants