Skip to content

fix: parse_response crashes on null output from Codex backend stream#3533

Open
thiagobarbosa wants to merge 4 commits into
openai:mainfrom
thiagobarbosa:fix/parse-response-on-null-output
Open

fix: parse_response crashes on null output from Codex backend stream#3533
thiagobarbosa wants to merge 4 commits into
openai:mainfrom
thiagobarbosa:fix/parse-response-on-null-output

Conversation

@thiagobarbosa

Copy link
Copy Markdown

Fix #3313

Fix a crash in parse_response when a Response from the Codex backend stream has a null (None) output field instead of a list.

Before this fix, any consumer receiving a Response with a null output (observed from the Codex backend stream) would hit a TypeError: 'NoneType' object is not iterable inside parse_response. The fix treats a missing/None output the same as an empty list, matching how other optional list fields are typically handled in this SDK.

  • src/openai/lib/_parsing/_responses.py: iterate over response.output or [] instead of response.output, so a None output no longer raises a TypeError and is treated as an empty output list. This file lives under src/openai/lib/, which per CONTRIBUTING.md is excluded from code generation, so it's safe to edit by hand.
  • tests/lib/responses/test_responses.py: add test_parse_response_handles_null_output, which constructs a Response with output=None and asserts parse_response(...) returns parsed.output == [] instead of raising.

Copilot AI review requested due to automatic review settings July 23, 2026 11:02
@thiagobarbosa
thiagobarbosa requested a review from a team as a code owner July 23, 2026 11:02

Copilot AI 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.

Pull request overview

Fixes a TypeError in parse_response() when the Codex backend stream returns a Response with output: null by treating None output as an empty list, and adds regression test coverage for that case.

Changes:

  • Guard parse_response() against response.output is None by iterating over response.output or [].
  • Add a unit test asserting output=None is parsed as [] without raising.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/openai/lib/_parsing/_responses.py Prevents iteration over None by defaulting missing/None output to an empty list.
tests/lib/responses/test_responses.py Adds a regression test to ensure parse_response() handles output=None and returns parsed.output == [].

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@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: 22b98e9963

ℹ️ 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 accumulated stream output on null completion

When this parser is used from the streaming path, response.completed is parsed from event.response while the actual output items have already been accumulated on the stream snapshot. If the backend sends output: null on the completion event after normal response.output_item.*/delta events, this fallback now returns a successful parsed response with output == []; get_final_response() and the wrapped completed event then lose all generated content instead of returning the accumulated response. Please have the stream completion path reuse the snapshot output when the completed response output is None.

Useful? React with 👍 / 👎.

Copilot AI review requested due to automatic review settings July 23, 2026 12:20

Copilot AI 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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread tests/lib/responses/test_responses.py Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 23, 2026 12:27

Copilot AI 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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread tests/lib/responses/test_responses.py
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 23, 2026 12:53

Copilot AI 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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread src/openai/lib/streaming/responses/_responses.py
Comment thread tests/lib/responses/test_responses.py
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 on null output from Codex backend stream

2 participants