fix(bedrock): preserve adaptive-thinking signatures in streaming reasoning#1683
Merged
gold-silver-copper merged 1 commit into0xPlaygrounds:mainfrom Apr 28, 2026
Conversation
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.
Closes #1684.
Summary
Streaming counterpart to #1675. The non-streaming
assistant_content.rsempty-text guard fixed in that PR has an analogue instreaming.rs: theContentBlockStophandler skips emittingRawStreamingChoice::Reasoningwheneverreasoning_state.content.is_empty(), even if aSignaturedelta has populatedreasoning_state.signature. Bedrock adaptive thinking can produce exactly that shape —ReasoningContentBlockDelta::Signaturewith no preceding non-emptyTextdelta — and the signature is silently dropped.Symptom
In a multi-turn streaming conversation against
eu.anthropic.claude-opus-4-7(or any Bedrock Anthropic model with adaptive thinking enabled), the consumer never receives aRawStreamingChoice::Reasoning { signature: Some(_), .. }event for signature-only blocks. On the next turn, replaying that conversation back to Bedrock fails with:— the same error that motivated #1675 on the non-streaming path.
Fix
Extracted a
finalize_reasoning(state)helper from the inline emission logic and relaxed the gate so aReasoningchunk is emitted whenever either content or signature is present; both-empty is still skipped.The helper extraction makes the emission decision unit-testable — the original inline form had no driver for the
stream!block. Four cases are now covered:Verification
Confirmed end-to-end against real Bedrock with
eu.anthropic.claude-opus-4-7andthinking={type: adaptive}, output_config={effort: high}:text_len=0with a populated signature is the exact shape that pre-fix would have been dropped at the!content.is_empty()guard.Test plan
cargo test -p rig-bedrock --lib(70 + 4 new tests pass)cargo clippy -p rig-bedrock --tests -- -D warningscargo fmt -p rig-bedrock --checkNotes
mainpost-fix(bedrock): handle adaptive-thinking interactions for prompt caching and reasoning conversion #1675, so this PR contains only the streaming-side change.finalize_reasoningis private to the module.