Skip to content

fix: handle null response.output in parse_response#3327

Open
xodn348 wants to merge 1 commit into
openai:mainfrom
xodn348:fix/issue-3325
Open

fix: handle null response.output in parse_response#3327
xodn348 wants to merge 1 commit into
openai:mainfrom
xodn348:fix/issue-3325

Conversation

@xodn348
Copy link
Copy Markdown

@xodn348 xodn348 commented May 28, 2026

Fixes #3325

What

parse_response() in src/openai/lib/_parsing/_responses.py crashes with TypeError: 'NoneType' object is not iterable when response.output is null. This can happen when the server sends a response.completed event with output: null while valid response.output_item.done events were streamed earlier. The fix coerces None to [] before iteration.

Verification

  • Build: pass
  • Tests: pass (5 passed)
  • Lint: pass (ruff)
  • Type check: pass (pyright, 0 errors)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@xodn348 xodn348 requested a review from a team as a code owner May 28, 2026 05:14
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: 74a244f293

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

P1 Badge Preserve streamed output when completion output is null

When a streamed Responses request ends with response.completed carrying output: null after earlier output item/content events, this fallback parses the completion payload as an empty ParsedResponse. ResponseStreamState.accumulate_event passes event.response directly into parse_response, and get_final_response()/the completed event then expose _completed_response, so callers receive empty output/output_text even though the accumulated snapshot contains the generated items. The null case needs to reuse or merge the accumulated stream snapshot instead of coercing it to [] here.

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