fix: handle null response.output in parse_response#3327
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 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 []): |
There was a problem hiding this comment.
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 👍 / 👎.
Fixes #3325
What
parse_response()insrc/openai/lib/_parsing/_responses.pycrashes withTypeError: 'NoneType' object is not iterablewhenresponse.outputisnull. This can happen when the server sends aresponse.completedevent withoutput: nullwhile validresponse.output_item.doneevents were streamed earlier. The fix coercesNoneto[]before iteration.Verification