Skip to content

fix(streaming): use event.index instead of at(-1) for content block lookup#1080

Open
yen0304 wants to merge 1 commit into
anthropics:mainfrom
yen0304:fix-streaming-content-block-index
Open

fix(streaming): use event.index instead of at(-1) for content block lookup#1080
yen0304 wants to merge 1 commit into
anthropics:mainfrom
yen0304:fix-streaming-content-block-index

Conversation

@yen0304

@yen0304 yen0304 commented Jun 4, 2026

Copy link
Copy Markdown

Summary

  • #addStreamEvent used .at(-1) to look up the current content block for event emission, while #accumulateMessage correctly used event.index
  • This would return the wrong content block if deltas arrived for a non-final block in multi-block messages
  • The Python SDK already uses event.index in the equivalent code path

Affects both MessageStream.ts and BetaMessageStream.ts (content_block_delta and content_block_stop handlers).

…ookup

The event emission code in #addStreamEvent used .at(-1) to look up the
current content block, while the accumulation code in #accumulateMessage
correctly used event.index. This is inconsistent and would return the
wrong content block if deltas ever arrived for a non-final block.

The Python SDK already uses event.index in the equivalent code path.
@yen0304 yen0304 requested a review from a team as a code owner June 4, 2026 17:26
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