Skip to content

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

Open
spokodev wants to merge 1 commit into
openai:mainfrom
spokodev:w33/openai-assistants-array-index
Open

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

Conversation

@spokodev

@spokodev spokodev commented Jul 2, 2026

Copy link
Copy Markdown

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.

@spokodev spokodev requested a review from a team as a code owner July 2, 2026 11:55
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.

1 participant