gateway: a Gemini tool schema with items is an array, not its enum's string, and Antigravity gets items only on arrays (ferock)

ferock on Discord: Claude Code, model group/gemini-3-8-flash on a local
magpie whose group is served by a remote magpie's Antigravity, 400
"Remote magpie: Antigravity: GenerateContentRequest.tools[0].
function_declarations[19].parameters.properties[display].items: field
predicate failed: $type == Type.ARRAY". It worked in the morning and
broke after updating. The tool's literal schema wasn't posted, and no
Claude Code 2.1.311 built-in has a display property with items (searched
the binary), so it is an MCP tool of theirs.

Cause: geminiToolTypes (68ee4117a, v0.1.1624, 10-27 01:26) runs in
forwardOnce for any body whose model names Gemini, the local magpie's
forward to a remote magpie included. geminiSchemaType typed an untyped
schema from its enum/const values before its keywords, so
{"items":{...},"enum":["a","b"]} went on as type "string" with items
beside it. The remote's plainSchema kept the explicit type and the
items, and Google refused the whole turn. Before 68ee4117a the same node
reached plainSchema untyped and was inferred an array.

- geminiSchemaType: an object's or array's keywords (properties, items
  and the rest, keywordType, split out of schemaTypes unchanged) decide
  before enum/const values.
- plainSchema (the remote's Antigravity side, so a local magpie from
  before is served too): items/minItems/maxItems are kept only on an
  array and properties/required/min-maxProperties/propertyOrdering only
  on an object, as JSON Schema reads them; of a type list it takes the
  type its items or properties are for (["string","array"] with items is
  an array, not a string with items).
- docs/subsystems/gateway-routing.md says both.
- Sibling not changed: kimiSchemaType/collectUntypedEnums still type
  such a node from its enum; whether Kimi refuses items on a string is
  unknown, filed as #3867.

Tests (antigravity_display_items_test.go): the shape the error points to
(an untyped display with items and a string enum, plus properties with a
const) through geminiToolTypes, and through parseAnthropic +
buildCodeAssist(antigravity) as Claude Code sent it, as this version's
local passes it on, and as an older local passes it on (display typed
"string", type lists, a string with object/array keywords); every node
sent has items only as an array and properties only as an object.

Run, in a worktree at origin/main 32ea16c5a:
- go test -tags nogui ./internal/gateway -run 'CodeAssist|Codeassist|
  Gemini|Schema|Antigravity|Kimi|Plain|Grok|OneOf|Tool|Vertex|Google|
  Shape|Enum' -count=1: ok (60s)
- gofmt -l internal/gateway: clean; go vet -tags nogui (darwin),
  GOOS=linux go vet -tags nogui, GOOS=windows go vet on internal/gateway:
  clean
Broken by hand: gemini_schema.go back to origin/main,
TestGeminiToolTypesItemsBeforeEnum and TestAntigravityItemsOnlyOnArrays
FAIL (display typed "string"); codeassist.go back to origin/main,
TestAntigravityItemsOnlyOnArrays FAILs (items, minItems, properties on
type "string").

Not tried: the reporter's literal tool schema (not posted; the fixture is
the shape the error and the update point to), a real Antigravity
account, and a real two-magpie setup. Not run: the whole gateway
package or ./... (another session's full internal/gateway run was on the
machine, load ~60-75).
This commit is contained in:
yetone
2026-10-27 16:34:19 +08:00
parent df83749218
commit d71362afcd
5 changed files with 158 additions and 9 deletions
+1 -1
View File
@@ -240,7 +240,7 @@ recorded as a prediction failure (`noPrediction`).
- A Chat upstream that wants a turn's reasoning back (`chatReplaysReasoning` in [`chat.go`](../../internal/gateway/chat.go): a host or a model, as magpie or the provider names it, with `deepseek` in it, such as OpenCode Go's `deepseek-v4.1-flash`, or Command Code's plugin) gets every assistant tool call with `reasoning_content`, relayed (`withReasoningOnToolTurns` in `passthrough`) or translated (`buildChat`). DeepSeek turns the whole request away ("The `reasoning_content` in the thinking mode must be passed back to the API") when a tool call made since the user's last message has none, which a client sends for a turn it saw no thinking on: another model's, a translated one (#1462). The turn's own thinking goes back as it came; one sent in `reasoning` or `reasoning_details` is copied in, and `reasoning` is then left out (`asReasoningContent`): a self-hosted DeepSeek server reads the two as one field and refused pi's tool turn, which carried its thinking in `reasoning`, as "duplicate field reasoning" (ArvinCharl on X, v0.1.1560), while `reasoning_details`, a list of typed entries that can hold an encrypted one, stays; otherwise it goes with a space (`noReasoning`: DeepSeek's Chat API takes an empty one, but a relay that leaves empty fields out would drop it). An assistant message right after a tool result, a reply with no call of its own, gets one too: DeepSeek refuses it the same way (checked 2026-10-12, #1822). A reply to the user, any other model and Mistral (#494) are sent as before.
- An assistant turn the user cut off before it said anything (only its thinking, an empty text, nothing; an isolated Codex reasoning item; a Gemini thought alone) stays in the agent's history and is sent on every later turn. DeepSeek and Kimi turn the whole request away over an assistant message with neither content nor tool calls, `reasoning_content` alone included ("Invalid assistant message: content or tool_calls must be set", #2599). Every Chat upstream gets such a turn left out, translated (`buildChat`, before `pairToolMessages`) or relayed (`silentAssistantsOut` in `passthrough`), by one rule (`withoutSilentAssistants` in [`chat.go`](../../internal/gateway/chat.go)): the two user messages it stood between join into one, and after a tool result the user's message follows the tool message. A prefill to go on from (`prefix`, `partial`, a Resume), a legacy `function_call`, a refusal and an audio reply stay, and a relayed body without such a turn goes byte for byte. `TestChatEmptyAssistantLeftOutFromAnthropic`, `…FromResponses`, `…FromGemini`, `TestChatRelayLeavesOutEmptyAssistant`, `TestChatRelaySilentAssistantsOnly`.
- Kimi's Chat API (`isKimi`: the Kimi platform's and a Kimi Code membership's hosts or presets) turns `reasoning_details` in a message away in any shape: an entry with a stream's `index` ("the reasoning_details at position 1 entry 0 must not contain streaming index") and any other entry ("… has an invalid type"), checked against api.kimi.com/coding on 2026-10-12. pi keeps another vendor's thinking there (MiMo's, through Command Code, with `index: 0`), so a conversation routed on to Kimi was refused on every turn (#1765). `passthrough` sends it to Kimi as `reasoning_content` (`reasoningDetailsAsContent`, with the message's `reasoning` left out once its text is there), which Kimi takes; a message with `reasoning_content` of its own keeps that. Another upstream that refuses a thinking field "at position N", as Kimi words it (a relay in front of it), is asked once more the same way and marked (`refusedInMessages`, `withoutMessageReasoning`).
- Vertex AI takes a function declaration's parameters as its own Schema object, whose `type` is required, and turns the whole request away over one schema without it, though the tool is never called: 400 "`mcp__cua-driver__drag` functionDeclaration `parameters.target` schema didn't specify the schema type field." (kthink on Discord: dsh with cua-driver's MCP tools, from before cua's own fix in its #4888, on Command Code's `google/gemini-3.8-flash`, which Command Code's gateway serves on Vertex; `target` was an anyOf of an untyped oneOf and null, `scope` a const). A body whose `model` names Gemini (`geminiNamed`: the id's last `/` segment starts with `gemini`, whoever serves it) has each untyped schema under its tools' `function.parameters`, `parameters` or `input_schema` given its type in place (`geminiToolTypes` in [`gemini_schema.go`](../../internal/gateway/gemini_schema.go), in `forwardOnce`, so a plugin's request too): from its enum or const values, its keywords or its branches, null left out, `{}` or a description alone a string, a tool's root an object. A node whose branches have more than one type, an unresolved `$ref` or union, and anything under `not` or `if` are left as they came, so such a schema can still be refused; every other model's tools go byte for byte. Google's own Gemini API and Code Assist are sent `parametersJsonSchema` and Antigravity `plainSchema`, so a Gemini-shaped body isn't walked (`TestGeminiToolTypesCuaDriverDrag`, with cua-driver's drag schema as its server listed it, `TestGeminiToolTypes`).
- Vertex AI takes a function declaration's parameters as its own Schema object, whose `type` is required, and turns the whole request away over one schema without it, though the tool is never called: 400 "`mcp__cua-driver__drag` functionDeclaration `parameters.target` schema didn't specify the schema type field." (kthink on Discord: dsh with cua-driver's MCP tools, from before cua's own fix in its #4888, on Command Code's `google/gemini-3.8-flash`, which Command Code's gateway serves on Vertex; `target` was an anyOf of an untyped oneOf and null, `scope` a const). A body whose `model` names Gemini (`geminiNamed`: the id's last `/` segment starts with `gemini`, whoever serves it) has each untyped schema under its tools' `function.parameters`, `parameters` or `input_schema` given its type in place (`geminiToolTypes` in [`gemini_schema.go`](../../internal/gateway/gemini_schema.go), in `forwardOnce`, so a plugin's request too): from its enum or const values, its keywords or its branches, null left out (an object's or array's keywords, `properties` or `items`, before its values: a string enum beside `items` typed `"string"` sent items on a string, and Antigravity turned the turn away with "properties[display].items: field predicate failed: $type == Type.ARRAY", ferock on Discord; `TestGeminiToolTypesItemsBeforeEnum`), `{}` or a description alone a string, a tool's root an object. A node whose branches have more than one type, an unresolved `$ref` or union, and anything under `not` or `if` are left as they came, so such a schema can still be refused; every other model's tools go byte for byte. Google's own Gemini API and Code Assist are sent `parametersJsonSchema` and Antigravity `plainSchema`, so a Gemini-shaped body isn't walked (`TestGeminiToolTypesCuaDriverDrag`, with cua-driver's drag schema as its server listed it, `TestGeminiToolTypes`). `plainSchema` itself keeps an array's keywords (`items`, `minItems`, `maxItems`) on an array only and an object's (`properties`, `required` …) on an object only, and of a type list takes the type its `items` or `properties` are for, so a body a magpie from before sends is taken too (`TestAntigravityItemsOnlyOnArrays`).
- A Responses request's top-level `access_programs`, the Cyber program Codex asks the model under (`{"cyber":"standard"}` on a subagent it inherits, OpenAI's Daybreak programs, magpie-releases#18), goes only where Codex itself would send it: codex-rs sends it with a ChatGPT sign-in, or an API key on its provider named `openai`, and to no other provider (`cyber_access_program.rs`, `for_auth`, `for_provider`). In `forwardOnce`, relayed or built (from Chat too), it goes as it came to a ChatGPT (Codex) account, a host ending in `openai.com`, another magpie (`IsRemoteMagpie`, whose own upstream decides) and a relay set `codexAsSent` when Codex sent the request; every other Responses upstream is sent the request without it (`keepsAccessPrograms`, `withoutTopMember`, the rest byte for byte). OpenCode Go answered it, for DeepSeek and GLM, with 503 "Upstream request failed: Endpoint is unavailable." and 200 without it or with null; its Haiku took it (#3172, three reporters' real A/B runs). It is taken out before the user's extraBody is merged, so an `access_programs` written there still goes. Chat and Messages builds never carry it; a Chat request relayed as it came keeps whatever its client wrote. `TestAccessProgramsGoToOpenAIAlone`, `TestWithoutTopMember`, `TestCodexAccessProgramsReachBackend`.
- Claude Code's deferred tools (ToolSearch, MCP tools that come and go) put blocks of their own in a message: a `tool_addition` (`tool` a `tool_reference` naming the tool, or a `tool_definition`), a `tool_removal`, and a `tool_reference`. Kimi's Anthropic endpoint refuses any of them with a whole-request 400 "Invalid request Error" that names nothing, so once a session had loaded a tool every turn failed (#2042); DeepSeek's takes a `tool_addition` naming a tool but refuses one defining it, a `tool_removal` and a message's `tool_reference` with 422 "unknown variant `tool_removal`" (both checked against the real endpoints on 2026-10-14). OpenCode Go also rejects DeepSeek inline definitions with a generic 422 "Upstream request failed: Endpoint is unavailable." (checked on 2026-10-15). Kimi and DeepSeek models on OpenCode are never sent these blocks (`forwardOnce`); a provider that refuses one in those words is asked again at once without them and not sent them again while magpie runs (`refuseShapes`, `shapeDeferred`; the retry loop reads a 422 as well as a 400). `withoutDeferredTools` drops the blocks and a message they leave empty; definitions present only in a `tool_addition.tool.definition` join the request's `tools` once by name (an existing top-level definition wins), and a `tool_reference` inside a `tool_result` (ToolSearch's answer, which both take) stays. Any other provider is sent them as Claude Code wrote them ([`anthropic_shapes.go`](../../internal/gateway/anthropic_shapes.go), `TestKimiIsSentNoDeferredToolBlocks`, `TestDeferredToolBlocksRefusedOnceLeftOut`, `TestOpenCodeDeepSeekInlineTools`, `TestDeferredInlineDefinitionPreserved`).
- ToolSearch's answer is a `tool_result` whose content is `tool_reference` blocks alone. OpenDesign's Anthropic endpoint can't read one: 422 "Failed to deserialize the JSON body into the target type: messages[4]: missing field `content`" (#2124, the reporter's direct request without magpie fails the same way; the same result with a text block beside the references is taken). A provider that refuses in those words while the request holds such a result is asked again at once with a text block first in each, "Tool <name> is loaded and can be called now." (`toolLoadedText`, the words a translated route already gives a model in `stringOrText`), the references and the `tool_use`/`tool_result` pairing kept, and is sent it that way while magpie runs (`refuseShapes`, `shapeRefsOnly`, `withRefsSaid`). This is in `forward`, so `/v1/messages`, `count_tokens` and a group's member all get it; a request translated to another API already carries the references as that text. Any other provider is sent the bare references (`TestRefsOnlyToolResultRefusedGetsText`, `TestRefsSaidLeavesOtherResults`).
@@ -0,0 +1,102 @@
package gateway
import (
"testing"
"github.com/tidwall/gjson"
)
// displayItemsAsk is a Claude Code request with a tool whose display
// property is an untyped array of choices: items, with the choices as a
// string enum beside them. ferock on Discord sent such a request through
// a routing group of a remote magpie's Antigravity Gemini, and Google
// turned it away: 400 "GenerateContentRequest.tools[0].
// function_declarations[19].parameters.properties[display].items: field
// predicate failed: $type == Type.ARRAY". The tool's literal schema
// wasn't posted; this is the shape that error and the update that broke it
// (geminiToolTypes, which typed such a node from its enum) point to.
const displayItemsAsk = `{"model":"group/gemini-3-8-flash","max_tokens":32,"messages":[{"role":"user","content":"hi"}],
"tools":[{"name":"show","description":"show rows","input_schema":{"type":"object","properties":{
"display":{"description":"columns to display","items":{"type":"string"},"enum":["name","size","date"]},
"filter":{"description":"a filter","properties":{"q":{"type":"string"}},"const":"x"},
"limit":{"type":"integer"}},"required":["display"]}}]}`
// A Gemini model's untyped schema that has items is an array and one
// that has properties an object, whatever its enum or const says: typed
// from its values, the node went on with items on a string.
func TestGeminiToolTypesItemsBeforeEnum(t *testing.T) {
out := geminiToolTypes([]byte(displayItemsAsk))
props := gjson.GetBytes(out, "tools.0.input_schema.properties")
if got := props.Get("display.type").String(); got != "array" {
t.Errorf("display typed %q, want array: %s", got, props.Get("display").Raw)
}
if got := props.Get("filter.type").String(); got != "object" {
t.Errorf("filter typed %q, want object: %s", got, props.Get("filter").Raw)
}
// an enum with no items or properties is still typed from its values
enum := `{"model":"gemini-3.8-flash","tools":[{"name":"a","input_schema":{"type":"object","properties":{"m":{"enum":["a","b"]}}}}]}`
if got := gjson.GetBytes(geminiToolTypes([]byte(enum)), "tools.0.input_schema.properties.m.type").String(); got != "string" {
t.Errorf("enum typed %q, want string", got)
}
}
// Every node Antigravity is sent has items only as an array and
// properties only as an object, on each route: the tool as Claude Code
// sent it, as this version's local magpie passes it on, and as a magpie
// from before passed it on (display typed "string").
func TestAntigravityItemsOnlyOnArrays(t *testing.T) {
older := `{"model":"group/gemini-3-8-flash","max_tokens":32,"messages":[{"role":"user","content":"hi"}],
"tools":[{"name":"show","description":"show rows","input_schema":{"type":"object","properties":{
"display":{"type":"string","description":"columns to display","items":{"type":"string"},"enum":["name","size","date"]},
"listed":{"type":["string","array","null"],"items":{"type":"string"}},
"shaped":{"type":["string","object"],"properties":{"q":{"type":"string"}}},
"word":{"type":"string","minItems":1,"properties":{"q":{"type":"string"}},"required":["q"]}}}}]}`
for name, body := range map[string]string{
"as sent": displayItemsAsk,
"local typed": string(geminiToolTypes([]byte(displayItemsAsk))),
"older local": older,
} {
r, err := parseAnthropic([]byte(body))
if err != nil {
t.Fatal(err)
}
decls := gjson.ParseBytes(buildCodeAssist(r, "gemini-3.8-flash", "antigravity")).Get("request.tools.0.functionDeclarations")
if !decls.IsArray() || len(decls.Array()) == 0 {
t.Fatalf("%s: no declarations", name)
}
var walk func(path string, s gjson.Result)
walk = func(path string, s gjson.Result) {
typ := s.Get("type").String()
for kw, want := range map[string]string{"items": "array", "minItems": "array", "properties": "object", "required": "object"} {
if s.Get(kw).Exists() && typ != want {
t.Errorf("%s: %s has %s on type %q: %s", name, path, kw, typ, s.Raw)
}
}
s.Get("properties").ForEach(func(k, v gjson.Result) bool {
walk(path+".properties."+k.String(), v)
return true
})
if it := s.Get("items"); it.IsObject() {
walk(path+".items", it)
}
}
walk("parameters", decls.Get("0.parameters"))
if name == "older local" {
p := decls.Get("0.parameters.properties")
if got := p.Get("listed.type").String(); got != "array" || !p.Get("listed.items").Exists() || !p.Get("listed.nullable").Bool() {
t.Errorf("listed: %s", p.Get("listed").Raw)
}
if got := p.Get("shaped.type").String(); got != "object" || !p.Get("shaped.properties.q").Exists() {
t.Errorf("shaped: %s", p.Get("shaped").Raw)
}
if got := p.Get("display.enum").Raw; got != `["name","size","date"]` {
t.Errorf("display's enum: %s", p.Get("display").Raw)
}
continue
}
d := decls.Get("0.parameters.properties.display")
if d.Get("type").String() != "array" || d.Get("items.type").String() != "string" {
t.Errorf("%s: display %s", name, d.Raw)
}
}
}
+28
View File
@@ -899,6 +899,14 @@ func plainSchema(raw json.RawMessage) json.RawMessage {
out["type"] = t
}
}
// Google has one type a node: of a list, the one
// its items or properties are for
for _, t := range ts {
if t == "array" && x["items"] != nil || t == "object" && x["properties"] != nil {
out["type"] = t
break
}
}
} else {
out["type"] = v
}
@@ -951,6 +959,26 @@ func plainSchema(raw json.RawMessage) json.RawMessage {
// plugins#375): any item is what JSON Schema means by none
out["items"] = map[string]any{}
}
if t, ok := out["type"].(string); ok {
// JSON Schema reads an array's keywords only on an array
// and an object's only on an object; Google turns the
// whole request away over one on another type ("properties
// [display].items: field predicate failed: $type ==
// Type.ARRAY", ferock on Discord: items beside a string
// enum)
if t != "array" {
delete(out, "items")
delete(out, "minItems")
delete(out, "maxItems")
}
if t != "object" {
delete(out, "properties")
delete(out, "required")
delete(out, "minProperties")
delete(out, "maxProperties")
delete(out, "propertyOrdering")
}
}
if req, ok := out["required"].([]any); ok {
// required names only the properties there are
props, _ := out["properties"].(map[string]any)
+9 -1
View File
@@ -22,7 +22,7 @@ import (
//
// Each schema with no type is given the one its values (enum, const,
// default), keywords (properties: object, items: array, pattern:
// string …) or branches (anyOf, oneOf, allOf, a local $ref) say, null
// string …; an object's or array's before its values) or branches (anyOf, oneOf, allOf, a local $ref) say, null
// left out: Vertex has one type a node, nullable apart. A node whose
// branches have more than one type, or a $ref or union whose types can't
// be told, is left as it came: no one type is right for it. One that says
@@ -98,6 +98,14 @@ func collectGeminiUntyped(body []byte, root, node gjson.Result, isRoot bool, ins
// geminiSchemaType is the one type an untyped schema s is given for
// Vertex, "" when it is left as it came.
func geminiSchemaType(root, s gjson.Result, isRoot bool) string {
if t := keywordType(s); t == "object" || t == "array" {
// properties or items say it before its values do: a schema
// with items and a string enum given "string" went to Google
// with items on a string, and Antigravity turned the whole turn
// away ("properties[display].items: field predicate failed:
// $type == Type.ARRAY", ferock on Discord)
return t
}
vals := s.Get("enum").Array()
if c := s.Get("const"); c.Exists() {
vals = []gjson.Result{c}
+18 -7
View File
@@ -495,6 +495,19 @@ func schemaTypes(root, s gjson.Result, depth int) map[string]bool {
return ts
}
}
t := keywordType(s)
if t == "" {
return nil
}
ts[t] = true
return ts
}
// keywordType is the type schema s's keywords say (properties: object,
// items: array, pattern: string, minimum: number), "" when they say none.
// An object's or an array's keywords come first: they hold schemas of
// their own, which a validator reads only under that type.
func keywordType(s gjson.Result) string {
has := func(keys ...string) bool {
for _, k := range keys {
if s.Get(k).Exists() {
@@ -505,15 +518,13 @@ func schemaTypes(root, s gjson.Result, depth int) map[string]bool {
}
switch {
case has("properties", "required", "additionalProperties", "patternProperties", "minProperties", "maxProperties", "propertyNames", "dependentRequired", "dependentSchemas", "unevaluatedProperties"):
ts["object"] = true
return "object"
case has("items", "prefixItems", "minItems", "maxItems", "uniqueItems", "contains", "unevaluatedItems"):
ts["array"] = true
return "array"
case has("minLength", "maxLength", "pattern", "format", "contentEncoding", "contentMediaType"):
ts["string"] = true
return "string"
case has("minimum", "maximum", "exclusiveMinimum", "exclusiveMaximum", "multipleOf"):
ts["number"] = true
default:
return nil
return "number"
}
return ts
return ""
}