Repository navigation
Keep Gemini thought signatures that sit on functionCall parts - #315
Merged
Merged
Conversation
…l parts Gemini with thinking enabled puts a turn's thought signature on the first functionCall part rather than on the thought text. The Gemini decoders only read `thoughtSignature` from `thought: true` parts, so a signature on a call was lost in the client's request history, in whole upstream responses and in upstream streams; on the way back the functionCall always got the `skip_thought_signature_validator` placeholder, and the conversation lost its reasoning continuity. The IR gets no new field: a signature on a functionCall part is represented as a Google-signed Thinking block with empty text placed immediately before the ToolCall it belongs to (`gemini::request:: call_signature` documents the shape). Other clients already carry such a block with the `tw1.g.` scheme and hand it back on the next turn, and the Gemini encoder recognises the shape and writes the signature on the functionCall part again, using the placeholder only when the call has no real signature. The placeholder itself is not read back as a signature, and adjacent thought parts without a signature are merged into the signed one so the signature covers the whole text. When the client is Gemini and the gateway streams a reply, a thought part's text and signature are emitted in the same part (the writer holds back one text delta per thinking block), and a function call's signature is emitted on the functionCall part. On same-format passthrough a carried signature on a functionCall part is replaced by the placeholder rather than removing the part. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Gemini with thinking enabled puts a turn's thought signature on the first
functionCallpart, not on the thought text. The Gemini decoders only readthoughtSignaturefromthought: trueparts, so a signature on a call was dropped in three places (the client's request history, whole upstream responses, upstream streams), and on the way back to Gemini the call always got theskip_thought_signature_validatorplaceholder.gemini/request.rs,gemini/response.rs,gemini/stream.rs): athoughtSignatureon afunctionCallpart becomes a Google-signed Thinking block with empty text placed immediately before the ToolCall it belongs to. No new IR field: other clients already carry such a block with thetw1.g.scheme and hand it back on the next turn.gemini::request::call_signaturedocuments the shape. The placeholder value is not read back as a signature. Adjacent thought parts without a signature are merged into the signed one (streaming writes thought text one part per delta), so the signature covers the whole text.gemini/request.rs): the shape above is written back on thefunctionCallpart; the placeholder is used only when the call has no real signature.gemini/response.rs,gemini/stream.rs): a call's signature is emitted on thefunctionCallpart; a thought part's text and signature are emitted in the same part (the stream writer holds back one text delta per thinking block, so thoughts still stream with a one-delta lag). A signature block not followed by a call still gets its own part, including at the end of the stream.convert::strip_carried): a carried signature on afunctionCallpart is replaced with the placeholder instead of the part being removed.Chat clients have no field to carry a signature, so Chat → Gemini → Chat still falls back to the placeholder (unchanged).
Tests
gemini/request.rs: decode keeps the call signature, ignores the placeholder, merges split thoughts; encode puts it back on the call and nowhere else.gemini/response.rs,gemini/stream.rs: decode keeps it (the existing fixtures already carried it); the stream writer puts text and signature in one part and the call's signature on the call.convert.rs: passthrough replaces a carried call signature with the placeholder.tests/matrix.rs: Gemini upstream behind Anthropic and Responses clients, whole and streamed: the signature reaches the client as a Google-signed block before the call, and the client's next turn puts it back on thefunctionCallpart.Verified locally:
cargo fmt --all -- --check,cargo clippy --workspace --all-targets -- -D warnings,cargo test -p tw-dialect(220 + integration tests, all green),cargo test -p tw-gateway.New messages
None. No protocol change.
🤖 Generated with Claude Code