fix(provider): port upstream Bedrock unsigned reasoning filter (anomalyco/opencode#45769)
Issue for this PR
Closes #1659
Type of change
- Bug fix
- New feature
- Refactor / code improvement
- Documentation
What does this PR do?
Ports anomalyco/opencode#45769 (filter unreplayable Bedrock reasoning before caching).
@ai-sdk/amazon-bedrock (4.0.112 here) only replays reasoning that has signature or redactedData. It drops any other reasoning when it converts messages. The fork's normalizeMessages kept Bedrock reasoning whenever its text was non-empty. Suppose an interrupted or unsigned turn leaves an assistant message with only Partial thought reasoning and an empty text part. That message survived the filter, and applyCaching added a cachePoint to it. The SDK then sent an assistant message with no content or only a cache point, Bedrock rejected the request, and the next turn in the session failed.
On @ai-sdk/amazon-bedrock, the filter now keeps only reasoning whose metadata has signature, redactedContent or redactedData. It reads that metadata from the stored provider namespace (providerOptions[model.providerID], which message() later remaps onto bedrock) and falls back to bedrock. Because this runs before applyCaching, a message left empty is removed, not cached. Text and tool calls next to unsigned reasoning are kept. Behavior for @ai-sdk/anthropic is unchanged. The change is wrapped in altimate_change ... upstream_fix: markers inside the existing fork block.
How did you verify your code works?
- Ported the upstream tests to
packages/opencode/test/provider/transform.test.ts("Bedrock reasoning replay"). Two of them run the transformed messages throughcreateAmazonBedrockwith a mockedfetchand assert the exact Converse request body, with and without cache points. The others cover signed or redacted reasoning across thebedrock,amazon-bedrockand custom provider namespaces, the stored-namespace precedence, kept text and tool calls, and unchanged behavior for non-Bedrock providers. 11 of the new tests fail onmain. With this change, all 391 tests in the file pass. bun run typecheck(tsgo) inpackages/opencodepasses, and so does the pre-pushbun typecheck.bun run script/upstream/analyze.ts --markers --base origin/main --strict: ok.
Cost side effects
None. This only removes message parts that the SDK already dropped.
Screenshots / recordings
Not a UI change.
Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR
- I checked for cost side effects (model calls, queries or cloud resources that grow with user data) and described them, or wrote "none"
Tracked in #1478. Related Bedrock work: #1425 (stream decoding and cached-token billing; it doesn't touch transform.ts).
Summary by cubic
Ports the upstream Bedrock unsigned reasoning filter so interrupted or unsigned reasoning no longer leaves empty or cache-only messages that Bedrock rejects.
- Applies only to
@ai-sdk/amazon-bedrock; Anthropic behavior is unchanged. - Reasoning without
signature,redactedContent, orredactedDatais removed before cache points are assigned, so empty messages are dropped instead of cached. - Adds ported upstream tests covering signed/redacted reasoning, namespace precedence, and provider behavior.