Skip to content

Guard Responses streams against missing output items#3131

Open
MukundaKatta wants to merge 1 commit intoopenai:mainfrom
MukundaKatta:codex/guard-null-response-output-item
Open

Guard Responses streams against missing output items#3131
MukundaKatta wants to merge 1 commit intoopenai:mainfrom
MukundaKatta:codex/guard-null-response-output-item

Conversation

@MukundaKatta
Copy link
Copy Markdown

Adds a defensive guard in the Responses stream accumulator for malformed response.output_item.added events where item is null, preventing an AttributeError before application code can recover.\n\nCloses #3125.\n\nVerification:\n- PYTHONPATH=src .venv/bin/python -m pytest tests/lib/responses/test_responses.py -q

@MukundaKatta MukundaKatta requested a review from a team as a code owner April 28, 2026 02:01
Copy link
Copy Markdown

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

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: b6b2703791

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +332 to +333
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.

P2 Badge Preserve output index when item is null

Returning early when response.output_item.added has item=None leaves snapshot.output shorter than the stream’s declared indices, but later handlers index into snapshot.output[event.output_index] (for example in response.content_part.added and response.output_text.delta). In malformed streams where a null item is followed by events for subsequent output_index values, this still raises IndexError, so the new guard does not reliably let consumers recover from the malformed event.

Useful? React with 👍 / 👎.

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.

1 participant