fix: preserve response stream indexes after empty items - #3126
Conversation
…t-item # Conflicts: # tests/lib/responses/test_responses.py
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e1a82ab817
ℹ️ 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".
| return construct_type_unchecked(type_=ParsedResponseSnapshot, value=event.response.to_dict()) | ||
| snapshot = construct_type_unchecked(type_=ParsedResponseSnapshot, value=event.response.to_dict()) | ||
| # Stream indexes can have gaps when a provider emits an empty added event. | ||
| self._output_items = dict(enumerate(snapshot.output)) |
There was a problem hiding this comment.
Handle null output in the initial response snapshot
When a provider sends response.created.response.output as null, this new enumerate(snapshot.output) raises TypeError immediately. Previously, a stream containing only that created event followed by a valid response.completed event could finish successfully, and parse_response() already treats null output as an empty list. Initialize the mapping from snapshot.output or [] so hardening null output-item events does not regress null initial snapshots.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Thanks, fixed in 215b34c. The mapping now uses snapshot.output or []. Added sync/async coverage for empty, null, and missing initial output, with and without empty added events. All 95 Responses tests pass on both Pydantic v1 and v2.
Castiron custom code✅ No new custom-code files detected. 43 mixed files remain; 0 existing customizations changed. Compared 43 existing customizations unchanged
3 more in the full report. A changed generated baseline means this report cannot reliably identify which handwritten lines changed. Inspect the custom-code diffDownload the exact patch produced by this run (requires repository access): gh run download 34527905328 --repo openai/openai-python \
--name castiron-custom-code-34527905328-1 --dir /tmp/castiron-custom-code-34527905328-1
git apply --stat /tmp/castiron-custom-code-34527905328-1/custom-code.patch
cat /tmp/castiron-custom-code-34527905328-1/custom-code.patchOr reproduce it from an SDK checkout containing the vendored reporter: git fetch --no-tags origin 7e31f8cb87f43568952bb53287e7478d76db9224 215b34c6b7c65bcef9cbc39393ad8cbc6b2baf79
python3 scripts/castiron/custom_code_report.py report \
--base 7e31f8cb87f43568952bb53287e7478d76db9224 \
--head 215b34c6b7c65bcef9cbc39393ad8cbc6b2baf79 --fetch --require-head-hash --public \
--out /tmp/castiron-custom-code-215b34c6b7c6
cat /tmp/castiron-custom-code-215b34c6b7c6/custom-code.patchThis is the current full custom patch for mixed files, not an attribution of only the handwritten lines changed by this PR. |
|
Thanks for the patch, @nightcityblade! Merged—really appreciate your contribution. |
Fixes #3125.
Skip null or missing
response.output_item.addeditems and track valid items by their original stream indexes. Later text and tool-call deltas reach the correct item even when indexes have gaps. Content for an item never received raises a clearRuntimeErrorinstead of being silently discarded.Preserves the finalized-output recovery from #3345 and keeps generated event types unchanged. Merged current main into the contributor branch and resolved the test conflicts.
Validation
Reviewed the complete diff; no unrelated changes or security findings.