fix(types): sync ParsedBetaContentBlock union with BetaContentBlock#1445
Open
abhicris wants to merge 1 commit intoanthropics:mainfrom
Open
fix(types): sync ParsedBetaContentBlock union with BetaContentBlock#1445abhicris wants to merge 1 commit intoanthropics:mainfrom
abhicris wants to merge 1 commit intoanthropics:mainfrom
Conversation
…loses anthropics#1422) `ParsedBetaContentBlock` (the union used by `ParsedBetaMessage.content` in the beta streaming accumulator) was missing three block types that the sibling `BetaContentBlock` does include: - `BetaWebFetchToolResultBlock` - `BetaAdvisorToolResultBlock` - `BetaToolSearchToolResultBlock` Impact: when `accumulate_event` in `lib/streaming/_beta_messages.py` calls `construct_type(type_=ParsedBetaContentBlock, value=...)` for a `content_block_start` carrying any of those three result blocks, pydantic's discriminated-union resolution fails to match and the block is silently dropped. The block never appears in `stream.get_final_message().content`, even though it was present on the wire. The issue called out `tool_search` and `web_fetch`; while syncing, also added `BetaAdvisorToolResultBlock` since it's present in `BetaContentBlock` and absent here for the same reason. Keeping the two unions in lockstep is the property we actually want.
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.
Closes #1422.
Bug
`ParsedBetaContentBlock` (the union used by `ParsedBetaMessage.content` in the beta streaming accumulator) was missing three block types that the sibling `BetaContentBlock` does include:
When `accumulate_event` in `lib/streaming/beta_messages.py` calls `construct_type(type=ParsedBetaContentBlock, value=event.content_block.to_dict())` for a `content_block_start` carrying any of those three result blocks, pydantic's discriminated-union resolution fails to match and the block is silently dropped from `stream.get_final_message().content`.
Fix
Add the missing imports and union members so `ParsedBetaContentBlock` mirrors `BetaContentBlock` exactly. Keeping the two unions in lockstep is the property we actually want — there's no reason any block type that streams should be absent from the parsed snapshot.
```diff
ParsedBetaContentBlock: TypeAlias = Annotated[
Union[
ParsedBetaTextBlock[ResponseFormatT],
BetaThinkingBlock,
BetaRedactedThinkingBlock,
BetaToolUseBlock,
BetaServerToolUseBlock,
BetaWebSearchToolResultBlock,
PropertyInfo(discriminator="type"),
]
```
`+6 / -0`. Type-only change; no runtime behavior change apart from the previously-dropped blocks now being present in `stream.get_final_message().content`.
The issue body explicitly named tool-search and web-fetch; advisor was added because it has the same root cause and the same fix. Happy to drop it if you'd rather keep this PR strictly to the issue's letter.
Contributed by kcolbchain.