Skip to content

fix: merge indexed streaming deltas on first chunk#3423

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

fix: merge indexed streaming deltas on first chunk#3423
fengjikui wants to merge 1 commit into
openai:mainfrom
fengjikui:codex/fix-duplicate-tool-call-deltas

Conversation

@fengjikui

Copy link
Copy Markdown

Fixes #3201.

Summary

accumulate_delta() already knows how to merge list entries by their logical index, but the first value for a key was assigned wholesale before that logic ran. If the first streamed tool_calls chunk contained multiple entries with the same index, the duplicate entries stayed as separate physical list elements and later argument fragments merged into only one of them.

This updates both streaming delta accumulators to route initial indexed lists through the existing indexed merge path instead of storing them wholesale. It also keeps primitive list accumulation on the primitive-list path by checking the incoming delta list as well.

Validation

I first added the regression test and confirmed it failed on current origin/main:

2 failed

Then after the fix:

PYTHONPATH=src uv run --with pytest --with pytest-asyncio --with pytest-xdist pytest tests/lib/test_streaming_deltas.py -q
# 2 passed

Related targeted checks:

env -u ALL_PROXY -u HTTPS_PROXY -u HTTP_PROXY -u all_proxy -u https_proxy -u http_proxy \
  PYTHONPATH=src uv run --with pytest --with pytest-asyncio --with pytest-xdist --with rich --with respx --with inline-snapshot \
  pytest tests/lib/test_streaming_deltas.py tests/lib/chat/test_completions_streaming.py tests/lib/test_assistants.py -q
# 25 passed

PYTHONPATH=src uv run --with ruff ruff format --check src/openai/lib/streaming/_deltas.py src/openai/lib/streaming/_assistants.py tests/lib/test_streaming_deltas.py
# 3 files already formatted

PYTHONPATH=src uv run --with ruff ruff check src/openai/lib/streaming/_deltas.py src/openai/lib/streaming/_assistants.py tests/lib/test_streaming_deltas.py
# All checks passed

git diff --check
# clean

@fengjikui fengjikui requested a review from a team as a code owner June 23, 2026 03:36
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