Skip to content

Error Writing Large Files (at least with Kimi K2.5) #10967

Closed

Description

@marcoschwartz

Description

Got an error while using the new Kimi K2.5 model - Invalid input for tool write: JSON parsing failed

Image

Plugins

No response

OpenCode version

1.1.39

Steps to reproduce

Just use Kimi K2.5 with any provider and ask to edit/write a large file

Screenshot and/or share link

No response

Operating System

macOS 26

Terminal

iTerm2

Activity

  1. github-actions commented on Jan 28, 2026

    @github-actions
    Contributor

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

    Feel free to ignore if none of these address your specific case.

  2. ideallove commented on Jan 28, 2026

    @ideallove
    Contributor

    I also encountered the same issue. I was working on Agent Skill yesterday and today. Yesterday it was completely correct, but today it failed.
    The SKILL I was using involved generating JSON, HTML, and escape characters, and the same problem occurred with the write component.
    I was using the Windows platform, with LLM being Claude Opus 4.5 and Minimax M2.1.
    Just now, I removed OpenCode and Desktop for version 1.1.39. After reverting to version 1.1.36, there were no abnormalities.

    Therefore, the temporary solution is to revert to version 1.1.36.
    I am currently attempting to analyze and review the updates from 1.1.37 to 1.1.39.
    Thank you to the developers for their work.

  3. ideallove commented on Jan 28, 2026

    @ideallove
    Contributor

    @marcoschwartz I have fixed the problem I encountered. Maybe your problem has also been resolved.

  4. Mithrillion commented on Jan 28, 2026

    @Mithrillion

    I think equally frustrating is that when you encounter this issue with Kimi K2.5, the agent just stops instead of retrying or continuing the task with a different approach, like in typical tool failures. And if it is in a subagent and the subagent fails, you often have to scrap the whole run, because you cannot simply ask it to continue.

  5. ideallove commented on Jan 29, 2026

    @ideallove
    Contributor

    Why This Causes invalid Tool Errors?

    • Without maxOutputTokens: The AI SDK doesn't send a max_tokens parameter to the provider
    • Provider uses default limit: Many providers default to a low value (e.g., kimi K2.5 default 32768 from https://platform.moonshot.ai/docs/guide/kimi-k2-5-quickstart)
    • Large tool calls get truncated: When writing files with substantial content, the JSON output exceeds the default limit
    • JSON becomes incomplete: Output is cut mid-string, e.g., {"content": "# -*- coding... (missing closing "})
    • Parse error occurs: JSON Parse error: Unterminated string
    • Fallback to invalid tool: The experimental_repairToolCall handler marks it as invalid

    It is more likely to trigger in the subagent. In conclusion, hardcoding will definitely cause problems.

    Apart from reverting to the previous version, adding a detection for JSON parsing might make the system more stable.

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions