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

bug(conpty): reviewer terminal not visible on Windows — ConPTY cannot spawn .cmd reviewer binaries

Open OrcInc opened this issue 4 months ago • 3 comments

Bug

On Windows, requesting a code review produces no visible reviewer terminal — the reviewer agent's terminal pane never appears in the center pane, leaving the user unable to watch or interact with the reviewer.

Source: Reported by [AB] in Discord (#🧑‍🔧-bug-triage) Platform: Windows Analyzed against: 86fc666cb (PR #3466) Confidence: Medium — strong code-level evidence for the primary hypothesis; needs confirmation from the reporter's daemon log to pin the exact failure path.

Reproduction

  1. Open a worker session on Windows (any agent harness that resolves to an .exe/native binary — e.g. Claude Code).
  2. Trigger a code review from the Reviews tab in the session inspector.
  3. Observe: no reviewer terminal appears in the center pane. The terminal either stays on the worker agent or shows nothing.

Root Cause (Primary Hypothesis — ConPTY .cmd spawn failure)

AO uses ConPTY as the terminal runtime on Windows (backend/internal/adapters/runtime/runtimeselect/runtimeselect.go:34), not tmux. When a review is triggered, the reviewer launcher spawns a new ConPTY host process:

reviews/trigger → agentLauncher.Spawn (review/launcher.go:179)
  → conpty.Runtime.Create (conpty/runtime.go:60)
    → defaultSpawnHost → spawns "ao pty-host review-<workerID> <cwd> <reviewerBinary> <args>"
      → RunHost (conpty/host_main.go:56) → newConPTY(cwd, reviewerBinary, args)
        → go-pty Command(shellCmd) → lookExtensions → exec.LookPath → CreateProcess

The reviewer adapters (backend/internal/adapters/reviewer/{codex,claudecode,opencode}/) all delegate to the worker agent adapter's GetLaunchCommand for binary resolution (e.g. reviewer/codex/codex.go:37 calls workeragent.New().GetLaunchCommand). These adapters list .cmd as a valid (often first-choice) Windows binary:

  • adapters/agent/crush/crush.go:178: WinNames: []string{"crush.cmd", "crush.exe", "crush"}
  • adapters/agent/amp/amp.go:132: WinNames: []string{"amp.cmd", "amp.exe", "amp"}
  • adapters/agent/kiro/kiro.go:183: WinNames: []string{"kiro-cli.cmd", "kiro-cli.exe", "kiro-cli"}

go-pty v0.2.3 (cmd_windows.go:126-140) calls windows.CreateProcess directly. CreateProcess cannot execute .cmd/.bat files — they are batch scripts, not PE executables. Go's stdlib os/exec wraps .cmd/.bat with cmd.exe /c internally, but go-pty bypasses that wrapping.

The result: if the reviewer binary resolves to a .cmd file, CreateProcess returns ERROR_BAD_EXE_FORMAT (193), newConPTY returns an error, the pty-host exits without printing READY:, and conpty.Runtime.Create returns an error — meaning the reviewer pane never gets created and the frontend has nothing to attach to.

Why workers may work but reviewers don't: The worker agent and reviewer can use different harnesses. If the worker resolves to .exe (e.g. Claude Code's claude.exe) while the reviewer harness resolves to .cmd, only the reviewer spawn fails. If both use the same .cmd-resolving harness, both would fail — see #3409.

Critical debuggability gap: spawn_windows.go:64 sets cmd.Stderr = io.Discard, discarding ALL pty-host diagnostics. The pty-host writes detailed errors to stderr (e.g. "conpty: start command: failed to create process: ...") but the parent throws them away, leaving only a generic "exited without printing READY."

Root Cause (Secondary Hypothesis — Frontend terminal switch)

If the ConPTY spawn succeeds (reviewer binary is .exe), there is a known design limitation (see #3303): the reviewer terminal replaces the worker terminal via a single terminalTarget state variable (SessionView.tsx:82). The reviewer pane appears only by overwriting the worker pane. If the frontend's onOpenReviewerTerminal callback doesn't fire (e.g. the reviews/trigger response lacks reviewerHandleId), or if the terminal switch races with a render cycle, the reviewer terminal would never be shown even though the pane exists.

This is less likely than the ConPTY hypothesis but cannot be ruled out without the reporter's daemon log.

Confirming the Diagnosis

The reporter can confirm the primary hypothesis by checking the daemon log:

# Look for the reviewer spawn error on Windows
findstr /C:"pty-host exited without printing READY" %USERPROFILE%\.ao\daemon.log
findstr /C:"conpty: start command" %USERPROFILE%\.ao\daemon.log
findstr /C:"reviewer" %USERPROFILE%\.ao\daemon.log

If those errors appear → ConPTY .cmd failure (primary). If they don't → investigate the frontend terminal switch (secondary).

Also useful: which reviewer harness is configured for the project, and which agent harness the worker uses. If they differ, that explains why only the reviewer fails.

Suggested Fix

ConPTY .cmd wrapping (fixes primary, also fixes #3409)

In host_conpty_windows.go, detect .cmd/.bat and wrap with cmd.exe /c before calling go-pty:

// In newConPTY, before cp.Command(shellCmd, shellArgs...):
lower := strings.ToLower(shellCmd)
if strings.HasSuffix(lower, ".cmd") || strings.HasSuffix(lower, ".bat") {
    shellArgs = append([]string{"/c", shellCmd}, shellArgs...)
    shellCmd = os.Getenv("COMSPEC")
    if shellCmd == "" {
        shellCmd = "cmd.exe"
    }
}

This mirrors what Go's stdlib exec.Command does internally for .bat/.cmd files since Go 1.19.

stderr capture (debuggability)

Replace cmd.Stderr = io.Discard in spawn_windows.go with a bytes.Buffer and include its contents in the error when READY isn't received.

Impact

  • Severity: Reviewer workflow completely broken on Windows when the reviewer binary resolves to .cmd. Users cannot see, watch, or interact with the reviewer agent.
  • Workaround: None from the user's perspective — they cannot control which binary extension the resolver picks.
  • Scope: Any Windows user whose reviewer agent harness resolves to a .cmd npm wrapper. This is the default for npm-installed CLIs on Windows.

Related

  • #3409 — Windows: Codex resolver prefers codex.cmd over codex.exe, but ConPTY cannot launch .cmd (systemic .cmd spawn failure — same root cause, worker agent symptom)
  • #3303 — Reviewer terminal should open as a new tab instead of replacing the worker agent terminal (design limitation that compounds this bug — even when the reviewer spawns, the terminal UX is poor)
  • #3467 — Add review terminal tabs and persist it (related UX enhancement)
  • #2688 — opencode agent fails to launch on Windows: env argv prefix isn't a Windows executable (prior Windows ConPTY spawn issue, now closed)

OrcInc avatar Aug 03 '26 16:08 OrcInc

Assigned to @somewherelostt

Rishet11 avatar Sep 14 '26 22:09 Rishet11

Closing as a duplicate of #5323. Windows reviewer launch remains tracked there; #3962 addressed terminal visibility.

Rishet11 avatar Oct 13 '26 20:10 Rishet11

i started a reviewer test on windows using pr #7410 and could see the reviewer in ao. i cancelled the test without submitting a review. i did not encounter the missing terminal on my setup.

codebanditssss avatar Oct 29 '26 16:10 codebanditssss