Repository navigation
Description
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_doneRoot 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 activePass 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
- #2284 — custom agent presets (broader; this issue works with built-in agents like
qwen-code,codex,claude) - [Feature]: Allow multiple named entries (aliases) per agent harness #9136 — agent aliases
- PR Launch and detect Qwen Code via its qwen executable #6530 — qwen-code agent support (merged; agent exists in
TUI_AGENT_CONFIG, coordinator can't use it) - PR #7758 — orchestration agent prompt injection fix (bracketed paste path; works correctly once an agent is present)
Activity
Disorrder commentedon Jul 22, 2026
I can propose a PR later