Skip to content

Handle null response output during parsing#3330

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

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

Conversation

@FU-max-boop
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 treats a null output the same as an empty output list during parsing, so stream consumers can still complete and inspect the final response instead of crashing in the parser.

Tests

  • uv run python -m pytest -o addopts="" tests/lib/responses/test_responses.py -q
  • uv run ruff check src/openai/lib/_parsing/_responses.py tests/lib/responses/test_responses.py
  • uv run ruff format --check src/openai/lib/_parsing/_responses.py tests/lib/responses/test_responses.py
  • uv run pyright src/openai/lib/_parsing/_responses.py tests/lib/responses/test_responses.py

@FU-max-boop FU-max-boop requested a review from a team as a code owner May 28, 2026 20:26
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: 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".

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 output when completed payload is null

When a streaming backend sends response.completed with output: null after earlier response.output_item.* events, this fallback parses the final payload as output=[]. The streaming accumulator sets _completed_response by calling parse_response(event.response, ...) on completion (src/openai/lib/streaming/responses/_responses.py:359-364), so ResponseCompletedEvent.response and get_final_response() lose all message/tool output that was already accumulated in the snapshot instead of letting consumers inspect it. In this null-output case, the parser/stream state should preserve the accumulated snapshot output rather than replacing it with an empty list.

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.

Fixed in d9b78c4d: ResponseStreamState now preserves the accumulated snapshot output when the final response.completed payload has output: null, and the new streaming regression test covers the created/output_item/content_part/text_delta/completed sequence.

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