fix(provider): resolve bedrock compaction failures for Claude models#17043
fix(provider): resolve bedrock compaction failures for Claude models#17043sergical wants to merge 1 commit intoanomalyco:devfrom
Conversation
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
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
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. |
|
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):
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. |
Summary
Fixes three root causes behind Bedrock Claude model compaction failures (#16486, #14332, #15715):
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.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.Auto-detect 1M context from user beta config — Users who configure
anthropicBeta: ["context-1m-2025-08-07"](Bedrock) oranthropic-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-authmodule issue in test env)Closes #16486
Related: #14332, #16356, #15715, #13199