Skip to content

fix(shell): drain stdout/stderr to prevent command hanging on large output - #154

Merged
skulidropek merged 3 commits into
ProverCoderAI:mainfrom
konard:issue-153-39dda3815f4e
Mar 18, 2026
Merged

fix(shell): drain stdout/stderr to prevent command hanging on large output#154
skulidropek merged 3 commits into
ProverCoderAI:mainfrom
konard:issue-153-39dda3815f4e

Conversation

@konard

@konardkonard commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

Problem

pnpm run docker-git clone <repo> --force --mcp-playwright hangs indefinitely and never completes.

Root Cause

In packages/lib/src/shell/command-runner.ts, both runCommandExitCode and runCommandCapture start 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 push or git stash pop during autoSyncState after 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

runCommandExitCode

Rewrote from a simple Effect.map(Command.exitCode(...), Number) to an Effect.scoped block that:

  1. Manually starts the process via executor.start
  2. Forks daemon fibers to drain bothprocess.stdout and process.stderr concurrently
  3. Awaits process.exitCode

runCommandCapture

Added 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 iff cmd terminates (no buffer deadlock)
  • ∀ cmd: runCommandCapture(cmd) terminates iff cmd terminates

Preconditions

  • Command process started with "pipe" for stdout, stderr, stdin

Postconditions

  • runCommandExitCode: returns numeric exit code, stdout/stderr fully consumed
  • runCommandCapture: returns decoded stdout string, stderr fully consumed, exit code validated

Test plan

  • Run pnpm run docker-git clone <repo> --force --mcp-playwright and verify it completes without hanging
  • CI checks pass (Build, Types, Lint, Test, E2E)

🤖 Generated with Claude Code

Fixes#153

konardand others added 2 commits March 18, 2026 07:23
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>
@konardkonard changed the title [WIP] Внедрить эти изменения в кодfix(shell): drain stdout/stderr to prevent command hanging on large outputMar 18, 2026
@konard
konard marked this pull request as ready for review March 18, 2026 07:26
@konard

Copy link
Copy Markdown
ContributorAuthor

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $0.324257
  • Calculated by Anthropic: $0.420490 USD
  • Difference: $0.096234 (+29.68%)

🤖 Models used:

  • Tool: Claude
  • Requested: sonnet
  • Main model: Claude Sonnet 4.6 (ID: claude-sonnet-4-6, Anthropic, cutoff: 2025-08)
    📎 Log file uploaded as Gist (401KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard

Copy link
Copy Markdown
ContributorAuthor

✅ Ready to merge

This pull request is now ready to be merged:

  • All CI checks have passed
  • No merge conflicts
  • No pending changes

Monitored by hive-mind with --auto-restart-until-mergeable flag

@skulidropek
skulidropek merged commit 27a6583 into ProverCoderAI:mainMar 18, 2026
12 checks passed
Sign up for freeto 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.

Внедрить эти изменения в код

2 participants

@konard@skulidropek