Repository navigation
Description
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)
- Install codev globally:
npm install -g @cluesmith/codev - Create a project and spawn a builder:
afx workspace start afx spawn 123 --protocol spir
- Check the generated
.builder-start.shin the worktree:cat .builders/spir-123/.builder-start.sh
- Observe the script contains:
opencode "$(cat '/path/to/.builder-prompt.txt')" - The builder crashes with EPIPE (broken pipe) because opencode receives the prompt as argv, not stdin.
Bug 2: opencode TUI freezes in Tower PTY
- Fix the spawn script to use stdin redirect (see fix below)
- Spawn a builder with opencode as the harness
- Open the Tower dashboard and click the builder terminal tab
- 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 runrepeatedly, 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:
- Generated spec
1488-protocols-e2e-tests-check-can-.md(11KB) - Committed as
8166036ce - Generated plan
1488-protocols-e2e-tests-check-can-.md(7.8KB) - 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
- Findings I Built a Conversational Todo Manager with Codev! #22, Why doesn't the protocol have any code? #24-27, docs: Add no-squash-merge rule #29 in the Windows findings artifact
- Depends on: Architect terminal fix (#2009) for full SPIR flow
- The non-interactive fix is in
spawn-worktree.tscommits480f20ba5,f81844bcf
Activity