fix: handle null response.output in parse_response#3361
Conversation
The parse_response() function iterates response.output without checking for None. The chatgpt.com Codex backend sometimes sends response.output: null in the consolidated response.completed event, even when valid response.output_item.done events were streamed earlier. This causes TypeError: 'NoneType' object is not iterable, killing the entire stream before the consumer can read the deltas. Fix: use (response.output or []) to handle null output gracefully. Fixes openai#3325
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4a9b095c0a
ℹ️ 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 completed payload is null
When the streaming backend sends response.completed.response.output: null after already sending response.output_item.* and text/function deltas, this turns the completed response into output=[]. In ResponseStreamState.accumulate_event, the final response.completed event and get_final_response() are built from parse_response(event.response), not from the accumulated snapshot, so consumers no longer crash but silently lose all streamed output and parsed content in exactly the scenario this change is meant to handle. The null case should fall back to the accumulated snapshot/output rather than an empty list.
Useful? React with 👍 / 👎.
Problem
parse_response()insrc/openai/lib/_parsing/_responses.pyiteratesresponse.outputwithout checking forNone. The chatgpt.com Codex backend sometimes sendsresponse.output: nullin the consolidatedresponse.completedevent, even when validresponse.output_item.doneevents were streamed earlier in the same response.This causes
TypeError: 'NoneType' object is not iterable, killing the entire stream before the consumer can read the deltas.Fix
Use
(response.output or [])to handle null output gracefully:Testing
parse_responseto verify againstFixes #3325