Skip to content

Fix abort duplicate split messages#1106

Merged
threepointone merged 3 commits intomainfrom
fix-abort-duplicates
Mar 20, 2026
Merged

Fix abort duplicate split messages#1106
threepointone merged 3 commits intomainfrom
fix-abort-duplicates

Conversation

@threepointone
Copy link
Contributor

@threepointone threepointone commented Mar 13, 2026

fixes #1100

Prevent duplicate assistant messages when a user aborts a live stream by keeping the requestId marked active until the server sends done:true. WebSocketChatTransport.finish now accepts a keepId flag and onAbort retains the requestId so in-flight server chunks are skipped by the dedup guard. useAgentChat.onAgentMessage now removes the kept ID when it sees data.done to avoid a minor memory leak. Added a test to verify the requestId is preserved after abort and cleaned up after the server's done broadcast, and included a changeset entry.


Open with Devin

@changeset-bot
Copy link

changeset-bot bot commented Mar 13, 2026

🦋 Changeset detected

Latest commit: 842e9a0

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

This PR includes changesets to release 1 package
Name Type
@cloudflare/ai-chat 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

Copy link
Contributor

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

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 potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 13, 2026

Open in StackBlitz

agents

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

@cloudflare/ai-chat

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

@cloudflare/codemode

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

hono-agents

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

@cloudflare/shell

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

@cloudflare/think

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

@cloudflare/voice

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

@cloudflare/worker-bundler

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

commit: 842e9a0

Prevent duplicate assistant messages when a user aborts a live stream by keeping the requestId marked active until the server sends done:true. WebSocketChatTransport.finish now accepts a keepId flag and onAbort retains the requestId so in-flight server chunks are skipped by the dedup guard. useAgentChat.onAgentMessage now removes the kept ID when it sees data.done to avoid a minor memory leak. Added a test to verify the requestId is preserved after abort and cleaned up after the server's done broadcast, and included a changeset entry.
Add a waitFor helper in resumable-streaming.test.ts and replace fragile setTimeout-based waits with condition-based polling. The helper polls a condition until a timeout (default 2000ms, interval 50ms). This makes the test wait for the full ACK → DB flush → replay round-trip and for replayed chunks (e.g. delta "B") to appear, improving reliability and reducing flakiness without changing test behavior.
Extend waitFor to accept and await async conditions (boolean | Promise<boolean>), and replace multiple ad-hoc setTimeout sleeps in resumable-streaming.test.ts with explicit waitFor checks (e.g. message count conditions and agentStub.getActiveStreamId() === null). This makes the tests more deterministic by removing arbitrary delays.
@threepointone threepointone merged commit 3184282 into main Mar 20, 2026
2 checks passed
@threepointone threepointone deleted the fix-abort-duplicates branch March 20, 2026 13:26
@github-actions github-actions bot mentioned this pull request Mar 20, 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.

useAgentChat: abort/stop causes duplicate split assistant message (localRequestIdsRef race)

1 participant