fix(epp): stop rejecting Anthropic blocks whose content is an object #3459
All Vouch review confidence checks passed
Residual risk 0.08 = Change Risk (0.41) × (1 − Review Confidence (0.81)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.41 · 167 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.71 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.307
Real PR Conversation Timeline
4 items
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
Approved
Approved these changes.
Thanks @ahg-g for the quick review and merge.
ahg-g
blacksoxx
What type of PR is this?
/kind bug
What this PR does / why we need it:
The Anthropic parser rejects a valid
/v1/messagesrequest that replays a server tool result whosecontentis an object, with a 400:AnthropicContentBlock.Contentwas typedAnthropicContent, which decodes a string or an array. In the Anthropic API the field's shape depends on the block type:| Block |
content||---|---|
|
tool_result,mcp_tool_result| string or array of blocks ||
web_search_tool_resultafter a failed search | object (web_search_tool_result_error) ||
bash_code_execution_tool_result| object (bash_code_execution_result) |Changes, in the shape of #3419:
Contentisjson.RawMessage. A newToolResultContent()decodes it asAnthropicContentfortool_resultblocks only, and the tokenizer'santhropicToolResultContent, the one reader, goes through it.tool_resultno longer fails the request at decode time;ToolResultContent()reports it as empty content. The request body forwarded upstream is unchanged, it is still the original payload.Which issue(s) this PR fixes:
Fixes #3457
Test plan:
requesthandling: aweb_search_tool_resulterror object and abash_code_execution_tool_resultobject decode with their bytes kept;ToolResultContent()for string, array, absent, null and object content and for a non-tool_result block; a malformed block below a tool_result decodes and reads as emptyparsers/anthropic: a request replaying both server tool results parses and keeps the object bytestokenizer: existing tool_result estimate and legacy render tests pass on the raw fieldgo test -raceforrequesthandling,parsers/anthropic,tokenizer,epp/handlers,epp/requestcontrol;go test ./pkg/epp/... ./pkg/common/...;go vet;gofmt;golangci-lint v2.14.0on the changed packagesRelease note:
``
release-note
``The EPP accepts Anthropic Messages requests that replay server tool results whose content is an object (web search errors, code execution results) instead of rejecting them with a 400.