Skip to content

fix(provider): resolve bedrock compaction failures for Claude models#17043

Closed
sergical wants to merge 1 commit intoanomalyco:devfrom
sergical:fix/bedrock-compaction-failures
Closed

fix(provider): resolve bedrock compaction failures for Claude models#17043
sergical wants to merge 1 commit intoanomalyco:devfrom
sergical:fix/bedrock-compaction-failures

Conversation

@sergical
Copy link
Contributor

Summary

Fixes three root causes behind Bedrock Claude model compaction failures (#16486, #14332, #15715):

  1. Empty content filtering for all Claude providers — The filter that strips empty text/reasoning parts only applied to @ai-sdk/anthropic. Bedrock and Vertex host the same Claude models with the same validation rules but weren't covered, causing "content field is empty" errors during compaction.

  2. Strip thinking block metadata during compaction — When compaction uses the same model as the conversation, providerMetadata (thinking block signatures) from old assistant messages were included. The Claude API validates these signatures match exactly, but pruned tool outputs change the surrounding context, causing "thinking or redacted_thinking blocks cannot be modified" rejections.

  3. Auto-detect 1M context from user beta config — Users who configure anthropicBeta: ["context-1m-2025-08-07"] (Bedrock) or anthropic-beta: "context-1m-..." header (Anthropic direct) now get their context limit auto-bumped to 1M. Previously models.dev reported 200k and compaction triggered too early.

Test plan

  • bun test test/provider/transform.test.ts — 89 tests pass (2 new for Bedrock/Vertex empty content filtering)
  • bun test test/session/message-v2.test.ts — 21 tests pass (2 new for stripMetadata behavior)
  • test/provider/provider.test.ts — 3 new tests for 1M context auto-detection (blocked by pre-existing @gitlab/opencode-gitlab-auth module issue in test env)
  • Typecheck clean (only pre-existing ACP/GitLab module errors)

Closes #16486
Related: #14332, #16356, #15715, #13199

Three fixes for Bedrock (and Anthropic direct) Claude model compaction:

1. Extend empty content filtering to all Claude-hosting providers. The
   filter previously only applied to @ai-sdk/anthropic but Bedrock and
   Vertex host the same models with the same validation rules.

2. Strip providerMetadata from reasoning parts during compaction. Thinking
   block signatures from old assistant messages caused the API to reject
   compaction requests with 'thinking blocks cannot be modified'.

3. Auto-detect 1M context window when user configures the context-1m beta
   flag (via anthropicBeta option on Bedrock or anthropic-beta header on
   Anthropic direct). Without this, models.dev reports 200k and compaction
   triggers too early for 1M users.

Closes anomalyco#16486
@github-actions github-actions bot added contributor needs:compliance This means the issue will auto-close after 2 hours. labels Mar 11, 2026
@github-actions
Copy link
Contributor

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
Copy link
Contributor

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

Based on my search, I found several related PRs that address similar issues but are distinct from the current PR #17043:

Related PRs (not duplicates):

  1. fix(provider): skip empty-text filtering for assistant messages in normalizeMessages (#16748) #16750 - fix(provider): skip empty-text filtering for assistant messages in normalizeMessages

    • Related to empty content filtering, but specific to assistant messages in normalizeMessages
  2. fix: filter empty content blocks for Bedrock provider #14586 - fix: filter empty content blocks for Bedrock provider

    • Earlier attempt to fix Bedrock empty content filtering
  3. fix: preserve thinking block signatures and fix compaction headroom asymmetry #14393 - fix: preserve thinking block signatures and fix compaction headroom asymmetry

  4. fix(provider): preserve redacted_thinking blocks and fix signature validation #12131 - fix(provider): preserve redacted_thinking blocks and fix signature validation

    • Earlier work on thinking block preservation
  5. feat(provider): add adaptive thinking and 1M context support for Claude Opus 4.6 #12342 - feat(provider): add adaptive thinking and 1M context support for Claude Opus 4.6

    • Related to 1M context support feature

These are all related PRs addressing similar issues, but PR #17043 appears to be the comprehensive fix combining all three root causes in a single PR. No exact duplicates of PR #17043 were found.

@sergical sergical closed this Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Opus 4.6 with beta string "anthropicBeta": ["context-1m-2025-08-07"] stopped working in AWS Bedrock

1 participant