From 00a2fa5808ba907b53ec45b7cb426fe68c783e8a Mon Sep 17 00:00:00 2001 From: Aiden Cline Date: Wed, 25 Nov 2026 20:43:28 -0600 Subject: [PATCH] fix(core): keep a tool call's keys when a required key is missing --- packages/core/src/plugin/tool-input-repair.ts | 3 +- .../tool-input-repair-integration.test.ts | 51 +++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/packages/core/src/plugin/tool-input-repair.ts b/packages/core/src/plugin/tool-input-repair.ts index 37264812a4f..0043e88a5ad 100644 --- a/packages/core/src/plugin/tool-input-repair.ts +++ b/packages/core/src/plugin/tool-input-repair.ts @@ -158,6 +158,7 @@ function repairObject( const properties = Predicate.isObject(schema.properties) ? schema.properties : {} const required = Array.isArray(schema.required) ? schema.required : [] + const missing = required.some((key) => !Object.hasOwn(parsed, key)) const patterned = Predicate.isObject(schema.patternProperties) const composed = Array.isArray(schema.allOf) || Array.isArray(schema.anyOf) || Array.isArray(schema.oneOf) @@ -166,7 +167,7 @@ function repairObject( const declared = Object.hasOwn(properties, key) const property = declared ? properties[key] : !patterned ? schema.additionalProperties : undefined - if (!declared && schema.additionalProperties === false && !patterned && !composed) { + if (!declared && schema.additionalProperties === false && !patterned && !composed && !missing) { const next = { ...result } delete next[key] return next diff --git a/packages/core/test/plugin/tool-input-repair-integration.test.ts b/packages/core/test/plugin/tool-input-repair-integration.test.ts index b450ae3b6b6..ec4167d0bf0 100644 --- a/packages/core/test/plugin/tool-input-repair-integration.test.ts +++ b/packages/core/test/plugin/tool-input-repair-integration.test.ts @@ -294,3 +294,54 @@ it.effect("repairs nested Code Mode calls against the Code Mode input schema", ( expect(executed).toEqual([{ count: 3, detail: true }, { count: 4 }]) }), ) + +it.effect("keeps undeclared keys when a required key is missing so the error shows them", () => + Effect.gen(function* () { + const plugins = yield* Plugin.Service + const registry = yield* Tool.Service + const executed: unknown[] = [] + yield* plugins.activate([ + { ...ToolInputRepairPlugin.Plugin, revision: "1" }, + { + id: "edit-tool", + revision: "1", + effect: (ctx) => + ctx.tool.transform((draft) => + draft.add({ + name: "edit", + options: { codemode: false }, + description: "Edit", + input: Schema.Struct({ path: Schema.String, oldString: Schema.String, newString: Schema.String }), + execute: (input) => Effect.sync(() => executed.push(input)).pipe(Effect.as({ content: "ok" })), + }), + ), + }, + ]) + const snapshot = yield* registry.snapshot() + const failed = yield* snapshot + .execute({ + ...identity, + call: { + type: "tool-call", + id: "call-wrong-keys", + name: "edit", + input: { path: "a.ts", old_string: "a", new_string: "b" }, + }, + }) + .pipe(Effect.flip) + expect(failed.message).toContain("oldString") + expect(failed.message).toContain("old_string") + expect(failed.message).toContain("new_string") + + yield* snapshot.execute({ + ...identity, + call: { + type: "tool-call", + id: "call-extra-key", + name: "edit", + input: { path: "a.ts", oldString: "a", newString: "b", extra: true }, + }, + }) + expect(executed).toEqual([{ path: "a.ts", oldString: "a", newString: "b" }]) + }), +)