fix(hooks): drain POSIX hook stdin without PATH
Summary
Codex/Grok/Claude POSIX managed hooks no longer depend on PATH just to read or drain hook stdin.
The shared hook prelude used cat in two places:
payload=$(cat)in every generated POSIX hook scriptcat >/dev/null 2>&1 || :in missing-script/no-op launchers
When a tool launches a Codex worker with a stripped or minimal PATH, those reads can fail before stdin is consumed. That turns an otherwise harmless no-op into hook exit noise or a broken pipe while Codex is still writing the hook payload.
This changes the shared reader to prefer /bin/cat before falling back to cat, so normal macOS/Linux/WSL shells consume stdin even when PATH is empty.
Validation
corepack pnpm exec vitest run --config config/vitest.config.ts src/main/agent-hooks/managed-hook-stdin-lifecycle.test.tscorepack pnpm exec oxlint src/main/agent-hooks/hook-stdin-contract.ts src/main/agent-hooks/managed-hook-stdin-lifecycle.test.tscorepack pnpm run typecheck:node
Related: #8110
No actionable comments were generated in the recent review. đ
âšī¸ Recent review info
âī¸ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 58b55bb8-7625-48b8-8418-bc446c77f429
đĨ Commits
Reviewing files that changed from the base of the PR and between 80b4b92c44380dbaf3cb21af58600e4365d4a039 and 6a2698846a6ea816375976de97969b9dd2151434.
đ Files selected for processing (7)
src/main/agent-hooks/hook-stdin-contract.tssrc/main/agent-hooks/installer-utils.test.tssrc/main/agent-hooks/managed-hook-stdin-lifecycle.test.tssrc/main/antigravity/hook-service.test.tssrc/main/codex/hook-service-wsl-runtime.test.tssrc/main/cursor/hook-service.test.tssrc/main/grok/hook-service.test.ts
đ§ Files skipped from review as they are similar to previous changes (1)
- src/main/agent-hooks/hook-stdin-contract.ts
đ Walkthrough
Walkthrough
Introduces a reusable POSIX stdin reader used by stdin draining and generated payload-capture scripts. Updates lifecycle assertions to reference the shared reader contract and adds coverage for executing generated hooks and missing-script launchers with an empty PATH, verifying successful exits and the absence of stdin errors.
đĨ Pre-merge checks | â 4 | â 1
â Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Description check | â ī¸ Warning | The description covers summary and validation, but it omits required template sections for screenshots, testing checklist, AI review report, security audit, and notes. | Add the missing template sections: Screenshots, the full Testing checklist, AI Review Report, Security Audit, and Notes, even if some are brief. |
â Passed checks (4 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | â Passed | The title is concise and matches the main change: POSIX hook stdin draining no longer depends on PATH. |
| Docstring Coverage | â Passed | No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. |
| Linked Issues check | â Passed | Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check | â Passed | Check skipped because no linked issues were found for this pull request. |
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.
Reviewed with an independent reproduction on both macOS and Ubuntu 20.04, driving the actual generated codex-hook.sh rather than a unit test alone.
Confirmed. Under a stripped PATH the old payload=$(cat) fails before consuming stdin, emitting cat: No such file or directory and giving the writer EPIPE â the broken pipe (os error 32) symptom in #8110. Your new test genuinely fails on revert, so it is a real regression guard.
One blocking defect, fixed and pushed. The change updated the shared constants but left five other test files asserting the literal old cat strings, breaking 10 pre-existing tests. CI did not catch this â the only check that ran was track-community-pr (7s); the vitest suite never ran. Those five now derive their assertions from the exported constants, so the contract has one source of truth.
One improvement, also pushed. I changed the reader to command -p cat instead of /bin/cat. command -p resolves from the shell's built-in default PATH, so it additionally survives hosts with no /bin/cat (NixOS) and ignores a worktree-local cat that could otherwise capture the payload. Verified directly: old form exits 127 under PATH="", new form reads the payload and exits 0.
I considered a pure-shell read loop, which needs no external binary, and rejected it with measurements: ~13x slower (272ms vs 21ms at 1MB) on a per-tool-call hot path, and it corrupts payloads â adds a trailing newline and mangles backslashes, disqualifying for JSON. The chosen shape also mirrors the file's own existing WINDOWS_HOOK_STDIN_READER precedent.
Honest gap worth stating: this stops the noise and the broken pipe, but does not restore delivery under a stripped PATH â curl is also unqualified, so the hook exits 0 having sent nothing. It converts a loud failure into a silent safe one. That matches your PR description, but it means #8110 is not fully closed.
Validation: 501 tests passing across the hook trees, typecheck exit 0.