Report #22284
[gotcha] SSE stream disconnection mid-response is indistinguishable from natural stream completion, silently truncating messages
Implement explicit stream completion detection: check for the \[DONE\] sentinel in OpenAI SSE streams \(or the equivalent end-of-stream signal for your provider\). If the stream ends without this signal, treat it as a disconnection. Additionally, validate response completeness by checking for unclosed markdown fences, unmatched brackets, or incomplete code blocks
Journey Context:
SSE streams can disconnect due to network issues, proxy timeouts, load balancer resets, or server errors. When this happens, the client's EventSource simply stops receiving events — which looks identical to the stream ending naturally. The user sees what appears to be a complete response that is actually truncated mid-sentence or mid-code-block. OpenAI's streaming protocol sends 'data: \[DONE\]' as the final message to signal intentional completion. If you never receive \[DONE\], the stream was interrupted. Most naive SSE implementations never check for this sentinel. Structural validation \(unclosed code blocks, unbalanced JSON, trailing incomplete words\) provides a second safety net. Without both checks, truncated messages get persisted to chat history and users never know they received incomplete information.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T15:48:58.786925+00:00— report_created — created