agent-orchestrator icon indicating copy to clipboard operation
agent-orchestrator copied to clipboard

bug(spawn): workspace + OpenCode fails chat start (ACP additionalDirectories unsupported)

Open harshitsinghbhandari opened this issue 2 months ago • 2 comments

Summary

ao spawn on a workspace project can create the git worktrees, then fail when starting the worker chat:

chat controller: ACP agent does not support additional workspace directories (CHAT_CONTROLLER_FAILED)

Seen on AgentLab (agentlab-in, kind workspace, default worker harness OpenCode) while spawning a new worker (agentlab-in-11) on 2026-09-19. Retry failed the same way. Existing workers on that project (agentlab-in-9, agentlab-in-10) already had a chat controller and kept running.

Why it happens

Workspace spawn does not only set cwd to the session root. It passes every child worktree path (except the root) as ACP additionalDirectories.

  • workspaceProjectDirectories in backend/internal/session_manager/chat_spawn.go (collects project.Worktrees whose path is not the session root)
  • ChatStart.AdditionalDirectories on the chat controller
  • ACP driver backend/internal/adapters/chatdriver/acp/driver.go calls normalizeAdditionalDirectories
  • backend/internal/adapters/chatdriver/acp/session_setup.go: if directories is non-empty and init.AgentCapabilities.SessionCapabilities.AdditionalDirectories == nil, return that error

OpenCode’s ACP initialize does not advertise sessionCapabilities.additionalDirectories. AO fails closed. The session is then a failed spawn even though worktree add may have already run.

This is not a bad ao spawn invocation. It is workspace project + ACP harness without that capability + at least one child worktree.

Repro

  1. Workspace project with multiple registered children (e.g. six git children).
  2. Default worker agent: OpenCode (ACP).
  3. ao spawn --project <id> --name test --prompt "ping"
  4. Observe CHAT_CONTROLLER_FAILED / ACP agent does not support additional workspace directories.

Single-repo projects should not hit this path (workspaceProjectDirectories returns nil when project is nil / not workspace).

Expected

Either:

  • Skip additionalDirectories when the agent does not advertise the capability, and still start chat with cwd = workspace root (children remain on disk under that root), or
  • Fail earlier with a harness/capability error before creating worktrees, or
  • Document that workspace workers require a harness that advertises additional directories (e.g. Claude Code) and refuse OpenCode at spawn validation.

Failing closed after worktree create leaves a half-made session.

Non-goals

  • Auto-registering unregistered clones on disk as workspace children (that is #5644).
  • Changing the “all children in one worktree” workspace model.

Unregistered extra checkouts (we had cloned alab-cli into the workspace folder without registering it) are not in workspaceRepos and should not be the dirs AO sends. The dirs that trigger this are the registered child worktrees.

Related

  • #5644 workspace CLI lifecycle (list/add/rm/sync). Different bug; same area.
  • #5643 add-repo CLI only.

Environment

  • AO CLI + daemon, 2026-09-19
  • Project kind: workspace (agentlab-in)
  • Worker harness: OpenCode
  • Error code: CHAT_CONTROLLER_FAILED

harshitsinghbhandari avatar Sep 19 '26 22:09 harshitsinghbhandari

Re-verified today (2026-09-25) on a different machine/project. Same root cause, two additional data points that extend the scope of the fix.

Repro (2026-09-25, workspace project censored, kind=workspace, 2 registered children: app + community-store, orchestrator harness opencode)

  1. ao spawn --project censored --kind orchestrator --harness opencode --mode chat -> fails: spawn censored-1: chat controller: ACP agent does not support additional workspace directories (CHAT_CONTROLLER_FAILED) [daemon request id bgAImmJG3P-084525]
  2. Same spawn with --mode tui -> works; session comes up.
  3. New: in the desktop UI, switching that running TUI session to chat fails with the same error. So the chat-controller mode-switch/attach path hits the same additionalDirectories fail-closed check, not just spawn-time ChatStart. Fix must cover both entry points.
  4. Control: a single-repo project runs opencode chat-mode sessions fine (verified in parallel) -> confirms this is specific to the multi-directory workspace shape, not a general opencode/ACP breakage.

Side note (separate, likely environmental): same workspace spawn with --harness claude-code --mode chat fails earlier and differently: chat driver incompatible: ACP initialize: peer disconnected before response (CHAT_DRIVER_INCOMPATIBLE) — ao doctor flags the claude binary as not on the daemon PATH on this machine. Not part of this fix.

Fix direction (endorsed, refined)

Degrade gracefully rather than fail closed, at both entry points:

  • When init.AgentCapabilities.SessionCapabilities.AdditionalDirectories is absent, start/attach chat with cwd only (workspace root or primary repo) and drop additionalDirectories. Children remain on disk under the root; agents that never advertise the capability still work.
  • Alternatively/additionally: capability-gate up front and surface a clear harness-capability error before side effects (worktree creation), instead of a half-made session.
  • The desktop UI mode-switch (TUI -> chat) must show a human-readable error for whichever failure mode remains; today it surfaces the opaque CHAT_CONTROLLER_FAILED text.

Where to look

  • backend/internal/session_manager/chat_spawn.go (workspaceProjectDirectories) — spawn path
  • chat controller mode-switch/attach path (same helper appears to be consulted when attaching a chat controller to a running TUI session) — confirm in source
  • backend/internal/adapters/chatdriver/acp/session_setup.go + driver.go (normalizeAdditionalDirectories) — the fail-closed check

Daemon records for the failed request: request id bgAImmJG3P-084525 (2026-09-25).

harsh-batheja avatar Sep 25 '26 09:09 harsh-batheja

I'm picking this up in a new follow-up, with #5684 and #5875 as prior context. I’m checking a scope-preserving approach: omit unsupported additional directories only when they are already contained within the session cwd, and continue rejecting genuinely external roots. No blanket cwd-only downgrade. I’ll verify fresh start and restore paths before posting results.

codebanditssss avatar Nov 01 '26 13:11 codebanditssss