Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

gateway: an array with no items goes to Antigravity with items {}, and Google's schema 400 falls through (plugins#375)

yetoneb28e5ffd81d7
diff --git a/internal/gateway/antigravity_array_items_test.go b/internal/gateway/antigravity_array_items_test.go
new file mode 100644
index 000000000..b37dacf16
--- /dev/null
+++ b/internal/gateway/antigravity_array_items_test.go
@@ -0,0 +1,130 @@
+package gateway
+
+import (
+ "encoding/json"
+ "reflect"
+ "strings"
+ "testing"
+
+ "github.com/tidwall/gjson"
+ "github.com/yetone/magpie/internal/provider"
+)
+
+// arrayItemsAsk is plugins#375's minimal reproduction, as gcq909893267
+// posted it: Claude Desktop's own MCP tools __batch and __guide, each with
+// an array property that has no items.
+const arrayItemsAsk = `{"model":"antigravity/gemini-3.8-flash","max_tokens":32,"messages":[{"role":"user","content":"reply with OK only"}],
+ "tools":[{"name":"art_batch","description":"batch","input_schema":{"type":"object","properties":{"batch":{"type":"array"},"verbose":{"type":"boolean"}}}},
+ {"name":"art_guide","description":"read topics","input_schema":{"type":"object","properties":{"items":{"type":"array","description":"topics"}}}}]}`
+
+// Google's 400 to it, the reporter's error line in Google's error shape.
+const arrayItems400 = `{"error":{"code":400,"message":"* GenerateContentRequest.tools[0].function_declarations[17].parameters.properties[batch].items: missing field.\n* GenerateContentRequest.tools[0].function_declarations[18].parameters.properties[items].items: missing field.\n","status":"INVALID_ARGUMENT"}}`
+
+// An array with no items goes to Antigravity with items {}, which Google
+// takes (the reporter's table: {} and {"type":"string"} both answer 200);
+// before, it went as it came and Google turned the whole turn away.
+func TestAntigravityArrayGetsItems(t *testing.T) {
+ r, err := parseAnthropic([]byte(arrayItemsAsk))
+ if err != nil {
+ t.Fatal(err)
+ }
+ env := gjson.ParseBytes(buildCodeAssist(r, "gemini-3.8-flash", "antigravity"))
+ decls := env.Get("request.tools.0.functionDeclarations")
+ if n := len(decls.Array()); n != 2 {
+ t.Fatalf("declarations %s", decls.Raw)
+ }
+ for i, path := range []string{"parameters.properties.batch", "parameters.properties.items"} {
+ node := decls.Get(string(rune('0'+i)) + "." + path)
+ if node.Get("type").String() != "array" || node.Get("items").Raw != "{}" {
+ t.Errorf("declaration %d %s: %s", i, path, node.Raw)
+ }
+ }
+ if d := decls.Get("1.parameters.properties.items.description").String(); d != "topics" {
+ t.Errorf("description lost: %q", d)
+ }
+}
+
+// Every array plainSchema writes has items, however deep it sits: under
+// properties, items, an anyOf/oneOf member, an allOf, a $ref to $defs, a
+// type list with null; one that has items keeps its own.
+func TestPlainSchemaArraysAllHaveItems(t *testing.T) {
+ in := `{"type":"object","$defs":{"Tags":{"type":"array","description":"tags"}},
+ "properties":{
+ "grid":{"type":"array","items":{"type":"array"}},
+ "maybe":{"anyOf":[{"type":"null"},{"type":"array"}]},
+ "one":{"oneOf":[{"type":"array","minItems":1},{"type":"string"}]},
+ "both":{"allOf":[{"type":"object","properties":{"list":{"type":"array"}}}]},
+ "tags":{"$ref":"#/$defs/Tags"},
+ "opt":{"type":["array","null"]},
+ "kept":{"type":"array","items":{"type":"string"}},
+ "deep":{"type":"object","properties":{"rows":{"type":"array","items":{"type":"object","properties":{"cells":{"type":"array"}}}}}}
+ }}`
+ want := `{"type":"object","properties":{
+ "grid":{"type":"array","items":{"type":"array","items":{}}},
+ "maybe":{"type":"array","items":{},"nullable":true},
+ "one":{"type":"array","items":{},"minItems":1},
+ "both":{"type":"object","properties":{"list":{"type":"array","items":{}}}},
+ "tags":{"type":"array","items":{},"description":"tags"},
+ "opt":{"type":"array","items":{},"nullable":true},
+ "kept":{"type":"array","items":{"type":"string"}},
+ "deep":{"type":"object","properties":{"rows":{"type":"array","items":{"type":"object","properties":{"cells":{"type":"array","items":{}}}}}}}
+ }}`
+ var got, exp any
+ if err := json.Unmarshal(plainSchema(json.RawMessage(in)), &got); err != nil {
+ t.Fatal(err)
+ }
+ json.Unmarshal([]byte(want), &exp)
+ if !reflect.DeepEqual(got, exp) {
+ b, _ := json.Marshal(got)
+ t.Errorf("got %s", b)
+ }
+ // a schema that isn't an array gets no items
+ if b := plainSchema(json.RawMessage(`{"type":"object","properties":{"s":{"type":"string"}}}`)); strings.Contains(string(b), "items") {
+ t.Errorf("items added to a non-array: %s", b)
+ }
+}
+
+// Google's refusal of a function declaration's schema is the request's
+// shape on that vendor, not the account's fault: the group's next member,
+// whose model took the same tools in the report, is asked, and the one
+// that refused doesn't rest. Before, the route ended on the 400 (the
+// reporter's tries held the one attempt).
+func TestGroupFailsOverGoogleSchema400(t *testing.T) {
+ fresh(t)
+ a := &scripted{replies: []reply{{400, "", arrayItems400}}}
+ b := &scripted{replies: []reply{{200, "", chatOK}}}
+ scriptedOn(t, "a", provider.Chat, a)
+ scriptedOn(t, "b", provider.Chat, b)
+ if err := provider.SaveGroup(provider.Group{Name: "G", Members: []string{"a/m", "b/m"}, Routing: provider.Ordered}); err != nil {
+ t.Fatal(err)
+ }
+ s := New()
+ code, body := postAs(t, s, "", `{"model":"group/g","messages":[{"role":"user","content":"hi"}]}`)
+ if code != 200 || !strings.Contains(body, "hello") || a.n != 1 || b.n != 1 {
+ t.Fatalf("%d %s (a %d, b %d)", code, body, a.n, b.n)
+ }
+ r := s.trace.routes[len(s.trace.routes)-1]
+ if len(r.Tries) != 2 || r.Tries[0].Status != 400 || r.Tries[0].Fail != failShape || r.Tries[0].Rest != nil {
+ t.Fatalf("tries %+v", r.Tries)
+ }
+
+ for _, x := range []struct {
+ status int
+ body string
+ want bool
+ }{
+ {400, arrayItems400, true},
+ // as magpie passed it on to the agent
+ {400, `{"error":{"message":"Antigravity: * GenerateContentRequest.tools[0].function_declarations[26].parameters.properties[batch].items: missing field.\n"}}`, true},
+ // Google's other wording for a schema keyword it doesn't take (#187)
+ {400, `{"error":{"code":400,"message":"Invalid JSON payload received. Unknown name \"exclusiveMinimum\" at 'request.tools[0].function_declarations[3].parameters.properties[0].value': Cannot find field.","status":"INVALID_ARGUMENT"}}`, true},
+ // a declaration's name, and the contents, are not the schema's
+ {400, `{"error":{"code":400,"message":"* GenerateContentRequest.tools[0].function_declarations[2].name: Invalid function name.","status":"INVALID_ARGUMENT"}}`, false},
+ {400, `{"error":{"code":400,"message":"* GenerateContentRequest.contents: contents is not specified\n","status":"INVALID_ARGUMENT"}}`, false},
+ {500, arrayItems400, false},
+ } {
+ if got := shapeRefused(x.status, []byte(x.body)); got != x.want {
+ t.Errorf("shapeRefused(%d, %s) = %v", x.status, x.body, got)
+ }
+ }
+}
diff --git a/internal/gateway/codeassist.go b/internal/gateway/codeassist.go
index 82a77969d..711b507f6 100644
--- a/internal/gateway/codeassist.go
+++ b/internal/gateway/codeassist.go
@@ -794,6 +794,13 @@ func plainSchema(raw json.RawMessage) json.RawMessage {
out["type"] = "array"
}
}
+ if out["type"] == "array" && out["items"] == nil {
+ // Google wants items on every array, and turns the whole
+ // request away over one with none ("…properties[batch].
+ // items: missing field", Claude Desktop's own MCP tools,
+ // plugins#375): any item is what JSON Schema means by none
+ out["items"] = map[string]any{}
+ }
if req, ok := out["required"].([]any); ok {
// required names only the properties there are
props, _ := out["properties"].(map[string]any)
diff --git a/internal/gateway/fallback.go b/internal/gateway/fallback.go
index 7ade0fbc4..b88c1efbd 100644
--- a/internal/gateway/fallback.go
+++ b/internal/gateway/fallback.go
@@ -1192,8 +1192,13 @@ func promptRefused(status int, body []byte) bool {
// custom tool turned away (customToolRefusal, DeepSeek's "Unsupported
// custom tool: 'exec'", #2656) where no translation took it in. A
// request missing what every API requires ("field required") or too long
-// for the model isn't one.
-var shapeWords = regexp.MustCompile(`(?i)failed to deserialize|unknown (item |content |input )?(type|variant|field|parameter)|unknown_parameter|unrecognized (request argument|field|parameter)|extra (inputs|fields) are not permitted|additional properties are not allowed|schema exceeds the maximum (nesting )?depth|schema[^"]{0,60}\bnesting depth\b`)
+// for the model isn't one. Google's refusal of a function declaration's
+// schema, which points at it (GenerateContentRequest.tools[0].
+// function_declarations[17].parameters.properties[batch].items: missing
+// field, plugins#375), is the same kind as OpenCode Go's: its subset of
+// JSON Schema is its own, and another vendor's model took the reporter's
+// same tools.
+var shapeWords = regexp.MustCompile(`(?i)failed to deserialize|unknown (item |content |input )?(type|variant|field|parameter)|unknown_parameter|unrecognized (request argument|field|parameter)|extra (inputs|fields) are not permitted|additional properties are not allowed|schema exceeds the maximum (nesting )?depth|schema[^"]{0,60}\bnesting depth\b|function_declarations\[\d+\]\.parameters\b`)
// unsaidWords are Command Code's Provider API turning a request away with
// nothing but a trace id: {"message":"invalid request error trace_id: