Skip to content

Large tool arguments (>~30KB) are truncated at the content boundary, causing "Unterminated string in JSON" — affects all tools incl. MCP #42224

Closed as not planned

Description

@zukktest-cell

Summary

When a tool call carries a real string-literal argument larger than roughly 30KB, the opencode client truncates the tool-call JSON exactly at the end of the embedded content (missing closing quote/brace), and the call fails with:

The arguments provided to the tool are invalid: Invalid input for tool <TOOL>: JSON parsing failed: Text: {…content…}. Error message: Unterminated string in JSON at position N (line 1 column N+1)

The failure position N always equals the length of the sent payload — the string is cut at the content boundary. Small arguments (a few KB) work fine.

Environment

  • opencode 1.18.15 and 1.18.18 (bug reproduces on both; upgrade did not fix it)
  • Windows 11, PowerShell 5.1, TUI
  • Reproduced on multiple tool types: bash (built-in), an MCP run_script tool, and task — i.e. it is not specific to any one tool or to MCP servers

Steps to reproduce

  1. Invoke any tool (e.g. bash) with an argument containing a literal string of ~30KB+ (e.g. a multi-line ASCII payload). Note: "a" * 30000-style runtime-generated strings do NOT reproduce it — the payload must physically be large in the tool-call argument.
  2. The client rejects the call before it ever reaches the tool/server: JSON parsing failed … Unterminated string in JSON at position N.

Evidence (position ≈ payload length)

Payload Tool Error position
29.6KB wrapper (base85-encoded) MCP run_script 79,585
70,100B raw script MCP run_script ~79,585
137,466B pure-ASCII (no quotes/backslashes/control chars) bash 137,466
189,623B pure-ASCII (nested) bash 189,623
240,586B pure-ASCII bash 240,586
1,035,824B pure-ASCII MCP run_script 1,035,824
1,039,076B pure-ASCII bash 1,039,076
Small args (few KB) bash / MCP OK

Key observations:

  • Character set is irrelevant: 100% pure-ASCII payloads containing no quotes, no backslashes, no control characters fail identically. Base85 + JSON-escaped payloads fail identically. The truncation is purely length-based.
  • JSON is truncated at the content boundary: position N ≈ exact payload length, i.e. the closing " and } are never emitted.
  • Never reached the target: the MCP server reported 0 requests received; all failures are client-side.
  • Cross-tool: bash (fully local, no network), MCP tools, and task tool all fail the same way.
  • Repro'd across two releases (1.18.15 → 1.18.18).

Expected behavior

Large tool arguments should either be transmitted intact, fail with an explicit size-limit error, or be configurable (e.g. a documented max tool-argument size). Currently there is no way to pass payloads >~30KB to any tool, which blocks legitimate workflows such as executing large scripts through MCP run_script or passing large data blobs.

Impact

  • Cannot execute any MCP tool that requires a >~30KB argument (e.g. running a 70KB script via run_script).
  • Affects all tool types uniformly, not just MCP.

Happy to provide additional traces (opencode.log excerpts, persisted tool-output files) on request.

Activity

  1. vladislav-miroshnikov commented on Sep 9, 2026

    @vladislav-miroshnikov

    @jlongster #42303 keeps the unterminated-JSON diagnosis qualified: arguments may have been truncated, and the original parse error is preserved. It also keeps the internal repair tool out of provider requests. The change improves the diagnosis; it doesn't fix transport-size limits.

    The branch has no conflicts and has focused regression coverage. Could you enable code CI and review that diagnostic change?

  2. thdxr commented on Oct 11, 2026

    @thdxr
    Member

    Thanks for the report! OpenCode 2.0 is now out and development is focused on V2, so we're closing issues filed against OpenCode 1. Please upgrade (opencode upgrade --major, details: https://anoma.ly/notes/opencode-2-0), and if this is still relevant on 2.0, reopen this issue or open a new one with your 2.0 version.

    — from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

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