Repository navigation
Surface an untyped Responses error frame instead of skipping it - #8650
Conversation
#8608 made the Responses reader skip a frame it cannot type, which is right for the case it was written for: an OpenAI-compatible endpoint behind a Responses base URL answering with Chat Completions chunks. An error payload is the exception. The bare {"error": {...}} such a proxy emits mid-stream carries no type and no SSE event name either, so it took the same path, and the generation ended with zero chunks and nothing to explain it -- a blank answer where the endpoint had said "rate limited". Measured on main: 0 chunks returned, no mention of the error. Before the skip existed that frame raised, which was at least loud. This says what happened instead, through the same _error_sse_line the typed response.failed and error events already use. A frame with no type, no event name and no error key is still skipped.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d695149e84
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| # returned a blank answer and no error at all: the whole | ||
| # generation ended with zero chunks and nothing to explain it. | ||
| # Raising was at least loud; this says what happened. | ||
| if isinstance(event.get("error"), (dict, str)): |
There was a problem hiding this comment.
Guard non-object frames before reading the error field
If an endpoint emits a valid JSON but non-object SSE frame such as data: null or data: [], response_event_type raises ValueError, but this handler then calls event.get(...) and raises AttributeError. These unrecognizable frames were previously skipped as intended; the new error detection should first verify that event is a dictionary so such frames do not terminate the stream.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Right, and it undid the point of the skip. data: null and data: [] are valid JSON and not dicts, so response_event_type rejects them and the error check that followed called .get() on them, raising AttributeError and killing the stream. Fixed in b5d9a5f by checking the type first. Parametrised over null, [], a bare string and a number, and all four fail without the guard.
data: null and data: [] are valid JSON and not dicts. response_event_type rejects them, and the error check that followed then called .get() on them, which raised AttributeError and killed the stream -- the exact failure the skip exists to avoid. Guard on the type first.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Follow-up to #8608, found by re-checking that fix rather than assuming it.
#8608 made the Responses reader skip a frame it cannot type. That is right for the case it was written for: an OpenAI-compatible endpoint behind a Responses base URL answering with Chat Completions chunks. An error payload is the exception.
The bare
{"error": {...}}such a proxy emits mid-stream carries notypeand no SSEevent:name either, so it took the same path. Measured onmain:The generation ends with zero chunks and nothing to explain it, so the user sees a blank answer where the endpoint had said "rate limited". Before the skip existed the same frame raised
ValueError: Responses event type is missing, which was at least loud.This surfaces it through the same
_error_sse_linethe typedresponse.failedanderrorevents already use. A frame with no type, no event name and no error key is still skipped, which is the case #8608 exists for.Two tests, both of which fail without the change in the direction they pin: the error frame is surfaced, and a Chat Completions frame on the Responses path is still skipped without a 502.