Repository navigation
Chat: the turn definition writes stream chunks in batches again, at once at tool events and pauses - #3357
Merged
Conversation
|
| Name | Type |
|---|---|
| agents | Patch |
| @cloudflare/ai-chat | Patch |
| @cloudflare/think | Patch |
| @cloudflare/agent-think | Patch |
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
agents
@cloudflare/ai-chat
@cloudflare/codemode
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
Contributor
|
✅ agents import sizes: no significant changes ( |
… event, a part's first delta, a step's end and when the model pauses; a tool cut off after only progress is reported interrupted
…again has its first delta written at once; tests that fail without each flush; a changeset line for the progress fix (rv-1, Devin)
mattzcarey
force-pushed
the
slim/chat-fn-batch
branch
from
November 27, 2026 03:37
a159d3c to
7a0958c
Compare
mattzcarey
added a commit
that referenced
this pull request
Nov 27, 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.
Since H2 (#3295), ThinkHarness's turns run through
chatTurnDefinition, which writes each stream chunk as its own row write. The release batched them. This puts the batching back in the definition, as the hosts' reply streams do: 10 chunks or 512 KB per write, into the stream's newest block while it stays under 256 KB.A batch is written at once when:
tool-input-available,tool-approval-request,tool-output-available/-error/-denied, but not progress);So a reset while a tool runs keeps the call. That's verify's F18 case: without the flush, the tool ran twice. A reset while the model is quiet keeps what it sent. A reader flushes first. A chunk over the capability's
maxChunkBytesgoes through the writer, which refuses it as before.It also fixes recovery taking a tool's progress for its result: a tool cut off after only progress output (
preliminary: true) is reported interrupted. This mattered on main too, since main stores progress.This is the batching part of #3298 (6d), split out per arch's ruling. The hunk is the same as on #3298 at 96c0d3f. The chat functions stay in #3298.
Streams.opennow marks a stream it creates as born in this isolate, so a new reply's buffered appends start at seq 0. Before, they reserved seqs as if an earlier isolate had buffered into it, which left a false hole at seq 0. A part id that comes back in a later step has its first delta written at once too.Tests (workers
chat-host, harness-think 142/142), each failing without the piece it names:chat-recovery.md: the release has this bug too).An oversized chunk is still refused.
Cost (statements / rows written per prompt, local workerd, perf's harness
probes/perf, a ThinkHarness on a Durable Object, the object's second prompt). Release is agents 0.34.0 and think 0.24.0, main is 9492a1a, head is this PR:hello(a short text reply)tool(one server tool)Statements are below the release in every row. Rows written are below it except the paced reply: 40 against 36, because a model that pauses between chunks is written at each pause, so a reset loses nothing it sent. Think's and AIChatAgent's own scenarios are unchanged; they don't run the definition yet.