Skip to content

Parallel tool calls run one after another (three subagents take three times as long) #44

Closed

Description

@nkoynov

When the model calls several tools in one step, OpenCode runs them one at a time.

Live repro (OpenCode 2.0.22 in T3, Claude Opus 5.5 1M High Fast, provider main f65ffc7), prompt "run three subagents in parallel, each runs sleep 8":

  • The three subagents never overlapped (max concurrency 1), and the turn took 50.4 s.
  • With two subagents, the second started only after the first finished.

Why: pump() ends the AI SDK step (finish: tool-calls) right after the first tool-call it emits, at six sites. Cursor sends each exec request as soon as that call is generated, so when the first exec arrives the model is still generating the others. The provider reads the next exec only after the first result has gone back. deliverContinuationResults and session.pending already handle several results.

Debug log (main plus a trace of the InteractionUpdate field number). OpenCode's concurrent title Run is not allowed tools, so its execs are refused, and its pump reads frames as they arrive:

title Run    20.661 tool_call_started (task 1)   20.668 exec
             21.099 tool_call_started (task 2)   21.099 exec
             21.540 iuField=27 tool_requests_listed {call_count: 3}
             21.540 tool_call_started (task 3)   21.540 exec
session Run  22.010 EMITTED subagent #0 -> step ends
             34.982 (after subagent 1 returned) EMITTED subagent #1 -> step ends
             46.392 (after subagent 2 returned) tool_requests_listed {3}, EMITTED subagent #2

Cursor reports when a step's calls are complete. InteractionUpdate field 27 tool_requests_listed is ToolRequestsListedUpdate|1 call_count 13 (uint32) in Cursor CLI 2026.10.01's agent.v1 descriptors. Cursor sends it once the model has finished generating the step's tool calls. For a single call it arrives before the exec; for three calls it arrives after the second exec and before the third.

Proposed design:

  • Declare field 27.
  • In pump, count the step's calls that have reached the provider: its exec request, or the display completion of a call no exec claimed. An edit's private prerequisite read doesn't count. Cursor also sends completions for the previous step's calls at the start of the next pass; those are ignored.
  • After a host tool call, keep the AI SDK step open until the listed count is reached, then finish: tool-calls. OpenCode starts each tool as its part arrives and returns all results in one continuation.
  • Until Cursor has sent a count in the process, keep today's behavior of one call per step.
  • If model output, turn_ended, the end of the Run or a read failure arrives while a step is held, close the step and queue that frame read for the next pass (session.queuedFrame, which every frame reader takes first, so nothing is skipped).
  • With several results per continuation, tool-result media must be split across them. The read/MCP image PRs (fix: return images read on a held Run as ReadSuccess.data #42 and fix: deliver MCP tool images on the held Run as McpImageContent #46) do that by result order, using OpenCode's markers.
  • If a held step's count is never met, close it after 1.5 s without frames. This only falls back to today's behavior. Our earlier local patch relied on timing windows; this design uses Cursor's count, and the timer is only a fallback.

A branch with this design and tests is ready if you want it as a PR: main...nkoynov:cursor-opencode-provider:fix/parallel-tool-calls

  • Results:
    • The three-subagent prompt reaches max concurrency 3 and takes 30–35 s, against 50.4 s on main.
    • With two subagents, both runs were parallel.
    • The log shows all three results returning in one continuation.
  • CI: the full CI gate passes.

Activity

  1. nkoynov commented on Oct 7, 2026

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

Metadata

Metadata

Assignees

No one assigned

    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