Skip to content

fix: close stdin on spawned processes to prevent hanging#155

Merged
tuannvm merged 5 commits intomainfrom
worktree-issues-153
Apr 10, 2026
Merged

fix: close stdin on spawned processes to prevent hanging#155
tuannvm merged 5 commits intomainfrom
worktree-issues-153

Conversation

@tuannvm
Copy link
Copy Markdown
Owner

@tuannvm tuannvm commented Apr 10, 2026

Summary

Fixes #153

When codex exec is spawned with stdio: ['pipe', 'pipe', 'pipe'], it waits for stdin EOF that never arrives, causing the subprocess to hang indefinitely.

Changes

  • Added child.stdin.end() immediately after spawn in both executeCommand() and executeCommandStreaming() in src/utils/command.ts

Testing

  • Build passes (npm run build)
  • All 76 tests pass

Summary by CodeRabbit

  • Bug Fixes
    • Spawned subprocesses now have their stdin closed after creation, ensuring command executions reliably complete when input ends; no other runtime outputs or behaviors changed.
  • Chores
    • Removed an automated code-review GitHub Actions workflow previously running on pull requests.

When codex exec is spawned with stdio pipes, it waits for stdin EOF
that never arrives, causing the process to hang indefinitely. Close
stdin immediately after spawn in both executeCommand and
executeCommandStreaming.

Fixes #153

Signed-off-by: Tommy Nguyen <[email protected]>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 10, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d2590e29-b358-4a4b-8a7a-6f6b39c80894

📥 Commits

Reviewing files that changed from the base of the PR and between ee759e7 and b9f9bb9.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (1)
  • .github/workflows/cursor.yml
💤 Files with no reviewable changes (1)
  • .github/workflows/cursor.yml

Walkthrough

The PR closes the spawned child process stdin by calling child.stdin?.end() in both executeCommand and executeCommandStreaming, and removes the .github/workflows/cursor.yml GitHub Actions workflow. No function signatures or public declarations were changed.

Changes

Cohort / File(s) Summary
Process stdin closure
src/utils/command.ts
After each spawn(...) call in executeCommand and executeCommandStreaming, call child.stdin?.end() so subprocesses receive EOF on stdin and won't hang waiting for input.
Workflow removal
.github/workflows/cursor.yml
Deleted the "Cursor Code Review" GitHub Actions workflow (entire file removed).

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant CommandUtil
    participant ChildProcess
    Caller->>CommandUtil: executeCommand(...) / executeCommandStreaming(...)
    CommandUtil->>ChildProcess: spawn(file, args, stdio: ['pipe','pipe','pipe'])
    CommandUtil->>ChildProcess: child.stdin?.end()  -- send EOF on stdin
    ChildProcess-->>CommandUtil: stdout / stderr streams
    ChildProcess-->>CommandUtil: exit / close
    CommandUtil-->>Caller: return result / streamed output
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 I closed the little pipe with care,
No more waiting in the midnight air.
EOF whispered, the command set free,
No more hangs — hop, skip, and flee! 🥕

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The deletion of .github/workflows/cursor.yml is unrelated to issue #153 and appears to be an out-of-scope change not mentioned in the PR objectives. Remove the workflow file deletion or explain in the PR description why this change is necessary and related to fixing the stdin hanging issue.
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: closing stdin on spawned processes to prevent hanging, which directly addresses the fix for issue #153.
Linked Issues check ✅ Passed The PR implements the primary fix from issue #153 by calling child.stdin.end() in both executeCommand() and executeCommandStreaming() as required.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch worktree-issues-153

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

tuannvm added 4 commits April 10, 2026 11:32
Codex review flagged that child.stdin is typed as Writable | null.
Using optional chaining prevents a potential crash if spawn options
change in the future.

Signed-off-by: Tommy Nguyen <[email protected]>
Fixes GHSA-92pp-h63x-v22m: middleware bypass via repeated slashes
in serveStatic. Bumped via npm audit fix.

Signed-off-by: Tommy Nguyen <[email protected]>
cursor-agent CLI intermittently crashes with exit code 1 (external
infra issue). Adding || true prevents the entire workflow from
failing when the tool itself crashes. Blocking review still works
via CRITICAL_ISSUES_FOUND env var.

Signed-off-by: Tommy Nguyen <[email protected]>
cursor-agent CLI is unreliable (crashes with exit code 1). Remove
the entire workflow to eliminate false-negative CI failures.

Signed-off-by: Tommy Nguyen <[email protected]>
@tuannvm tuannvm merged commit 13382b4 into main Apr 10, 2026
4 of 5 checks passed
@tuannvm tuannvm deleted the worktree-issues-153 branch April 10, 2026 20:07
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.

Bug: codex exec hangs forever when spawned with stdio pipe — stdin never closed

1 participant