GeezerVison is showing github.com — fix(provider): port upstream Bedrock unsigned reasoning filter (anomalyco/opencode#45769) by devin-ai-integration[bot] · Pull Request #1661 · AltimateAI/altimate-code
Conversation
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 through createAmazonBedrock with a mocked fetch and assert the exact Converse request body, with and without cache points. The others cover signed or redacted reasoning across the bedrock, amazon-bedrock and 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 on main. With this change, all 391 tests in the file pass.
bun run typecheck (tsgo) in packages/opencode passes, and so does the pre-push bun 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).
Written by Devin
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, or redactedData is 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.
Written for commit d5f9469. Summary will update on new commits.

Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…lyco/opencode#45769)
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Important
Review skipped
Bot user detected.
To trigger a single review, invoke the @coderabbitai review command.
Run configuration
-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
20e48c87-9d26-46c7-a8e1-7c8788cde85f
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Share
-
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖 Code Review — OpenCodeReview (Gemini) — 2 finding(s)
- 2 anchored to a line (posted inline when the comment stream is on)
- 0 without a line anchor
All findings (full text)
1. packages/opencode/src/provider/transform.ts (L144)
[🔵 LOW] According to the review checklist, avoid using the any type without providing an explanatory comment. If the exact type is unknown, consider using unknown (e.g., Record<string, unknown>), or add a comment explaining why any is necessary.
Suggested change:
const options = part.providerOptions as Record<string, unknown> | undefined
2. packages/opencode/src/provider/transform.ts (L146-L148)
[🔵 LOW] The review checklist strictly prohibits the use of non-strict equality operators (!=). Please replace != null with strict inequality checks (!== null and/or !== undefined).
Suggested change:
return (
(metadata?.signature !== undefined && metadata?.signature !== null) ||
(metadata?.redactedContent !== undefined && metadata?.redactedContent !== null) ||
(metadata?.redactedData !== undefined && metadata?.redactedData !== null)
)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
// The Bedrock SDK only replays signed or redacted reasoning. Unsigned reasoning must go
|
|
|
// before cache points are assigned, or it can leave an empty or cache-point-only message.
|
|
|
if (model.api.npm === "@ai-sdk/amazon-bedrock") {
|
|
|
const options = part.providerOptions as Record<string, any> | undefined
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[🔵 LOW] According to the review checklist, avoid using the any type without providing an explanatory comment. If the exact type is unknown, consider using unknown (e.g., Record<string, unknown>), or add a comment explaining why any is necessary.
Suggested change:
|
const options = part.providerOptions as Record<string, any> | undefined |
|
const options = part.providerOptions as Record<string, unknown> | undefined |
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Comment on lines
+146
to
+148
|
|
return (
|
|
|
metadata?.signature != null || metadata?.redactedContent != null || metadata?.redactedData != null
|
|
|
)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[🔵 LOW] The review checklist strictly prohibits the use of non-strict equality operators (!=). Please replace != null with strict inequality checks (!== null and/or !== undefined).
Suggested change:
|
return ( |
|
metadata?.signature != null || metadata?.redactedContent != null || metadata?.redactedData != null |
|
) |
|
return ( |
|
(metadata?.signature !== undefined && metadata?.signature !== null) || |
|
(metadata?.redactedContent !== undefined && metadata?.redactedContent !== null) || |
|
(metadata?.redactedData !== undefined && metadata?.redactedData !== null) |
|
) |
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
🤖 Code Review — OpenCodeReview (Gemini) — No Issues Found
No supported files changed.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This branch has not been deployed
No deployments
Reviewers
At least 1 approving review is required to merge this pull request.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|