Skip to content

fix(parsing): guard response.output None in parse_response#3431

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

fix(parsing): guard response.output None in parse_response#3431
Shriniwas410 wants to merge 1 commit into
openai:mainfrom
Shriniwas410:fix/parse-response-null-output-1782238422

Conversation

@Shriniwas410

Copy link
Copy Markdown

parse_response() iterates response.output directly without a None check. The Codex backend (chatgpt.com) sometimes sends response.output: null in the response.completed event even when valid output items were streamed earlier, causing TypeError: 'NoneType' object is not iterable inside the stream accumulator.

Replacing for output in response.output with for output in (response.output or []) matches the existing null-safety pattern used elsewhere in the SDK and prevents the crash without changing behavior when output is non-null.

Fixes #3325

@Shriniwas410 Shriniwas410 requested a review from a team as a code owner June 23, 2026 18:13

@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: 1eb8476f27

ℹ️ 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 completion omits it

When a streamed response.completed event has response.output == None, this fallback parses an empty list even though ResponseStreamState has already accumulated the real output from prior response.output_item.added and delta events. In that backend case, get_final_response() and the emitted response.completed.response no longer crash, but they silently return output=[], so output_text, parsed text, and tool calls are lost despite having been streamed successfully.

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