Repository navigation
fix(ai): ignore bare null SSE frames - #50793
Merged
Merged
Conversation
Some OpenAI-compatible proxies serialize an empty flush as a bare `data: null` frame, between events or after [DONE]. The frame reached the protocol decoder, failed the event schema, and aborted the whole step with "Invalid <route> stream event". Drop it in the shared SSE framing next to the existing empty-frame filter. No protocol has a null event, so this is lossless for Chat, Responses, Anthropic Messages, and Gemini alike. Every other payload, including other non-object JSON and malformed objects, still reaches the decoder and fails loudly.
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 #50314
Problem
Some OpenAI-compatible proxies serialize an empty flush as a bare
data: nullSSE frame — mid-stream between real events, or trailing after[DONE]. This has been observed on both Chat Completions and Responses endpoints.sseFramingonly drops empty frames and[DONE], so"null"reaches the protocol decoder, fails the event schema (every protocol's event is a struct), and aborts the whole step:Change
packages/ai/src/protocols/shared.ts—sseFramingnow drops a frame whose data is exactlynull, beside the existing empty-frame filter.Framing.sse,sseWithDone,sseEvents) instead of patching each parser separately.nullonly. That is the only shape seen in the wild. Other non-object JSON (0,"null",[]) and malformed objects still reach the decoder and fail loudly with the offending frame attached, so a misconfigured endpoint is still diagnosed immediately.[DONE]; framing still never parses JSON.Tests
test/schema.test.ts—sseFramingdropsdata: null(plain, named-event, and after[DONE]) while keeping"null",0, and real payloads.test/provider/openai-compatible-chat.test.ts— null frames interleaved between Chat deltas produce the full text and a cleanstop.test/provider/openai-compatible-responses.test.ts— null frames interleaved between and after Responses events produce the full text and a finish.All three fail without the change and pass with it.
bun testinpackages/ai: 1436 pass, 0 fail.bun run check: 35/35.