Repository navigation
fix(examples): stream all of a Pi message's text in Channels - #2519
Merged
Merged
Conversation
The Channels example's Pi adapter emitted text chunks only for text and thinking start and delta changes. pi-durable builds its agent events from commits, so text can also arrive in the message_start partial, in a whole block or message change, or only in the saved entry at message_end. The adapter dropped all four, so a response's chunks could miss the start, the end, or all of an answer. The web UI hid this by repainting from the saved message when the turn settled, but a channel that reads only chunks lost the text. RunChunks now counts the characters it has emitted for each content block and emits the missing suffix from every fuller copy of the text: the message_start partial, block and message changes, and the saved entry before the message's parts close. This relies on pi only appending to a block's text, which holds for the live partial and the entry it saves. Fixes #2518
|
ghostwriternr
marked this pull request as ready for review
October 7, 2026 12:01
Contributor
|
✅ agents import sizes: no significant changes ( |
agents
@cloudflare/ai-chat
@cloudflare/codemode
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
cjol
approved these changes
Oct 9, 2026
cjol
left a comment
Member
There was a problem hiding this comment.
I think this adapter will change shortly in another PR but worth getting the fix in the base
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.
Fixes #2518.
The Channels example's Pi adapter (
examples/next/channels/src/pi/channels-harness.ts) emitted text chunks only fortext_start,thinking_start,text_deltaandthinking_deltachanges. pi-durable builds its agent events from commits, so one event can carry several model updates, and text also arrives in themessage_startpartial, in wholeblockandmessagechanges, and only in the saved entry atmessage_end. The adapter dropped text in all four places, so a response's chunks could miss the start, the end, or all of an answer. The web UI hid this by repainting from the saved message when the turn settled, but a channel that reads only chunks, such as one that speaks them, lost the text.RunChunksnow counts the characters it has emitted for each content block and emits the missing suffix from every fuller copy of the text: themessage_startpartial,blockandmessagechanges, and the saved entry before the message's parts close. Every existing delta path goes through the same counter, so text is never emitted twice. This relies on pi only appending to a block's text, which holds for the live partial and the entry it saves.The example has no test setup, so there are no automated tests here.