fix: ignore empty stream output items - #3399
Conversation
|
Gentle nudge on this one — small fix so an empty stream output item isn't surfaced as a real chunk. Green and conflict-free; could a maintainer take a look when there's a window? Thanks! |
97ba69e to
b28f4e9
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b28f4e9f0e
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| item = getattr(event, "item", None) | ||
| if item is None: | ||
| return snapshot |
There was a problem hiding this comment.
Ignore follow-up events for the missing output item
When a null response.output_item.added is followed by the normal response.content_part.added or delta events for the same output_index, returning the unchanged snapshot leaves that index absent, so handle_event() crashes on snapshot.output[event.output_index]. It also shifts later valid items to the wrong index if the response contains multiple outputs. To tolerate this malformed event throughout the stream, preserve the output-index alignment or suppress subsequent events associated with the missing item.
Useful? React with 👍 / 👎.
|
Thanks for the patch! We merged the fix in #3126, so closing this as a duplicate. We appreciate your contribution. |
Fixes #3125.
Summary
response.output_item.addedevent has noitem.To verify
$env:PYTHONPATH=(Resolve-Path .\src).Path; python -m pytest tests\lib\responses\test_responses.py -q$env:PYTHONPATH=(Resolve-Path .\src).Path; python -m ruff check src\openai\lib\streaming\responses\_responses.py tests\lib\responses\test_responses.py$env:PYTHONPATH=(Resolve-Path .\src).Path; python -m py_compile src\openai\lib\streaming\responses\_responses.py tests\lib\responses\test_responses.pygit diff --check