fix(responses): initialize null streaming output before accumulating items - #3881
Open
Chirag-Bhardwaj wants to merge 1 commit into
Open
Chirag-Bhardwaj wants to merge 1 commit into
Chirag-Bhardwaj wants to merge 1 commit into
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.
Changes being requested
Normalize null or omitted
response.created.response.outputto an empty list in the Responses stream's internal snapshot. The index map already tolerates these values, but the snapshot retainsNone, so the nextresponse.output_item.addedraisesAttributeError: 'NoneType' object has no attribute 'append'in both sync and async streams.This extends the existing null-output handling from #3345 to stream initialization. The change is confined to the handwritten streaming helper. Existing output lists and terminal-response precedence are preserved.
The existing public-client regression test now covers null, omitted, and empty initial output across sync/async streams, with and without items, and all four terminal-output variants. It verifies final structured text, function arguments, citations, refusals, status, and usage using synthetic SSE through
httpx2.MockTransport; no live API calls or credentials are required. This is a locally reproduced SDK edge case, not a claim that the production API currently emits this payload.Additional context & links
Validated on Python 3.10.16 against main
b77076d23b6f3e34453b0fadd8cd2a001627e365:./scripts/test -n 4: 13,209 passed / 162 skipped on Pydantic v2; 13,195 passed / 176 skipped on v1../scripts/lint: Ruff, Pyright, Mypy, and import check passed../scripts/build, changed-file formatting, andgit diff --checkpassed.