Skip to content

Fix responses stream null output item handling#3426

Open
fengjikui wants to merge 1 commit into
openai:mainfrom
fengjikui:codex/skip-null-output-item
Open

Fix responses stream null output item handling#3426
fengjikui wants to merge 1 commit into
openai:mainfrom
fengjikui:codex/skip-null-output-item

Conversation

@fengjikui

Copy link
Copy Markdown

Fixes #3125.

Summary

ResponseStreamState.accumulate_event() assumes every response.output_item.added event has an item. Some OpenAI-compatible Responses streams can send item: null; when that happens the SDK currently raises before user code can recover:

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

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/main by feeding ResponseStreamState.handle_event() a normal response.created event followed by response.output_item.added with item=None; current main raises the AttributeError above.

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.12s
  • env -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.87s
  • uv 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 -> passed
  • git diff --check -> clean

@fengjikui fengjikui requested a review from a team as a code owner June 23, 2026 08:04
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

1 participant