fix: add missing content block types to ParsedContentBlock and ParsedBetaContentBlock#1379
Open
atishay2 wants to merge 3 commits intoanthropics:mainfrom
Open
fix: add missing content block types to ParsedContentBlock and ParsedBetaContentBlock#1379atishay2 wants to merge 3 commits intoanthropics:mainfrom
atishay2 wants to merge 3 commits intoanthropics:mainfrom
Conversation
added 3 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
…BetaContentBlock ParsedContentBlock was missing ContainerUploadBlock, which is present in ContentBlock. ParsedBetaContentBlock was missing BetaWebFetchToolResultBlock, BetaAdvisorToolResultBlock, and BetaToolSearchToolResultBlock, all of which are present in BetaContentBlock. When the API returns these block types in a streaming response, they are silently dropped from get_final_message().content because construct_type() cannot match them against the incomplete discriminated union.
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.
Summary
ParsedContentBlockandParsedBetaContentBlockhave fallen behind their base union types as new server-generated block types were added to the API.ParsedContentBlock(parsed_message.py) is missing:ContainerUploadBlock— present inContentBlockParsedBetaContentBlock(beta/parsed_beta_message.py) is missing:BetaWebFetchToolResultBlock— present inBetaContentBlockBetaAdvisorToolResultBlock— present inBetaContentBlockBetaToolSearchToolResultBlock— present inBetaContentBlockImpact
When the API returns any of these block types in a streaming or non-streaming response,
construct_type()cannot match them against the discriminated union and silently drops them. This meansget_final_message().contentreturns an incomplete list with no error or warning — the same class of silent data loss fixed for other server tool result types in #1364.Fix
Add the missing imports and union members to bring
ParsedContentBlockandParsedBetaContentBlockin sync withContentBlockandBetaContentBlockrespectively.Relates to #1364.