fix(parsing): guard response.output None in parse_response#3431
fix(parsing): guard response.output None in parse_response#3431Shriniwas410 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1eb8476f27
ℹ️ 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 []): |
There was a problem hiding this comment.
Preserve streamed output when completion omits it
When a streamed response.completed event has response.output == None, this fallback parses an empty list even though ResponseStreamState has already accumulated the real output from prior response.output_item.added and delta events. In that backend case, get_final_response() and the emitted response.completed.response no longer crash, but they silently return output=[], so output_text, parsed text, and tool calls are lost despite having been streamed successfully.
Useful? React with 👍 / 👎.
parse_response()iteratesresponse.outputdirectly without a None check. The Codex backend (chatgpt.com) sometimes sendsresponse.output: nullin theresponse.completedevent even when valid output items were streamed earlier, causingTypeError: 'NoneType' object is not iterableinside the stream accumulator.Replacing
for output in response.outputwithfor output in (response.output or [])matches the existing null-safety pattern used elsewhere in the SDK and prevents the crash without changing behavior when output is non-null.Fixes #3325