Anthropic wire: interrupted-turn replay drops thinking signature, causes hard 400 "Invalid signature in thinking block"
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 52/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- typescript
Direzione di ricerca
Start by reading the streaming consumers, finalizeReasoning(), toWireMessages(), and assistantParts() described in the issue, then compare how the gateway path handles thinking metadata with consumeFullStream. Reproduce an interrupted turn and inspect the replayed assistant message. Done means the replay preserves the thinking signature and redacted data, and the interrupted request no longer fails with the reported 400.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
Anthropic-wire sessions fail with a hard 400 whenever the user sends a new message while the model is still streaming. The error is unavoidable in that scenario and the only recovery is continue or restarting the session:
Error: 400 Invalid_request_error Upstream request failed: [invalid_request_error]
messages.1.content.0: Invalid signature in thinking block. The block is bound to
a different conversation. Remove the block, or set
`thinking.block_binding.prefix_mismatch_behavior` ...
Trace ID: 907c498bc0028b25be7ae3dc058394f7
Environment
- Command Code 1.87.3 (
dist/cli.mjs) - Linux
- Custom BYOK provider in
~/.commandcode/providers.jsonwith"api": "anthropic-messages" - Model:
claude-haiku-5-5
Steps to reproduce
-
Configure a BYOK provider using the Anthropic Messages wire:
{ "provider": { "opencode": { "baseURL": "https://opencode.ai/inference/go/anthropic", "models": { "claude-haiku-5-5": { "api": "anthropic-messages" } } } } } -
Start a session on that model and let it produce a turn containing real thinking.
-
While the turn is still streaming, type and submit a new message.
-
The request fails with the 400 above, every time.
Root cause (located in dist/cli.mjs, v1.87.3)
Anthropic thinking blocks carry a signature that is bound to one specific assistant prefix. Command Code has two streaming consumers and only one of them round-trips that signature:
consumeFullStream(AI SDK path, used byrunAiSdkStreamfor custom providers):finalizeReasoningpushes{type:"thinking", thinking:c, signature:u}whereucomes fromreadReasoningMetadata()— the real signature is preserved and replayed. This path works.consumeStream(Command Code gateway/alpha/generatepath):finalizeReasoninghardcodes{type:"thinking", thinking:u, signature:""}. AdditionallytoWireMessages()serializes the thinking block as only{type:"reasoning", text:n.thinking}— thesignatureandredactedDatafields are dropped entirely, so the gateway never receives them.
When a turn is interrupted mid-stream, withResumedAssistantTurn() rebuilds the partial assistant turn via assistantParts(). That helper only emits a reasoning part when r.signature || r.redactedData is truthy. On the gateway path the signature is always "", so the replayed assistant turn goes out with a thinking block that has no signature (or an empty one). The upstream rejects it as "bound to a different conversation".
Verification performed
I ran a local fake Anthropic endpoint and captured the actual request bodies with cmd -p --resume:
- Plain
--resumecontinuation on a customanthropic-messagesprovider: the 64-character signature is fully replayed (messages[1]thinking block carries it), and the call succeeds. So ordinary multi-turn history is fine. - The failure is specific to the interrupted-turn replay / gateway path, where the signature is lost as described above.
This confirms the defect is in the interrupted-replay serialization, not in the BYOK provider, the proxy, or normal history handling.
Relationship to existing issues
This looks like the same class of defect as #877 and #887 (BYOK thinking/reasoning content dropped from replayed history). The fix referenced in #877 (PR #5283) does not appear to be present in the published 1.87.3 build — toWireMessages() still omits signature completely.
Note that @ai-sdk/anthropic 3.0.135 (already a dependency of 1.87.3) supports the escape hatch:
"thinking": { "blockBinding": { "prefixMismatchBehavior": "drop_block" } }
which automatically adds the thinking-binding-controls-2026-08-01 beta and makes the upstream drop a mismatched block instead of erroring. Command Code's thinkingHook() never sets this, so the option is currently unreachable from the client.
Expected behavior
Either:
- Preserve and replay
signature/redactedDataon theconsumeStreamgateway path (match whatconsumeFullStreamalready does), or - Set
thinking.blockBinding.prefixMismatchBehavior: "drop_block"for Anthropic-wire models so a stale signature degrades gracefully instead of producing a hard 400.
Option 1 is the correct fix; option 2 would at least stop the session from dying.
Workaround for affected users
- Do not send messages while a turn is still streaming; wait for it to finish.
- If you must interrupt, start a fresh process with
cmd -p "..." --resume <sessionId>, which takes the signature-preserving path.
- Lingua principale
- Nessun dato sulla lingua
- Stelle
- 4.2k
- Fork
- 377
- Merge medio
- 1g 17m
- PR unite (30g)
- 7
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di CommandCodeAI/command-code
-
Provider /v1/messages rejects role:"system" inside messages[] — Claude Code ≥ 2.1.154 incompatibleAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
CommandCodeAI/command-code#1085 ·
I maintainer di solito rispondono entro 1 giorno
-
Feature request: auto-reconnect remote control (/rc) after restartForse già presa @aliarain l’ha presa 20 giorni fa. Apertap2
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
CommandCodeAI/command-code#992 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
CommandCodeAI/command-code#933 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
CommandCodeAI/command-code#855 ·
I maintainer di solito rispondono entro 1 giorno
-
grep tool passes empty file type to ripgrepForse già presa @ahmadbilaldev l’ha presa 19 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
CommandCodeAI/command-code#655 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di CommandCodeAI/command-code
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
UKGovernmentBEIS/inspect_ai#6512 ·
I maintainer di solito rispondono entro 1 giorno
-
area/c++ area/core kind/bug-report
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
tensorflow/quantum#1140 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 68/100
Kav-K/GPTDiscord#501 ·
I maintainer di solito rispondono entro 1 giorno