Skip to content

fix(hooks): write hook output synchronously so process.exit cannot drop it - #1112

Merged
DietrichGebert merged 1 commit into
mainfrom
fix/hook-stdout-sync
Oct 13, 2026
Merged

DietrichGebert merged 1 commit into
mainfrom
fix/hook-stdout-sync

Conversation

@DietrichGebert

Copy link
Copy Markdown
Owner

Fixes #1043.

Every hook calls process.exit() right after writeHookOutput(). On macOS a write to a pipe is asynchronous, so when the pipe cannot take the whole output at once, the rest is still pending when the process exits and is lost. The host then gets truncated or empty JSON and no ruleset.

writeHookOutput() is the one place all hook output goes through. It now writes with fs.writeSync(1, ...), so the output is complete before any exit. All callers already wrap it in try/catch, so a closed reader (EPIPE) still never fails the hook.

Checked on macOS with a pipe that is already full when the hook starts (the reader drains it only later):

main this PR
mode tracker (/ponytail lite) 0 bytes valid JSON, 2951 chars
subagent 0 bytes valid JSON, 2859 chars

A reader that closed the pipe: all three hooks exit 0 with no stderr. npm test passes (136 + 29).

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.

Hook stdout JSON is truncated on macOS after mode changes and subagent start

1 participant