fix(httpclient): drop comment-only SSE events that crash openai-go#2662
Merged
dgageot merged 1 commit intodocker:mainfrom May 6, 2026
Merged
fix(httpclient): drop comment-only SSE events that crash openai-go#2662dgageot merged 1 commit intodocker:mainfrom
dgageot merged 1 commit intodocker:mainfrom
Conversation
Some upstreams (notably OpenRouter) inject SSE comment frames as keep-alives. The OpenAI Go SDK's stream parser treats the trailing blank line as an event boundary and then JSON-unmarshals the empty payload, which fails with 'unexpected end of JSON input' and tears down the whole completion. Wrap the HTTP transport with a streaming pre-filter that, on responses whose Content-Type starts with text/event-stream (case-insensitive), drops events containing no 'data:' lines. Well-formed events pass through verbatim and non-SSE responses are untouched. Assisted-By: docker-agent
There was a problem hiding this comment.
Assessment: 🟢 APPROVE
The SSE comment-only event filter is well-implemented. The logic correctly identifies and drops events with no data: lines, handles CRLF normalization, propagates underlying reader errors, and the transport wrapping in client.go is clean. No bugs found in the changed code.
derekmisler
approved these changes
May 6, 2026
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.
Some upstreams (notably OpenRouter) inject SSE comment frames as keep-alives:
The OpenAI Go SDK's
ssestream.Streamcorrectly ignores comment lines but still treats the trailing blank line as an event boundary, then unconditionally JSON-unmarshals the resulting empty payload. That fails withunexpected end of JSON inputand tears down the whole completion.Fix
Wrap the HTTP transport with a streaming pre-filter that, on responses whose
Content-Typestarts withtext/event-stream(case-insensitive, charset parameters allowed), drops events containing nodata:lines. Well-formed events pass through verbatim and non-SSE responses are untouched.The filter:
data:payload sizes (32 MB scanner buffer, matching openai-go's own decoder);go test -race).Tests
pkg/httpclient/sse_filter_test.gocovers, among other things:event:/id:headers (also dropped);event:/id:when accompanied bydata:;Content-Typematching with charset parameter, mixed case, and uppercase (the case-insensitive matching is verified to actually catch a regression);Validation
go build ./...✅go test ./pkg/httpclient/... -race -count=1✅mise lint✅ (golangci-lint and the project's custom linter)Assisted-By: docker-agent