Round-trip provider metadata on tool calls; Gemini requires it

Gemini 3 models attach a thought signature to every function call
and reject the follow-up -- 400, "Function call is missing a
thought_signature in functionCall parts" -- when the assistant
message echoing that call does not carry it back. The gateway
rebuilt the assistant turn from id, name and arguments alone, so
every tool-using run on Gemini died on its second model call, after
a first call that looked perfectly healthy. Found when production
was pointed at Gemini on 2026-09-22; rolled back to Groq within
minutes.

ToolCall gains an opaque Extra field: the raw JSON of the wire's
extra_content, captured on both the streaming and non-streaming
paths and emitted verbatim on the next request. The gateway does
not read it and must not -- the point of one wire shape is that a
vendor's private fields pass through untouched. Absent stays
absent; no provider receives a null it never sent.

Also: Gemini wraps its error body in a one-element array, which
the message parser read as "no detail". The trajectory therefore
said only "the model rejected the request" where the body named
the missing signature outright. Unwrapped now, so the next
provider quirk is legible in the trajectory instead of costing a
day of proxy captures.

Verified end to end with the real gateway against real Gemini: a
three-turn tool-calling run completed and the proxy confirmed the
signature on every echoed call.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJvibeSc1JYXjatankqM1g
This commit is contained in:
2026-09-22 13:15:39 +05:30
parent 5166fde764
commit 797ee5f2d2
4 changed files with 166 additions and 3 deletions

View File

@@ -85,6 +85,25 @@ type ToolCall struct {
ID string
Name string
Input json.RawMessage
// Extra is provider metadata attached to the call, carried back to the
// provider verbatim on the next turn and never read here.
//
// It exists because at least one provider requires it. Gemini 3 models
// attach a "thought signature" to every function call and REJECT the
// follow-up request — 400, "Function call is missing a thought_signature"
// — if the assistant message that echoes the call does not carry it back.
// A gateway that rebuilds the assistant turn from ID, Name and Input alone
// drops it, and every tool-using run dies on its second model call while
// the first one looked perfectly healthy. That is exactly what happened
// on 2026-09-22 when production was pointed at Gemini.
//
// The gateway does not know what is in it and must not: the whole point
// of speaking one wire shape is that a vendor's private fields pass
// through untouched. It is the raw JSON of the call's extra_content
// object, or nil when the provider sent none, in which case it is omitted
// from the request again.
Extra json.RawMessage
}
// ToolResult is what came back, on its way to the model.