fix(think): wrap stream-resume ACK fallback in sendIfOpen#1463
Merged
whoiskatrin merged 1 commit intomainfrom May 5, 2026
Merged
fix(think): wrap stream-resume ACK fallback in sendIfOpen#1463whoiskatrin merged 1 commit intomainfrom
whoiskatrin merged 1 commit intomainfrom
Conversation
Mirror the sendIfOpen pattern that ai-chat already uses for the stream-resume ACK fallback. Without this, when the WebSocket closes during ResumableStream.replayCompletedChunksByRequestId the method now returns false (since #1376), and the fallback bare connection.send() in _handleStreamResumeAck throws TypeError: WebSocket send() after close up through onMessage.
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
🦋 Changeset detectedLatest commit: 0c5e260 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
agents
@cloudflare/ai-chat
@cloudflare/codemode
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
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.
Summary
Follow-up to #1376. That PR hardened
agents/chatand@cloudflare/ai-chatagainst the closed-WebSocket replay race but intentionally left@cloudflare/thinkfor a separate PR. This is that PR.ResumableStream.replayCompletedChunksByRequestIdnow returnsfalseboth when no completed stream is found and when asendIfOpencall fails because the socket closed mid-replay. The matching fallback inpackages/ai-chat/src/index.tswas updated to usesendIfOpen, but the identical pattern inpackages/think/src/think.ts:_handleStreamResumeAckstill used a bareconnection.send()— so on the close-mid-replay path it would throwTypeError: WebSocket send() after closeup throughonMessage, which is exactly the failure mode #1376 set out to prevent.This PR mirrors the
sendIfOpenhelper from@cloudflare/ai-chatinto@cloudflare/thinkand routes the fallbackdone: truesend through it.Review & Testing Checklist for Human
sendIfOpen/isWebSocketClosedSendErrorintothink.tsis preferred over exporting a shared helper fromagents/chat(the same duplication already exists in@cloudflare/ai-chatandagents/chat/resumable-stream.ts).@cloudflare/thinkpatch — matches the release process you'd expect for this kind of resilience fix.Notes
sendIfOpenonly swallowsTypeError: "WebSocket send() after close"and re-throws everything else.npm run check,npm run lint, andnpx nx run @cloudflare/think:test(289 tests) all pass.Link to Devin session: https://app.devin.ai/sessions/303193c332f24e08b4c8525adb58e285
Requested by: @whoiskatrin