Skip to content

[ENG-21157] fix(agents): replay Gemini thought signatures through OpenAI-compatible proxies - #280

Merged
orswn merged 5 commits into
boonfrom
okka/eng-21157/gemini-thought-signatures
Nov 6, 2026
Merged

orswn merged 5 commits into
boonfrom
okka/eng-21157/gemini-thought-signatures

Conversation

@orswn

@orswn orswn commented Oct 11, 2026 •

Copy link
Copy Markdown
Collaborator

Related: ENG-21157

What Problem This Solves

Gemini 3 models fail every tool loop when they run behind an OpenAI-compatible proxy, such as the Boon LLM gateway.

Gemini returns a thought signature on the first tool call of a model turn, in extra_content.google.thought_signature. The next request must send it back on that tool call. Vertex AI rejects the request without it:

400 Function call is missing a thought_signature in functionCall parts

The OpenAI-completions transport already stores and replays these signatures, but only for provider google or a Google endpoint class. A gateway URL is a custom or local endpoint class. The signature is stored and never sent back, so the first tool call works and the request after the tool result fails.

Why This Change Was Made

  • New opt-in model compat flag requiresGoogleThoughtSignatures.
  • When it is true, isGoogleOpenAICompatModel returns true for that model, whatever the endpoint class. The existing replay path then runs unchanged.
  • The flag also turns on the skip_thought_signature_validator fallback for unsigned tool calls. Before, that fallback needed gemini-3 in the model id, so a proxy alias such as gateway-planner sent those calls with no signature.
  • The strict config schema, the config types and the model catalog normalizer accept the key. Without the schema entry, config validation rejects it.
  • Replay logic does not change. Models without the flag keep the current behavior.

Why a flag and not detection by model id:

  • A proxy alias can hide the model family.
  • A non-Gemini model behind the same proxy must not get extra_content.google on its tool calls.

Model entry used in the tests below:

{
  "id": "gemini-3.8-flash",
  "api": "openai-completions",
  "reasoning": true,
  "compat": {
    "requiresGoogleThoughtSignatures": true,
    "supportsReasoningEffort": true,
    "supportedReasoningEfforts": ["low", "medium", "high"],
    "maxTokensField": "max_completion_tokens",
    "supportsUsageInStreaming": true,
    "supportsDeveloperRole": false,
    "supportsStore": false,
    "supportsStrictMode": false
  }
}

Only the first flag is new. Without supportsReasoningEffort, a custom endpoint sends no reasoning_effort.

Parallel tool calls: Vertex signs only the first call of a parallel set. The transport sends skip_thought_signature_validator for the unsigned calls of a gemini-3 model, or of any model with the flag. Vertex accepted this shape in the live run below.

User Impact

  • No change for current models. No fleet or trial model config sets the flag.
  • A host can run a Gemini 3 model through the LLM gateway after its model entry sets the flag.
  • That also needs the gateway change in getboon/boon-llm-gateway#130. It is not part of this PR.
  • getboon/boon-llm-gateway#130 sends Gemini 3 models to the global Vertex location in code. The gateway env does not change.

Evidence

Unit tests. The first 6 rows failed before the change, the last 2 passed before and after:

Test Before After
Same-route thought_signature is sent back when the flag is set fail pass
Unsigned tool call from another route gets the skip-validator signature when the flag is set fail pass
Parallel streamed tool calls: the next request sends the signature on the first call and the skip sentinel on the second fail pass
The same parallel replay for a flagged alias id without gemini-3 fail pass
Tool call from another route on a flagged alias id gets the skip-validator signature fail pass
Config accepts requiresGoogleThoughtSignatures fail pass
No extra_content without the flag pass pass
Config rejects the misspelled requiresGoogleThoughtSignature pass pass

Re-run on head d789184288b, after the merge of boon (2026-11-05):

node scripts/run-vitest.mjs src/agents/openai-transport-stream.test.ts src/config/config-misc.test.ts packages/model-catalog-core/src/*.test.ts
  unit 22 passed, runtime-config 92 passed, agents 290 passed
pnpm tsgo:core           exit 0
pnpm tsgo:core:test      exit 0
oxlint and oxfmt --check on the 7 changed files: clean

Re-run on head 5726e460678, after the merge of boon with #328 (2026-11-05): the same commands give the same results. The 10 test files that #328 changed pass on this head too (329 tests).

Config flow: the real validateConfigObject and resolveModel keep compat.requiresGoogleThoughtSignatures: true on the resolved model. No other code path strips the key, and the same-route history transforms keep the signature.

Live tool loop with the transport from this branch (createOpenAICompletionsTransportStreamFn). Vertex AI gemini-3.8-flash, reasoning high, through a local LLM gateway with the gateway change. The prompt asks for 2 parallel get_weather calls, then the second request sends both tool results:

Flag Request 1 Signatures on the 2 calls Request 2 sends Request 2
set 200, 2 parallel calls first only (600 chars) first: signature, second: skip sentinel 200, "Rome is warmer"
not set 200, 2 parallel calls first only (880 chars) no signatures fails (3 attempts)

Without the flag the gateway returns 502 on the stream. The same request without streaming returns the Vertex 400 above.

Re-check on head 4fa361065f3 after the merge of boon (2026-11-05). Same probe, through a local gateway built from getboon/boon-llm-gateway#130 after its merge of main:

Flag Request 1 Signatures on the 2 calls Request 2 sends Request 2
set 200, 2 parallel calls first only (952 chars) first: signature, second: skip sentinel 200, "Rome is warmer than Paris."
not set 200, 2 parallel calls first only (612 chars) no signatures 502 all providers failed (3 attempts)

Re-check on the head d789184288b (2026-11-05), through a local gateway built from the head of getboon/boon-llm-gateway#130. The alias rows go through a small local test proxy that maps the model gateway-planner to gemini-3.8-flash, the way an OpenAI-compatible proxy can hide the model family:

Model id Flag Request 1 Signatures on the 2 calls Request 2 sends Request 2
gemini-3.8-flash set 200, 2 parallel calls first only (924 chars) first: signature, second: skip sentinel 200, "Rome is warmer."
gemini-3.8-flash not set 200, 2 parallel calls first only (788 chars) no signatures 502 all providers failed (3 attempts)
gateway-planner (alias) set 200, 2 parallel calls first only (844 chars) first: signature, second: skip sentinel 200, "Therefore, Rome is warmer."
gateway-planner (alias) not set 200, 2 parallel calls first only (700 chars) no signatures 502 all providers failed (3 attempts)

Re-check on the head 5726e460678 after the merge of boon with #328 (2026-11-05). #328 sends the per-turn context as a separate user message right after the active user message. On this route it stays a separate message, so Gemini gets two user messages in a row. Same probe with that message added through buildRuntimeContextCustomMessage, through a local gateway built from the head of getboon/boon-llm-gateway#130:

Flag Request 1 roles Request 1 Request 2 roles Request 2 sends Request 2
set system, user, user 200, 2 parallel calls, signature on the first only (1,132 chars) system, user, user, assistant, tool, tool first: signature, second: skip sentinel 200, "Rome is warmer than Paris."
not set system, user, user 200, 2 parallel calls, signature on the first only (972 chars) system, user, user, assistant, tool, tool no signatures 502 all providers failed (3 attempts)

Agent run: the same change, applied to v2026.6.34-boon.3 together with the Claude fix from #278, served a Boon agent on Gemini 3.8 Flash with the flag set. After that run, boon changed openai-transport-stream.ts only in the xAI encrypted-content retry check. The Gemini replay path is the same. The agent ran the agent regression suite 4 times, 11 scenarios each:

  • 857 Gemini turns: 659 ended in tool calls (663 calls), 198 in a reply.
  • 0 turns ended in an error. No request failed on thought_signature.
  • 4 turns had 2 parallel tool calls, each with the signature on the first call only. The next request after each of them returned 200.

Summary by cubic

Fixes Gemini 3 tool loops failing when the model runs behind an OpenAI-compatible proxy, such as the Boon LLM gateway. Vertex AI requires the thought_signature from the first tool call to be replayed on the next request, but the replay logic only ran for Google endpoints, not custom or local endpoint classes.

Adds an opt-in compat.requiresGoogleThoughtSignatures model flag. When set, the existing thought-signature replay path and the skip-validator fallback run for that model regardless of endpoint class or model id, so proxied aliases replay the first call's signature and send skip_thought_signature_validator on unsigned calls. Models without the flag keep current behavior. The config schema, config types, and model catalog normalizer now accept the key, and the parallel tool-call test verifies the next request replays the signature on the first call and the skip sentinel on the second.

Rollout

  • Hosts running Gemini 3 behind a gateway must set "requiresGoogleThoughtSignatures": true on the model entry.
  • Also requires the gateway change in getboon/boon-llm-gateway#130 and GOOGLE_CLOUD_LOCATION=global; neither is part of this PR.

Written for commit d789184. Summary will update on new commits.

View guided diff Turn on auto-fix

…nAI-compatible proxies

Gemini 3 models return a thought signature on the first tool call of a
turn (extra_content.google.thought_signature). Vertex AI rejects the
next request when the signature is not replayed:

  400 Function call is missing a thought_signature in functionCall parts

The OpenAI-completions transport already stores the signature and
replays it, but only for provider "google" or a Google endpoint class.
A Gemini model behind an OpenAI-compatible proxy, such as an LLM
gateway, has a custom or local endpoint class. Its signatures are
stored and never sent back, so every tool loop fails on the second
request.

Add the opt-in model compat flag requiresGoogleThoughtSignatures. When
it is true, the existing replay path runs for that model, whatever the
endpoint class. Models without the flag do not change. The flag is
accepted by the config schema, the config types and the model catalog
normalizer.
@orswn
orswn requested a review from a team October 11, 2026 20:27

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 7 files

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread src/config/types.models.ts Resolved
@orswn

orswn commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 5, 2026

Copy link
Copy Markdown

@cubic-dev-ai review

@orswn I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 7 files

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

orswn added 2 commits November 5, 2026 14:44
… proxy

The parallel tool-call test for a proxied Gemini model stopped after
stream parsing. It could not catch a lost signature on the first call or
a lost skip-validator sentinel on the second call when the next request
sends the parallel set back, which is the shape a real agent turn sends.

Build the next request from the parsed output and both tool results, and
assert that the first call carries its thought_signature and the second
carries skip_thought_signature_validator.
…iases

With compat.requiresGoogleThoughtSignatures set, signature replay runs
for a proxied model whatever its id. The skip-validator fallback still
needed "gemini-3" in the model id. A proxy alias without it sent the
unsigned calls of a parallel set, and tool calls from another route,
with no signature, and Vertex AI rejects that request.

Let the flag also enable the fallback. Run the parallel replay test for
a gemini-3 id and for an alias id, and cover a cross-route call on an
alias id.

@boon-hermes-bot boon-hermes-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The update to ensures aliased proxy IDs correctly receive the sentinel for parallel tool calls and cross-route tool calls. Clean implementation and comprehensive test coverage.

@boon-hermes-bot boon-hermes-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The update to requiresGoogleCompatToolCallThoughtSignature ensures aliased proxy IDs correctly receive the skip_thought_signature_validator sentinel for parallel tool calls and cross-route tool calls. Clean implementation and comprehensive test coverage.

@boon-hermes-bot boon-hermes-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-verified after merge of boon into the PR branch (head 5726e46). CI is all green and all checks pass cleanly. Approved.

@orswn
orswn merged commit 49b4466 into boon Nov 6, 2026
147 checks passed
@orswn
orswn deleted the okka/eng-21157/gemini-thought-signatures branch November 6, 2026 12:00
orswn added a commit that referenced this pull request Nov 9, 2026
Cut the fork release for the PRs merged to boon after the
v2026.6.35-boon.4 tag:

- #328 (ENG-22237): replayed user turns keep the same bytes, so a new
  user message in Boon Web, Slack and MS Teams reads the previous
  prompt from cache instead of writing the whole history again.
- #280 (ENG-21157): opt-in model compat flag
  requiresGoogleThoughtSignatures, so Gemini 3 tool loops work behind
  an OpenAI-compatible proxy. No fleet model config sets it yet.
- #327: the v2026.6.35-boon.4 tag was cut from the PR branch. The
  review fixes that merged after it change tests and one comment only.

Bump the root package.json and npm-shrinkwrap.json, all 136 bundled
plugin manifests (scripts/sync-plugin-versions.ts), and the version and
openclaw peer floor in every extension npm-shrinkwrap.json
(scripts/generate-npm-shrinkwrap.mjs --all). The regeneration also
picks up the registry's updated deprecation text for @smithy/core
3.24.6 in amazon-bedrock, amazon-bedrock-mantle and tlon; no resolved
version or integrity changes. Add the 2026.6.35-boon.5 CHANGELOG.md
section. No source or dependency change beyond the merged PRs above.
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.

2 participants