Repository navigation
fix(amazon-bedrock): long Claude sessions get turns rejected with "thinking block bound to a different conversation" - #208704
Conversation
…e requests Bedrock Converse adaptive Claude requests now carry thinking.block_binding drop_block and the thinking-binding-controls-2026-08-01 beta through the shared applyAnthropicThinkingBindingControls helper, so replayed thinking bound to an older prefix is dropped server-side instead of rejecting the turn and stripping all thinking. GovCloud keeps rejection recovery, matching its display omission.
|
🦞👀 ClawSweeper review completeClawSweeper finished reviewing this revision. |
|
Observed proof (isolated built Gateways, local Bedrock Converse and api.anthropic.com stand-ins, no real credentials): |
|
Same session proof on the exact head cf7c776 (built Gateway, local Converse stand-in): |
|
Landed in e1945e6. Thanks @michaeljgood71 for the report and the rejection counts. On Amazon Bedrock, Claude models with adaptive thinking now send Anthropic's thinking-binding controls (the |
…inking block bound to a different conversation" (openclaw#208704) Root cause: `extensions/amazon-bedrock/stream.runtime.ts:1104` (`:1155` in 2026.11.10) builds adaptive Claude thinking for Bedrock Converse without `thinking.block_binding` or the `thinking-binding-controls-2026-08-01` beta, which the direct Anthropic route adds through the shared `applyAnthropicThinkingBindingControls`. So any replayed thinking block whose earlier history changed is rejected instead of dropped. Fixes openclaw#208675. Thanks @michaeljgood71 for the report, the boto3 check and the patch that pointed straight at the fix. ## What Problem This Solves Fixes: long Bedrock Claude sessions with adaptive thinking get the first request of a turn rejected ("Invalid `signature` in `thinking` block. The block is bound to a different conversation") whenever earlier history changed, for example after cache-TTL pruning, compaction or a model switch. OpenClaw then retries without thinking and drops the session's earlier reasoning. ## User Impact Bedrock Claude requests with adaptive thinking now carry the same thinking-binding controls as direct Anthropic API-key requests. Bedrock drops only the stale thinking blocks, the turn succeeds on the first request, and the rest of the reasoning stays in the session. Budget-based Bedrock thinking, GovCloud (which already omits `thinking.display` for its older schema), and the direct Anthropic request are unchanged. ## Why This Change Was Made openclaw#136782 added the controls for direct API-key requests only and left Bedrock on reject-and-retry. The reporter showed Bedrock Converse accepts both controls and drops the stale block. The Bedrock request builder now calls the shared helper on its adaptive branch, so it follows the same rule (adaptive thinking only) and the same beta value, sent as Converse `anthropic_beta`. The helper is re-exported from the existing private-local `provider-stream-shared` SDK seam; no new helper or policy copy. Docs updated where they listed Bedrock as excluded. Not covered: openclaw#198838 (custom provider ids on api.anthropic.com). Its cause is the separate direct-route gate `isDirectAnthropicModel` requiring provider id `anthropic`, which this Bedrock path never goes through. ## Evidence Isolated built Gateway, real `openclaw agent` turns in one session, `au.anthropic.claude-sonnet-5-5` on `amazon-bedrock` pointed at a local Converse stand-in. The stand-in signs each thinking block over the exact request prefix and rejects a replayed block whose prefix changed with Bedrock's ValidationException unless both `drop_block` and the beta are present. Turn 1 reads four files, turns 2-4 are plain, then the `contextPruning: cache-ttl` TTL expires and turn 5 trims turn 1's tool results (the reporter's setting), turn 6 is plain. Two runs per side, identical: - main (8e38da2): turn 5 and turn 6 each rejected once (400), 4 `[session-recovery]` lines (`retrying once without thinking blocks`, `stripped thinking blocks ... repaired=5`, `unable to repair rejected thinking replay`), later requests replay 0 thinking blocks. - this branch: 0 rejected requests, 0 `[session-recovery]` lines; turn 5 replays 5 blocks (4 stale dropped by the stand-in, 1 kept), turn 6 replays 6. Controls: a Bedrock model without adaptive thinking (Haiku 4.5, budget thinking) sends identical requests on both builds (9/9 after normalizing temp paths and timestamps). The bundled `anthropic` provider, through a local TLS stand-in for api.anthropic.com, sends byte-identical requests and `anthropic-beta` headers on both builds (4/4); built `packages/ai/dist` is identical. Regression: the Bedrock request-composition table fails on main (8 cases, no `block_binding`/`anthropic_beta`) and passes here; GovCloud adaptive and budget rows assert no controls. `agent-tools.prefix-stability`, the Anthropic binding transport parity test and the Bedrock stream, replay and plugin tests pass. Observed proof lines: openclaw#208704 (comment) Merge danger: two-way door. A revert restores the old request shape; nothing is stored or migrated. Blast radius: Bedrock Claude requests with adaptive thinking outside GovCloud. If a Bedrock region rejected the controls, those requests would fail rather than fall back; the reporter's boto3 Converse checks on Bedrock accepted them. Co-authored-by: Ayaan Zaidi <[email protected]>
Root cause:
extensions/amazon-bedrock/stream.runtime.ts:1104(:1155in 2026.11.10) builds adaptive Claude thinking for Bedrock Converse withoutthinking.block_bindingor thethinking-binding-controls-2026-08-01beta, which the direct Anthropic route adds through the sharedapplyAnthropicThinkingBindingControls. So any replayed thinking block whose earlier history changed is rejected instead of dropped.Fixes #208675. Thanks @michaeljgood71 for the report, the boto3 check and the patch that pointed straight at the fix.
What Problem This Solves
Fixes: long Bedrock Claude sessions with adaptive thinking get the first request of a turn rejected ("Invalid
signatureinthinkingblock. The block is bound to a different conversation") whenever earlier history changed, for example after cache-TTL pruning, compaction or a model switch. OpenClaw then retries without thinking and drops the session's earlier reasoning.User Impact
Bedrock Claude requests with adaptive thinking now carry the same thinking-binding controls as direct Anthropic API-key requests. Bedrock drops only the stale thinking blocks, the turn succeeds on the first request, and the rest of the reasoning stays in the session. Budget-based Bedrock thinking, GovCloud (which already omits
thinking.displayfor its older schema), and the direct Anthropic request are unchanged.Why This Change Was Made
#136782 added the controls for direct API-key requests only and left Bedrock on reject-and-retry. The reporter showed Bedrock Converse accepts both controls and drops the stale block. The Bedrock request builder now calls the shared helper on its adaptive branch, so it follows the same rule (adaptive thinking only) and the same beta value, sent as Converse
anthropic_beta. The helper is re-exported from the existing private-localprovider-stream-sharedSDK seam; no new helper or policy copy. Docs updated where they listed Bedrock as excluded.Not covered: #198838 (custom provider ids on api.anthropic.com). Its cause is the separate direct-route gate
isDirectAnthropicModelrequiring provider idanthropic, which this Bedrock path never goes through.Evidence
Isolated built Gateway, real
openclaw agentturns in one session,au.anthropic.claude-sonnet-5-5onamazon-bedrockpointed at a local Converse stand-in. The stand-in signs each thinking block over the exact request prefix and rejects a replayed block whose prefix changed with Bedrock's ValidationException unless bothdrop_blockand the beta are present. Turn 1 reads four files, turns 2-4 are plain, then thecontextPruning: cache-ttlTTL expires and turn 5 trims turn 1's tool results (the reporter's setting), turn 6 is plain. Two runs per side, identical:[session-recovery]lines (retrying once without thinking blocks,stripped thinking blocks ... repaired=5,unable to repair rejected thinking replay), later requests replay 0 thinking blocks.[session-recovery]lines; turn 5 replays 5 blocks (4 stale dropped by the stand-in, 1 kept), turn 6 replays 6.Controls: a Bedrock model without adaptive thinking (Haiku 4.5, budget thinking) sends identical requests on both builds (9/9 after normalizing temp paths and timestamps). The bundled
anthropicprovider, through a local TLS stand-in for api.anthropic.com, sends byte-identical requests andanthropic-betaheaders on both builds (4/4); builtpackages/ai/distis identical. Regression: the Bedrock request-composition table fails on main (8 cases, noblock_binding/anthropic_beta) and passes here; GovCloud adaptive and budget rows assert no controls.agent-tools.prefix-stability, the Anthropic binding transport parity test and the Bedrock stream, replay and plugin tests pass.Observed proof lines: #208704 (comment)
Merge danger: two-way door. A revert restores the old request shape; nothing is stored or migrated. Blast radius: Bedrock Claude requests with adaptive thinking outside GovCloud. If a Bedrock region rejected the controls, those requests would fail rather than fall back; the reporter's boto3 Converse checks on Bedrock accepted them.