Skip to content

provider: Bedrock non-Anthropic message cleanup and xhigh→max#25189

Closed
jackmazac wants to merge 1 commit intoanomalyco:devfrom
jackmazac:pr/upstream-4-bedrock-transform
Closed

provider: Bedrock non-Anthropic message cleanup and xhigh→max#25189
jackmazac wants to merge 1 commit intoanomalyco:devfrom
jackmazac:pr/upstream-4-bedrock-transform

Conversation

@jackmazac
Copy link
Copy Markdown

Summary

Some Amazon Bedrock models are not the Anthropic Claude adapter: they use different wire shapes. Sending them Anthropic-style extras—reasoning blocks from another stack, or cache breakpoints their stack does not understand—causes failures or empty turns. Separately, Bedrock’s adaptive “extra high” reasoning knob must map to a value the SDK accepts. This PR tightens Bedrock message shaping and variant config for those cases.

Problem (plain language)

  1. Wrong shape for the wrong engine: Assistant messages can still carry reasoning or cache metadata meant for Claude-on-Anthropic. When the active Bedrock model is something else, that metadata should not be forwarded as-is.
  2. Empty assistant turns: After stripping unsupported parts, a message could end up with no content; providers reject empty assistant messages.
  3. Reasoning effort label mismatch: The UI may offer xhigh, but Bedrock’s adaptive config for this path expects max for that tier—sending xhigh literally can break or be ignored.

Technical breakdown

  1. normalizeMessages (Bedrock npm @ai-sdk/amazon-bedrock, API id without anthropic or mistral):
    • Strip cachePoint from providerOptions under bedrock and model.providerID buckets.
    • Remove reasoning / redacted-reasoning parts from assistant array content; if nothing remains, insert a minimal text placeholder.
  2. variants for @ai-sdk/amazon-bedrock adaptive map: maxReasoningEffort: effort === "xhigh" ? "max" : effort, while preserving upstream Opus 4.7 display: "summarized" behavior on the xhigh variant row.

Solution

  • Add a dedicated early branch in normalizeMessages before interleaved handling for non-Anthropic, non-Mistral Bedrock models.
  • Map xhighmax for adaptive reasoningConfig.maxReasoningEffort on Bedrock.
  • Extend transform.test.ts so Bedrock Opus 4.7 xhigh expects max plus display: "summarized".

Files

  • packages/opencode/src/provider/transform.ts
  • packages/opencode/test/provider/transform.test.ts

How to test

From packages/opencode:

bun typecheck
bun test test/provider/transform.test.ts

Merge order

Best reviewed after PR #25186 (catalog 200K / 1M split), since users pick the -1m rows this transform complements. Still compiles independently if merged out of order.

normalizeMessages strips cachePoint and reasoning for amazon-bedrock
models without anthropic/mistral ids; placeholder if assistant empty.
Map adaptive xhigh reasoning effort to max for Bedrock; test expects
max + display summarized for opus 4.7.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

Hey! Your PR title provider: Bedrock non-Anthropic message cleanup and xhigh→max doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label May 1, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

The following comment was made by an LLM, it may be inaccurate:

Based on my search, I found several related PRs that address similar concerns around Bedrock message handling and reasoning effort configuration:

Related PRs

  1. fix: set display 'summarized' for Opus 4.7 on Bedrock #23331 - "fix: set display 'summarized' for Opus 4.7 on Bedrock"

    • Related because it addresses the display: "summarized" behavior mentioned in this PR for the xhigh variant.
  2. provider: split Bedrock Claude into 200K and 1M catalog entries #25186 - "provider: split Bedrock Claude into 200K and 1M catalog entries"

  3. fix(provider): preserve Bedrock Claude reasoning replay #23927 - "fix(provider): preserve Bedrock Claude reasoning replay"

    • Related to Bedrock-specific reasoning handling and message transformation.
  4. fix(provider): preserve assistant message content when reasoning blocks present #21370 - "fix(provider): preserve assistant message content when reasoning blocks present"

    • Addresses similar concerns about preserving assistant message content when reasoning blocks are involved.
  5. fix(provider): skip empty-text filtering for assistant messages in normalizeMessages (#16748) #16750 - "fix(provider): skip empty-text filtering for assistant messages in normalizeMessages"

    • Directly related to the empty assistant message problem this PR addresses.

However, none of these appear to be exact duplicates of the current PR. They address related but distinct issues in the Bedrock provider implementation.

@jackmazac
Copy link
Copy Markdown
Author

Closing to reopen with a linked issue and the repo PR template per CONTRIBUTING.

@jackmazac jackmazac closed this May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs:compliance This means the issue will auto-close after 2 hours. needs:title

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant