Skip to content

fix(provider): Anthropic normalize splits tool-call from tool-result causing dangling tool_use error #25774

@codeg-dev

Description

@codeg-dev

Description

In packages/opencode/src/provider/transform.ts, normalizeMessages() splits assistant turns where text trails tool-call blocks for Anthropic / Vertex Anthropic models. The current split filter groups only tool-call parts together and treats tool-result as non-tool content, so an assistant turn shaped like:

[tool-call, tool-result, text]

becomes:

msg A: [tool-result, text]
msg B: [tool-call]

After provider/SDK merge this still presents tool_use blocks without a paired tool_result immediately after, so Anthropic returns:

tool_use ids were found without tool_result blocks immediately after

OpenCode version

1.14.33 (also reproduces against current dev).

Steps to reproduce

  1. Use a Claude / Vertex Anthropic model.
  2. Have an assistant turn whose content ends up shaped like [tool-call, tool-result, text] or [tool-call, text, tool-result] (this can happen during reconstruction or when tool-result is co-located with the originating tool-call).
  3. Send another user turn so the assistant turn is replayed in normalizeMessages().
  4. The provider rejects the request with tool_use ids were found without tool_result blocks immediately after.

The fix is small: keep tool-call and tool-result paired during the split (treat both as "tool" parts).

Operating System

macOS 26.0.1 / 25.4.0 (Apple Silicon).

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions