Skip to content

Surface an untyped Responses error frame instead of skipping it - #8650

Merged
danielhanchen merged 5 commits into
mainfrom
fix-untyped-responses-error
Aug 13, 2026
Merged

danielhanchen merged 5 commits into
mainfrom
fix-untyped-responses-error

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

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 no type and no SSE event: name either, so it took the same path. Measured on main:

CHUNKS: 0
MENTIONS RATE LIMIT: False

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_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, 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.

danielhanchen and others added 2 commits August 13, 2026 07:03
#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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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)):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

danielhanchen and others added 2 commits August 13, 2026 07:55
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.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 4d0d2960b9

ℹ️ 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".

@danielhanchen
danielhanchen merged commit ab9f23b into main Aug 13, 2026
42 of 44 checks passed
@danielhanchen
danielhanchen deleted the fix-untyped-responses-error branch August 13, 2026 09:32
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.

1 participant