Skip to content

fix: guard against item=None in response.output_item.added accumulator - #3240

Closed
sharziki wants to merge 1 commit into
openai:mainfrom
sharziki:fix/3125-stream-accumulator-null-item
Closed

sharziki wants to merge 1 commit into
openai:mainfrom
sharziki:fix/3125-stream-accumulator-null-item

Conversation

@sharziki

@sharziki sharziki commented May 15, 2026

Copy link
Copy Markdown

Summary

Closes #3125

The Responses stream accumulator assumed every response.output_item.added event includes a non-null item and immediately accessed event.item.type. OpenAI-compatible providers can emit this event with item=None, which crashes streaming with AttributeError.

Changes

  • src/openai/lib/streaming/responses/_responses.py: Add a defensive None check before inspecting event.item.type, so malformed/null output-item events are skipped instead of crashing the stream accumulator

Verification

  • Not run; small defensive guard in the accumulator path

🤖 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

The Responses stream accumulator assumed event.item is always present
for response.output_item.added events and immediately accessed
event.item.type. When an OpenAI-compatible provider sends this event
with item=None, the client crashes with:

  AttributeError: 'NoneType' object has no attribute 'type'

Add a defensive None check so the accumulator gracefully skips
malformed events instead of crashing.

Closes openai#3125

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@sharziki
sharziki force-pushed the fix/3125-stream-accumulator-null-item branch from fec1f1f to 2a90721 Compare June 6, 2026 22:29
@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