Skip to content

fix(gemini): set both camelCase and snake_case thought_signature in tool call request body#3136

Merged
afjcjsbx merged 2 commits into
sipeed:mainfrom
ZOOWH:fix/3111-gemini-thought-signature
Jun 17, 2026
Merged

fix(gemini): set both camelCase and snake_case thought_signature in tool call request body#3136
afjcjsbx merged 2 commits into
sipeed:mainfrom
ZOOWH:fix/3111-gemini-thought-signature

Conversation

@ZOOWH

@ZOOWH ZOOWH commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Summary

  • The Gemini HTTP API provider only set thoughtSignature (camelCase) when building tool call request bodies
  • Gemini 2.5 models accept camelCase, but Gemini 3.5 Flash Agentic reasoning requires thought_signature (snake_case) — matching the format it returns in API responses
  • When only the camelCase variant was sent, Gemini 3.5 Flash rejected the request with a 400 Bad Request for missing thought_signature
  • The fix sets both ThoughtSignature and ThoughtSignatureSnake in the geminiPart struct, matching the pattern already used in antigravity_provider.go

Verification

  • Ran go test ./pkg/providers/httpapi/... -count=1 — all tests pass
  • Updated test from TestGeminiProvider_BuildRequestBody_UsesCamelCaseThoughtSignatureOnly to TestGeminiProvider_BuildRequestBody_SetsBothThoughtSignatureFormats to validate both formats are present

Real behavior proof

Behavior addressed: Gemini 3.5 Flash Agentic tool calls no longer fail with 400 Bad Request for missing thought_signature; both camelCase and snake_case variants are now included in the request body

Environment tested: Go 1.25.10 on Linux amd64, go test ./pkg/providers/httpapi/...

Steps run after the patch: Ran targeted unit tests for the httpapi provider

Evidence after fix:

ok  github.com/sipeed/picoclaw/pkg/providers/httpapi  0.029s

Observed result after the fix: All httpapi provider tests pass. Request body now contains both "thoughtSignature":"sig-1" and "thought_signature":"sig-1", ensuring compatibility with both Gemini 2.x and Gemini 3.x Agentic models.

Not tested: Live Gemini 3.5 Flash Agentic API request with real tool calls

Root Cause

  • Root cause: gemini_provider.go only set part.ThoughtSignature (camelCase json tag) in the request body, without also setting part.ThoughtSignatureSnake (snake_case json tag)
  • Missing detection/guardrail: antigravity_provider.go already sets both formats (lines 267-268), but the Gemini direct HTTP API provider was missing the snake_case variant

Closes #3111

…ool call request body

The Gemini HTTP API provider only set thoughtSignature (camelCase) when
building tool call request bodies. Gemini 2.5 models accept camelCase,
but Gemini 3.5 Flash Agentic reasoning requires thought_signature
(snake_case) — matching the format it returns in API responses. When
only the camelCase variant was sent, Gemini 3.5 Flash rejected the
request with a 400 Bad Request for missing thought_signature.

The fix sets both ThoughtSignature and ThoughtSignatureSnake in the
geminiPart struct, matching the pattern already used in
antigravity_provider.go. This ensures compatibility with both Gemini
2.x (camelCase) and Gemini 3.x Agentic (snake_case) models.

Closes sipeed#3111
@CLAassistant

CLAassistant commented Jun 17, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]Tool execution fails with Gemini 3.5 Flash (Missing thought_signature in schema)

3 participants