Fix streaming delta merge for duplicate tool call indexes - #3425
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8a006bb32c
ℹ️ 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".
…utor # Conflicts: # tests/lib/chat/test_completions_streaming.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. |
Castiron custom code✅ No new custom-code files detected. 36 mixed files remain; 0 existing customizations changed. Compared 36 existing customizations unchanged
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 34505850390 --repo openai/openai-python \
--name castiron-custom-code-34505850390-1 --dir /tmp/castiron-custom-code-34505850390-1
git apply --stat /tmp/castiron-custom-code-34505850390-1/custom-code.patch
cat /tmp/castiron-custom-code-34505850390-1/custom-code.patchOr reproduce it from an SDK checkout containing the vendored reporter: git fetch --no-tags origin 802b334928d8f0c3e24e5fce15a0eaa1b28c61cd ac1c3c445261639676a69a956c1a22153ee16c7a
python3 scripts/castiron/custom_code_report.py report \
--base 802b334928d8f0c3e24e5fce15a0eaa1b28c61cd \
--head ac1c3c445261639676a69a956c1a22153ee16c7a --fetch --require-head-hash --public \
--out /tmp/castiron-custom-code-ac1c3c445261
cat /tmp/castiron-custom-code-ac1c3c445261/custom-code.patchThis is the current full custom patch for mixed files, not an attribution of only the handwritten lines changed by this PR. |
marcuswood-oai
left a comment
There was a problem hiding this comment.
Thanks for the fix and regression tests! We’ve simplified the shared accumulator and expanded the coverage. The full diff review and checks look good.
Pull request was closed
Fixes #3201.
Summary
Streaming tool call deltas can include multiple entries with the same logical
indexin the first chunk. The accumulator used to assign that first list wholesale when the key was absent orNone, so duplicate-index entries bypassed the existing recursive merge path and later argument fragments merged into the wrong physical list entry.This changes the streaming delta accumulators to initialize indexed lists through the existing merge loop instead of taking the first indexed list as-is. It also applies the same initial-list normalization to the chat completion snapshot path and the matching assistant streaming accumulator, which shared the same early-return behavior.
Root cause
accumulate_delta()already knew how to merge list entries by their logicalindex, but only after an accumulator entry existed. When the first streamed value fortool_callscontained two entries withindex: 0, the fast path copied both entries directly into the snapshot. The next chunk then merged into physical slot0while the earlier arguments fragment stayed orphaned in physical slot1, producing invalid final JSON.Validation
Reproduced on current
origin/mainwith a minimal script: duplicateindex: 0entries remained as two physical list entries and the assertion that they merge failed.