fix(cli): restore SIGPIPE default on Unix
Summary
- restore the default SIGPIPE disposition at process startup on Unix
- prevents Rust print macros from panicking on normal closed-pipe CLI usage like
openhuman-core --help | head - add a Unix integration test that closes the stdout pipe and verifies stderr does not contain a broken-pipe panic
Closes #3535
Tests
cargo fmt --checkgit diff --check
Attempted but blocked locally:
env CC=/usr/bin/gcc CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=/usr/bin/gcc cargo test --test cli_sigpipe -- --nocapture- blocked by missing system pkg-config deps:
alsa.pcandxi.pc
- blocked by missing system pkg-config deps:
Summary by CodeRabbit
- Bug Fixes
- Fixed a crash that occurred when the CLI's output pipe was closed before completion (e.g., when piping to commands like
head).
- Fixed a crash that occurred when the CLI's output pipe was closed before completion (e.g., when piping to commands like
[!NOTE] Currently processing new changes in this PR. This may take a few minutes, please wait...
βοΈ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID:
d185a8d4-5385-4884-8501-863963eb85fbπ₯ Commits
Reviewing files that changed from the base of the PR and between 5a540d2dbe2c2dc7cc4a7c105267b1f0cfc255f4 and 1a1dbc8782df893f48bbea3016071db939f662f8.
π Files selected for processing (1)
tests/cli_sigpipe.rs_____________________________________________________________________________ < Rabbit check: I hopped through the diff and found carrots... and landmines. > ----------------------------------------------------------------------------- \ \ \ \ /\ ( ) .( o ).
π Walkthrough
Walkthrough
Adds libc = "0.2" as a direct dependency, introduces a restore_default_sigpipe function that calls libc::signal(SIGPIPE, SIG_DFL) on Unix (no-op on non-Unix), invokes it at the start of main, and adds an integration test verifying the CLI does not panic when its stdout pipe is closed early.
Changes
SIGPIPE default handler and integration test
| Layer / File(s) | Summary |
|---|---|
libc dependency and restore_default_sigpipe implementation Cargo.toml, src/main.rs |
Pins libc = "0.2" as a direct dependency. Adds restore_default_sigpipe with a #[cfg(unix)] body calling libc::signal(SIGPIPE, SIG_DFL) and a #[cfg(not(unix))] no-op stub. Calls the function at the very start of main before dotenv loading and Sentry initialization. |
Broken-pipe integration test tests/cli_sigpipe.rs |
Adds #[cfg(unix)] test help_output_closed_pipe_does_not_panic that spawns the CLI binary with --help, immediately drops the captured stdout handle, waits for the process, and asserts stderr contains neither "Broken pipe" nor "panicked". |
Estimated code review effort
π― 2 (Simple) | β±οΈ ~10 minutes
Poem
π A pipe snapped shut, the stream ran dry, No panic now, the writes just die.
SIG_DFLset before the start, A tiny fix, a steady heart. Broken pipes shall quietly fade β hooray! β¨
π₯ Pre-merge checks | β 5
β Passed checks (5 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | β Passed | Check skipped - CodeRabbitβs high-level summary is enabled. |
| Title check | β Passed | The title clearly describes the main change: restoring the SIGPIPE default on Unix for the CLI. |
| Linked Issues check | β Passed | The PR restores SIGPIPE on Unix and adds a regression test covering closed-pipe output, matching the issue goals. |
| Out of Scope Changes check | β Passed | The changes are limited to the SIGPIPE fix, its libc dependency, and the regression test, with no unrelated additions. |
| Docstring Coverage | β Passed | No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. |
βοΈ Tip: You can configure your own custom pre-merge checks in the settings.
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.
Comment @coderabbitai help to get the list of available commands and usage tips.
I checked the failing Rust Core Coverage (cargo-llvm-cov) job. The tests completed and lcov-core.info was generated; the failure happened in post-job cleanup/rust-cache while running cargo metadata --all-features, which failed to unpack windows v0.57.0 because the runner hit No space left on device.
I tried gh run rerun 27481248697 --failed, but GitHub rejected it because I do not have admin rights. This looks like an infra/cache disk-space failure rather than a code failure; a maintainer rerun should be the next step.
I addressed the remaining CodeRabbit test nit in a helper PR because direct push to the source branch returned 403: https://github.com/YonganZhang/openhuman/pull/4
What changed:
- The closed-pipe CLI regression test now asserts that the child process either exits successfully or is terminated by SIGPIPE.
- The existing stderr checks for broken-pipe/panic text are preserved.
Validation:
- cargo fmt --manifest-path Cargo.toml --check
- git diff --check -- tests/cli_sigpipe.rs
- cargo test --manifest-path Cargo.toml --test cli_sigpipe was attempted on this Windows environment, but compilation did not finish before a 5 minute timeout. The test body is Unix-only via #[cfg(unix)], so Linux CI is the authoritative execution path.
The existing Rust Core Coverage failure still appears to be the runner disk/cache cleanup issue noted above rather than a code failure.
Review: fix is correct, but the regression test is likely a false-green
The production fix is sound β
β restoring SIGPIPE β SIG_DFL as the first statement in main() (before the banner and sentry::init) is the idiomatic ripgrep/fd approach and covers both Sentry groups (OPENHUMAN-CORE-C stdout/help and OPENHUMAN-CORE-1Q stderr/banner) since it's a global reset. The #[cfg(unix)] guard + non-unix no-op keeps Windows unaffected. No concerns there.
The regression test (tests/cli_sigpipe.rs) doesn't reliably exercise the bug, though β οΈ
-
Pipe-buffer race β possible false-green.
--helpoutput is a few KB, well under the 64 KB kernel pipe buffer. Afterdrop(child.stdout.take()), the child can write its entire output into the buffer in a singlewrite()that succeeds immediately, then exit cleanly β never hittingEPIPE, with or without the fix. So this test can pass even if the bug were reintroduced. To actually force the broken-pipe path, mirror the issue's repro (--help | head -n 1): read one line, then close, so the next write fails β or emit output larger than the pipe buffer. -
No exit-status assertion. Acceptance criterion #1 asks for a clean exit status; the test only greps stderr for
"Broken pipe"/"panicked"and ignoresoutput.status. CodeRabbit's nit (assertstatus.success() || status.signal() == Some(SIGPIPE)) addresses this, but that change currently lives in a helper PR against the fork (YonganZhang/openhuman#4) and is not in this branch β the diff here still has the weaker test.
Suggested before merge: fold the exit-status assertion and a repro that truly triggers EPIPE (read-one-line-then-close, or oversized output) directly into this branch, so "regression safety" is met substantively rather than nominally.
[!CAUTION] Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.
Error details
{}