fix(loop-context): don't crash when an --on-exceed hook ignores stdin - #524
Merged
cobusgreyling merged 1 commit intoAug 17, 2026
Conversation
runOnExceedHook() piped the escalation decision to the hook script's stdin with no 'error' listener on the stream itself. If the script exits without ever reading stdin -- a completely ordinary shape for a notify script (e.g. one that just does `echo escalated`) -- writing to that already-closed pipe raises an 'error' event on the stream (EPIPE on POSIX, EOF on Windows). Node treats an unhandled stream 'error' as an uncaught exception by default, crashing the whole loop-context process, even though this hook is documented and coded as fire-and-forget: the crash happens after the circuit breaker has already made its decision, so it turns a successful --check run into a hard failure for a reason entirely unrelated to the ledger. Attach a no-op 'error' listener on child.stdin so a write-after-close failure is absorbed instead of escalating past the 'close' handler, which already resolves the promise regardless of how the hook exited. Test plan: added a regression test with a hook script that never reads stdin, using a large ledger error string so the piped decision JSON reliably exceeds the OS pipe buffer (removing timing flakiness from the repro) -- confirmed it fails with the exact "write EOF" crash against the pre-fix code and passes with the fix. Full clean rebuild + npm test: 52/52 passing. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
cobusgreyling
approved these changes
Aug 17, 2026
cobusgreyling
left a comment
Owner
There was a problem hiding this comment.
Fire-and-forget --on-exceed hook must not crash the process on EPIPE when the script never reads stdin. No-op stdin error listener is the right fix; the large-payload test makes the race reliable.
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.
Problem
runOnExceedHook() piped the escalation decision to the hook script's
stdin with no 'error' listener on the stream itself. If the script
exits without ever reading stdin -- a completely ordinary shape for a
notify script (e.g. one that just does
echo escalated) -- writing tothat already-closed pipe raises an 'error' event on the stream (EPIPE
on POSIX, EOF on Windows). Node treats an unhandled stream 'error' as
an uncaught exception by default, crashing the whole loop-context
process, even though this hook is documented and coded as
fire-and-forget: the crash happens after the circuit breaker has
already made its decision, so it turns a successful --check run into
a hard failure for a reason entirely unrelated to the ledger.
Fix
Attach a no-op 'error' listener on child.stdin so a write-after-close
failure is absorbed instead of escalating past the 'close' handler,
which already resolves the promise regardless of how the hook exited.
Test plan
Added a regression test with a hook script that never reads stdin,
using a large ledger error string so the piped decision JSON reliably
exceeds the OS pipe buffer (removing timing flakiness from the repro)
-- confirmed it fails with the exact "write EOF" crash against the
pre-fix code and passes with the fix. Full clean rebuild + npm test:
52/52 passing.