Skip to content

fix: preserve response stream indexes after empty items - #3126

Merged
marcuswood-oai merged 4 commits into
openai:mainfrom
nightcityblade:fix/issue-3125
Sep 10, 2026
Merged

fix: preserve response stream indexes after empty items#3126
marcuswood-oai merged 4 commits into
openai:mainfrom
nightcityblade:fix/issue-3125

Conversation

@nightcityblade

@nightcityblade nightcityblade commented Apr 26, 2026

Copy link
Copy Markdown
Contributor

Fixes #3125.

Skip null or missing response.output_item.added items 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 clear RuntimeError instead 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

  • Responses suite: 95 passed with Pydantic v2 and 95 passed with v1 on Python 3.10.
  • Broader handwritten SDK and streaming suite: 2,125 passed, 83 skipped.
  • Sync/async mock-stream coverage includes missing/null items, reused and sparse indexes, text/tool deltas, empty/null/missing initial output, and completion recovery. The original guard fails the new gap regression.
  • Ruff, Pyright (0 errors), Mypy (1,834 source files), compilation, and import smoke checks passed.
  • Forty fine-tuning tests require the local Steady server. Its dependency download from JSR failed; a representative connection failure also reproduces with main. These tests were excluded from the passing broad run.

Reviewed the complete diff; no unrelated changes or security findings.

@nightcityblade
nightcityblade requested a review from a team as a code owner April 26, 2026 15:05
@marcuswood-oai marcuswood-oai changed the title fix: guard null output items in response streams fix: preserve response stream indexes after empty items Sep 10, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 10, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-10T20:39:57.590611Z 215b34c New commits
🔒 Security Review Completed 2026-09-10T20:41:59.128661Z 215b34c New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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

Copy link
Copy Markdown

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

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 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 👍 / 👎.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

github-actions Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Castiron custom code

✅ No new custom-code files detected.

43 mixed files remain; 0 existing customizations changed.

Compared 7e31f8cb87f4215b34c6b7c6. Generated baselines verified.

43 existing customizations unchanged
  • api.md
  • scripts/castiron/README.md
  • scripts/castiron/custom_code_report.py
  • scripts/castiron/test_custom_code_report.py
  • src/openai/init.py
  • src/openai/_client.py
  • src/openai/resources/audio/transcriptions.py
  • src/openai/resources/audio/translations.py
  • src/openai/resources/beta/agents/sessions/sessions.py
  • src/openai/resources/beta/beta.py
  • src/openai/resources/beta/responses/responses.py
  • src/openai/resources/beta/threads/runs/runs.py
  • src/openai/resources/beta/threads/threads.py
  • src/openai/resources/chat/completions/completions.py
  • src/openai/resources/embeddings.py
  • src/openai/resources/files.py
  • src/openai/resources/live/forks.py
  • src/openai/resources/live/live.py
  • src/openai/resources/live/sideband.py
  • src/openai/resources/realtime/realtime.py
  • src/openai/resources/responses/responses.py
  • src/openai/resources/uploads/uploads.py
  • src/openai/resources/vector_stores/file_batches.py
  • src/openai/resources/vector_stores/files.py
  • src/openai/resources/videos.py
  • src/openai/resources/webhooks/init.py
  • src/openai/resources/webhooks/webhooks.py
  • src/openai/types/beta/agent_session_message.py
  • src/openai/types/chat/init.py
  • src/openai/types/chat/chat_completion_message_tool_call.py
  • src/openai/types/fine_tuning/fine_tuning_job_integration.py
  • src/openai/types/responses/init.py
  • src/openai/types/responses/response.py
  • src/openai/types/responses/response_function_web_search.py
  • src/openai/types/responses/response_function_web_search_param.py
  • src/openai/types/responses/responses_client_event.py
  • src/openai/types/responses/responses_client_event_param.py
  • src/openai/types/responses/tool.py
  • src/openai/types/responses/tool_param.py
  • src/openai/types/webhooks/init.py

3 more in the full report.

A changed generated baseline means this report cannot reliably identify which handwritten lines changed.

Inspect the custom-code diff

Download 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.patch

Or 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.patch

This is the current full custom patch for mixed files, not an attribution of only the handwritten lines changed by this PR.

Full report and patch

@marcuswood-oai
marcuswood-oai merged commit 8f84fbd into openai:main Sep 10, 2026
16 checks passed
@openai-sdks openai-sdks Bot mentioned this pull request Sep 10, 2026
@marcuswood-oai

Copy link
Copy Markdown
Contributor

Thanks for the patch, @nightcityblade! Merged—really 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