fix(shell): drain stdout/stderr to prevent command hanging on large output#154
Merged
skulidropek merged 3 commits intoProverCoderAI:mainfrom Mar 18, 2026
Merged
Conversation
Adding .gitkeep for PR creation (default mode). This file will be removed when the task is complete. Issue: ProverCoderAI#153
…apture to prevent buffer deadlock When child processes are started with piped stdout/stderr, the OS pipe buffer (~64 KB) can fill up causing the process to hang indefinitely waiting for the buffer to drain. - runCommandExitCode: rewritten to use Effect.scoped + daemon fibers that drain both stdout and stderr concurrently while waiting for exit - runCommandCapture: adds a daemon fiber to drain stderr so large stderr output no longer blocks the process Fixes: pnpm run docker-git clone <repo> --force --mcp-playwright hanging Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This reverts commit 129ad1d.
Contributor
Author
🤖 Solution Draft LogThis log file contains the complete execution trace of the AI solution draft process. 💰 Cost estimation:
🤖 Models used:
Now working session is ended, feel free to review and add any feedback on the solution draft. |
Contributor
Author
✅ Ready to mergeThis pull request is now ready to be merged:
Monitored by hive-mind with --auto-restart-until-mergeable flag |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
pnpm run docker-git clone <repo> --force --mcp-playwrighthangs indefinitely and never completes.Root Cause
In
packages/lib/src/shell/command-runner.ts, bothrunCommandExitCodeandrunCommandCapturestart child processes with"pipe"mode for stdout/stderr but do not drain those streams. The OS pipe buffer is typically ~64 KB. When a sub-command (e.g.git pushorgit stash popduringautoSyncStateafter a successful clone) writes more than that to stdout or stderr, the child process blocks waiting for the buffer to drain — and since nobody is reading it, it hangs forever.Fix
runCommandExitCodeRewrote from a simple
Effect.map(Command.exitCode(...), Number)to anEffect.scopedblock that:executor.startprocess.stdoutandprocess.stderrconcurrentlyprocess.exitCoderunCommandCaptureAdded
yield* _(Effect.forkDaemon(Stream.runDrain(process.stderr)))before collecting stdout, so large stderr output no longer causes a deadlock.Mathematical Guarantees
Invariants
∀ cmd: runCommandExitCode(cmd)terminates iffcmdterminates (no buffer deadlock)∀ cmd: runCommandCapture(cmd)terminates iffcmdterminatesPreconditions
"pipe"for stdout, stderr, stdinPostconditions
runCommandExitCode: returns numeric exit code, stdout/stderr fully consumedrunCommandCapture: returns decoded stdout string, stderr fully consumed, exit code validatedTest plan
pnpm run docker-git clone <repo> --force --mcp-playwrightand verify it completes without hanging🤖 Generated with Claude Code
Fixes #153