Skip to content

run: drain piped child stdout/stderr to prevent Ralph loop deadlock#194

Open
selimdev00 wants to merge 2 commits into
LarsCowe:mainfrom
selimdev00:fix/ralph-stdout-drain
Open

run: drain piped child stdout/stderr to prevent Ralph loop deadlock#194
selimdev00 wants to merge 2 commits into
LarsCowe:mainfrom
selimdev00:fix/ralph-stdout-drain

Conversation

@selimdev00

Copy link
Copy Markdown

Problem

In dashboard and swarm mode, spawnRalphLoop spawns the loop with stdio: ["ignore", "pipe", "pipe"], but nothing ever consumes the child's stdout/stderr — the dashboards read progress from .ralph/ state files, not from the pipe.

Node child-process pipes start paused. Once the loop (and the agent CLI it drives) writes more than the OS pipe buffer (~64KB), the child blocks on write() indefinitely. The loop then hangs forever: onExit never fires, so bmalph run --dashboard and bmalph run --swarm (where every worker is spawned this way) stall and never resolve. It only takes one verbose agent turn to cross 64KB.

Fix

When stdio is piped (inheritStdio === false), put both streams into flowing mode so their buffers drain and the child can always make progress:

if (!options.inheritStdio) {
  child.stdout?.resume();
  child.stderr?.resume();
}

This preserves existing behavior (dashboard mode already shows state-file progress, not raw child output) while removing the deadlock. The inheritStdio === true path is unchanged. Output is discarded, same as today — a follow-up could instead tee each stream to a per-worker log file under .ralph/logs/ for swarm debugging.

Tests

  • Asserts stdout.resume() / stderr.resume() are each called once when inheritStdio is false.
  • Asserts the inherited-stdio path (no stream handles) skips draining without throwing.
  • Full unit suite passes (1837).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant