Skip to content

fix(assistants): place array delta entries by index instead of appending#1963

Merged
HAYDEN-OAI merged 1 commit into
openai:mainfrom
spokodev:w33/openai-assistants-array-index
Jul 6, 2026
Merged

fix(assistants): place array delta entries by index instead of appending#1963
HAYDEN-OAI merged 1 commit into
openai:mainfrom
spokodev:w33/openai-assistants-array-index

Conversation

@spokodev

@spokodev spokodev commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

When accumulating streamed array deltas, AssistantStream.accumulateDelta
reads and writes entries by their index field. The branch that handles a
not-yet-seen entry appended it with push instead of assigning it at
accValue[index]. These only agree when the index equals the current array
length, so any non-contiguous or out-of-order index lands the entry at the
wrong position.

The consequence is data corruption: because the entry is not at accValue[index],
a later fragment for the same index finds an empty slot and appends again. The
same tool call (or content block) ends up as two separate array entries with
split, invalid JSON arguments in the accumulated snapshot.

This assigns the entry at its index, matching the sibling branch and the
Python SDK, which uses insert(index, entry) for the same case. The existing
contiguous path is unchanged.

Added a unit test that seeds an entry at index 0, then streams two fragments
for index 2. Before the fix the array holds two index-2 entries with split
arguments; after the fix it holds one merged entry.

@HAYDEN-OAI HAYDEN-OAI left a comment

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 for the clear explanation and the focused regression test. using the delta entry's index here matches the surrounding snapshot logic and fixes the out-of-order accumulation case cleanly. great work!

@HAYDEN-OAI HAYDEN-OAI merged commit 0e18d30 into openai:main Jul 6, 2026
10 checks passed
@stainless-app stainless-app Bot mentioned this pull request Jul 6, 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.

2 participants