Skip to content

server: the next turn's background prefill carries the reply's reasoning - #3264

Merged
ashhart merged 4 commits into
mainfrom
lead/warm-reasoning
Nov 19, 2026
Merged

ashhart merged 4 commits into
mainfrom
lead/warm-reasoning

Conversation

@ashhart

@ashhart ashhart commented Nov 13, 2026

Copy link
Copy Markdown
Owner

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.reply takes the reply's reasoning. When the client sends reasoning back, it puts the reasoning into its own copy of the reply as reasoning_content. "Sends it back" is warm.echoesReasoning: the latest assistant message in the request has reasoning_content, or there is no assistant message yet.
  • A client whose history has no reasoning gets the old guess, so clients that drop reasoning lose nothing.
  • The copy handed to cortheon's remember is unchanged.
  • openai.zig changes by one line; the rest is in warm.zig.

How it was found, on an M5 Ultra with Qwen3.8-Flash-Next serving omp:

  • In one omp session, requests waited 40.8 s in total behind background passes. In a logged example, a background pass prefilled 72,517 to 82,381 in 2.3 s, then the real request waited 2,324 ms and prefilled 72,517 to 82,519 again.
  • A logging proxy showed omp sends each reply back byte for byte, reasoning and tool-call arguments included. Rendering the guess from omp's own request through /tokenize gives 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.zig checks 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, plus echoesReasoning on its own. It fails without the warm.reply change. zig build test-server-cpu and zig build -Dfixed-cpu test-golden pass, 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.

  • Synthena (Ash's Agent)

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
ashhart force-pushed the lead/warm-reasoning branch from d99b55e to 042f56b Compare November 19, 2026 22:41
@ashhart
ashhart merged commit 20dc018 into main Nov 19, 2026
1 of 10 checks passed
@ashhart
ashhart deleted the lead/warm-reasoning branch November 19, 2026 22:41
ashhart added a commit that referenced this pull request Nov 19, 2026
ashhart added a commit that referenced this pull request Nov 19, 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.

1 participant