Skip to content

Write tool fails silently on large files (~1000+ lines) #19604

Closed as duplicate

Description

@jdocker8

Bug

The Write tool has started failing silently when writing files approximately 1000+ lines long. The tool call appears to execute but returns a failure/abort with no error message. This happens consistently — multiple retries produce the same result.

Impact

High — this drastically reduces productivity for any task that involves creating documentation or large code files. The user has to manually notice the repeated failures and intervene with guidance to write in sections.

Reproduction

  1. Have the agent attempt to write a markdown file that would be ~800-1200+ lines in a single Write tool call
  2. The tool call fails/aborts silently — no content is written, no error message is returned
  3. Retrying produces the same failure

Workaround

Writing the file in smaller sections (create with first ~300-400 lines, then use Edit to append subsequent sections) works reliably. But the agent doesn't do this automatically — the user has to catch the failure pattern and instruct the agent to use this approach.

Expected behavior

Either:

  • Write should handle files of any reasonable size (at least up to several thousand lines), OR
  • Write should return a clear error message when the content exceeds a size limit, so the agent can automatically fall back to writing in sections

Additional context

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Mar 29, 2026
  2. github-actions commented on Mar 29, 2026

    @github-actions
    Contributor

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

    Please review those issues and comment if yours is distinct.

  3. jdocker8 commented on Mar 29, 2026

    @jdocker8
    Author

    Interesting this particular file it was having issues writing wasn't related to a very long file, it was 574 lines total so maybe it's related to context being too large that it needs to include when writing the file?

    opencode had said this when it successfully wrote the file in pieces:

    Good — the splice worked. The locked decisions table is in hub-people-design.md (lines 55-97) with all 41 rows, properly formatted. The 703A source has the verbose originals. Now let me read the source material for the next sections I need to add.

  4. jdocker8 commented on Mar 30, 2026

    @jdocker8
    Author

    Examples of the issue in my 2 current sessions:

    Image Image
  5. assigned and unassigned on Apr 26, 2026
  6. removed
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  7. jdocker8 commented on May 6, 2026

    @jdocker8
    Author

    Heads-up — #24529 looks like a related-but-distinct bug in the same area. There the edit tool does write the file to disk, but a downstream crash (output.args.filePath undefined) marks the call Failed in the TUI while the model still receives Edit applied successfully. and proceeds. PR #24537 is open with a fix.

    Different symptom from this one (here, no content is written and the model never sees an error), but same theme of tool failures not propagating cleanly. I just commented there confirming a second setup hitting it, in case the maintainers want to cross-reference.

  8. phitonthel commented on May 6, 2026

    @phitonthel

    Can confirm, having a similar issue with write tool

    Image
  9. jdocker8 commented on May 22, 2026

    @jdocker8
    Author

    I wanted to mention I still see this issue on a regular basis, including another example from today:

    Image
  10. amirasyraf commented on May 30, 2026

    @amirasyraf

    This is such a frequent issue for me. I use opencode for a lot of research and quick POCs and that involves writing large files. OpenCode fails to write quite consistently.

    Instructing it to write in batches is the only way around it. But it's not efficient because that involves unnecessary back and forth.

  11. Devilstriker-v2 commented on Jun 2, 2026

    @Devilstriker-v2

    Also having the same issue. Any plans to fix it, as this is probably(at least for me) the most annoying in the moment.

  12. ChanifRusydi commented on Jun 4, 2026

    @ChanifRusydi

    Also having the same issue, although no silently and rather intermittently.
    The error message in my case is as follows :

    invalid [tool=edit, error=Invalid input for tool edit: JSON parsing failed: Text: {"filePath": "{real-path-in-here}", "newStri.
    Error message: JSON Parse error: Unterminated string]
    
  13. Orqino commented on Jun 9, 2026

    @Orqino

    What is the status of this topic? Can't believe that this is not the most annoying bug for everyone at the moment.

  14. lorenzoridolfi commented on Jun 23, 2026

    @lorenzoridolfi

    I am experiencing the same issue. It's a major bug, and the OpenCode team does not seem to be giving it the necessary attention required to fix it.

  15. lorenzoridolfi commented on Jun 23, 2026

    @lorenzoridolfi

    With version 1.17.9, the situation is even worse, and the problem occurs much more often!

  16. shochdoerfer commented on Jun 29, 2026

    @shochdoerfer

    I have the same issues with 1.17.11. Can't get any work done today ;(

  17. SynapseScribe commented on Jun 29, 2026

    @SynapseScribe

    in my experience i observed edit/write tools may fail when vram is too tight or if model too dumb. as a workaround i added to system prompt to just use shell/pwsh for editing/creating files, but that sometimes also fails for complex text (eg quotes back ticks etc). currently using qwen 3.6 27b on rtx 4080 super. playing with context size and gpu offload can help at some extent

  18. shochdoerfer commented on Jun 30, 2026

    @shochdoerfer

    Looks like I found the issue in my setup: I am using the opencode-tool-search plugin to reduce context usage by deferring tool descriptions. Maybe that plugin is not compatible any more with the latest OpenCode release.

    After uninstalling the plugin, things are working a lot better again.

    EDIT: I have to amend my findings. While at first it seemed to have solved a few issues, using OpenCode without the tool search plugin for more tasks showed that it did not really help. Similar to what others mentioned above, it works fine for "smaller writes" but fails when writing a lot of text/code.

    This is not model specific, all our used models have the same issue. It fails on our small self-hosted model (Qwen Coder 30B), on larger hosted models (e.g. GPT OSS 120B) and even on the models provided by the OpenCode team (e.g. Big Pickle).

  19. lraubuch commented on Jul 2, 2026

    @lraubuch

    I experienced the same issue right now when trying to write a PRD after a grilling session.
    After having no other choice I prompted my agent to write 10 Lines at a time. This actually worked but used a ton of tool calls for a 35K document.

    What I experienced. There seemed to also be a confusion since I renamed a file which had a different name in the context. It seemed to have a problem with that aswell.
    I found the following in the opencode logs:

    timestamp=X level=WARN run=Y message="loop exit with orphaned interrupted tool" session.id=Z messageID=XY tool=write callID=YZ
    
  20. bateau84 commented on Jul 4, 2026

    @bateau84

    i am experiencing the same thing on version 1.17.13

  21. shochdoerfer commented on Jul 18, 2026

    @shochdoerfer

    I've updated to 1.18 the other day and it seems to work a lot better. I tried several times to let it write larger Markdown files and that worked without any issues.

  22. jdocker8 commented on Jul 20, 2026

    @jdocker8
    Author

    I've updated to 1.18 the other day and it seems to work a lot better. I tried several times to let it write larger Markdown files and that worked without any issues.

    I've been using opencode for about 30 minutes after using Codex and Claude Code the last few weeks. already had the write fail issue. I'm on version 1.18.4. Luckily I know about it and can quickly give it a number that doesn't slow it down too much and it can keep working.

    Image
  23. jpedrick commented on Jul 28, 2026

    @jpedrick

    I ran into this today using some of the most expensive models. This burned a lot of my Zen funds re-debugging this. It would be great if the write Failed errors provided some description of what went wrong.

  24. brambora69123 commented on Aug 27, 2026

    @brambora69123

    I also get this bug, but theres no failures at all, the model keeps looping, thinking it needs to write the file. Experiencing this with Kimi K3 (custom provider). When i tell it to write it in parts, that it might be a bug, it all of a sudden writes the files fine and stops looping.

  25. neriousy commented on Oct 1, 2026

    @neriousy
    Member

    Closing as a duplicate of #18108. Large write calls usually fail because the tool call gets cut off at the model's output token limit, and OpenCode doesn't report that clearly or recover from it. Please follow and 👍 there.

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