Skip to content

[Feature]: orchestration run --agent — coordinator should create agent terminals, not bare shells #9942

Open

Description

@Disorrder

Problem

orca orchestration run coordinator creates bare terminals (no agent) when no idle terminals are available, then dispatches task preambles into zsh/bash via sendTerminalAgentPrompt() (bracketed paste + \r). The shell tries to execute the preamble text and fails with parse error near ')'. The task is marked dispatched but never completes — no agent exists to process it.

Additionally, getAvailableTerminals() does not verify that a terminal runs a recognized agent (connected && writable only), so the coordinator dispatches into bare shells even when they exist alongside agent terminals.

Reproduction

# 1. Create tasks
orca orchestration task-create --spec "Write hello.txt" --display-name "test-task"

# 2. Start coordinator (no agent terminals exist)
orca orchestration run --spec "test" --max-concurrent 1 --worktree active

# 3. Coordinator creates a bare terminal, pastes preamble into zsh
# → zsh: parse error near `)'
# → task stuck in "dispatched" forever, no worker_done

Root cause (source reference)

dispatchReadyTasks() (src/main/runtime/orchestration/coordinator.ts:359):

if (terminals.length === 0 && slotsAvailable > 0) {
  const created = await this.runtime.createTerminal(this.opts.worktree, {
    title: `Worker: ${readyTasks[0].spec.slice(0, 40)}`
    // ← No command, no launchAgent. Creates a bare zsh terminal.
  });
  terminals.push(created.handle);
}

getAvailableTerminals():

return result.terminals.filter(
  (t) => t.handle !== this.opts.coordinatorHandle
      && !busyHandles.has(t.handle)
      && t.connected && t.writable
      // ← No getTerminalAgentStatus() check. Bare shells pass.
).map((t) => t.handle);

Meanwhile, runtime.createTerminal() already supports launchAgent (used by worktree create --agent), and runtime.getTerminalAgentStatus() already exists but is never called by the coordinator.

Note: the dispatch --inject RPC path (src/main/runtime/rpc/methods/orchestration.ts:475) already validates agent presence — "Cannot dispatch --inject to terminal: no recognized agent detected" — but the coordinator bypasses this by using sendTerminalAgentPrompt() directly.

Proposed solution

1. Add --agent <id> to orchestration run

orca orchestration run --spec "..." --agent qwen-code --max-concurrent 4 --worktree active

Pass through: CLI spec → handler → RPC RunParams → Coordinator.opts.agent.

2. Create agent terminals when --agent is set

if (terminals.length === 0 && slotsAvailable > 0) {
  const created = await this.runtime.createTerminal(this.opts.worktree, {
    title: `Worker: ${readyTasks[0].spec.slice(0, 40)}`,
    ...(this.opts.agent ? { launchAgent: this.opts.agent } : {}),
  });
  terminals.push(created.handle);

  // Wait for agent TUI to be ready before dispatching:
  if (this.opts.agent) {
    await this.runtime.waitForTerminal(created.handle, {
      condition: "tui-idle",
      timeoutMs: 30_000,
    });
  }
}

3. Filter by agent presence in getAvailableTerminals()

When this.opts.agent is set, call getTerminalAgentStatus() and exclude terminals where isRunningAgent === false. This prevents dispatching into bare shells that happen to be open.

4. Without --agent — preserve current behavior

No --agent flag → bare terminal creation, no agent filter (backward compatible).

Files to modify

File Change
src/main/runtime/orchestration/coordinator.ts opts.agent, agent terminal creation + tui-idle wait, agent filter in getAvailableTerminals()
src/main/runtime/orchestration/types.ts agent?: string in coordinator options
src/cli/specs/orchestration.ts 'agent' in orchestration run allowedFlags
src/cli/handlers/orchestration.ts Pass agent flag in RPC call
src/main/runtime/rpc/methods/orchestration.ts agent in RunParams zod schema

Related

Activity

  1. Disorrder commented on Jul 22, 2026

    @Disorrder
    Author

    I can propose a PR later

  2. added
    enhancement
    on Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions