fix(openai): capture ResponseFailed errors in stream mode - #1582
Conversation
Fixes 0xPlaygrounds#1562 When OpenAI returns an error during streaming (e.g. context_length_exceeded), the response chunk arrives as ResponseFailed but was silently ignored by the else branch, resulting in an empty FinalResponse with zero tokens. Replace the if-let with an explicit match on ResponseChunkKind: - ResponseCompleted: existing behavior (record span, extract usage) - ResponseFailed | ResponseIncomplete: extract response.error (code + message) and yield CompletionError::ProviderError, consistent with how SSE errors and the WebSocket implementation handle failures - Other variants: continue (no change)
|
I pushed a follow-up to keep the streaming path closer to the existing websocket implementation and to add regression coverage for the original bug in #1562. The core behavior change is the same: when the OpenAI Responses API ends a stream with I also refactored the streaming-side error formatting into small local helpers so the architecture matches websocket more closely:
I also removed the extra Finally, I added streaming regression tests using
I kept the scope local. Preserving structured provider errors ( |
Fixes #1562
When OpenAI returns an error during streaming (e.g.
context_length_exceeded), the response chunk arrives asResponseFailedbut was silently ignored by theelsebranch, resulting in an emptyFinalResponsewith zero tokens.This change replaces the
if-letwith an explicitmatchonResponseChunkKind:ResponseCompleted: existing behavior (record span, extract usage)ResponseFailed | ResponseIncomplete: extractresponse.error(code + message) and yieldCompletionError::ProviderError, consistent with how SSE errors and the WebSocket implementation handle failures