Skip to content

Commit db28e2d

Browse files
wtfsayoclaude
andcommitted
fix(devin): keep outer constraints when folding a Gemini anyOf
Folding each existing anyOf branch into the outer keywords let a branch override a contradicting outer keyword, so `{maxLength: 5, anyOf: [{maxLength: 50}]}` loosened to 50. On any such disagreement, keep both constraints under allOf instead; live, gemini-3-8-flash-medium accepts allOf. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent d84edae commit db28e2d

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

‎src/adapters/devin/cloud-direct/tool-schema.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ const isSchema = (value: unknown): value is Schema => !!value && typeof value ==
3434
/**
3535
* `{type: [T, "null"], ...rest}` becomes `{anyOf: [{...rest, type: T}, {type: "null"}]}`,
3636
* so type-specific keywords (items, properties, ...) stay attached to their type.
37-
* An existing anyOf is folded in branch by branch rather than nested under allOf.
37+
* An existing anyOf is folded in branch by branch when no branch contradicts an
38+
* outer keyword, and kept beside the split under allOf when one does.
3839
*/
3940
function splitTypeArray(node: Schema, types: unknown[]): Schema {
4041
const annotations: Schema = {};
@@ -46,6 +47,15 @@ function splitTypeArray(node: Schema, types: unknown[]): Schema {
4647
const concrete = types.filter((type) => type !== 'null');
4748
const allowsNull = concrete.length < types.length;
4849
const existing = Array.isArray(node.anyOf) ? node.anyOf : undefined;
50+
// Folding merges each branch into the outer keywords, which is only exact when
51+
// they never disagree: `{maxLength: 5, anyOf: [{maxLength: 50}]}` folded would
52+
// loosen the outer limit. On a disagreement keep both constraints under allOf,
53+
// which this backend accepts (live: gemini-3-8-flash-medium).
54+
if (existing?.some((branch) => isSchema(branch) && Object.keys(branch).some(
55+
(key) => key !== 'type' && key in rest && JSON.stringify(branch[key]) !== JSON.stringify(rest[key]),
56+
))) {
57+
return { ...annotations, allOf: [splitTypeArray({ ...rest, type: types }, types), { anyOf: existing }] };
58+
}
4959
const branches: unknown[] = [];
5060
let nullReachable = allowsNull && !existing;
5161
if (!existing) {

‎tests/providers/devin-chat-wire-fixes.test.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,19 @@ describe("Gemini tool schema type arrays", () => {
137137
});
138138
});
139139

140-
test("an existing anyOf is folded in, never nested under allOf", () => {
140+
test("a branch that contradicts an outer keyword keeps both constraints under allOf", () => {
141+
const out = normalizeDevinToolParameters("gemini-x", {
142+
type: ["string", "null"], maxLength: 5, anyOf: [{ maxLength: 50 }, { type: "null" }],
143+
}) as any;
144+
expect(out).toEqual({
145+
allOf: [
146+
{ anyOf: [{ maxLength: 5, type: "string" }, { type: "null" }] },
147+
{ anyOf: [{ maxLength: 50 }, { type: "null" }] },
148+
],
149+
});
150+
});
151+
152+
test("an existing anyOf that agrees with the outer keywords is folded in, not nested under allOf", () => {
141153
const out = normalizeDevinToolParameters("MODEL_GOOGLE_GEMINI_2_5_PRO", {
142154
type: ["object", "null"], anyOf: [{ required: ["a"] }, { required: ["b"] }],
143155
}) as any;

0 commit comments

Comments
 (0)