Skip to content

qwen3-coder fails to call edit tool #6918

Closed as not planned
Closed as not planned

Description

@mausch

Description

When using https://openrouter.ai/qwen/qwen3-coder:free it fails to call the edit tool.

It fails over and over again with:

Error: The edit tool was called with invalid arguments: [
  {
    "expected": "string",
    "code": "invalid_type",
    "path": [
      "oldString"
    ],
    "message": "Invalid input: expected string, received object"
  },
  {
    "expected": "string",
    "code": "invalid_type",
    "path": [
      "newString"
    ],
    "message": "Invalid input: expected string, received object"
  }
].
Please rewrite the input so it satisfies the expected schema.

Plugins

none

OpenCode version

1.1.1

Steps to reproduce

  1. Set provider to Openrouter
  2. Set model to qwen/qwen3-coder:free
  3. Ask it to make any edits

Screenshot and/or share link

Image

Operating System

NixOS

Terminal

xterm

Activity

  1. github-actions commented on Jan 5, 2026

    @github-actions
    Contributor

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

    The root cause appears to be that some LLM models (like Qwen3-coder) pass JSON objects for oldString and newString when they should pass strings. This is similar to the broader issue documented in #6838 where models struggle with properly stringifying JSON content for the edit tool.

    Feel free to ignore if your specific case differs from these existing issues.

  2. PhantomKnight287 commented on Jan 6, 2026

    @PhantomKnight287

    Facing same on Macos 15.6.1 and Ghostty

  3. arne-fuchs commented on Jan 20, 2026

    @arne-fuchs

    Same here. Qwen is hard to use with opencode and always made problems. AFAIK: the problem is not opencode in particular but also qwen3 misunderstanding the tools/capabilities provided by opencode. I heard of proxies acting as "man in the middle" fixing tool calling for qwen3.
    Edit: Please notice that those proxies only have been tested with Qwen3-Coder-30B-A3B-Instruct. Other Qwen3 variations may have different problems. I had no luck the versions provided by ollama

  4. GiveMe-A-Name commented on Jan 28, 2026

    @GiveMe-A-Name

    Same problems with GLM4.7

  5. nabil86 commented on Feb 4, 2026

    @nabil86

    I have same issue with GLM 4.7-flash & qwen3-coder .
    i'm using ollama (localy)

  6. GiveMe-A-Name commented on Feb 5, 2026

    @GiveMe-A-Name

    Every time I want read or write files using ai. I will occur error.
    And this issues don't solved in opencode@1.1.15

    It's so sad

    Image
  7. giraudremi92 commented on Feb 5, 2026

    @giraudremi92

    same on qwen 3 coder next 80b
    sometimes its go on with cat

    Image
  8. itsShnik commented on Feb 10, 2026

    @itsShnik

    Same problem with gemini-3-pro-preview high (variant)

  9. CVeRiTy commented on Feb 13, 2026

    @CVeRiTy

    Very similar problem with Qwen3-Coder-Next. I receive this consistently when it tries to call the write tool:

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

    I receive this error a fair bit. Eventually it figures out to use a different method, or I cancel and tell it to use a different method.

  10. mihaj commented on Feb 13, 2026

    @mihaj

    I get this quite a but with Qwen3-Coder-Next. not sure if it has anything to do with this long token generation steps (more than 1500 fore example).

    I am using LM Studio 0.4.2 (Build 2), OpenCode 1.1.62 and Llama 2.2.0 runtime in LM Studio. Model is from Qwen3-Coder-Next Unsloth MXFP4.

  11. gtrak commented on Feb 13, 2026

    @gtrak

    There's some upstream bugs:
    ggml-org/llama.cpp#19430 hard crash
    ggml-org/llama.cpp#19382 broken filePath json

    Is there any known workaround?

  12. 25 remaining items

  13. Rudd-O commented on Mar 12, 2026

    @Rudd-O

    I was gonna try GLM 4.7 but now I've read it has the same problem.

    This problem slows down the agent substantially and wastes context.

  14. FN-FAL113 commented on Mar 13, 2026

    @FN-FAL113

    After using opencode for some time now, write issues happens mostly when context window reaches above 50-70% of model's configured context window limit. Thinking if its the model's attention span or just hallucinations that cause looping when invoking tools

  15. mlazzarotto commented on Apr 8, 2026

    @mlazzarotto

    Is this the same issue? I'm using Qwen3-coder 480B in OpenCode 1.4.0

    → Read build.sh [limit=5, offset=56]
    Now I'll make the correct edit with the exact content:
    ← Edit build.sh 
    Could not find oldString in the file. It must match exactly, including whitespace, indentation, and line endings.
    

    Image

  16. bhuv-z commented on Apr 9, 2026

    @bhuv-z

    Facing a similar issue. Qwen Coder Next hosted through LM Studio:
    Processes promt for several minutes, only for tool call to fail
    Image

  17. added a commit that references this issue on Apr 9, 2026
    a327f8b
  18. bhuv-z commented on Apr 12, 2026

    @bhuv-z

    Can someone take a look at the PR's and approve one of them, there seem to be 3 addressing this, with one all green.

  19. peterdenham commented on Apr 19, 2026

    @peterdenham

    I am no longer able to reproduce this issue with Qwen3.5 . Maybe it was fixed in a recent opencode release?

  20. ariel-udc commented on Apr 19, 2026

    @ariel-udc

    I just got the same error using Qwen 3.6 plus:

    • OpenCode 1.2.15
    • Provider: Opencode Go
    INFO  2026-04-19T11:41:40 +0ms service=permission permission=todowrite pattern=* action={"permission":"*","pattern":"*","action":"allow"} evaluated
    INFO  2026-04-19T11:41:40 +4ms service=bus type=todo.updated publishing
    INFO  2026-04-19T11:41:40 +1ms service=bus type=message.part.updated publishing
    INFO  2026-04-19T11:41:40 +1ms service=bus type=message.part.updated publishing
    INFO  2026-04-19T11:41:40 +78ms service=snapshot hash=65861c6391ae10aa5c82d4542a47086f1c32362a
     cwd=/home/***/Documents/freelo/udc/wtwh/query_newsletter_leads git=/home/***/.local/share/opencode/snapshot/9aec4f28ff886aa347c24f7b3ce292f0a53b23ee tracking
    ERROR 2026-04-19T11:41:40 +1ms service=session.processor error=[
      {
        "expected": "string",
        "code": "invalid_type",
        "path": [
          "reason"
        ],
        "message": "Invalid input: expected string, received object"
      }
    ] stack="ZodError: [\n  {\n    \"expected\": \"string\",\n    \"code\": \"invalid_type\",\n    \"path\": [\n      \"reason\"\n    ],\n    \"message\": \"Invalid input: expected string, received object\"\n  }\n]" process
    INFO  2026-04-19T11:41:40 +1ms service=bus type=session.status publishing
    INFO  2026-04-19T11:41:44 +4003ms service=llm providerID=opencode-go modelID=qwen3.6-plus sessionID=ses_25a76d86fffeMgxg2jhROK462N small=false agent=build mode=primary stream
    INFO  2026-04-19T11:41:44 +3ms service=bus type=session.status publishing
    INFO  2026-04-19T11:41:49 +4412ms service=snapshot hash=65861c6391ae10aa5c82d4542a47086f1c32362a
    
  21. peterdenham commented on Apr 19, 2026

    @peterdenham

    @ariel-udc can you retry with the latest opencode version - 1.14.18? Qwen 3.5 & 3.6 were able to write json objects to files here.

  22. bhuv-z commented on Apr 21, 2026

    @bhuv-z

    @peterdenham Problem still occurs on latest opencode with qwen3.6-35b-a3b

    Image

    Native file-io tool calls work seamless on Claude Code. Issue seems to be only in opencode.

  23. the-webguys commented on Apr 22, 2026

    @the-webguys

    @peterdenham Problem still occurs on latest opencode with qwen3.6-35b-a3b
    Image

    Native file-io tool calls work seamless on Claude Code. Issue seems to be only in opencode.

    I just published a tool to bridge this issue and hopefully more:

    https://github.com/the-webguys/llama-BridgeAI

  24. removed
    bugSomething isn't working
    on May 3, 2026
  25. github-actions commented on Jul 3, 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