Repository navigation
fix(hooks): stop the Windows hook payload consuming its own stdin - #19272
brennanb2025 wants to merge 1 commit into
Conversation
On Windows PowerShell 5.1, Set-ExecutionPolicy takes a host confirmation path even with -Force -ErrorAction SilentlyContinue. With stdin redirected — how every agent delivers hook JSON — that prompt consumes the payload and echoes it to stdout, so the agent rejects the hook output as malformed JSON and the script behind it reads empty stdin. Emit the bypass only for a payload that runs a .ps1. Copilot ships the only managed .ps1 hook and still needs it under a locked-down policy; every other hook is a .cmd, which execution policy does not govern. The launch shape is unchanged by construction, and a test pins that: the shape was chosen by AV measurement at CreateProcess, so it may only change alongside a new measurement.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (4)
Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review. 📝 WalkthroughWalkthroughThe PowerShell hook launcher now accepts an optional execution-policy bypass setting. The setting defaults to disabled and enables the bypass snippet only when requested. The installer derives the setting from the managed script path, enabling it for Merge Risk: ⚪ Minimal · up to Windows .cmd hooks no longer include the PowerShell execution-policy command that could consume hook stdin, while .ps1 hooks retain it. The changed behavior is covered for both payload types and is ready to merge. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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 |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the fix that makes the Windows hook launcher's execution-policy bypass conditional on the payload being a .ps1, so .cmd hooks stop triggering the PowerShell 5.1 stdin-consuming Set-ExecutionPolicy cmdlet.
needsHookExecutionPolicyBypass+WindowsPowerShellHookOptions— the bypass becomes an explicitexecutionPolicyBypassoption onencodeWindowsPowerShellHookCommand/wrapWindowsPowerShellEncodedCommand, defaulting tofalse.wrapWindowsHookCommand(installer-utils.ts) — keys the bypass off the script extension, so only Copilot's.ps1keeps it and every.cmdhook drops it.- Test coverage — a headline identity test pins the AV-measured launch shape byte-identical across payloads (with an anti-vacuity guard that the payloads differ), plus new
.cmd-omission,.ps1-retention, and helper tests; four pre-existing assertions narrowed to the explicit{ executionPolicyBypass: true }path.
I traced every caller of the two launcher entry points to confirm the .ps1/.cmd split is complete and correct: Copilot (copilot-managed-hook-definitions.ts) is the only .ps1 and keeps the bypass; Claude's encoded fallback (hook-settings.ts), runtime-home-hook-command.ts, and the .cmd agents all run batch files and correctly drop it. No .ps1 path loses the bypass and no .cmd path keeps it. The default-false asymmetry (loud GPO failure vs. silent stdin corruption) and the shape-invariance safety argument are sound, and the two touched test files pass locally.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the fix that makes the Windows hook launcher's execution-policy bypass conditional on the payload being a .ps1, so .cmd hooks stop triggering the PowerShell 5.1 stdin-consuming Set-ExecutionPolicy cmdlet.
needsHookExecutionPolicyBypass+WindowsPowerShellHookOptions— the bypass becomes an explicitexecutionPolicyBypassoption onencodeWindowsPowerShellHookCommand/wrapWindowsPowerShellEncodedCommand, defaulting tofalse.wrapWindowsHookCommand(installer-utils.ts) — keys the bypass off the script extension, so only Copilot's.ps1keeps it and every.cmdhook drops it.- Test coverage — a headline identity test pins the AV-measured launch shape byte-identical across payloads (with an anti-vacuity guard that the payloads differ), plus new
.cmd-omission,.ps1-retention, and helper tests; four pre-existing assertions narrowed to the explicit{ executionPolicyBypass: true }path.
I traced every caller of the two launcher entry points to confirm the .ps1/.cmd split is complete and correct: Copilot (copilot-managed-hook-definitions.ts) is the only .ps1 and keeps the bypass; Claude's encoded fallback (hook-settings.ts), runtime-home-hook-command.ts, and the .cmd agents all run batch files and correctly drop it. No .ps1 path loses the bypass and no .cmd path keeps it. The default-false asymmetry (loud GPO failure vs. silent stdin corruption) and the shape-invariance safety argument are sound, and the two touched test files pass locally.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
Status: reviewed CLEAN · one body claim corrected · Windows validation not runIndependent review — CLEANA wholly fresh reviewer found no defect. Two non-blocking observations, both acted on. The load-bearing claim was verified three independent ways. This entire fix rests on It also checked the surface where a second Launch-shape identity was verified by execution, not by trusting the test. The reviewer bundled the two production modules and called them directly, confirming the shape is identical across both option values and across both hook kinds through The four modified assertions were each checked for weakening. All were narrowed in scope, not weakened. The subtlest is A claim in this PR's description was wrong, and is correctedThe body said the change leaves "the command line byte-identical." Measured, the full command line is 513 versus 209 characters — identical in the flag portion, different in the base64 payload. As written the claim was checkable and false. It now says the executable path and switches are byte-identical, that everything up to A second overstatement is also corrected: the sibling assertion pins shape identity one level up at On the headline test, preciselyThe reviewer checked each leg does independent work. Leg 3 (the two payloads genuinely differ) is the non-vacuity guard and goes red on ablation; leg 2 (the exact documented shape) goes red on a switches-constant mutation — the change STA-6357 itself proposes. They fail against different mutations, which is why the pair is worth having. Worth stating plainly: legs 1 and 2 overlap with two pre-existing tests that already assert Manual validation: not runNo Windows host executed this change. The mechanism — that What makes this safe to land without that proof is the asymmetry stated in the body: the change cannot alter the launch shape, and a test fails if anyone makes it. That is genuinely different from a fix whose safety depends on the unverified behaviour. The measurement-gated half — adding |
|
I’m checking the Antigravity path in this proposal against current code. Follow-up draft #21666 adds real Windows process coverage to the existing Windows CI lane, with no launcher change yet so the first run establishes the baseline. The test installs Antigravity's managed scripts in an isolated directory, pipes a multi-KB Unicode JSON payload through the same command builder, and requires byte-exact delivery to a loopback listener plus exactly Two rebase/review constraints:
The proposal's distinction between |
|
Windows baseline verification is complete in #21666, with the existing launcher unchanged. ELI5: the hook delivered the entire message and returned the permission response correctly on the Windows CI host, even when a space in its path forced it through PowerShell.
This does not reproduce the reported stdin loss on this Windows host. It verifies installed managed scripts and the generated launcher with synthetic hook input; it does not run the Windows agy binary, exercise the reporter's machine/GPO/AV setup, or prove live sidebar transitions. The proposed production change remains unadopted pending evidence of the failing host condition and a corresponding before/after check. Copilot's |

Fixes STA-6357.
The defect
Orca's Windows hook launcher prepends
Set-ExecutionPolicy … Bypassto every encoded PowerShell payload. Under PowerShell 5.1 that cmdlet consumes the hook's stdin, so the hook receives an empty or truncated payload and fails.Blast radius is wider than the ticket suggests. After #18875 Claude reaches the encoded path only as a fallback, but Copilot, Cursor, Gemini, Droid and Command-Code go through it on every hook event, and the
.cmdwrapper falls back to it whenever a path is not cmd-safe.Why not the fix the ticket proposes
STA-6357 suggests
WINDOWS_POWERSHELL_HOOK_SWITCHES = '-NoProfile -NonInteractive'.That command line's exact shape was chosen by AV measurement (#16003, recorded in the launcher's own comment): on the reporting host every variant containing
-WindowStyle Hiddenexited 126, while-NoProfile -EncodedCommandsucceeded five times out of five. The denial happens at CreateProcess and matches on the flag combination — and-NoProfile -NonInteractive -EncodedCommanddoes not appear in that measured table. Adding the switch would be an unmeasured change to the shape that STA-6325 was about, shipped blind.The fix
The execution-policy prefix exists solely so managed
.ps1hooks can run under a Restricted or AllSigned policy.copilot-hook.ps1is the only.ps1managed hook — Claude, Codex, Cursor, Gemini, Droid, Grok, Devin, Antigravity and Command-Code are all.cmd, which execution policy does not govern at all.So the prefix is now conditional on the payload being a
.ps1. That removes the stdin-consuming cmdlet for every affected agent while leaving the executable path and the switches byte-identical — everything up to-EncodedCommandis unchanged; only the base64 payload after it differs. #16003 measured the denial at CreateProcess and independent of the payload (anexit 0payload was denied too), so the flag combination is the entire AV surface: no AV risk, no re-measurement, and no coupling to STA-6325.The option defaults to false deliberately, and the reasoning is commented: forgetting it on a
.ps1produces a loud policy failure under a locked-down GPO, whereas the reverse mistake silently corrupts every hook's stdin. The quiet failure is the one kept off the default.The headline test
keeps the launch shape byte-identical whichever payload it carries (AV-measured; re-measure before changing)asserts the command line is identical with and without the bypass, equals the exact documented shape, and that the two payloads genuinely differ — so the identity assertion cannot pass vacuously. A sibling assertion ininstaller-utils.test.tspins the same shape identity one level up, across the.cmdand.ps1callers ofwrapWindowsHookCommand.Its comment records that the denial is at CreateProcess, that folding
-NonInteractiveinto the switches constant is the tempting change (STA-6357 proposes exactly that), and that altering the shape requires a measurement rather than an argument. If someone later makes that change, this test is the prompt to go read STA-6885.Reviewer's attention, flagged rather than buried
Four existing assertions in the launcher suite were modified. They asserted the bypass unconditionally, which is the old contract; they are now scoped to
{ executionPolicyBypass: true }, keeping every assertion about what the bypass looks like when present — try/catch wrapping, ordering after the progress silencer, exact text.This is called out because that file's own comment records that "#16576 round 3 dropped a required launcher invariant by accident and updated the tests to match, so nothing caught it." No invariant was weakened here — the scope was narrowed and new ones added — but it is precisely the shape of mistake that file warns about, and it deserves an eye.
Evidence
Reverting the two production files turns 9 tests red: the headline identity test, both
.cmdomission tests, theneedsHookExecutionPolicyBypasscases, and four pre-existing tests via the updated expectation helper.All hook subsystems (
agent-hooks, claude, copilot, cursor, gemini, droid, codex, grok, devin, antigravity, command-code): 324 files, 3,143 passed, 0 failed. Typecheck, oxfmt, oxlint, max-lines, ts-nocheck, reliability manifest and the changed-code gate all clean.The Windows gap, stated not buried
This cannot prove that removing the prefix actually stops PS 5.1 consuming stdin, that hook JSON parses cleanly afterwards, or that the payload arrives non-empty. Those need a Windows host with PowerShell 5.1 — the reporter measured them; this change did not.
What makes it safe to land without that proof is the asymmetry: the change cannot alter the launch shape, and there is a test that fails if anyone makes it.
Related
.ps1still needs-NonInteractive, which would alter the shape and is therefore blocked on an AV measurement. Filed with the required steps and a fallback if the measurement comes back denied.powershell.exe -EncodedCommandwrapper) adds 1-5 s per hook event and is killed under load, leaving suspended orphan processes #18875. Evidence commented on that issue as a code reading; confirming it needs the reporting host, so the status is left alone.