Skip to content

fix: merge duplicate streaming tool call deltas#3438

Closed
fengjikui wants to merge 1 commit into
openai:mainfrom
fengjikui:codex/merge-duplicate-tool-call-deltas
Closed

fix: merge duplicate streaming tool call deltas#3438
fengjikui wants to merge 1 commit into
openai:mainfrom
fengjikui:codex/merge-duplicate-tool-call-deltas

Conversation

@fengjikui

Copy link
Copy Markdown

Fixes #3201.

Summary

Streaming tool call deltas can contain multiple entries for the same index in a single chunk. The previous accumulator stored the first list delta as-is when the field was missing from the accumulator, so duplicate index entries from that initial chunk stayed split apart. A later delta for the same index then merged into the first physical list item, leaving earlier argument fragments stranded in a second item.

This changes list accumulation to use the same index-aware merge logic when a list field is first created, and shares that behavior between the chat and assistants streaming accumulators. It also adds a regression test covering duplicate tool_calls[0] entries in the initial accumulated list.

Validation

  • Manual repro from Streaming tool_call deltas with duplicate indexes in first chunk are accumulated incorrectly #3201 now passes
  • env -u ALL_PROXY -u HTTPS_PROXY -u HTTP_PROXY -u all_proxy -u https_proxy -u http_proxy .venv/bin/python -m pytest tests/lib/test_streaming_deltas.py tests/lib/chat/test_completions_streaming.py -q
  • .venv/bin/python -m ruff format --check src/openai/lib/streaming/_deltas.py src/openai/lib/streaming/_assistants.py tests/lib/test_streaming_deltas.py
  • .venv/bin/python -m ruff check src/openai/lib/streaming/_deltas.py src/openai/lib/streaming/_assistants.py tests/lib/test_streaming_deltas.py
  • .venv/bin/python -m mypy src/openai/lib/streaming/_deltas.py src/openai/lib/streaming/_assistants.py tests/lib/test_streaming_deltas.py
  • git diff --check

@fengjikui fengjikui requested a review from a team as a code owner June 24, 2026 17:37
@fengjikui

Copy link
Copy Markdown
Author

Closing this as a duplicate of #3425. #3425 covers the same #3201 issue and includes the broader initial chat completion snapshot path plus regression coverage, so keeping a single PR should make review easier.

@fengjikui fengjikui closed this Jun 24, 2026
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.

Streaming tool_call deltas with duplicate indexes in first chunk are accumulated incorrectly

1 participant