Skip to content

Parallel tool calls corrupt arguments JSON: "JSON parsing failed" with merged/truncated text #52789

Closed as not planned

Description

@jairomello

Description

Version: 1.18.34 (binary at ~/.opencode/bin/opencode)

Describe the bug

When an assistant message contains multiple tool calls in parallel (especially mixing an MCP tool call with a built-in tool like bash), the arguments JSON delivered to the tool is sometimes corrupted in two distinct ways:

  1. Merged arguments — the arguments of one tool call are nested inside a parameter of another tool call.
  2. Truncated arguments — the JSON string is cut mid-value, failing with Unexpected EOF.

The error surfaced to the model is:

Invalid input for tool <name>: JSON parsing failed: Text: <corrupted text>.
Error message: JSON Parse error: ...

Evidence from a real session (reproduced 5+ times)

Case 1 — merged: a parallel list_tasks (MCP) + bash call delivered this text to list_tasks (its fields param received the bash args object):

{"fields": {"command": "grep -rn \"attachment\\|anexo\" apps/api/src/routes/attachments.ts | head -5; echo \"---\"; ls apps/api/src/routes/ | grep -i attach", "workdir": "/home/jairo/Projetos/azyboard"}}

Error: JSON Parse error: Expected '}'

Case 2 — truncated: a parallel list_tasks (MCP) + other tool call delivered:

{"includeDescriptions":

Error: JSON Parse error: Unexpected EOF

Observed pattern

  • Serial (non-parallel) tool calls never failed in the session.
  • Parallel calls with two MCP tools also worked.
  • Failures concentrated on MCP tool call + built-in tool call in the same assistant message.
  • The corrupted text always starts with the first tool's parameter key, then splices in the second tool's arguments object.

Expected behavior

Each tool call in a parallel set receives its own, intact arguments JSON.

Impact

MCP tools with medium-sized argument payloads fail intermittently; the model must retry serially. Users of MCP servers see "tool errors" caused purely by the harness layer. As a mitigation on our side we reduced tool schema required-fields (less JSON per call), but the merging/truncation itself is in the harness.

Additional context

  • The error strings JSON parsing failed: Text: ${h} and Invalid input for tool '${YZ}': ${String(OW)} are present in the compiled binary.
  • Reproduced while using a local stdio MCP server (bun run apps/mcp/src/index.ts) with @modelcontextprotocol/sdk.

Plugins

none

OpenCode version

1.18.34

Steps to reproduce

  1. Configure a local stdio MCP server in opencode.json (e.g. {"mcp": {"my-server": {"type": "local", "command": ["bun", "run", "server.ts"]}}}) exposing tools with medium-sized JSON schemas (the Azy Board list_tasks tool has ~14 optional params).
  2. Start a session and, in a single assistant message, issue one MCP tool call in parallel with one built-in tool call (e.g. bash), with non-trivial arguments on both. Example pair that failed repeatedly:
    • my-server.list_tasks with {"fields": ["id","title","status","columnId"], "includeDescriptions": true}
    • bash with {"command": "grep -rn \"foo\\|bar\" apps/", "workdir": "/repo"}
  3. Repeat step 2 several times (intermittent, ~30–50% of parallel batches in my session; never happened with serial calls).
  4. Observe the tool error Invalid input for tool <name>: JSON parsing failed: Text: ... where the Text: shows either:
    • the bash args object nested under the MCP tool's first parameter key (merged calls), e.g.
      {"fields": {"command": "grep ...", "workdir": "..."}} → JSON Parse error: Expected '}'
    • or the MCP tool's JSON cut mid-value (truncated call), e.g.
      {"includeDescriptions": → JSON Parse error: Unexpected EOF

Reproducibility: serial tool calls (one per message) never failed in a ~2h session; parallel MCP+MCP calls also worked. The corruption appears specifically when a MCP tool call and a built-in tool call share the same assistant message.

Screenshot and/or share link

No response

Operating System

Linux

Terminal

Konsole

Activity

  1. github-actions commented on Oct 2, 2026

    @github-actions
    Contributor

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

    • #43311: Reports corrupted MCP tool-call parameters during batched/concurrent calls, including JSON parsing failures.
  2. rekram1-node commented on Oct 3, 2026

    @rekram1-node
    Collaborator
  3. 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