GgbondHi6930 on X: a Smart group of DeepSeek and a Claude API key. A
conversation ran on DeepSeek at max effort; with DeepSeek unticked its
next turn went to Claude and failed "signature in thinking". A new
conversation worked.
Cause: DeepSeek's Anthropic endpoint signs each thinking block with its
reply's id, a UUID (checked against api.deepseek.com/anthropic). The
agent keeps those blocks and sends them back, so the first Claude turn
carries them, and Claude refuses the request, 400 "messages.1.content.0:
Invalid `signature` in `thinking` block" (real reply through
OpenRouter's Anthropic route, req_011CgfP4zyRcUhPiTg5sLpoe). Until now
magpie mended this only after the refusal, in forward's bound-thinking
retry. That needs the refusal to reach forward as a 400/422 with
Claude's wording, and it spends a request. With fakes that answer as
Claude does, main recovers through it, on Messages (whole and streamed)
and on Codex's Responses. So the reporter's failure is where that retry
can't read the refusal. A relay's status or wording is the likely case;
it is not reproduced exactly.
Change: forwardOnce, which every route to an Anthropic upstream passes
(relayed, translated Chat/Responses, group fallback and Smart routing,
a plugin's fetch, count_tokens), now calls withoutForeignThinking. For
an upstream serving Claude (api.anthropic.com, or a claude- model name)
and not DeepSeek, it leaves out each thinking block whose signature is a
UUID. Those blocks never reach Claude, and refuseBoundThinking reads a
refusal's indices against that same body. These go byte for byte:
- Claude's own signatures (base64; 3,000 of Claude Code's own were
checked, all base64 and 800+ characters);
- unsigned blocks (Claude took one in a real request);
- redacted_thinking;
- other vendors' signatures, which the retry still mends.
DeepSeek's endpoint and every other upstream get the body unchanged.
Tests (thinking_switch_test.go):
- TestDeepSeekThinkingThenClaude: the reporter's case, whole and
streamed. 3 DeepSeek tool turns, then DeepSeek unticked and 3 Claude
turns. Claude refuses nothing and gets its own blocks back as signed.
With DeepSeek ticked again and Claude unticked, DeepSeek is sent every
block, its own and Claude's.
- TestDeepSeekThinkingThenClaudeResponses: the same through Codex's
/v1/responses.
- TestWithoutForeignThinking: Claude, DeepSeek and Kimi upstreams.
Run on mote (mote-run):
- gofmt -l, go vet ./..., GOOS=linux go vet -tags nogui ./... and
GOOS=windows go vet ./...: clean, at cfa9a6987 (base 17d2ef10f).
- go test -timeout 45m ./internal/gateway/... ./internal/provider/...
at cfa9a6987: provider ok. Gateway ok except
TestCodexPoolSaysTheClientsVersion, which is #4807 (passes alone 3/3;
commented there). It was fixed on main by 17f2387e1, which this commit
is rebased onto.
- After the rebase onto 17f2387e1, which touched none of these files'
code: -run 'Thinking|Bound|TestCodexPoolSaysTheClientsVersion' ok.
Broken by hand: with withoutForeignThinking returning the body as it
came, all three tests go red ("Claude refused 1 of its 4 requests",
"Claude refused 1 of its 3 requests", "message 1 = [thinking,text]").
Not tried:
- a real Claude account through magpie; no Anthropic key was usable
here, and the relay accounts found (aihubmix, yylx) are out of credit;
- the reporter's own relay;
- Chat Completions clients, which carry no signatures;
- Kimi, GLM and MiniMax signatures, which the refusal path still mends.