Skip to content

fix: add missing server tool result types to ParsedContentBlock#1364

Open
atishay2 wants to merge 2 commits intoanthropics:mainfrom
atishay2:fix/server-tool-result-not-delivered
Open

fix: add missing server tool result types to ParsedContentBlock#1364
atishay2 wants to merge 2 commits intoanthropics:mainfrom
atishay2:fix/server-tool-result-not-delivered

Conversation

@atishay2
Copy link
Copy Markdown

Fixes #1325

Root cause

ParsedContentBlock in types/parsed_message.py only included WebSearchToolResultBlock but was missing 5 other server tool result types that exist in the main ContentBlock union:

  • CodeExecutionToolResultBlock
  • WebFetchToolResultBlock
  • BashCodeExecutionToolResultBlock
  • TextEditorCodeExecutionToolResultBlock
  • ToolSearchToolResultBlock

When any of these arrived as content_block_start events during streaming, construct_type(type_=ParsedContentBlock, ...) failed discriminated union parsing and silently dropped the block from current_snapshot.content. As a result, get_final_message().content was missing server tool results when client tools ran concurrently with server tools.

Fix

Add all 5 missing types to ParsedContentBlock to match ContentBlock. One file changed.

Tests

Added sync and async regression tests (TestServerToolResultBlocks) with a new fixture that streams a message containing:

  • server_tool_use block
  • client tool_use block (concurrent)
  • web_search_tool_result block
  • code_execution_tool_result block

Both tests assert all 4 blocks are present in get_final_message().content and that all 4 content_block_start events are delivered to the caller.

Test results

2 passed in 1.53s
479 passed, 5 failed (pre-existing test_aws.py failures due to ANTHROPIC_API_KEY in env — identical to existing CI baseline)

Atishay Tiwari 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ServerToolResult not delivered when client tools interrupt the stream (code_execution + client tool concurrency)

1 participant