Repository navigation
fix(agent-hooks): guard every Windows missing-target fallback before it reads stdin - #19415
Conversation
…it reads stdin The #11549 rule was written once in cmd syntax and re-typed by hand elsewhere, so the PowerShell and Git Bash launchers never got it. Derive all three dialects from one list of vars and apply them wherever a missing target makes the caller the stdin owner. - wrapWindowsHookCommand and the runtime-home PowerShell branch guard before ReadToEnd, and emit the fallback answer before the guard so a gate event outside a pane is not answered with silence. - The runtime-home Git Bash fallback picks its rule by platform: POSIX keeps capture-first (#8110), Windows answers, guards, then drains. - The Antigravity wrapper disables delayed expansion like its core; with a `!` in the hooks path it was missing the core on every event (#9358/#9941). Tests drive the wrapper through the production `cmd /d /c` chain under both delayed-expansion states, and the cross-agent ratchet now covers the launchers with an abandoned pipe rather than requiring the unguarded drain.
|
This run was cancelled 🛑 The workflow was cancelled before completion. Please check the link below for details. |
📝 WalkthroughWalkthroughThe change centralizes Windows hook environment variables and adds Git Bash and PowerShell guards. Windows launchers now emit fallback output before guarding and reading stdin. Runtime-home fallbacks select platform-specific behavior. Antigravity wrappers disable delayed expansion and guard missing-core paths. Tests cover launcher stdin modes, missing variables, delayed expansion, fallback ordering, and payload delivery. Priority: ➖ Normal — Impact reflects medium issue severity. Severity of issue fixed: Medium Merge Risk: 🔵 Low · up to Windows hook fallbacks are intended to return neutral JSON before handling stdin, but one lifecycle test could still pass if that output is removed. This is a bounded test-coverage gap that should be corrected before relying on the test for this behavior. 🚥 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.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 00253f90-39c3-4ea4-a927-4cd6d8054f84
📒 Files selected for processing (8)
src/main/agent-hooks/hook-stdin-contract.tssrc/main/agent-hooks/installer-utils.test.tssrc/main/agent-hooks/installer-utils.tssrc/main/agent-hooks/managed-hook-stdin-lifecycle.test.tssrc/main/agent-hooks/runtime-home-hook-command.tssrc/main/antigravity/hook-script.tssrc/main/antigravity/windows-hook-payload-delivery.test.tssrc/main/copilot/copilot-managed-script.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
| expect(decoded.indexOf("Write-Output '{}'"), `${name} answers first`).toBeLessThan( | ||
| decoded.indexOf(WINDOWS_POWERSHELL_HOOK_ENVIRONMENT_GUARD) | ||
| ) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Assert that the fallback output exists.
At Line 342, indexOf("Write-Output '{}'") returns -1 when the fallback is absent. The comparison still passes when the guard exists. A missing fallback in wrapRuntimeHomeHookCommand would not fail this test.
Proposed fix
+ expect(decoded.indexOf("Write-Output '{}'"), `${name} emits fallback`).toBeGreaterThan(-1)
expect(decoded.indexOf("Write-Output '{}'"), `${name} answers first`).toBeLessThan(
decoded.indexOf(WINDOWS_POWERSHELL_HOOK_ENVIRONMENT_GUARD)
)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| expect(decoded.indexOf("Write-Output '{}'"), `${name} answers first`).toBeLessThan( | |
| decoded.indexOf(WINDOWS_POWERSHELL_HOOK_ENVIRONMENT_GUARD) | |
| ) | |
| expect(decoded.indexOf("Write-Output '{}'"), `${name} emits fallback`).toBeGreaterThan(-1) | |
| expect(decoded.indexOf("Write-Output '{}'"), `${name} answers first`).toBeLessThan( | |
| decoded.indexOf(WINDOWS_POWERSHELL_HOOK_ENVIRONMENT_GUARD) | |
| ) |

The bug
On Windows, a hook script sometimes can't find the file it's supposed to run — antivirus quarantined it, or an uninstall left half of it behind.
When that happens the hook falls back to a small "do nothing useful" path. That path ends with: read whatever the agent is sending us, and throw it away.
That read never finishes if nobody ever closes the pipe. And nobody closes the pipe when the hook runs outside Orca — from a plain terminal, say. So the hook just sits there. Forever. One stuck process, and often one visible black console window, for every single hook event.
This is the same bug we already fixed once (#11549). We fixed it in the hook scripts. We missed the launchers.
Why we missed it
The rule is "check for Orca's environment variables before you read stdin."
That rule was written down once, in
.cmdsyntax. Everywhere else it was retyped by hand — once in PowerShell for Copilot, once in shell for Kimi. The two launchers never got a copy at all.So this PR writes the variable names down once and generates all three versions from them. Now they can't drift apart again.
What's fixed
1. The PowerShell launcher (
wrapWindowsHookCommand) — used by Copilot, Cursor, Droid, Gemini, Command Code on every event, and by Antigravity/Codex/Devin/Grok when the file path has a space in it. It now checks the environment before reading.It also had a second problem: it printed its fallback answer after the read. So for a "should I allow this tool?" event, the answer came out only once the read finished — which is never. Antigravity treats no answer as "deny". The answer now comes first.
2. The Git Bash launcher — same bug, found by the new test. Its fallback now picks the right rule for the machine it's on: Linux/Mac keep the old behaviour (their callers do close the pipe — see #8110), Windows gets the guard.
3. The Antigravity wrapper had a separate, worse bug. If your hooks folder path contains a
!and Windows has "delayed expansion" turned on, cmd eats the!and the wrapper can't find the real hook script. It silently falls into the do-nothing path on every event — so Orca shows no agent status at all. The core script already protected against this; the wrapper didn't. One word fixes it.Proof, same script both ways:
Tests
The old test spawned the hook in a way that silently disabled delayed expansion. That's the exact thing this file's
!-in-the-pane-key checks exist to catch — so they couldn't fail, on any machine, ever.Tests now use the real launch shape from the bug report and run every event twice, once with delayed expansion off and once on, with a
!in the folder path so there's something to actually break.The cross-agent stdin test previously required the buggy behaviour. It now checks the correct rule, and it holds the pipe open instead of closing it — which is the only way to catch a read that never returns.
Every fix was checked by undoing it and confirming a test goes red:
Verification
Run on real Windows 11, Node 24.
main: 5 tests that call/bin/sh(can't work from Windows) and 3 that create symlinks (needs Developer Mode). Untouched — unrelated to this PR.Note for the reviewer
This started as a 2-line Antigravity fix. Reviewing it turned up the same bug in two launchers plus the separate
!bug, so it grew to 8 files. The extra changes are all the same root cause and are covered by the table above — but if you'd rather have the launcher work split into its own PR, say so and I'll pull it out.Out of scope, unchanged: STA-5074's env-present core hang is still there. The core still waits past 3s for EOF;
curl --max-timedoes not bound its read of stdin.