Skip to content

fix(examples): stream all of a Pi message's text in Channels - #2519

Merged
cjol merged 1 commit into
mainfrom
fix/channels-pi-streamed-text
Oct 9, 2026
Merged

cjol merged 1 commit into
mainfrom
fix/channels-pi-streamed-text

Conversation

@ghostwriternr

Copy link
Copy Markdown
Member

Fixes #2518.

The Channels example's Pi adapter (examples/next/channels/src/pi/channels-harness.ts) emitted text chunks only for text_start, thinking_start, text_delta and thinking_delta changes. pi-durable builds its agent events from commits, so one event can carry several model updates, and text also arrives in the message_start partial, in whole block and message changes, and only in the saved entry at message_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.

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. 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.

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
@changeset-bot

changeset-bot Bot commented Oct 7, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 298cafc

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

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

@ghostwriternr
ghostwriternr marked this pull request as ready for review October 7, 2026 12:01
@agent-think

agent-think Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

✅ agents import sizes: no significant changes (66ae9558 → 298cafc0, workflow run)

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

Devin Review

Comment thread examples/next/channels/src/pi/channels-harness.ts
@pkg-pr-new

pkg-pr-new Bot commented Oct 7, 2026

Copy link
Copy Markdown

Open in StackBlitz

agents

npm i https://pkg.pr.new/agents@2519

@cloudflare/ai-chat

npm i https://pkg.pr.new/@cloudflare/ai-chat@2519

@cloudflare/codemode

npm i https://pkg.pr.new/@cloudflare/codemode@2519

hono-agents

npm i https://pkg.pr.new/hono-agents@2519

@cloudflare/shell

npm i https://pkg.pr.new/@cloudflare/shell@2519

@cloudflare/think

npm i https://pkg.pr.new/@cloudflare/think@2519

@cloudflare/voice

npm i https://pkg.pr.new/@cloudflare/voice@2519

@cloudflare/worker-bundler

npm i https://pkg.pr.new/@cloudflare/worker-bundler@2519

commit: 298cafc

@cjol cjol left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this adapter will change shortly in another PR but worth getting the fix in the base

@cjol
cjol merged commit ae95bb9 into main Oct 9, 2026
8 checks passed
@cjol
cjol deleted the fix/channels-pi-streamed-text branch October 9, 2026 11:33
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.

Channels Pi example: response chunks are missing text that the saved message has

2 participants