Fix #1466: Resumable Streams#1486
Open
JiwaniZakir wants to merge 1 commit intovercel:mainfrom
Open
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
|
@JiwaniZakir is attempting to deploy a commit to the Templates Test vtest314 Team on Vercel. A member of the Team first needs to authorize it. |
Comment on lines
+103
to
+110
| const emptyStream = new ReadableStream({ | ||
| start(controller) { | ||
| controller.close(); | ||
| }, | ||
| }); | ||
|
|
||
| return new Response( | ||
| await streamContext.resumeExistingStream(recentStreamId, emptyStream), |
Contributor
There was a problem hiding this comment.
Suggested change
| const emptyStream = new ReadableStream({ | |
| start(controller) { | |
| controller.close(); | |
| }, | |
| }); | |
| return new Response( | |
| await streamContext.resumeExistingStream(recentStreamId, emptyStream), | |
| return new Response( | |
| await streamContext.resumeExistingStream(recentStreamId), |
resumeExistingStream is called with a ReadableStream as the second argument where a number (skipCharacters) is expected, causing the stream to be coerced to NaN.
Author
|
— passing |
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.
Closes #1466
Before
When a user reloaded mid-stream, the browser called
GET /api/chat?chatId=...to resume the stream. That route did not exist — the fileapp/(chat)/api/chat/route.tsonly exported aPOSThandler. The missing route caused the request to fall through with a204 No Contentresponse, leaving the UI in a broken loading state with no stream data replayed.After
GET /api/chatis now implemented and handles stream resumption end-to-end:400ifchatIdis absent from query params.401if the request is unauthenticated.403if the authenticated user does not own the chat.204if no chat, no stream context, or no recorded stream IDs are found (graceful no-op).getStreamIdsByChatId({ chatId }), callsstreamContext.resumeExistingStream(recentStreamId, emptyStream), and returns the result as atext/event-streamresponse with status200.Changes
app/(chat)/api/chat/route.ts: AddedGETexport implementing the resumable stream logic described above. AddedgetStreamIdsByChatIdto the import list from the DB layer. AnemptyStream(ReadableStreamthat closes immediately) is passed as the fallback toresumeExistingStreamso the response is well-formed even when the original stream has already ended.tests/e2e/api.test.ts: Added a"Resumable Streams"test suite with two unauthenticated cases —GET /api/chatwith nochatIdexpects400, andGET /api/chat?chatId=nonexistentwithout a session expects401— covering the input validation and auth guard paths.Testing
E2E tests added in
tests/e2e/api.test.tsverify the error paths directly against the running server:Manual verification: reloading the page mid-stream now replays buffered SSE events rather than rendering the broken empty-state shown in the issue screenshot.
This PR was created with AI assistance (Claude). The changes were reviewed by quality gates and a critic model before submission.