fix: add missing server tool result types to ParsedContentBlock#1364
Open
atishay2 wants to merge 2 commits intoanthropics:mainfrom
Open
fix: add missing server tool result types to ParsedContentBlock#1364atishay2 wants to merge 2 commits intoanthropics:mainfrom
atishay2 wants to merge 2 commits intoanthropics:mainfrom
Conversation
added 2 commits
April 11, 2026 20:56
…silently The __stream__ methods in Stream and AsyncStream used separate if statements with no else clause, causing any unrecognized event type to be silently dropped. This broke client.beta.sessions.events.stream() entirely since managed agents emit different event names (agent.message, session.status_*) that don't match the hardcoded Messages API event list. Fix: Convert if/if/if/if to if/elif/elif/elif/else in both sync and async __stream__ methods so unknown events pass through process_data() instead of being silently discarded. Fixes anthropics#1357
ParsedContentBlock in types/parsed_message.py only included WebSearchToolResultBlock but was missing 5 other server tool result types: - CodeExecutionToolResultBlock - WebFetchToolResultBlock - BashCodeExecutionToolResultBlock - TextEditorCodeExecutionToolResultBlock - ToolSearchToolResultBlock When any of these arrived as content_block_start events during streaming, construct_type() failed discriminated union parsing and silently dropped them from current_snapshot.content. As a result, get_final_message().content was missing server tool results when client tools ran concurrently with server tools — the bug reported in anthropics#1325. Fix: add all 5 missing types to ParsedContentBlock to match ContentBlock. Adds sync + async regression tests with a fixture that streams both web_search_tool_result and code_execution_tool_result blocks alongside a concurrent client tool_use, asserting all 4 blocks are present in get_final_message().content. Fixes anthropics#1325
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 #1325
Root cause
ParsedContentBlockintypes/parsed_message.pyonly includedWebSearchToolResultBlockbut was missing 5 other server tool result types that exist in the mainContentBlockunion:CodeExecutionToolResultBlockWebFetchToolResultBlockBashCodeExecutionToolResultBlockTextEditorCodeExecutionToolResultBlockToolSearchToolResultBlockWhen any of these arrived as
content_block_startevents during streaming,construct_type(type_=ParsedContentBlock, ...)failed discriminated union parsing and silently dropped the block fromcurrent_snapshot.content. As a result,get_final_message().contentwas missing server tool results when client tools ran concurrently with server tools.Fix
Add all 5 missing types to
ParsedContentBlockto matchContentBlock. One file changed.Tests
Added sync and async regression tests (
TestServerToolResultBlocks) with a new fixture that streams a message containing:server_tool_useblocktool_useblock (concurrent)web_search_tool_resultblockcode_execution_tool_resultblockBoth tests assert all 4 blocks are present in
get_final_message().contentand that all 4content_block_startevents are delivered to the caller.Test results