Skip to content

fix: handle null response.output in parse_response - #3418

Closed
nightcityblade wants to merge 2 commits into
openai:mainfrom
nightcityblade:fix/issue-3325
Closed

fix: handle null response.output in parse_response#3418
nightcityblade wants to merge 2 commits into
openai:mainfrom
nightcityblade:fix/issue-3325

Conversation

@nightcityblade

Copy link
Copy Markdown

Summary

Handle responses where response.output is null when parsing response snapshots, avoiding a TypeError during response.completed handling.

Changes

  • Iterate over response.output or [] in parse_response()
  • Add a targeted regression test covering a Response with null output

Testing

  • uv run pytest tests/lib/responses/test_responses.py -q
  • uv run pyright src/openai/lib/_parsing/_responses.py tests/lib/responses/test_responses.py

Fixes #3325

@nightcityblade
nightcityblade requested a review from a team as a code owner June 22, 2026 03: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: 88c5b765f7

ℹ️ 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 when final output is null

When streaming, the API can send response.completed with event.response.output as null after earlier response.output_item.* and delta events have populated the snapshot. ResponseStreamState.accumulate_event() stores _completed_response from parse_response(event.response), and get_final_response() returns that object, so this fallback turns those completed streams into a parsed response with empty output/output_text, discarding the already accumulated content instead of parsing the snapshot.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for catching this. I updated the stream accumulator so that when the terminal response.completed payload has output: null, it preserves the accumulated snapshot output while keeping the final response metadata. I also added a regression test covering streamed output deltas followed by a completed event with null output.

Tests run:

  • uv run pytest tests/lib/responses/test_responses.py -q
  • uv run ruff check src/openai/lib/streaming/responses/_responses.py tests/lib/responses/test_responses.py
  • uv run ruff format --check src/openai/lib/streaming/responses/_responses.py tests/lib/responses/test_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