Skip to content

OpenAI-compatible models can call write/edit with invalid schema arguments #29142

@deffenda

Description

@deffenda

Description

OpenCode intermittently invokes built-in write and edit tools with invalid argument shapes when using OpenAI-compatible models. The UI surfaces schema errors instead of recovering or prompting the model with the exact expected schema.

This causes repeated failed tool calls and can trap an agent in a loop. I have seen it with local Qwen via LM Studio, and a similar planner flow with DeepSeek V4 Flash Free when the prompt asked the model to create a task packet file.

Related/possibly duplicate issues:

This report adds concrete edit failures as well as write failures on OpenCode 1.15.10.

OpenCode version

opencode version: 1.15.10
os: Darwin 25.5.0 arm64
terminal: dumb
plugins: none

Installed as the macOS desktop app / CLI.

Model/provider setup

Observed primarily with:

  • qwen3-coder-next/qwen3-coder-next
  • OpenAI-compatible provider pointed at LM Studio, http://127.0.0.1:1234/v1

Also observed in a planner workflow using:

  • opencode/deepseek-v4-flash-free

Symptoms

Write tool failure

From captured output:

✗ Write requirements.txt failed
Error: The write tool was called with invalid arguments: SchemaError(Missing key
  at ["content"]).
Please rewrite the input so it satisfies the expected schema.

Another captured run:

Error: The write tool was called with invalid arguments: SchemaError(Missing key
  at ["content"]).
Please rewrite the input so it satisfies the expected schema.

The model appeared to send a write call using a non-matching key such as fileContent rather than the expected content key.

Edit tool failure

From captured output:

✗ Edit  failed
Error: The edit tool was called with invalid arguments: SchemaError(Missing key
  at ["filePath"]).
Please rewrite the input so it satisfies the expected schema.

This repeated many times in one session. In the same run, valid-looking edit attempts also sometimes failed with normal semantic errors such as multiple oldString matches, then subsequent attempts lost the filePath entirely and hit schema validation.

Steps to reproduce

One reliable pattern for me:

  1. Configure an OpenAI-compatible local model in OpenCode, e.g. LM Studio serving Qwen Coder.
  2. Run opencode run with a coding task that requires creating or editing files.
  3. Ask the agent to create or modify files using OpenCode's normal write/edit tools.
  4. Observe write or edit tool calls fail schema validation before execution.

Example command shape:

opencode run \
  --dir /path/to/repo \
  --agent qwen \
  --model qwen3-coder-next/qwen3-coder-next \
  "Read a local task packet and implement the listed files."

The issue appears more likely with local/OpenAI-compatible models, but the failure is surfaced by OpenCode's tool schema handling.

Expected behavior

OpenCode should either:

  • expose tool schemas to models in a way that reliably causes correct keys (content, filePath, etc.), or
  • repair/reject malformed tool calls with a clear model-visible correction, or
  • include enough diagnostics to show the malformed tool-call payload safely.

At minimum, if the model sends fileContent for write, it would be helpful to either accept common aliases or return a tool error that explicitly says write requires { filePath, content }.

Actual behavior

OpenCode displays:

The write tool was called with invalid arguments: SchemaError(Missing key at ["content"])

and/or:

The edit tool was called with invalid arguments: SchemaError(Missing key at ["filePath"])

The agent often retries and accumulates many failed tool calls. I had to work around it by disabling edit/write for local agents and making the harness write files itself from final chat output, or forcing shell heredocs.

Workaround used locally

Project agent config now denies the problematic tools:

permission:
  read: allow
  glob: allow
  grep: allow
  list: allow
  bash: allow
  edit: deny
  write: deny

For planner flows, I changed prompts so the model returns markdown between markers, then an external shell harness writes the file. For implementer flows, I force shell heredocs instead of OpenCode write / edit.

This works around the issue, but it removes one of OpenCode's core file-editing paths for local models.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions