Skip to content

Windows: builder spawn script passes prompt as argv (EPIPE) and opencode TUI freezes in Tower PTY #2010

Backlog

Description

@OdyAsh

Builder PTY Freeze & Spawn Script Broken on Windows

Context

Codev builders are AI agents that implement code in isolated git worktrees. The Tower spawns each builder in a PTY (pseudo-terminal) session and runs a .builder-start.sh script that launches the agent (opencode or claude) with the task prompt.

When we tried to run a SPIR flow on Windows, the builder either froze at the opencode TUI start screen or crashed with EPIPE errors. This blocked all implementation work — the builder could never write code.

Environment

  • OS: Windows 11 (build 22631)
  • Node: v22.23.3
  • npm: 10.9.9
  • pnpm: 10.33.0
  • codev: 3.3.8 (global npm install)
  • Shell: Git Bash (for builder scripts), PowerShell (for Tower)
  • Tower: v3.3.8
  • opencode: 1.19.6
  • claude: 2.1.332

Steps to Reproduce

Bug 1: Builder spawn script passes prompt as argv (EPIPE)

  1. Install codev globally: npm install -g @cluesmith/codev
  2. Create a project and spawn a builder:
    afx workspace start
    afx spawn 123 --protocol spir
  3. Check the generated .builder-start.sh in the worktree:
    cat .builders/spir-123/.builder-start.sh
  4. Observe the script contains:
    opencode "$(cat '/path/to/.builder-prompt.txt')"
  5. The builder crashes with EPIPE (broken pipe) because opencode receives the prompt as argv, not stdin.

Bug 2: opencode TUI freezes in Tower PTY

  1. Fix the spawn script to use stdin redirect (see fix below)
  2. Spawn a builder with opencode as the harness
  3. Open the Tower dashboard and click the builder terminal tab
  4. Observe opencode freezes at the start screen — never renders, never responds

Expected Behavior

The builder should launch, read the prompt, generate code, and commit changes. The opencode TUI should render in the Tower dashboard and be interactive.

Actual Behavior

Bug 1: EPIPE crash

The builder script passes the prompt as a command-line argument:

opencode "$(cat '.builder-prompt.txt')"

On Windows, opencode expects the prompt via stdin, not argv. The prompt text gets concatenated with the path, causing:

Error: Failed to change directory to D:\CS\projects\codev\.builders\spir-1488\You are a Builder. Read codev\roles\builder.md...

Or EPIPE (broken pipe) when opencode tries to read stdin that isn't there.

Bug 2: TUI freeze

Even with the stdin fix, opencode's TUI freezes when launched through the Tower's PTY:

  • Process is alive (PID 19700), responding to OS signals
  • CPU stays idle (11.4s after 60s — no active generation)
  • 0 requests reach the model API proxy
  • Process never exits, never renders the TUI

Root Cause

Bug 1: opencode expects stdin, not argv

opencode reads the prompt from stdin (like echo "prompt" | opencode), not as a positional argument. The .builder-start.sh script passes it as argv (opencode "$(cat prompt)"), which works on Linux/Mac (opencode may tolerate it) but fails on Windows where the argv gets mangled.

This is opencode-specific, not Windows-specific. The bug is the combination of opencode + argv passing. On Linux/Mac, the shell may handle the argv differently, but the correct approach is always stdin.

Bug 2: ConPTY not recognized as real TTY

The Tower uses node-pty with ConPTY (Windows Pseudo Console) to create PTY sessions. opencode's TUI checks isatty() to determine if it's running in a real terminal. ConPTY returns false (or behaves differently), so opencode thinks it's not interactive and freezes.

On Linux/Mac, the Tower's PTY is a real pseudo-terminal (forkpty), so isatty() returns true and the TUI works.

Possible Fix

Bug 1 fix (tested and working):

Change the spawn script to use stdin redirect:

# Before (broken):
opencode "$(cat '/path/to/.builder-prompt.txt')"

# After (fixed):
opencode < '/path/to/.builder-prompt.txt'

This is committed in the source (spawn-worktree.ts line 1218):

const promptArg = isOpencode
  ? `< '${scriptLocalPath(promptFile)}'`
  : `"$(cat '${scriptLocalPath(promptFile)}')"`;

Status: Fixed in source, needs release. The global CLI (3.3.8) still has the old pattern.

Bug 2 fix (tested and working for builders):

Use non-interactive mode instead of TUI mode:

# Before (freezes):
opencode < '/path/to/.builder-prompt.txt'

# After (works):
opencode run < '/path/to/.builder-prompt.txt'

For claude:

# Before (freezes):
claude < '/path/to/.builder-prompt.txt'

# After (works):
claude --print < '/path/to/.builder-prompt.txt'

This is committed in the source (spawn-worktree.ts line 1212):

const nonInteractiveCmd = baseCmd.includes('opencode')
  ? `${launchCmd} run`
  : baseCmd.includes('claude')
    ? `${launchCmd} --print`
    : launchCmd;

Status: Fixed in source, tested working. Builder successfully generated spec and plan for issue #1488.

Bug 2 alternative fix (for architect, not builder):

The architect needs to be long-running, so non-interactive mode doesn't work. The architect needs either:

  • A loop that runs opencode run repeatedly, processing mail between runs
  • A real TTY (deep ConPTY fix)

Evidence

Bug 1: EPIPE error

Error: Failed to change directory to D:\CS\projects\codev\.builders\spir-1488\You are a Builder. Read codev\roles\builder.md for your full role definition.

Bug 2: TUI freeze

  • opencode PID 19700: alive, responding, CPU 11.4s after 60s (idle)
  • 0 proxy requests after 2+ minutes
  • Process never exits

Fix verification

After applying both fixes, the builder successfully:

  1. Generated spec 1488-protocols-e2e-tests-check-can-.md (11KB)
  2. Committed as 8166036ce
  3. Generated plan 1488-protocols-e2e-tests-check-can-.md (7.8KB)
  4. Transitioned to implement phase

Impact

  • Blocks all builder work on Windows — no code can be written
  • Blocks SPIR/ASPIR/AIR flows — builders are the implementation stage
  • Workaround exists — use the fixed source build instead of global CLI

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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