devin 0.1.25: an anyOf beside a type, below a tool's root, goes to Gemini models as a merged branch or a oneOf (#458)

songyq26's Kimi Code Read tool (line_offset: anyOf of two integers) and
any Optional field made every devin/gemini-4-argon request 400 "There is
an issue with this request". The cause is a type beside the anyOf:
magpie's gateway (geminiToolTypes) writes the type the branches agree on
beside an untyped anyOf for a Gemini-named model, and Devin's Gemini
models refuse {type: T, anyOf: [...]} anywhere below the root. An untyped
anyOf, a root anyOf and a oneOf beside a type are taken, which is why the
reporter's matrix showed oneOf as OK.

geminiSchema now changes only an anyOf beside a type, at depth > 0: null
branches become nullable, one branch left of the same type (or none) is
merged into the schema, two or more go as a oneOf (into allOf if a oneOf
is already there). The recursion already reaches properties, items,
additionalProperties and anyOf/oneOf/allOf members, so each gets it.

Run:
- HOME=$(mktemp -d) bun test in packages/devin (on mote): 119 pass, 0 fail.
  bun scripts/check.mjs devin passes.
- Broken by hand: with index.mjs at origin/main, 9 new tests fail
  (8 fixtures incl. kimiRead from the reporter's literal line_offset, and
  the unit test); the 30 others pass.
- Real account, plugin fetch to gemini-4-argon: on 0.1.24, typed anyOf in
  properties / items / of objects and Kimi's line_offset with the
  gateway's type 400; untyped anyOf, root anyOf and typed oneOf 200. With
  this change all 17 probe shapes 200. A first try that turned every
  nested anyOf into a oneOf made {nullable, oneOf} with no type, which
  Devin refused, so untyped anyOf is left as it came.
Not tried: Claude / swe-2 models live (their path is unchanged);
other plugins (grok, qoder, workbuddy, kimi-work) have their own
cleaners for other vendors' rules and don't share geminiSchema.
This commit is contained in:
yetone
2026-10-28 13:21:49 +08:00
parent c2eb8de4f7
commit 2c30818458
3 changed files with 86 additions and 2 deletions
+59
View File
@@ -35,6 +35,30 @@ const REFUSED = {
unionNoItems: P({ a: { anyOf: [{ type: "array" }, { type: "null" }] } }),
propsNoType: P({ a: { properties: { b: { type: "string" } } } }),
enumNoType: P({ a: { enum: ["x", "y"] } }),
// an anyOf beside a type, below the root (plugins#458, songyq26): what
// magpie's gateway sends for a Gemini model, as it writes the type the
// branches agree on beside an untyped anyOf. typedAnyOf, typedAnyOfObjects,
// typedAnyOfItems and kimiRead were sent to gemini-4-argon on a real
// account: 400 on 0.1.24, taken as built here.
typedAnyOf: P({ a: { type: "integer", anyOf: [{ type: "integer" }, { type: "null" }] } }),
typedAnyOfObjects: P({ a: { type: "object", anyOf: [P({ b: { type: "string" } }), P({ c: { type: "integer" } })] } }),
typedAnyOfItems: P({ a: { type: "array", items: { type: "integer", anyOf: [{ type: "integer" }, { type: "null" }] } } }),
typedAnyOfAdditional: P({ a: { type: "object", additionalProperties: { type: "string", anyOf: [{ type: "string" }, { type: "null" }] } } }),
typedAnyOfInOneOf: P({ a: { oneOf: [P({ b: { type: "integer", anyOf: [{ type: "integer" }, { type: "null" }] } }), { type: "string" }] } }),
typedAnyOfInAllOf: P({ a: { allOf: [P({ b: { type: "integer", anyOf: [{ type: "integer" }, { type: "null" }] } })] } }),
typedAnyOfInAnyOf: P({ a: { anyOf: [P({ b: { type: "integer", anyOf: [{ type: "integer" }, { type: "null" }] } }), { type: "null" }] } }),
// Kimi Code's Read, line_offset as the reporter quoted it, with the type
// magpie's gateway writes beside it
kimiRead: P({
path: { type: "string" },
line_offset: {
type: "integer",
anyOf: [
{ type: "integer", minimum: 1, maximum: 9007199254740991 },
{ type: "integer", minimum: -9007199254740991, exclusiveMaximum: 0 },
],
},
}),
}
const chatWith = (parameters) => ({
@@ -49,9 +73,11 @@ function refused(s, at = "$") {
if (Array.isArray(s.type)) out.push(at + " list type")
if (s.type === "array" && (!s.items || typeof s.items !== "object" || Array.isArray(s.items))) out.push(at + " items")
if (s.type === undefined && (s.properties || s.enum)) out.push(at + " no type")
if (at !== "$" && s.type !== undefined && s.anyOf) out.push(at + " anyOf beside a type")
for (const [k, v] of Object.entries(s.properties ?? {})) out.push(...refused(v, at + "." + k))
for (const k of ["anyOf", "oneOf", "allOf"]) for (const [i, v] of (s[k] ?? []).entries()) out.push(...refused(v, `${at}.${k}[${i}]`))
if (s.items) out.push(...refused(s.items, at + "[]"))
if (s.additionalProperties) out.push(...refused(s.additionalProperties, at + "{}"))
return out
}
@@ -95,3 +121,36 @@ test("a schema Gemini takes goes as it came", () => {
}
expect(sent(_internal.build(chatWith(parameters), "gemini-4-argon-medium", "k")).t).toEqual(parameters)
})
test("below the root an anyOf beside a type goes as a merged branch or a oneOf (plugins#458)", () => {
const g = (s) => _internal.geminiSchema(P({ a: s })).properties.a
// the null branch is nullable, the one left is merged; the schema's own
// words stay
expect(g({ type: "integer", description: "d", anyOf: [{ type: "integer", minimum: 1 }, { type: "null" }] })).toEqual({
type: "integer",
minimum: 1,
description: "d",
nullable: true,
})
expect(g({ type: "array", anyOf: [{ type: "array" }, { type: "null" }] })).toEqual({ type: "array", items: {}, nullable: true })
// two or more stay as a oneOf, which Devin takes beside a type
expect(g({ type: "integer", anyOf: [{ type: "integer", minimum: 1 }, { type: "integer", exclusiveMaximum: 0 }] })).toEqual({
type: "integer",
oneOf: [{ type: "integer", minimum: 1 }, { type: "integer", exclusiveMaximum: 0 }],
})
// a branch of another type than the schema's is not merged over it
expect(g({ type: "string", anyOf: [{ type: "integer" }] })).toEqual({ type: "string", oneOf: [{ type: "integer" }] })
// a oneOf already there keeps its place; the anyOf's goes in allOf
expect(g({ type: "integer", oneOf: [{ minimum: 5 }, { maximum: 1 }], anyOf: [{ minimum: 1 }, { maximum: 9 }] })).toEqual({
type: "integer",
oneOf: [{ minimum: 5 }, { maximum: 1 }],
allOf: [{ oneOf: [{ minimum: 1 }, { maximum: 9 }] }],
})
// an anyOf with no type is taken, and so is one at the root: both go as
// they came (a nullable oneOf with no type is refused)
const untyped = { anyOf: [{ type: "string", minLength: 1 }, { type: "null" }] }
expect(g(untyped)).toEqual(untyped)
expect(g({ type: ["string", "number", "null"] })).toEqual({ nullable: true, anyOf: [{ type: "string" }, { type: "number" }] })
const root = { type: "object", anyOf: [P({ b: { type: "string" } }), P({ c: { type: "integer" } })] }
expect(_internal.geminiSchema(root)).toEqual(root)
})
+26 -1
View File
@@ -1298,9 +1298,21 @@ const isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v)
// schema with properties is an object; an enum's type comes from its
// values, and an enum of mixed values goes. The caller's own is never
// changed.
//
// Below the root it also refuses an anyOf beside a type, which is what
// magpie's gateway sends for a Gemini model: it writes the type the
// branches agree on beside an anyOf that had none, so Kimi Code's Read
// (line_offset: anyOf of two integers) and every Optional field came in
// as {type: "integer", anyOf: [...]} and were refused (songyq26,
// plugins#458). A oneOf beside a type, an anyOf at the root and an anyOf
// with no type are taken, and a oneOf with no type beside nullable is
// not, so only an anyOf beside a type is changed: its null branches
// become nullable, one branch left of that type (or of none) is merged
// into the schema, and two or more are sent as a oneOf (into allOf when
// there is a oneOf already).
function geminiSchema(s, depth = 0) {
if (!isObj(s) || depth > 32) return s
const out = { ...s }
let out = { ...s }
const sub = (v) => geminiSchema(v, depth + 1)
for (const k of ["properties", "patternProperties", "$defs", "definitions", "dependentSchemas"])
if (isObj(out[k])) out[k] = Object.fromEntries(Object.entries(out[k]).map(([n, v]) => [n, sub(v)]))
@@ -1319,6 +1331,19 @@ function geminiSchema(s, depth = 0) {
}
if (out.type === undefined) delete out.type
}
if (depth > 0 && out.type !== undefined && Array.isArray(out.anyOf)) {
const isNull = (b) => isObj(b) && b.type === "null"
const some = out.anyOf.filter((b) => !isNull(b))
if (some.length < out.anyOf.length) out.nullable = true
delete out.anyOf
const one = some.length === 1 && isObj(some[0]) ? some[0] : undefined
if (one && (one.type === undefined || one.type === out.type)) {
out = { ...one, ...out }
} else if (some.length) {
if (!Array.isArray(out.oneOf)) out.oneOf = some
else out.allOf = [...(Array.isArray(out.allOf) ? out.allOf : []), { oneOf: some }]
}
}
if (out.type === undefined && Array.isArray(out.enum)) {
const vals = out.enum.filter((v) => v !== null)
if (vals.length < out.enum.length) out.nullable = true
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-devin-auth",
"version": "0.1.24",
"version": "0.1.25",
"description": "Devin subscriptions (the devin CLI's account) in OpenCode and magpie",
"type": "module",
"main": "./index.mjs",