Gemini 3's thought signature rides in the call id magpie gives the
client (<id>__ts__<base64url>). A client that caps ids (40 characters
in the report) sends back part of it, and unpadded base64 only rejects
a length that is 1 mod 4, so at three of four lengths unsignedID decoded
the leftover into a partial signature. Gemini answered it with 400
"Corrupted thought signature" instead of the call going with
skip_thought_signature_validator.
The mark now carries the signature's length: <id>__ts<n>__<sig> and
<id>__tsr<n>__<text>. unsignedID reads the first mark; a length that
doesn't match what is left, or a mark cut inside its digits, is no
signature, and the id stays as the client sent it. Ids from earlier
versions (__ts__, __tsr__, no length) are still read as before.
Every path that takes a signature off an id goes through unsignedID:
the Chat relay (chatCallSignatures), unsignCalls for translated
requests (Chat, Gemini, Code Assist/Antigravity, Vertex), and
geminiParts. The anthropic mp_ id wrapper already checks its round
trip, so a cut one is left alone.
Tests: realistic ids (Gemini's function-call-N and magpie's
call_<newID>, with vertexCallSig, a 315-byte signature as measured in
the report, and a non-canonical one) cut at every length carry no
signature; through chatCallSignatures, buildChat, buildCodeAssist and
geminiParts each cut sends skip or nothing; the reporter's 40-character
cut through the gateway reaches Gemini as skip; old-format ids still
read. All four new tests fail on the old code.
Run: go test -tags nogui ./... (full suite, under the queue lock),
gofmt -l, GOOS=linux and GOOS=windows go vet -tags nogui
./internal/gateway.
ump45nose posted the same root cause and an equivalent fix on #1536
(fork commit 415e45f2, `__tsn__<len>_` marks). Its handling matched
this one case for case; the two literal old-form ids from its test are
taken into TestOldSignedIDsStillRead.
Co-authored-by: ump45nose <52391318+ump45nose@users.noreply.github.com>