Fix responses stream null output item handling#3426
Open
fengjikui wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3125.
Summary
ResponseStreamState.accumulate_event()assumes everyresponse.output_item.addedevent has anitem. Some OpenAI-compatible Responses streams can senditem: null; when that happens the SDK currently raises before user code can recover:This treats a null added item as a no-op for the accumulated snapshot, matching the fact that there is no concrete output item to append.
Validation
I reproduced the failure on current
origin/mainby feedingResponseStreamState.handle_event()a normalresponse.createdevent followed byresponse.output_item.addedwithitem=None; current main raises theAttributeErrorabove.On this branch:
uv run --with pytest --with pytest-asyncio --with respx --with inline-snapshot pytest -o addopts='' tests/lib/responses/test_responses.py::test_response_stream_ignores_null_output_item_added -q->1 passed in 0.12senv -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy uv run --with pytest --with pytest-asyncio --with respx --with inline-snapshot pytest -o addopts='' tests/lib/responses/test_responses.py -q->6 passed in 0.87suv run --with ruff ruff check src/openai/lib/streaming/responses/_responses.py tests/lib/responses/test_responses.py->All checks passed!uv run python -m py_compile src/openai/lib/streaming/responses/_responses.py tests/lib/responses/test_responses.py-> passedgit diff --check-> clean