Guard Responses streams against missing output items#3131
Guard Responses streams against missing output items#3131MukundaKatta wants to merge 1 commit intoopenai:mainfrom
Conversation
There was a problem hiding this comment.
💡 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".
| if item is None: | ||
| return snapshot |
There was a problem hiding this comment.
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 👍 / 👎.
Adds a defensive guard in the Responses stream accumulator for malformed
response.output_item.addedevents whereitemis 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