Skip to content

Can not write files #18151

Closed as not planned
Closed as not planned

Description

@dctr

Description

I am consistently seeing write failures when trying to write new files. (Small patches usually work.)

Most of the time, I see the tool just having {} arguments, and the return is `Write Failed: Tool execution aborted.

One out of the 10+ attempts looked like this:

The write tool was called with invalid arguments: [
  {
    "expected": "string",
    "code": "invalid_type",
    "path": [
      "content"
    ],
    "message": "Invalid input: expected string, received undefined"
  },
  {
    "expected": "string",
    "code": "invalid_type",
    "path": [
      "filePath"
    ],
    "message": "Invalid input: expected string, received undefined"
  }
].
Please rewrite the input so it satisfies the expected schema.

Plugins

None

OpenCode version

Desktop, Version 1.2.27

Steps to reproduce

  1. Tell AI to come up with "something", and have it write it to a file.
  2. AI uses write tool call
  3. ???
  4. Repeats several times and fails

Screenshot and/or share link

No response

Operating System

macOS 26.3.1

Terminal

Desktop app, but also happens on iTerm

Activity

  1. added
    bugSomething isn't working
    on Mar 18, 2026
  2. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Mar 18, 2026
  3. github-actions commented on Mar 18, 2026

    @github-actions
    Contributor

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

    If your issue is the same as #18131, please consider adding your details there instead.

  4. RewFa-CEO commented on Mar 19, 2026

    @RewFa-CEO

    Root Cause Analysis

    This issue appears to be related to how the write tool arguments are being processed/passed through the AI model response pipeline.

    Error Analysis

    The error indicates:

    For both and fields - this suggests the arguments are being lost or undefined somewhere in the tool call chain.

    Likely Root Causes

    1. Tool Call Argument Parsing Issue
    The tool is likely implemented as part of the edit/apply system. When the AI model generates a write operation, the arguments may not be properly extracted or validated before being passed to the tool execution layer.

    2. Streaming Response Handling
    If using streaming responses from the LLM, there could be a race condition where tool calls are parsed before complete arguments are received.

    3. Schema Validation Timing
    The error shows arguments are - this typically happens when:

    • The tool call arguments object is created before all fields are populated
    • There's a schema mismatch between what the model outputs and what the tool expects

    Recommended Investigation

    1. Check how tool is defined in the tool registry
    2. Look at the tool argument extraction/validation logic
    3. Verify the schema definition matches what the LLM is being told to output

    Possible Fix

    Ensure the tool schema explicitly marks fields as required and add validation before executing the tool to provide better error messages.

  5. dctr commented on Mar 20, 2026

    @dctr
    Author

    To clarify, I am not running a custom model. This happens with Claude Sonnet/Opus 4.6

  6. Taudris commented on Apr 2, 2026

    @Taudris

    Still happening on 1.3.13 with Opus 4.6 on Copilot.

    It also completely stops the agent, which is damaging to productivity.

  7. removed
    bugSomething isn't working
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  8. ChanifRusydi commented on Jun 4, 2026

    @ChanifRusydi

    Same here with latest version (1.15.13) and claude-opus-4.8
    A few observable error is as follows :

    invalid [tool=edit, error=Invalid input for tool edit: JSON parsing failed: Text: {"filePath": "{real-file-path-here}", "newStri.
    Error message: JSON Parse error: Unterminated string]
    
    invalid [tool=write, error=Invalid input for tool write: JSON parsing failed: Text: {"content": .
    Error message: JSON Parse error: Unexpected EOF]
    

    Its also observed that it happen mostly when writing into file with big chunks

  9. shochdoerfer commented on Jun 29, 2026

    @shochdoerfer

    I am having similar issues with various models (even the ones provided by OpenCode, e.g. Big Pickle). Things got worse in the last 2 weeks, I would say.

    I haven't installed any new plugins or added MCP servers or changed the config.

  10. adarshmadrecha commented on Jul 11, 2026

    @adarshmadrecha

    The same issue still on latest (v1.17.18)
    Model: MiniMax M3

    Image
  11. github-actions commented on Sep 10, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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