Repository navigation
fix(runtime): tolerate BrokenPipe when writing the hook payload to stdin - #3410
Merged
Merged
Conversation
A hook that exits without reading all of its stdin closes the pipe while CommandWithStdin::output_with_stdin is still writing the JSON payload. The write fails with BrokenPipe, and the error was propagated, so the hook was reported as "failed to start ...: Broken pipe (os error 32)" even though it ran and exited normally. A failed PreToolUse hook then denies the tool call, and a failed PostToolUse hook marks the tool result as an error. Any payload larger than the pipe buffer (64 KiB on Linux) triggers it for a hook that does not read stdin. The payload carries tool_input twice, so a write_file of about 40 KB is enough. plugins/src/hooks.rs already tolerates BrokenPipe for the same reason (ROADMAP ultraworkers#25). Apply the same handling to the runtime hook runner, and add a regression test.
Yeachan-Heo
approved these changes
Nov 27, 2026
Yeachan-Heo
left a comment
Contributor
There was a problem hiding this comment.
✅ Review Complete
Verification Summary:
- Reproduction on main: Test added to main branch fails with BrokenPipe error as expected
- Fix validation: Test passes on PR head with the BrokenPipe handling fix applied
- Child process handling: After BrokenPipe is caught, the code continues to wait for child process (exit status/stdout/stderr/timeout loop preserved)
- Local gates:
cargo fmt --all --check✓cargo clippy --workspace --all-targets✓cargo test -p runtime hooks- 16 passed ✓
- CI status: All checks passing
- build ✓
- docs source-of-truth ✓
- cargo fmt ✓
- cargo test --workspace ✓
- cargo clippy --workspace ✓
- Windows tests (windows-latest) ✓
- Windows tests (windows-11-arm) ✓
The fix correctly mirrors the existing BrokenPipe handling in plugins/src/hooks.rs and prevents hooks that ignore stdin from being reported as failed when large payloads exceed the pipe buffer.
Merged
Yeachan-Heo
added a commit
that referenced
this pull request
Nov 27, 2026
- Bump version 0.1.15 -> 0.1.16 - Add CHANGELOG entry for #3410 hook BrokenPipe fix Co-authored-by: Watch <watch@local>
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.
Summary
BrokenPipe.runtime/src/hooks.rsreturned that error, so the hook was reported asfailed to start ... Broken pipe (os error 32)even though it ran and exited 0. A failed PreToolUse hook denies the tool call and a failed PostToolUse hook marks the result as an error.tool_inputtwice, so a ~40 KBwrite_fileis enough. A hook likeecho okorcargo fmtthat ignores stdin hits it.plugins/src/hooks.rsalready ignoresBrokenPipeon this write. The runtime copy, whichConversationRuntimeuses for configured hooks, was missed. This applies the same handling: ignoreBrokenPipe, still collect the exit status and output. Other write errors still propagate.Anti-slop triage
hooks::tests::hook_that_ignores_stdin_is_not_failed_by_a_payload_larger_than_the_pipe. Onmainit fails withPreToolUse hook ... failed to start for write_file: Broken pipe (os error 32)(6 of 6 runs); with the change it passes (6 of 6 runs). Onmaina PreToolUse payload of 10 KB is fine, while 40/70/100/130 KB all fail.Verification
git diff --checkpasses.Ran
cargo test -p runtime --lib hooks::(12 passed),cargo fmt --all --checkandcargo clippy -p runtime --lib --tests(no warnings). The full workspace suite was not run locally, and the new test is#[cfg(unix)]because I could not check Windows pipe sizes.I used an AI assistant (Claude) while working on this; I reproduced the failure, reviewed the change and checked the test fails without it.
Resolution gate