Skip to content

fix: handle mid-stream error events in OpenAI SSE streaming#8027

Closed
dale-lakes wants to merge 1 commit intoblock:mainfrom
dale-lakes:fix/handle-sse-error-events
Closed

fix: handle mid-stream error events in OpenAI SSE streaming#8027
dale-lakes wants to merge 1 commit intoblock:mainfrom
dale-lakes:fix/handle-sse-error-events

Conversation

@dale-lakes
Copy link
Copy Markdown
Contributor

Summary

  • Check for error key in SSE data events before deserializing as StreamingChunk
  • Return a clear error message instead of crashing with "Stream decode error"

Problem

When an OpenAI-compatible server sends a mid-stream error like {"error": {"message": "Internal server error", ...}}, response_to_streaming_message tries to deserialize it as a StreamingChunk and fails because there's no choices field. This propagates as ProviderError::RequestFailed("Stream decode error: error decoding response body"), killing the session.

This error format is used by vLLM, SGLang, Exo, and OpenAI itself. The official OpenAI Python client handles it by checking data.get("error") before deserialization.

Fix

Added parse_streaming_chunk() that checks for an error key in the JSON before attempting StreamingChunk deserialization. Applied to both deserialization sites in response_to_streaming_message.

Closes #8021

When an OpenAI-compatible server sends an error object mid-stream
(e.g. {"error": {"message": "..."}}) the deserializer would fail
trying to parse it as a StreamingChunk, crashing with "Stream decode
error". This format is used by vLLM, SGLang, Exo, and OpenAI itself.

Check for an error key before attempting StreamingChunk deserialization,
matching the pattern used by the official OpenAI Python client.

Closes block#8021

Signed-off-by: Clyde <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@DOsinga
Copy link
Copy Markdown
Collaborator

DOsinga commented Mar 20, 2026

thanks @spitfire55 - in order to merge faster, we just push to branches these days. since yours is on a branch, I'll continue on #8301 and will close this

@DOsinga DOsinga closed this Mar 20, 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.

OpenAI provider crashes on mid-stream error events from local inference servers

2 participants