Skip to content

Fix unhandled content_block_stop event in Anthropic streaming#6555

Open
nikita-kibitkin wants to merge 1 commit into
spring-projects:1.1.xfrom
nikita-kibitkin:gh-6372-content-block-stop-1.1.x
Open

Fix unhandled content_block_stop event in Anthropic streaming#6555
nikita-kibitkin wants to merge 1 commit into
spring-projects:1.1.xfrom
nikita-kibitkin:gh-6372-content-block-stop-1.1.x

Conversation

@nikita-kibitkin

Copy link
Copy Markdown

Fixes #6372

For non-tool streams the content_block_stop event passes through the tool-merge reduce untouched, and StreamHelper.eventToChatCompletionResponse has no branch for it, so every text content block logs "Unhandled event type: CONTENT_BLOCK_STOP" and emits an empty ChatResponse chunk to consumers. main/2.0 is not affected, so this targets 1.1.x only.

The event cannot simply be dropped before conversion: resetting the aggregated builder content is its load-bearing side effect, without it the message_delta chunk re-emits the last text delta. So StreamHelper now handles content_block_stop explicitly (resets content, no warning) and the converted chunk is dropped in the existing terminal filter of chatCompletionStream. Same behavior as the 2.0 module, tool-use aggregation unchanged.

Testing: new AnthropicApiChatCompletionStreamTests (MockWebServer, no live API) covers a text stream (no CONTENT_BLOCK_STOP chunk, deltas intact; verified to fail without the fix) and a tool-use stream (aggregated tool call still reaches the message_delta chunk). Module tests, spring-javaformat and checkstyle clean.

 - Handle content_block_stop explicitly in StreamHelper: reset the
   aggregated content instead of falling through to the "Unhandled
   event type" warning logged for every streamed content block.
 - Filter the resulting empty chunk out of chatCompletionStream so
   consumers no longer receive an empty ChatResponse per content block,
   matching the 2.0 module behavior.
 - Add mock-server streaming tests for the text and tool-use event
   sequences, verifying the tool-use aggregation path is unchanged.

Fixes spring-projects#6372

Signed-off-by: Nikita Kibitkin <nikita.n.kibitkin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants