Skip to content

fix: handle null response.output in parse_response#3349

Open
gavin913-lss wants to merge 1 commit into
openai:mainfrom
gavin913-lss:fix/parse-response-null-output
Open

fix: handle null response.output in parse_response#3349
gavin913-lss wants to merge 1 commit into
openai:mainfrom
gavin913-lss:fix/parse-response-null-output

Conversation

@gavin913-lss
Copy link
Copy Markdown

What breaks

parse_response() in src/openai/lib/_parsing/_responses.py crashes with TypeError when response.output is None.

The chatgpt.com Codex backend (https://chatgpt.com/backend-api/codex) sometimes sends response.output: null in the consolidated response.completed event — even when valid response.output_item.done events were streamed earlier. The SDK then raises TypeError: 'NoneType' object is not iterable inside parse_response().

Fixes #3325

Root cause

Line 61 does for output in response.output: without checking for None. When the Codex backend sends response.output: null, iterating over None crashes.

Fix

Add a fallback to empty list when response.output is None:

for output in response.output or []:

This is safe because:

  • If response.output is a valid list, it iterates normally
  • If response.output is None, it iterates over nothing (no output items to parse)
  • The earlier streamed events already populated the output items, so the final consolidated event having null output is a no-op

The chatgpt.com Codex backend sometimes sends response.output: null in
the consolidated response.completed event. The previous code iterated
response.output without checking for None, causing TypeError.

Add a fallback to empty list when response.output is None.

Fixes openai#3325
@gavin913-lss gavin913-lss requested a review from a team as a code owner June 1, 2026 14:35
Copy link
Copy Markdown

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

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: dadb254510

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

output_list: List[ParsedResponseOutputItem[TextFormatT]] = []

for output in response.output:
for output in response.output or []:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve streamed output when final payload omits it

When the streaming response.completed event has event.response.output == None (the scenario described by this fix), this fallback makes parse_response() build a final ParsedResponse with output=[]. In the streaming path, ResponseStreamState.accumulate_event() calls parse_response(response=event.response) for response.completed instead of parsing the accumulated snapshot, so get_final_response() and the emitted completed event lose all output items/text/tool calls that arrived via earlier response.output_item.added and delta events. This avoids the crash but turns valid streamed responses into empty final responses; the fallback should preserve the accumulated snapshot or otherwise not replace missing final output with an empty list.

Useful? React with 👍 / 👎.

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.

parse_response crashes with TypeError when response.output is null in response.completed event (chatgpt.com Codex backend)

1 participant