Skip to content

Handle null response output during parsing - #3330

Closed
FU-max-boop wants to merge 3 commits into
openai:mainfrom
FU-max-boop:fix/parse-null-response-output
Closed

Handle null response output during parsing#3330
FU-max-boop wants to merge 3 commits into
openai:mainfrom
FU-max-boop:fix/parse-null-response-output

Conversation

@FU-max-boop

@FU-max-boop FU-max-boop commented May 28, 2026

Copy link
Copy Markdown

Summary

Fixes #3325.

parse_response() currently assumes response.output is always iterable. Some streaming backends can send a final response.completed payload with output: null after emitting valid output-item events, which causes a bare TypeError in the response stream accumulator.

This change:

  • treats a null final output as empty for standalone response parsing;
  • preserves already accumulated streaming output when the final completion payload has output: null;\n- applies refusal, content-part, and output-item finalization events before recovering that output;
  • covers both standalone parsing and the created/output-item/content-part/text-delta/completed streaming sequence.

The branch has been rebased onto the current main and the prior test-file conflict is resolved.

Tests

  • pytest tests/lib/responses/test_responses.py -q — 11 passed
  • ruff check src/openai/lib/_parsing/_responses.py src/openai/lib/streaming/responses/_responses.py tests/lib/responses/test_responses.py
  • ruff format --check src/openai/lib/_parsing/_responses.py src/openai/lib/streaming/responses/_responses.py tests/lib/responses/test_responses.py
  • scripts/run-pyright src/openai/lib/_parsing/_responses.py src/openai/lib/streaming/responses/_responses.py tests/lib/responses/test_responses.py
  • git diff --check

@FU-max-boop
FU-max-boop requested a review from a team as a code owner May 28, 2026 20:26

@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: c5de32017b

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

Comment thread src/openai/lib/_parsing/_responses.py
@FU-max-boop
FU-max-boop force-pushed the fix/parse-null-response-output branch from d9b78c4 to a6aa9c2 Compare August 12, 2026 07:34

Copy link
Copy Markdown
Author

Rebased this branch onto the current main (a1eeab5) and resolved the test-file conflict while preserving both null-output regressions. The resolved review fix is now in a6aa9c2; focused tests (9), Ruff, Pyright, formatting, and git diff --check all pass locally.

@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: a6aa9c2a0a

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

Comment thread src/openai/lib/streaming/responses/_responses.py
@marcuswood-oai

Copy link
Copy Markdown
Contributor

Thank you for the contribution! The null-output parsing and stream recovery fix has landed in #3345, so I am closing this PR as superseded. We appreciate your help!

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)

2 participants