Skip to content

fix(streaming): skip control-only SSE blocks with no data - #3839

Closed
lazerg wants to merge 1 commit into
openai:mainfrom
lazerg:fix/sse-control-only-blocks
Closed

fix(streaming): skip control-only SSE blocks with no data#3839
lazerg wants to merge 1 commit into
openai:mainfrom
lazerg:fix/sse-control-only-blocks

Conversation

@lazerg

@lazerg lazerg commented Sep 10, 2026

Copy link
Copy Markdown
  • I understand that this repository is auto-generated and my pull request may not be merged

Changes being requested

An SSE block carrying only retry: or id: has no data, but the blank-line guard in SSEDecoder.decode() also looked at _last_event_id and _retry, so it dispatched an event with empty data anyway. Stream.__stream__() runs every event through sse.json(), and that empty event ends an otherwise valid stream with a JSON decoding error before the next data event is read. _last_event_id is kept across events on purpose, so once a stream has sent an id: field, any later blank line hits the same path.

The guard now dispatches only when an event name or data is buffered. Both fields stay on the decoder, so the next real event still reports the current id and retry.

Additional context & links

Closes #3833

tests/test_streaming.py::test_control_only_blocks_are_skipped fails on main and passes with this change. The streaming and SSE framing suites pass, and ruff check and format are clean on both touched files.

@lazerg
lazerg requested a review from a team as a code owner September 10, 2026 02:28
@lazerg

lazerg commented Sep 10, 2026

Copy link
Copy Markdown
Author

Closing since the linked issue was closed. Happy to reopen if it turns out the fix is still wanted.

@lazerg lazerg closed this Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Streaming fails on SSE control-only events with empty data

1 participant