You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SSE stream drops the final event (finish_reason / response.completed lost) when the server omits the trailing blank line #2725
When an SSE stream ends right after the final data: line (without the trailing blank line \n\n), the final event is silently dropped. For the Responses API this event is usually response.completed, so downstream strict clients see the stream end with no terminal event and raise "OpenAI Responses stream ended before a terminal response event", then retry.
Reproduced on openai-node 6.40.0 and still present on 7.15.0 (Node v22).
Repro
A local HTTP server returns a text/event-stream body for a chat.completions streaming call, in three variants:
A final event ends with a trailing blank line \n\n (conformant)
Result: A reports finish_reason; B and C never do (1 chunk instead of 2), with no error raised.
Root cause
core/streaming.mjs -> streamSSE(): SSEDecoder.decode(line) only emits a parsed event when it sees an empty line; iterSSEChunks() yields the leftover bytes at EOF, but the decoder is never flushed, so a trailing unterminated event is discarded.
Proposed fix (verified on 6.40.0 and 7.15.0)
After the lineDecoder.flush() loop in streamSSE(), flush any pending event:
constsse=sseDecoder.decode("");if(sse)yieldsse;
Verified against conformant, multi-event, and comment-trailing streams: no regression; the trailing event is now delivered.
Impact
Any gateway/proxy that closes the connection immediately after the final data: line (a common server race, especially under load) triggers this. The symptom is intermittent and load-dependent, so it reads as network flakiness.
Activity
fix(streaming): emit terminal SSE events missing a trailing blank line (