Skip to content

fix: #2013 - correctly invoke controller.error during mid-stream closure and update tests accordingly - #2019

Open
justanotherbyte wants to merge 3 commits into
cloudflare:mainfrom
justanotherbyte:fix/2013-socket-close
Open

fix: #2013 - correctly invoke controller.error during mid-stream closure and update tests accordingly#2019
justanotherbyte wants to merge 3 commits into
cloudflare:mainfrom
justanotherbyte:fix/2013-socket-close

Conversation

@justanotherbyte

@justanotherbyte justanotherbyte commented Aug 3, 2026

Copy link
Copy Markdown

This PR aims to fix #2013 by correctly invoking controller.error during a websocket closure before receiving a done: true frame. This previously led to the AI SDK's useChat interpreting this as a normal completion.

Tests have also been updated accordingly.


Open in Devin Review

…tream closure and update tests accordingly
@changeset-bot

changeset-bot Bot commented Aug 3, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 76184b5

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

@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 2 potential issues.

View 3 additional findings in Devin Review.

Open in Devin Review

Comment on lines +436 to +440
finish(
() => controller.error(new Error("WebSocket closed mid-stream")),
false,
false
);

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.

🟡 Bug fix to a published package ships without a release note entry

The published chat transport package is changed to report dropped connections as failures (controller.error(...) at packages/agents/src/chat/ws-chat-transport.ts:437) without adding the required release-note file, so the fix will not be versioned or published.
Impact: Users won't receive the fix in a released version and the change won't appear in the changelog.

Repository rule: changesets are required for package bug fixes

AGENTS.md (Contributing → Changesets) states: "Changes to packages/ that affect the public API or fix bugs need a changeset". This PR modifies packages/agents/src/chat/ws-chat-transport.ts (a behavioural bug fix that also changes observable transport semantics for @cloudflare/ai-chat consumers) but .changeset/ contains no new entry for agents (existing files: flux-keyterms-array.md, fresh-types-agree.md, fuzzy-pandas-pay.md, neat-spans-nest.md, none added by this commit).

Prompt for agents
AGENTS.md requires a changeset for any bug fix in packages/. Add a new file under .changeset/ (e.g. via `pnpm exec changeset`) declaring a patch bump for the `agents` package, describing that a WebSocket close before the terminal done frame now errors the chat stream instead of closing it cleanly (fixes #2013).
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

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.

please add a changeset

Comment thread packages/agents/src/chat/ws-chat-transport.ts
@pkg-pr-new

pkg-pr-new Bot commented Aug 3, 2026

Copy link
Copy Markdown

Open in StackBlitz

agents

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

@cloudflare/ai-chat

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

@cloudflare/codemode

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

create-think

npm i https://pkg.pr.new/create-think@2019

hono-agents

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

@cloudflare/shell

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

@cloudflare/think

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

@cloudflare/voice

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

@cloudflare/worker-bundler

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

commit: 76184b5

justanotherbyte and others added 2 commits August 3, 2026 15:43
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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.

Socket close mid-stream is treated as a completed response

2 participants