Repository navigation
server: streamed reasoning_content equals the whole reply's, whitespace at either end stripped - #1743
Merged
Merged
Conversation
Owner
|
Thanks @jayleaton, a clean one. Rebased onto main with a changelog line; |
jayleaton
force-pushed
the
stream-reasoning-trailing-ws
branch
from
October 31, 2026 12:27
4ecefc3 to
b00fb77
Compare
…ce at either end stripped The whole reply strips its reasoning (pyStrip) while the stream sent it as decoded, so a thinking stream's joined reasoning deltas kept the newline before </think> (and any leading whitespace) the whole reply drops. The stream now sends the stripped reasoning: whitespace waits until more reasoning follows it, and is never sent when the block closes or the reply ends. Tests: a stream/whole equality case set in think_split_test.zig (leading, interior, trailing whitespace; a reply-written opener; a cut reply; whitespace-only reasoning) at five strides, and the WordPiece and loop-stop stream checks now compare exactly instead of trimming the stream's trailing whitespace. Nine frozen stream goldens recorded the old trailing whitespace and now match their non-streamed counterparts.
ashhart
force-pushed
the
stream-reasoning-trailing-ws
branch
from
October 31, 2026 15:48
b00fb77 to
ed032c9
Compare
Owner
|
Thank you @jayleaton. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes. |
ashhart
added a commit
that referenced
this pull request
Oct 31, 2026
Owner
|
Thanks @jayleaton! Streamed reasoning that equals the finished reply byte for byte is in 1.2.1: https://github.com/ashhart/TensorFold/releases/tag/v1.2.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
With thinking on, the same greedy request gave a
reasoning_contentthat differed by one trailing newline depending onstream. The whole replypyStrips the reasoning, but the stream sent it as decoded. The joined deltas therefore kept the\nbefore</think>, and any leading whitespace, which the whole reply drops. Content, tool calls, finish reason and usage were already equal.The stream now sends the same stripped reasoning (
chat.zig, the streamed think split):Only whitespace is ever held back. Every thinking split goes through this code: Qwen's
</think>(close token or written), a reply-written<think>, MiniMax<mm:think>, Gemma's thought channel and the WordPiece close./v1/responsesand Anthropic streams build on these deltas. Harmony with thinking off already matched.Found by LocalRouter's chat qualification, which compares stream and whole replies byte for byte. It has carried a named exception for this since v1.1.1 and still needed it in v1.1.4. No issue is open upstream.
Overlap: the one line this changes in
chat.zigis also edited by #1336 (recipient split). It merges by keeping #1336's split and wrapping itssplit.reasoninginreply_text.pyStripas here. No other open pull request conflicts with this one.Receipt
zig build native -Dcpu=apple_m1 -Dversion=1.0.0.acea3b52; candidate is4ecefc32.TensorFold/Qwen3.8-27B-MLX-4bitwith--drafter z-lab/Qwen3.8-27B-DFlash2, served with--context 32768 --prompt-cache-gib 4 --parallel 1.Stream against whole on the same server,
temperature0,seed7,max_tokens1024:reasoning_content\nchat_template_kwargs.enable_thinking: true\nThe candidate's streamed reasoning is byte-identical (
cmp) to main's whole reply, so only the stream changed.LocalRouter saw the same 1-byte difference on CUDA (GB10, v1.1.1 and v1.1.4 release binaries).
tools/bench_openai.py: n/a. The change holds only whitespace bytes of reasoning deltas and does nothing on the decode path.think_split_test.zigcovers leading, interior and trailing whitespace, a reply-written opener, a reply cut atmax_tokens, and whitespace-only reasoning (no field, no deltas). It runs at strides 1, 2, 3, half and 256, and fails on main (main streams"\n Plan\n\nstep two \n"where the whole reply has"Plan\n\nstep two").reasoning_contentdeltas. They now match their non-streamed counterparts (stops/*,tools/bad_tool*,tools/xml_tool*,responses/tools-stream); only reasoning deltas changed.zig fmt --checkon the touched files passes.python3 tools/zig/lean_check.pyreports 424 on main and on this branch, so it adds nothing.zig build test/test-golden, which this pull request's CI runs: I don't run the zig suites on the machines I use.Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (Unchanged: tokens and content are identical; drafts were on in the receipt.)