fix(bedrock): omit, don't rewrite, an unsigned trailing thinking block on Anthropic
Fixes #7908
What
On Anthropic-via-Bedrock with extended thinking, a thinking-only response whose thinking block lost its signature in streaming (the signature delta never arrives; _process_response/streaming leave provider_name=None) used to be re-sent on the output-validation retry rewritten as <thinking> text — the one payload modification the API deterministically rejects with a 400, killing the run with no output, one request later, silently.
Change
In BedrockConverseModel._map_messages, for the latest assistant message on the Anthropic thinking variant, a thinking block with no provider attribution is now omitted with a UserWarning instead of rewritten:
- a turn the omission empties is dropped entirely (the existing
if content:guard), so the retry re-asks the original prompt — the two user turns are folded by the existing merge pass — instead of sending a payload the API can never accept; - older-history thinking keeps the tagged-text rewrite (the API only protects the latest assistant message — pinned by a new test);
- unsigned-reasoning families (DeepSeek R1, Nova) are untouched: their rewrite was never a modification any API checks, so the omission is gated on
bedrock_thinking_variant == 'anthropic', not onbedrock_send_back_thinking_parts(DeepSeek R1 sets the latter but its thinking arrives unsigned by design — pinned by new tests); - foreign-provider thinking parts (
provider_nameset) still take the rewrite even in the trailing position — the API never saw them.
This is the adapter-level boundary from the triage comment: the graph keeps the response + retry; the adapter owes a survivable payload (same invariant as #6139 for OpenAI chat histories), and the omission is now observable, as the issue's direction 3 asked.
Tests
Seven new _map_messages unit tests in tests/models/test_bedrock.py assert the exact wire form: the issue's scenario (assistant turn absent, warning raised, user turns merged), unsigned-trailing-beside-a-tool-call (turn kept minus the block), older-history rewrite, signed trailing sent verbatim as reasoningContent, foreign trailing rewrite, Nova rewrite, DeepSeek R1 rewrite. Full tests/models/test_bedrock.py: 200 passed (the pre-existing DeepSeek VCR test covers the unsigned-reasoning boundary end-to-end as well). ruff check/format and pyright clean.