Skip to content

fix(cli): exit on broken pipes - #33660

Closed
lin-hongkuan wants to merge 1 commit into
anomalyco:devfrom
lin-hongkuan:broken-pipe-exit
Closed

lin-hongkuan wants to merge 1 commit into
anomalyco:devfrom
lin-hongkuan:broken-pipe-exit

Conversation

@lin-hongkuan

Copy link
Copy Markdown

Issue for this PR

Closes #33653

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

OpenCode can keep running after stdout or stderr is closed by a parent process. When that broken pipe surfaces as an EPIPE stream error, the process should stop instead of continuing to retry writes.

This PR adds a small broken-pipe helper, installs it in the main CLI entrypoint for commands such as opencode run --format json, and reuses the same detection in the TUI worker handlers. The handler exits only for EPIPE errors; non-EPIPE stream errors are rethrown by the main stream listener so normal failures are not silently swallowed.

How did you verify your code works?

  • bun test test/cli/broken-pipe.test.ts from packages/opencode
  • bun test test/cli/run/run-process.test.ts from packages/opencode
  • bun run typecheck from packages/opencode
  • git diff --check from the repo root

Screenshots / recordings

Not applicable; this is CLI subprocess error handling.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

If you do not follow this template your PR will be automatically rejected.

@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI/server subprocess can spin at 100% CPU when stdout pipe is closed (EPIPE)

1 participant