fix(fetch): ignore SSE comment lines instead of ending the stream - #13187
Open
pacocartones wants to merge 1 commit into
Open
fix(fetch): ignore SSE comment lines instead of ending the stream#13187pacocartones wants to merge 1 commit into
pacocartones wants to merge 1 commit into
Conversation
parseSseLine treated a `: ping` keep-alive as done: true, which breaks out of the line loop in streamSse. When a server or proxy flushes that comment in the same chunk as the data events that follow, those events are left in the buffer and the trailing-buffer fallback cannot parse them, so the rest of the model response is silently dropped. Per the SSE spec any line starting with a colon is a comment and must be ignored, so return done: false for it and keep draining the buffer.
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.
Description
parseSseLinereturned{ done: true }for the: pingkeep-alive comment, andstreamSseuses that flag tobreakout of the loop that drains the line buffer.When a server or proxy flushes the comment in the same chunk as the
data:events that follow (common with TCP/TLS coalescing and gateways such as LiteLLM or nginx), those events stay in the buffer. If the stream ends at that point, the trailing-buffer fallback sees a value starting with\n, does not match thedata:prefix, and yields nothing — so the remainder of the model response is silently dropped, with no error and no log.Per the SSE spec, any line starting with a colon is a comment and must be ignored. This changes the branch to match any
:-prefixed line and return{ done: false }, so the buffer keeps draining.streamSseis the shared helper behind most providers (OpenAI, Anthropic, Deepseek, Moonshot, VertexAI, LlamaStack, Inception, SiliconFlow, HuggingFace, Cohere), so this affects any of them talking to a server that sends SSE comments.AI Code Review
@continue-reviewChecklist
Screen recording or screenshot
Not applicable — no user-facing UI change. The behaviour is covered by the unit test below.
Tests
Added
ignores SSE comment lines that share a chunk with data eventstopackages/fetch/src/stream.test.ts. It pushes a single chunk containing: pingfollowed by twodata:events anddata: [DONE].Before the fix the test fails with
expected [] to deeply equal [ { foo: 'bar' }, { baz: 42 } ]— the entire response is lost. After the fix both events are yielded.npx vitest runinpackages/fetch: 6 files, 83 tests passing.