Skip to content

fix(ai): drop Gemini enums on non-string schemas - #196742

Merged
obviyus merged 1 commit into
mainfrom
fix/196717-gemini-boolean-enum
Nov 10, 2026
Merged

obviyus merged 1 commit into
mainfrom
fix/196717-gemini-boolean-enum

Conversation

@obviyus

@obviyus obviyus commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #196717. Thanks @yixiaoer-520 for the report and the wire capture.

Problem

Every Gemini or Vertex turn that exposes the built-in read tool fails with HTTP 400. The read tool declares optional as the boolean literal true, and the Gemini schema cleaner sends it as {"type": "boolean", "enum": ["true"]}. Google accepts enum only on string schemas with string entries (Schema.enum is repeated string, "Possible values of the element of Type.STRING with enum format" in google/ai/generativelanguage/v1beta/content.proto), so the whole request is rejected.

Root cause

cleanSchemaForGemini stringifies const and enum entries. #104567 (1338b0d) first stringified them and retyped the schema to string; its final revision (8055932) deliberately kept the declared type "so tool argument generation and runtime validation still agree": a string-typed optional would make Gemini send "true", which the canonical Type.Literal(true) validation (#185581) rejects. Keeping the type while emitting string entries leaves a non-string schema with an enum, which Google rejects. #182390 (5eab3f5) last touched this cleaner but only made type scalar; it does not change enum handling.

Fix

In the Gemini cleaner, keep const/enum (stringified, as before) only when the declared type is string or absent. For any other declared type, keep the type and drop the enum. read.optional now goes out as {"type": "boolean", "description": ...}: Gemini accepts it, the model still generates a real boolean, and canonical validation still accepts only true. Numeric enums follow the same rule. Non-Gemini providers and string enums are unchanged.

Evidence

Built Gateway (pnpm build, openclaw gateway run) on secretless Docker, Node 24.22.1. One openclaw agent turn through the Gateway per provider, with the default tool set (14 tools, read included). The Gemini provider (google-generative-ai) points at a local stand-in that applies Google's enum rule (enum only on STRING schemas with string entries) and answers violations with Google's INVALID_ARGUMENT 400 body; it records every request. Control provider: OpenAI-compatible on the same stand-in.

  • Main 3686da563c54 (2/2 runs): Gemini request rejected, * GenerateContentRequest.tools[0].function_declarations[9].parameters.properties[optional].enum: only allowed for STRING type; the turn fails (LLM request rejected ... | 400, exit 1).
  • Candidate aa23553561d7 (2/2 runs): Gemini request accepted (200) and the turn completes. In run 2 the stand-in answers with read({"path":"missing-196717.txt","optional":true}) (a real boolean); canonical validation accepts it and the real read tool returns Optional file not found: missing-196717.txt.
  • read.optional on the Gemini wire: main {"type":"boolean","enum":["true"],"description":...}, candidate {"type":"boolean","description":...}.
  • Controls: the other 13 Gemini tool schemas are byte-identical; the rest of read is unchanged; all 7 string enums (for example exec.host, github_publish.action) are unchanged; the OpenAI-compatible request's 14 tools are byte-identical to main (read.optional stays {"type":"boolean","const":true,...}).
  • Focused tests: clean-for-gemini, tool-search-runtime, agent-tools-parameter-schema, agent-tools.schema, agent-tools.prefix-stability, message-tool-schema pass. The updated clean-for-gemini and tool-search-runtime cases fail on the base source (3 failures) and pass on head.

Captures: run 1 #196742 (comment), run 2 with the tool-call round trip and the base-failing tests #196742 (comment)

Not covered: there is no live Google key in this loop, so acceptance is shown against the documented rule (Schema.enum in google/ai/generativelanguage/v1beta/content.proto) and the same real Gemini error other clients report for this shape (anomalyco/opencode#28397), not a live Gemini call.

@clawsweeper

clawsweeper Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@obviyus

obviyus commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator Author

Built-Gateway capture (secretless Docker, node:24.22.1). One openclaw agent turn through openclaw gateway run per provider; the stand-in records each request body.

== main-1
{"url":"/v1beta/models/gemini-3-flash:streamGenerateContent?alt=sse","status":400,"tools":14,"error":"* GenerateContentRequest.tools[0].function_declarations[9].parameters.properties[optional].enum: only allowed for STRING type\n"}
{"url":"/v1/chat/completions","status":200,"tools":14,"error":null}
turn gemini: exit 1
turn openai: exit 0
== cand-1
{"url":"/v1beta/models/gemini-3-flash:streamGenerateContent?alt=sse","status":200,"tools":14,"error":null}
{"url":"/v1/chat/completions","status":200,"tools":14,"error":null}
turn gemini: exit 0
turn openai: exit 0

== main-1 gemini CLI result
[openclaw] Reason: LLM request rejected: \* GenerateContentRequest\.tools\[0\]\.function\_declarations\[9\]\.parameters\.properties\[optional\]\.enum\: only allowed for STRING type | 400
== cand-1 gemini reply
P196717_GEMINI_OK

== controls (compare.mjs main-1 cand-1)
{
  "geminiTools": 14,
  "geminiChangedTools": [
    "read"
  ],
  "geminiOtherToolsByteIdentical": true,
  "readOptionalMain": {
    "type": "boolean",
    "enum": [
      "true"
    ],
    "description": "Missing paths return structured not_found instead of failing."
  },
  "readOptionalCand": {
    "type": "boolean",
    "description": "Missing paths return structured not_found instead of failing."
  },
  "readOtherFieldsIdentical": true,
  "stringEnumCount": 7,
  "stringEnumsUnchanged": true,
  "openaiReadOptional": {
    "type": "boolean",
    "const": true,
    "description": "Missing paths return structured not_found instead of failing."
  },
  "openaiToolCount": 14,
  "openaiToolsByteIdentical": true
}

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Nov 10, 2026
@obviyus

obviyus commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 10, 2026
@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

The PR drops enum constraints from explicitly non-string Gemini schemas while preserving their declared types and string enums.

Example: A Gemini agent turn includes read.optional, whose canonical schema permits boolean true.

  • Before: The wire schema is {"type":"boolean","enum":["true"]}, which violates Google's documented enum restriction.
  • After: The wire schema is {"type":"boolean"}, while local validation retains the canonical literal-true constraint.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, contract-aligned repair with shipped Gateway round-trip evidence, meaningful base-failing regressions, and successful exact-head gates; external acceptance is supported by Google's contract rather than a live Google run.
Proof confidence 🐚 platinum hermit (4/6) This collaborator-authored PR is outside the ordinary contributor proof gate; inspected terminal captures nevertheless exercise the built Gateway, real Gemini HTTP transport, corrected read.optional schema, and real read handler on the reviewed head.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Gemini can reject an entire agent turn because a built-in tool advertises a boolean field with a string enum.
Reason: The collaborator-authored direction repairs a documented provider-contract violation without adding configuration, changing canonical tool inputs, or introducing another projection path.

Merge readiness

✅ Ready for maintainer review

Keep this PR: it fixes a current Gemini request-schema failure at the existing shared owner, preserves canonical input validation, and has no actionable findings; exact-head CI is green.

Priority: P1
Reviewed head: aa23553561d7ab28caffbb48450ca3b1fa68c2ac

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied Gateway captures use a local provider stand-in and do not establish live Google or Vertex acceptance.
Agent review details

How this fits together

Tool finalization projects canonical parameter schemas through the shared Gemini cleaner before provider serialization; returned tool arguments are validated against the canonical execution schema.

flowchart LR
  A[Canonical tool schemas] --> B[Gemini schema cleaner]
  B --> C[Gemini HTTP transport]
  C --> D[Model tool arguments]
  D --> E[Canonical input validation]
  E --> F[Read tool result]
Loading

Technical review

Best possible solution:

Keep the fix in the shared Gemini projection owner while preserving canonical execution validation and unchanged string enums.

Do we have a high-confidence way to reproduce the issue?

Current-main source deterministically emits the reported boolean/string-enum mismatch, corroborated by the reporter's wire capture and supplied base-failing Gateway trace; no target code was executed during this review.

Is this the best way to solve the issue?

The patch is the smallest complete repair: filter unsupported enum projections at the existing shared owner, retain primitive types, and update existing boolean, nested numeric, and consumer regressions.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 53aed90ae4c7.

Provenance checked

  • Gemini const and enum projection changes intended behavior with a stated reason (1338b0d: Stringify primitive enum entries to avoid TYPE_STRING rejections; the final revision deliberately preserved declared primitive types so generation and execution agree.)
  • Canonical Tool Search regression expectation keeps the original intent (afbe0a8: Protect canonical boolean input validation through deferred publication and metadata-preserving wrappers; the PR changes the advertised-schema expectation while retaining that execution check.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit f16e8bc adds packages/ai/src/providers/clean-for-gemini.ts:232 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: f16e8bc092e7; files: packages/ai/src/providers/clean-for-gemini.ts)
  • Ayaan Zaidi: Raw commit 1d7fd50 adds packages/ai/src/providers/clean-for-gemini.ts:389 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 1d7fd50b912f; files: packages/ai/src/providers/clean-for-gemini.ts)
  • yy19971996: Raw commit afbe0a8 adds src/agents/tool-search-runtime.test.ts:248 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: afbe0a8e8f2c; files: src/agents/tool-search-runtime.test.ts)

PR surface

Source +4, Tests -2. Total +2 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 6 2 +4
Tests 2 5 7 -2
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 11 9 +2

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove merge-risk: 🚨 compatibility: Current PR review selected no merge-risk labels.

Label justifications:

  • P1: An invalid schema on the built-in read tool can reject an entire Gemini tool-bearing agent turn before any useful response.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-10T16:17:46.381Z sha aa23553 :: needs maintainer review before merge. :: none

Reviewed November 10, 2026, 11:32 AM ET / 16:32 UTC (Revision 2).

@obviyus

obviyus commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator Author

Second built-Gateway run on the same images (main 3686da563c54, head aa23553561d7), plus a tool-call round trip: on the first Gemini request the stand-in returns read({"path":"missing-196717.txt","optional":true}) with a real boolean, as Gemini does for a type: boolean field.

== main-2
{"url":"/v1beta/models/gemini-3-flash:streamGenerateContent?alt=sse","status":400,"error":"* GenerateContentRequest.tools[0].function_declarations[9].parameters.properties[optional].enum: only allowed for STRING type\n","functionResponse":[]}
{"url":"/v1/chat/completions","status":200,"error":null,"functionResponse":[]}
turn gemini: exit 1
turn openai: exit 0
== cand-2
{"url":"/v1beta/models/gemini-3-flash:streamGenerateContent?alt=sse","status":200,"error":null,"functionResponse":[]}
{"url":"/v1beta/models/gemini-3-flash:streamGenerateContent?alt=sse","status":200,"error":null,"functionResponse":[{"name":"read","response":{"output":"Optional file not found: missing-196717.txt."}}]}
{"url":"/v1/chat/completions","status":200,"error":null,"functionResponse":[]}
turn gemini: exit 0
turn openai: exit 0

== controls (main-2 vs cand-2)
{"geminiTools":14,"geminiChangedTools":["read"],"geminiOtherToolsByteIdentical":true,"readOptionalMain":{"type":"boolean","enum":["true"],"description":"Missing paths return structured not_found instead of failing."},"readOptionalCand":{"type":"boolean","description":"Missing paths return structured not_found instead of failing."},"readOtherFieldsIdentical":true,"stringEnumCount":7,"stringEnumsUnchanged":true,"openaiReadOptional":{"type":"boolean","const":true,"description":"Missing paths return structured not_found instead of failing."},"openaiToolCount":14,"openaiToolsByteIdentical":true}

So on head the Gemini request is accepted, the model-generated boolean optional: true passes canonical validation, and the real read tool returns its structured optional not-found result. Main never gets past the first request.

Updated regressions fail on the base source and pass on head (node scripts/run-vitest.mjs packages/ai/src/providers/clean-for-gemini.test.ts src/agents/tool-search-runtime.test.ts, with only clean-for-gemini.ts swapped to 3686da563c54):

      Tests  1 failed | 45 passed (46)
      Tests  2 failed | 14 passed (16)
 FAIL  |agents-core| src/agents/tool-search-runtime.test.ts > Tool Search input schemas > keeps canonical Gemini read arguments through deferred publication and wrappers
 FAIL  |unit| packages/ai/src/providers/clean-for-gemini.test.ts > cleanSchemaForGemini > boolean const
 FAIL  |unit| packages/ai/src/providers/clean-for-gemini.test.ts > cleanSchemaForGemini > drops nested numeric enums while preserving their number type
 × |agents-core| src/agents/tool-search-runtime.test.ts > Tool Search input schemas > keeps canonical Gemini read arguments through deferred publication and wrappers
 × |unit| packages/ai/src/providers/clean-for-gemini.test.ts > cleanSchemaForGemini > boolean const
 × |unit| packages/ai/src/providers/clean-for-gemini.test.ts > cleanSchemaForGemini > drops nested numeric enums while preserving their number type
⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯
⎯⎯⎯⎯⎯⎯⎯ Failed Tests 2 ⎯⎯⎯⎯⎯⎯⎯
-- head
      Tests  16 passed (16)
      Tests  46 passed (46)

Real Google behavior for the main shape: the Gemini API returns GenerateContentRequest.tools[0].function_declarations[N].parameters.properties[X].enum: only allowed for STRING type for a non-string schema carrying an enum (anomalyco/opencode#28397, AI Studio key). Schema.enum is repeated string, documented for Type.STRING (https://github.com/googleapis/googleapis/blob/master/google/ai/generativelanguage/v1beta/content.proto). The head shape is a plain {"type":"boolean"}.

@obviyus

obviyus commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 10, 2026
@obviyus
obviyus merged commit 543917c into main Nov 10, 2026
169 checks passed
@obviyus
obviyus deleted the fix/196717-gemini-boolean-enum branch November 10, 2026 16:37
@obviyus

obviyus commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in 543917c. Thanks @yixiaoer-520 for the report.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 11, 2026
fix(ai): drop non-string enums from Gemini tool schemas

The read tool declares optional as the boolean literal true. The Gemini schema cleaner turned that into {"type":"boolean","enum":["true"]}, but Google allows enum only on string types, so every Gemini and Vertex request carrying the read tool failed with HTTP 400 "enum: only allowed for STRING type". openclaw#104567 deliberately keeps the declared type so tool arguments still match local validation (openclaw#185581); changing the type to string would make Gemini send "true" and fail that check. The cleaner now keeps enums only when the declared type is string or missing, and drops the enum for other types while keeping the type. read.optional goes out as a plain boolean, and the original schema still accepts only true. Other providers' schemas are unchanged.

Evidence: a built Gateway on node:24.22.1 in secretless Docker with 14 tools including read, against a local stand-in that enforces Google's enum rule and returns the real 400 body, two runs each. On main the request failed with "...parameters.properties[optional].enum: only allowed for STRING type". With this change the request was accepted, and the stand-in's read call with optional true passed local validation and ran. The other 13 Gemini tool schemas, every string enum and the OpenAI-compatible request are byte-identical to main. Details: openclaw#196742.

Closes openclaw#196717. Thanks @yixiaoer-520 for the report.

Co-authored-by: Ayaan Zaidi <[email protected]>
RomneyDa pushed a commit that referenced this pull request Nov 12, 2026
Adapt retained normalizer coverage without importing the superseded tool-search fixture. Production change from 543917c.

Independent local review omitted by explicit release-owner instruction; scoped regression and static checks passed.

Co-authored-by: Ayaan Zaidi <[email protected]>

Co-authored-by: RomneyDa <[email protected]>

Co-authored-by: vincentkoc <[email protected]>
(cherry picked from commit 4f5f8d62795ffe1b9981692f2f8d8058f6078178)
github-actions Bot pushed a commit to clawhaven/openclaw that referenced this pull request Nov 16, 2026
Adapt to the 2026.11.4 release owners and fixtures; preserve current safety and timeout contracts. Source inspected by release owner. Independent local review explicitly waived by Dallin; CI qualification remains pending.

(cherry picked from commit 543917c)

Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

read tool: boolean literal serialized as string enum breaks Gemini/Vertex tool schema (HTTP 400)

1 participant