Skip to content

fix(streams): re-poll after a live batch before waiting for a wakeup - #2458

Merged
cjol merged 1 commit into
mainfrom
channels/00-streams-wakeup
Oct 2, 2026
Merged

cjol merged 1 commit into
mainfrom
channels/00-streams-wakeup

Conversation

@cjol

@cjol cjol commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

This PR fixes a live Streams reader that could stall when chunks were appended while it was still handling the previous batch.

Why

  • readBatches yielded a short live batch, then waited for the next append. An append made while the consumer held that batch woke no waiter, so the reader stalled until a later append or the stream's end.
  • Channels hit this when a harness emitted text-start and text-delta back to back: the Slack surface stopped after the first chunk.

Code Changes

  • streams.ts re-polls after any non-empty batch before waiting. The poll that finds nothing and the waiter registration stay synchronous.
  • capability.test.ts appends while a consumer holds a batch and checks the reader still sees it.
  • Patch changeset for agents.

Devin Review

@changeset-bot

changeset-bot Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 85b92eb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
agents Patch
@cloudflare/agent-think Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@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: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@cjol
cjol added this pull request to stack #2460 October 2, 2026 17:39
@agent-think

agent-think Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

✅ agents import sizes: no significant changes (74570a19 → 85b92ebc, workflow run)

@pkg-pr-new

pkg-pr-new Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

agents

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

@cloudflare/ai-chat

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

@cloudflare/codemode

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

hono-agents

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

@cloudflare/shell

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

@cloudflare/think

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

@cloudflare/voice

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

@cloudflare/worker-bundler

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

commit: 85b92eb

This PR fixes a live `Streams` reader that could stall when chunks were appended while it was still handling the previous batch.

## Why

- `readBatches` yielded a short live batch, then waited for the next append. An append made while the consumer held that batch woke no waiter, so the reader stalled until a later append or the stream's end.
- Channels hit this when a harness emitted `text-start` and `text-delta` back to back: the Slack surface stopped after the first chunk.

## Code Changes

- `streams.ts` re-polls after any non-empty batch before waiting. The poll that finds nothing and the waiter registration stay synchronous.
- `capability.test.ts` appends while a consumer holds a batch and checks the reader still sees it.
- Patch changeset for `agents`.
@cjol
cjol force-pushed the channels/00-streams-wakeup branch from 1a45634 to 85b92eb Compare October 2, 2026 18:20
@cjol
cjol merged commit 6bf0378 into main Oct 2, 2026
16 checks passed
@cjol
cjol deleted the channels/00-streams-wakeup branch October 2, 2026 19:20
@github-actions github-actions Bot mentioned this pull request Oct 2, 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