Skip to content

fix: handle null response output in parser#3362

Open
puneetdixit200 wants to merge 1 commit into
openai:mainfrom
puneetdixit200:codex/handle-null-response-output
Open

fix: handle null response output in parser#3362
puneetdixit200 wants to merge 1 commit into
openai:mainfrom
puneetdixit200:codex/handle-null-response-output

Conversation

@puneetdixit200
Copy link
Copy Markdown

  • I understand that this repository is auto-generated and my pull request may not be merged

Changes being requested

Fixes #3325.

parse_response now treats a null response.output as an empty output list before iterating, avoiding a TypeError when a completed response event has output: null. Added a regression test that constructs that response shape and verifies parsing returns output=[].

AI-assisted: yes.

Additional context & links

Verification run locally:

  • .venv/bin/python -m pytest -o addopts='' tests/lib/responses/test_responses.py -q -> 6 passed
  • .venv/bin/ruff format --check src/openai/lib/_parsing/_responses.py tests/lib/responses/test_responses.py -> 2 files already formatted
  • .venv/bin/ruff check src/openai/lib/_parsing/_responses.py tests/lib/responses/test_responses.py -> all checks passed
  • .venv/bin/mypy src/openai/lib/_parsing/_responses.py -> success, no issues found in 1 source file
  • git diff --check -> passed

Not run: full ./scripts/test; the repository docs note most tests require the mock server, and this change is covered by the focused responses parser test file.

@puneetdixit200 puneetdixit200 requested a review from a team as a code owner June 4, 2026 09:10
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: f3adae0750

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

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.

P2 Badge Preserve streamed output when completed event omits it

When the Responses stream has already accumulated output items and the final response.completed event carries output: null (the case this change is trying to tolerate), this line converts the final response's output to []. I checked ResponseStreamState.accumulate_event: on response.completed it sets _completed_response = parse_response(... event.response ...) (src/openai/lib/streaming/responses/_responses.py:359-364), and get_final_response() returns that object, not the accumulated snapshot. As a result, streamed calls with text/tool output but a null final output no longer raise, but response.completed.response, get_final_response().output, and output_text are empty, silently dropping the data sent by the earlier stream events.

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