GeezerVison is showing github.com — V2: tool input repair uses the live schema instead of the request snapshot · Issue #53025 · anomalyco/opencode
V2: tool input repair uses the live schema instead of the request snapshot #53025DescriptionDescription
Tool input repair reads the current tool definition from ctx.tool.list(), but execution validates against the definition captured by Tool.snapshot(). If the registered schema changes after snapshot creation, repair can turn valid arguments into invalid ones.
I reproduced this with a live openai/gpt-6-luna session. The captured tool accepts { value: string }, and the model sends {"value":"false"}. After the live registry schema changes to { value: boolean }, repair converts the string to a boolean and validation fails:
Invalid arguments for tool "schema_probe":
- value: Expected string
Arguments provided:
{
"value": false
}
The persisted tool record confirms the model originally sent a string. Disabling the repair plugin makes the same reproduction succeed with Received "false" (string).
Expected behavior: repair should use the same captured tool definition as validation and execution.
Plugins
Built-in ToolInputRepairPlugin and a local reproduction plugin, repro.captured-schema. The reproduction plugin changes the registered schema after snapshot creation; it does not modify model responses or tool-call arguments.
OpenCode version
V2 source at d1f8f5b35ef90499902797129457f2102abe18b6 (package version 2.0.22), built locally with Bun 1.4.2.
Steps to reproduce
- Register a direct tool named
schema_probe with input schema Schema.Struct({ value: Schema.String }).
- In the first primary
session.model.request hook, update its registered input schema to Schema.Struct({ value: Schema.Boolean }). The request has already captured the string schema.
- Ask the model to call
schema_probe once with {"value":"false"}.
- Observe that the model sends a string, but validation reports a boolean and rejects the call.
- Disable
opencode.tool.input.repair and repeat in a fresh standalone process. The captured tool now correctly receives the string.
Integration tests also reproduce the same mismatch through direct execution and Code Mode.
Screenshot and/or share link
N/A.
Operating System
Ubuntu 24.04.5 LTS (Noble Numbat)
Terminal
Non-interactive CLI: opencode run --standalone --format json. Activityopencodejr commented on Oct 27, 2026 Thanks for the clear report. I've reproduced this on 2.0.22, and it still happens on the latest dev (14e378b6).
Steps (no model needed, using the core test fixtures):
- Activate
ToolInputRepairPlugin and register schema_probe with input { value: string }.
- Take a tool snapshot.
- Change the registered schema to
{ value: boolean }.
- Run
{ value: "false" } through the earlier snapshot.
Repair converts the value to false using the live schema, then validation against the captured string schema rejects it with value: Expected string. Without the repair plugin, the tool receives "false" as expected.
The cause looks like the one you identified: packages/core/src/plugin/tool-input-repair.ts looks up the schema with ctx.tool.list() instead of using the definition captured in the request snapshot. The script below reproduces it as a Bun test in packages/core.
Reproduction script (repro-53025.test.ts)
// Reproduction for anomalyco/opencode#53025: tool input repair uses the live registry schema
// instead of the schema captured by the request snapshot that validates and executes the call.
// Run from packages/core: bun test test/plugin/repro-53025.test.ts
import { expect } from "bun:test"
import { Effect, Schema } from "effect"
import { Agent } from "@opencode/core/agent"
import { Plugin } from "@opencode/core/plugin"
import { ToolInputRepairPlugin } from "@opencode/core/plugin/tool-input-repair"
import { Session } from "@opencode/core/session"
import { SessionMessage } from "@opencode/core/session/message"
import { Tool } from "@opencode/core/tool"
import { testEffect } from "../lib/effect"
import { PluginTestLayer } from "./fixture"
const it = testEffect(PluginTestLayer)
const identity = {
sessionID: Session.ID.make("ses_repro"),
agent: Agent.ID.make("build"),
messageID: SessionMessage.ID.make("msg_repro"),
}
it.effect("repair uses the captured snapshot schema, not the live one", () =>
Effect.gen(function* () {
const plugins = yield* Plugin.Service
const registry = yield* Tool.Service
const executed: unknown[] = []
yield* plugins.activate([{ ...ToolInputRepairPlugin.Plugin, revision: "1" }])
yield* registry.transform((draft) =>
draft.add({
name: "schema_probe",
options: { codemode: false },
description: "Probe",
input: Schema.Struct({ value: Schema.String }),
execute: (input) => Effect.sync(() => executed.push(input)).pipe(Effect.as({ content: "ok" })),
}),
)
// The request captures the string schema here.
const snapshot = yield* registry.snapshot()
// Later, the live registry schema changes.
yield* registry.transform((draft) =>
draft.update("schema_probe", (tool) => {
tool.input = Schema.Struct({ value: Schema.Boolean })
}),
)
const result = yield* snapshot
.execute({
...identity,
call: { type: "tool-call", id: "call-1", name: "schema_probe", input: { value: "false" } },
})
.pipe(Effect.result)
console.log("result:", JSON.stringify(result, null, 2))
expect(executed).toEqual([{ value: "false" }])
}),
)
Run it: bun repro-53025.test.ts
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|