fix(amazon-bedrock): do not replay unsigned reasoning content in multi-turn messages#14724
Closed
KiraPC wants to merge 1 commit into
Closed
fix(amazon-bedrock): do not replay unsigned reasoning content in multi-turn messages#14724KiraPC wants to merge 1 commit into
KiraPC wants to merge 1 commit into
Conversation
…i-turn messages Remove the else branch in convertToBedrockChatMessages that replayed unsigned reasoning (no signature, no redactedData) as reasoningContent blocks. This was inadvertently introduced in vercel#13972 when the outer if (reasoningMetadata != null) guard was replaced with optional chaining. The only case reaching this branch was OpenAI models with extended thinking on Bedrock, which produce reasoningContent without a signature. Replaying it caused the model to leak raw <reasoning> tags into the visible text response. Signed (Anthropic) and redacted reasoning are unaffected.
Collaborator
|
signed github commits are needed for community PRs |
Collaborator
|
continued in #15181; will add you as a co-author |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
PR #13972 fixed a bug where
trimIfLast()invalidated Anthropic reasoning signatures by trimming trailing whitespace. During that refactoring, the code structure inconvert-to-bedrock-chat-messages.tschanged from:to:
The outer
if (reasoningMetadata != null)guard was removed and replaced with optional chaining. This inadvertently introduced anelsecatch-all that replays unsigned reasoning (reasoning parts with noproviderMetadata) asreasoningContentblocks — a case that was previously silently dropped.The PR #13972 commit message states: "reasoning blocks without a signature still get trimmed as before", but Anthropic models always include a signature. The only case reaching the
elsebranch is unsigned reasoning from non-Anthropic models (e.g., OpenAI extended thinking on Bedrock), which should not be replayed.Summary
elsecatch-all branch in thereasoningcase ofconvertToBedrockChatMessagessignatureorredactedDataare now silently dropped (restoring pre-fix(amazon-bedrock): preserve reasoning text when signature is present #13972 behavior for this specific case)Why the
elsebranch is unnecessarysignature→ handled by theifbranchredactedData→ handled by theelse ifbranch<reasoning>tags into the visible text responseManual Verification
Tested against real Bedrock models with a multi-turn agent + tool-use scenario (non-streaming
generateText):openai.gpt-oss-120b-1:0<reasoning>tags (33-100% of runs)us.anthropic.claude-sonnet-4-20250514-v1:0moonshotai.kimi-k2.5amazon.nova-pro-v1:0Checklist
pnpm changesetin the project root)Related Issues
<reasoning>tags leaked into text response for OpenAI models on Bedrock during multi-turn tool use #14720