← Back to Pull requests

fix(epp): stop rejecting Anthropic blocks whose content is an object #3459

Merged
blacksoxx merged 6 files (167 lines) on Oct 15, 2026 18:53 UTC
View on GitHub
blacksoxx blacksoxx commented on Oct 15, 2026 16:44 UTC
Author

What type of PR is this?

/kind bug

What this PR does / why we need it:

The Anthropic parser rejects a valid /v1/messages request that replays a server tool result whose content is an object, with a 400:

error parsing messages request: anthropic content: must be a string or an array of content blocks

AnthropicContentBlock.Content was typed AnthropicContent, 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_result after 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:

  • Content is json.RawMessage. A new ToolResultContent() decodes it as AnthropicContent for tool_result blocks only, and the tokenizer's anthropicToolResultContent, the one reader, goes through it.

  • A malformed block below a tool_result no 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: a web_search_tool_result error object and a bash_code_execution_tool_result object 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 empty

  • parsers/anthropic: a request replaying both server tool results parses and keeps the object bytes

  • tokenizer: existing tool_result estimate and legacy render tests pass on the raw field

  • go test -race for requesthandling, parsers/anthropic, tokenizer, epp/handlers, epp/requestcontrol; go test ./pkg/epp/... ./pkg/common/...; go vet; gofmt; golangci-lint v2.14.0 on the changed packages
  • Release 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.
    ``

    Diff: 167 lines (+141 / -26) across 6 files Reviewer: ahg-g Review duration: 128m
    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
    0.41
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.71 · 1 substantive comment(s)
    0.71
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    81%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Oct 15, 2026 16:44 UTC
    Reviewer

    Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

    ahg-g ahg-g approved these changes on Oct 15, 2026 18:14 UTC
    Approved Reviewer

    Approved these changes.

    blacksoxx blacksoxx commented on Oct 16, 2026 21:43 UTC
    Author

    Thanks @ahg-g for the quick review and merge.

    Reviewers
    Assignees
    blacksoxx blacksoxx
    Labels
    risk: low confidence: 81.1% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 41.0% (MEDIUM) · Higher = larger blast radius
    41.0%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 81.1% · Lower = rushed or shallow review
    81.1%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 7.8% · Safe to merge
    7.8%