Fix unhandled content_block_stop event in Anthropic streaming#6555
Open
nikita-kibitkin wants to merge 1 commit into
Open
Fix unhandled content_block_stop event in Anthropic streaming#6555nikita-kibitkin wants to merge 1 commit into
nikita-kibitkin wants to merge 1 commit into
Conversation
- 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.