Skip to content

write tool: filePath truncated when content is large — field order puts content first #29140

Description

@strasharo

Summary

When using local OpenAI-compatible backends (Ollama, LM Studio, llama.cpp), the `write` tool frequently fails with:

```
SchemaError(Missing key at ["filePath"])
```

even though the model intended to provide a filePath.

Root cause

The `write` tool schema defines `content` before `filePath`:

```ts
o.Struct({
content: o.String.annotate(...), // first
filePath: o.String.annotate(...), // second
})
```

Local models generate tool-call arguments in schema field order. When `content` is large (e.g. writing a full source file), the model exhausts its output token budget before reaching `filePath`, producing a valid JSON object with content but no filePath.

Fix

Swap the field order so `filePath` is declared before `content`. The model then generates the path first, and only the content can be truncated — which is a recoverable error vs. a missing path.

Related

Workaround

Swap the field order in the opencode binary. Works correctly after the patch with Qwen3.6, Qwen2.5-Coder, and Qwen3-Coder via Ollama.

Activity

  1. github-actions commented on May 24, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    If your issue is specifically about the field ordering fix as a mitigation (putting filePath before content so the path is always captured before truncation), it may be a worthwhile complement to #18108's broader recovery-focused approach — worth clarifying the distinction in a comment there.

  2. strasharo commented on May 24, 2026

    @strasharo
    Author

    Marking as duplicate of #18108 which covers this and the full failure chain in much more detail. The field-order swap (filePath before content) is a useful mitigation but #18108's P0 fix (detecting truncation in repairToolCall) is the proper fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions