Repository navigation
server: the next turn's background prefill carries the reply's reasoning - #3264
Merged
Merged
Conversation
ashhart
force-pushed
the
lead/warm-reasoning
branch
2 times, most recently
from
November 19, 2026 01:49
9f0f8e9 to
d99b55e
Compare
This was referenced Nov 19, 2026
After a chat reply the server prefills the next turn's shared prompt in the background. It built its copy of the reply from role, content and tool calls only, so with thinking on it left out the reasoning the client was sent. Agent clients such as omp send that reasoning back, and the checkpoint's template renders it, so the guess differed from the real next request at the reply's first reasoning token every time: the request then waited for the background pass and redid it from before the reply. warm.reply now takes the reply's reasoning and puts it into its own copy of the reply when the client sends reasoning back (warm.echoesReasoning: the latest assistant message has reasoning_content, or there is none). A client whose history has no reasoning gets the old guess. The copy handed to cortheon's remember is unchanged. warm_reasoning_test.zig: the first-turn guess carries the reasoning, an echoing client keeps getting it, a dropping client does not; it fails without the fix. test-server-cpu and test-golden pass; lean 0 new. Served on an M5 Ultra (Qwen3.8-Flash-Next, an omp tool loop): the next two requests resumed at 7,868 and 7,947, the background passes' ends, and prefilled only the new tool results (17 and 22 tokens), where before they restarted at 7,653, before the reply. Earlier in a real omp session requests had waited 40.8 s in total behind background passes they then redid.
echoesReasoning assumed a client echoes reasoning when its history has no assistant message yet. Our web and desktop clients drop reasoning_content, and Qwen3.8 renders an empty think block for them, so their first follow-up missed the background pass at its first token. Return false for that case and pin it in warm_reasoning_test.zig; later turns still follow what the history shows.
ashhart
force-pushed
the
lead/warm-reasoning
branch
from
November 19, 2026 22:41
d99b55e to
042f56b
Compare
ashhart
added a commit
that referenced
this pull request
Nov 19, 2026
ashhart
added a commit
that referenced
this pull request
Nov 19, 2026
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.
After a chat reply, the server prefills the next turn's shared prompt in the background (
warm.zig), so that turn resumes past the reply. Its copy of the reply had role, content and tool calls, but not the reasoning the client was sent. Agent clients such as omp send that reasoning back, and the checkpoint's template renders it, so with thinking on the guess differed from the real next request at the reply's first reasoning token, every time. The request then waited for the background pass to finish and redid the work from before the reply.warm.replytakes the reply's reasoning. When the client sends reasoning back, it puts the reasoning into its own copy of the reply asreasoning_content. "Sends it back" iswarm.echoesReasoning: the latest assistant message in the request hasreasoning_content, or there is no assistant message yet.rememberis unchanged.openai.zigchanges by one line; the rest is inwarm.zig.How it was found, on an M5 Ultra with Qwen3.8-Flash-Next serving omp:
/tokenizegives a prefix of the real prompt. The server's guess was 16 tokens shorter, the size of the reply's reasoning.With the fix, the same omp tool loop: the next two requests resumed at 7,868 and 7,947, the background passes' ends, and prefilled only the new tool results (17 and 22 tokens). Before, both restarted at 7,653, before the reply.
Tests:
warm_reasoning_test.zigchecks that a first turn's guess carries the reasoning, that a client that sends reasoning back keeps getting it, and that a client whose history dropped it does not, plusechoesReasoningon its own. It fails without thewarm.replychange.zig build test-server-cpuandzig build -Dfixed-cpu test-goldenpass, and lean has no new problems.Not changed: a background pass still yields to a waiting request only between prompt calls, which can be up to 16,384 rows. With the guess hitting, a request that waits now mostly waits for work it needs anyway, so call sizes are left alone until real sessions are measured.