FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Bedrock Claude Opus 4.7 replays thinking blocks through interleaved OpenAI-compatible transform · Issue #23926 · anomalyco/opencode · GitHub

Bedrock Claude Opus 4.7 replays thinking blocks through interleaved OpenAI-compatible transform #23926

Description

Description

Bug Report

Description

When using Claude Opus 4.7 via Amazon Bedrock, OpenCode can replay assistant reasoning/thinking blocks through the interleaved reasoning transform in packages/opencode/src/provider/transform.ts.
That transform is intended for OpenAI-compatible providers (reasoning_content / reasoning_details style fields), but it can also run for Bedrock models if the model catalog marks them as interleaved.
For Bedrock Claude models, this is invalid: native Anthropic/Bedrock thinking blocks must be replayed as content blocks with their original metadata/signature preserved. Rewriting them into providerOptions.openaiCompatible[...] strips the native structure and can cause Bedrock validation failures.

Error

Example failure:

undefined: The model returned the following errors:
{"type":"error","error":{"type":"invalid_request_error","message":"messages.1.content.0.thinking.signature: Field required"}}
``` txt
Root cause
In packages/opencode/src/provider/transform.ts, normalizeMessages() has this path:
```txt
if (typeof model.capabilities.interleaved === "object" && model.capabilities.interleaved.field) {
  // collect reasoning text
  // remove reasoning blocks from content
  // move text to providerOptions.openaiCompatible[field]
}

This path is too broad. It is not restricted to @ai-sdk/openai-compatible, so Bedrock models can be routed through logic that is only valid for OpenAI-compatible providers.
For Anthropic models on Bedrock, reasoning blocks should remain native reasoning/thinking content with provider metadata preserved, not be rewritten into openaiCompatible.reasoning_content.
Why this matters for Opus 4.7
Opus 4.7 uses adaptive thinking and Bedrock expects prior thinking blocks to be replayed unchanged. If OpenCode rewrites them into an OpenAI-compatible shape, the request no longer matches the Bedrock/Anthropic format and signatures can no longer validate correctly.
Proposed fix
Restrict the interleaved rewrite to OpenAI-compatible providers only:

if (
  model.api.npm === "@ai-sdk/openai-compatible" &&
  typeof model.capabilities.interleaved === "object" &&
  model.capabilities.interleaved.field
) {
  ...
}

This keeps the interleaved behavior for providers that actually use reasoning_content / reasoning_details, while preserving native reasoning blocks for Bedrock Claude models.
Related issues / PRs
This appears related in symptom space, but not identical in root cause:

Plugins

oh-my-openagent

OpenCode version

1.14.20

Steps to reproduce

  1. Configure OpenCode to use Amazon Bedrock.

  2. Select Claude Opus 4.7 as the model.

  3. Use a reasoning-heavy variant such as xhigh or max so adaptive thinking is likely to be emitted.

  4. Start a fresh session.

  5. Send a prompt that reliably triggers extended thinking, for example:
    Compare three approaches for migrating a large TypeScript monorepo from one provider SDK to another, including risks, rollout strategy, and rollback plan.

  6. After the assistant responds, send a follow-up in the same session that depends on the previous turn, for example:
    Now turn that into a concrete phased migration plan with checkpoints and failure criteria.

  7. If it does not fail on the first follow-up, continue with 1–2 more follow-ups in the same session so OpenCode replays prior assistant thinking blocks.

  8. Observe the next Bedrock request fail with an error like:
    undefined: The model returned the following errors:
    {"type":"error","error":{"type":"invalid_request_error","message":"messages.1.content.0.thinking.signature: Field required"}}

Screenshot and/or share link

Operating System

Ubuntu 22.04 on WSL

Terminal

bash

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


Back | FazBrowse Home | New Git URL