fix: useChat status stays ready during stream resumption#999
Open
threepointone wants to merge 1 commit intomainfrom
Open
fix: useChat status stays ready during stream resumption#999threepointone wants to merge 1 commit intomainfrom
threepointone wants to merge 1 commit intomainfrom
Conversation
🦋 Changeset detectedLatest commit: 51d8c4e 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 |
commit: |
This was referenced Feb 26, 2026
d8d2301 to
ebf0252
Compare
Implement WebSocketChatTransport.reconnectToStream() to return a proper ReadableStream for resumed streams, and forward the resume option to useChat. This lets the AI SDK's pipeline process resumed chunks natively, correctly managing status, isLoading, and abort during stream resumption. - reconnectToStream sends RESUME_REQUEST, waits for RESUMING, sends ACK, returns ReadableStream fed by replayed + live chunks - 100ms delayed explicit request avoids double-RESUMING race with onConnect - onAgentMessage guards with localRequestIdsRef to skip transport-handled chunks - Removed duplicate RESUME_REQUEST from useEffect (transport owns it now) - Updated test to verify progressive chunk processing
ebf0252 to
51d8c4e
Compare
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.
Problem
useChat'sstatusstayed"ready"during stream resumption after a page refresh. This meantisLoadingwas false and no abort button or thinking indicator appeared during resume.The root cause: resumed stream chunks flowed through
onAgentMessage→setMessagesdirectly, bypassing the AI SDK's transport pipeline. SinceuseChatnever saw the chunks, it never transitionedstatusto"streaming".Fix
WebSocketChatTransport.reconnectToStream()now returns a properReadableStream<UIMessageChunk>for resumed streams:CF_AGENT_STREAM_RESUMINGCF_AGENT_STREAM_RESUME_REQUEST(100ms delayed to avoid double-RESUMING race withonConnect)ReadableStreamfed by replayed + live chunksnull(no active stream)useAgentChatchanges:resumeoption touseChatso it callstransport.reconnectToStream()onAgentMessagewithlocalRequestIdsRefto skip chunks already handled by the transportCF_AGENT_STREAM_RESUME_REQUESTfromuseEffect(transport owns it now)Testing
npm run checkpasses (typecheck + lint + format across 44 projects)