Skip to content

fix(runtime): tolerate BrokenPipe when writing the hook payload to stdin - #3410

Merged
Yeachan-Heo merged 1 commit into
ultraworkers:mainfrom
JayPokale:fix-hook-pipe-io
Nov 27, 2026
Merged

Yeachan-Heo merged 1 commit into
ultraworkers:mainfrom
JayPokale:fix-hook-pipe-io

Conversation

@JayPokale

Copy link
Copy Markdown
Contributor

Summary

  • A hook that exits without reading all of its stdin closes the pipe while the runner is still writing the JSON payload, and the write fails with BrokenPipe. runtime/src/hooks.rs returned that error, so the hook was reported as failed 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.
  • It only shows up when the payload is bigger than the pipe buffer (64 KiB on Linux). The payload carries tool_input twice, so a ~40 KB write_file is enough. A hook like echo ok or cargo fmt that ignores stdin hits it.
  • The plugin hook runner in plugins/src/hooks.rs already ignores BrokenPipe on this write. The runtime copy, which ConversationRuntime uses for configured hooks, was missed. This applies the same handling: ignore BrokenPipe, still collect the exit status and output. Other write errors still propagate.

Anti-slop triage

  • Classification: actionable-fix
  • Evidence: new test hooks::tests::hook_that_ignores_stdin_is_not_failed_by_a_payload_larger_than_the_pipe. On main it fails with PreToolUse 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). On main a PreToolUse payload of 10 KB is fine, while 40/70/100/130 KB all fail.
  • Non-destructive review result: merge candidate

Verification

  • Targeted tests/docs checks ran, or the gap is explicitly recorded.
  • git diff --check passes.
  • No live secrets, tokens, private logs, or unrelated generated churn are included.

Ran cargo test -p runtime --lib hooks:: (12 passed), cargo fmt --all --check and cargo 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

  • If this PR resolves an issue, the issue number and fix evidence are linked. (No issue filed; evidence is in the triage section above.)
  • If this PR should not merge, the rejection/defer rationale is evidence-backed and does not rely on vibes. (Not applicable.)
  • I did not merge/close remote PRs or issues from an automation lane without owner approval.

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 Yeachan-Heo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Review Complete

Verification Summary:

  1. Reproduction on main: Test added to main branch fails with BrokenPipe error as expected
  2. Fix validation: Test passes on PR head with the BrokenPipe handling fix applied
  3. Child process handling: After BrokenPipe is caught, the code continues to wait for child process (exit status/stdout/stderr/timeout loop preserved)
  4. Local gates:
    • cargo fmt --all --check ✓
    • cargo clippy --workspace --all-targets ✓
    • cargo test -p runtime hooks - 16 passed ✓
  5. 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.

@Yeachan-Heo
Yeachan-Heo merged commit 365fa14 into ultraworkers:main Nov 27, 2026
7 checks passed
@Yeachan-Heo Yeachan-Heo mentioned this pull request Nov 27, 2026
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>
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.

2 participants