Skip to content

fix: ignore empty stream output items - #3399

Closed
he-yufeng wants to merge 1 commit into
openai:mainfrom
he-yufeng:fix/stream-output-item-none
Closed

fix: ignore empty stream output items#3399
he-yufeng wants to merge 1 commit into
openai:mainfrom
he-yufeng:fix/stream-output-item-none

Conversation

@he-yufeng

Copy link
Copy Markdown
Contributor

Fixes #3125.

Summary

  • Guard the Responses stream accumulator when a malformed response.output_item.added event has no item.
  • Leave the current response snapshot unchanged instead of crashing before user code can handle the stream.
  • Add a regression test for the malformed event shape.

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.py
  • git diff --check

@he-yufeng

Copy link
Copy Markdown
Contributor Author

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!

@he-yufeng
he-yufeng force-pushed the fix/stream-output-item-none branch from 97ba69e to b28f4e9 Compare August 17, 2026 00:05

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +331 to +333
item = getattr(event, "item", None)
if item is None:
return snapshot

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

@marcuswood-oai

Copy link
Copy Markdown
Contributor

Thanks for the patch! We merged the fix in #3126, so closing this as a duplicate. We appreciate your contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Responses stream accumulator crashes when response.output_item.added has item=None

2 participants