Skip to content

Subagents dispatched sequentially instead of in parallel #29638

Description

@PointFiveBool

Description

When I ask the model to run multiple independent tasks in parallel, I only ever see one subagent running at a time. Each one finishes before the next starts, even though they should be independent and could run concurrently.

This is a re-report of #14195 (closed due to inactivity) — the bug is still present.

I poked around the code a bit. The session loop in src/session/prompt.ts around line 1734 does tasks.pop() then calls handleSubtask which blocks until the subagent finishes — so it naturally processes one at a time. Seems like it should collect all subtasks from tasks and run them with Effect.forEach(..., { concurrency: "unbounded" }) instead. Something like:

const subtasks = tasks.filter(t => t.type === "subtask")
const remaining = tasks.filter(t => t.type !== "subtask")
if (subtasks.length > 0) {
  yield* Effect.forEach(subtasks, (task) =>
    handleSubtask({ task, model, lastUser, sessionID, session, msgs })
  , { concurrency: "unbounded" })
  continue
}

Each handleSubtask call has its own local state (assistantMessage, part, summaryUserMsg) so they shouldn't step on each other.

There's also a minor thing — the background param on the task tool is hidden from the LLM behind an experimentalBackgroundSubagents flag (task.ts:332), so even if the model wanted to dispatch non-blocking tasks it can't. Might be worth exposing that or at least defaulting it on.

Plugins

None

OpenCode version

v1.15.11

Steps to reproduce

  1. Start an opencode session with a model that supports parallel tool calls
  2. Ask a task that the LLM will decompose into 2+ independent subtasks (e.g. "Implement these 3 features in parallel: A, B, and C")
  3. Observe the subagent dispatch — only 1 subagent runs at a time, each completing before the next starts
  4. Expected: all subagents start concurrently and run in parallel

Screenshot and/or share link

N/A

Operating System

Linux (Ubuntu 22.04)

Terminal

Alacritty

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