fix: handle null response.output in parse_response - #3418
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 88c5b765f7
ℹ️ 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 accumulated stream output when final output is null
When streaming, the API can send response.completed with event.response.output as null after earlier response.output_item.* and delta events have populated the snapshot. ResponseStreamState.accumulate_event() stores _completed_response from parse_response(event.response), and get_final_response() returns that object, so this fallback turns those completed streams into a parsed response with empty output/output_text, discarding the already accumulated content instead of parsing the snapshot.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Thanks for catching this. I updated the stream accumulator so that when the terminal response.completed payload has output: null, it preserves the accumulated snapshot output while keeping the final response metadata. I also added a regression test covering streamed output deltas followed by a completed event with null output.
Tests run:
uv run pytest tests/lib/responses/test_responses.py -quv run ruff check src/openai/lib/streaming/responses/_responses.py tests/lib/responses/test_responses.pyuv run ruff format --check src/openai/lib/streaming/responses/_responses.py tests/lib/responses/test_responses.py
|
Thank you for the contribution! The null-output parsing and stream recovery fix has landed in #3345, so I am closing this PR as superseded. We appreciate your help! |
Summary
Handle responses where
response.outputisnullwhen parsing response snapshots, avoiding aTypeErrorduringresponse.completedhandling.Changes
response.output or []inparse_response()Responsewith null outputTesting
uv run pytest tests/lib/responses/test_responses.py -quv run pyright src/openai/lib/_parsing/_responses.py tests/lib/responses/test_responses.pyFixes #3325