Repository navigation
fix(agent-hooks): stop Antigravity's Windows hook from spawning PowerShell on every event - #15520
Conversation
…Shell per event (#15117) Antigravity was the last agent posting hook status through Windows PowerShell 5.1. Every hook event — roughly one every 2-6s during an active session — paid a ~300ms interpreter cold start, which is what made the console the agent allocates for each hook long enough to see as continuous flashing. Move the Windows POST to the shared curl.exe builder every other agent already uses. curl finishes in ~10ms and, unlike PowerShell, does not recode the UTF-8 payload through the console code page. Because the curl line percent-expands values, the script also needs `setlocal DisableDelayedExpansion` (#9358/#9941) so a `!` in a pane key or worktree path is not eaten as a delayed reference.
…arries no payload
The PowerShell post substituted `{}` for empty stdin, and the POSIX script does
the same before posting. curl forwards stdin verbatim, so a payload-less event
now arrives as `payload=""` and the shared ingest dropped it — losing the status
transition its `hook_event_name` still carried.
Accept an empty Antigravity payload as `{}` at the ingest boundary, scoped to
that source so every other agent keeps rejecting a body it cannot parse.
…y object Real-Windows validation showed curl omits a `--data-urlencode name@-` field entirely when stdin is empty, so a payload-less event arrives with no `payload` key rather than an empty one. Accept both shapes.
An over-broad `oxfmt --write` over src/shared/ reformatted a file this change does not touch. That file's drift is pre-existing on main; restoring it keeps the PR diff to the Antigravity hook.
📝 WalkthroughWalkthroughWindows Antigravity hooks now use the shared 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 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: 2
🧹 Nitpick comments (1)
src/main/antigravity/hook-script.ts (1)
10-16: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winShorten implementation-history comments.
Keep only the non-obvious constraint in each comment. Move issue history and performance narrative to the PR description.
src/main/antigravity/hook-script.ts#L10-L16: Remove the PowerShell and console-flash history. Keep a brief transport rationale if needed.src/main/antigravity/hook-script.ts#L24-L26: Reduce the delayed-expansion rationale to one line.src/main/antigravity/hook-service.test.ts#L101-L102: Remove the repeated performance explanation.src/main/antigravity/windows-hook-payload-delivery.test.ts#L1-L7: Replace the suite preamble with one brief test-purpose comment, or remove it.As per coding guidelines, “Comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through code.”
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: c4c80e64-ee5a-433c-bc39-064074786983
📒 Files selected for processing (5)
src/main/antigravity/hook-script.tssrc/main/antigravity/hook-service.test.tssrc/main/antigravity/windows-hook-payload-delivery.test.tssrc/shared/agent-hook-listener-antigravity.test.tssrc/shared/agent-hook-listener.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.
…erpreter The Antigravity drift was invisible to per-agent tests. The shared builder took only `(source)` and could not add the extra form field Antigravity needs, so it forked a private copy of the then-correct PowerShell command (#2100); when the shared builder moved to curl (#6402) every caller was fixed for free and the copy silently was not. Assert the violated invariant across all ten batch-script agents at once, and generate under a mocked win32 platform so the POSIX CI legs guard it too. Verified to fail on the pre-fix script, naming the offending file.
…cover blank payloads - The missing-pane case closed stdin, so a hook that read before the env guard would still pass on an EOF the real caller never sends. Abandon the pipe instead (#11549). - Cover whitespace-only payloads, which the trim() in the ingest already accepts. - Trim comments to the repo's concise-comment rule; the drift history lives in the PR.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/main/agent-hooks/windows-hook-post-interpreter.test.ts (1)
1-11: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueReduce the file header comment.
This 11-line history is longer than needed for this test. Keep one concise comment that states the invariant.
As per coding guidelines: “Comments must be concise, non-obvious, and brief—prefer one line.”
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 7beffafc-9494-46da-9edf-8203825c1803
📒 Files selected for processing (2)
src/main/agent-hooks/windows-hook-post-interpreter.test.tssrc/main/antigravity/hook-script.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/main/antigravity/hook-script.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review.
|
Thanks — all three findings were valid and are addressed in c951dcc. 1. Missing-pane test provided an EOF the real caller never sends ( 2. Whitespace-only payloads uncovered — added, and widened past the suggestion to 3. Comments too long — agreed, and it was a straight violation of this repo's own Also added since the review: Re-validated on a real Windows 11 host, not just an emulated platform check. |
…ressed Filtering to posting scripts before asserting hid the failure that matters: a script that swaps its curl POST for an interpreter no longer matches the filter, so the suite failed on an opaque count instead of naming the file. Assert no-interpreter across every .cmd first, then narrow. Scoped the follow-on assertions correctly while doing it — claude-statusline.cmd posts to its own pathname and stages a temp file rather than piping stdin, which the previous shape would have flagged. Verified both regression shapes now name the offending agent.
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 5665aa22-9a43-48e4-94e0-eb6f6323a085
📒 Files selected for processing (1)
src/main/agent-hooks/windows-hook-post-interpreter.test.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review.
| expect(script.body, `${script.name} must not spawn an interpreter`).not.toMatch( | ||
| /powershell(\.exe)?/i | ||
| ) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
sed -n '90,135p' src/main/agent-hooks/windows-hook-post-interpreter.test.ts
rg -n --glob '*.ts' --glob '*.tsx' --glob '*.js' --glob '*.jsx' 'pwsh|powershell' src/main/agent-hooksRepository: stablyai/orca
Length of output: 5967
🏁 Script executed:
sed -n '1,95p' src/main/agent-hooks/windows-hook-post-interpreter.test.ts
sed -n '135,190p' src/main/agent-hooks/windows-hook-post-interpreter.test.ts
rg -n 'BATCH_SCRIPT_INSTALLERS|pwsh\.exe|pwsh\b' src/main/agent-hooks src/sharedRepository: stablyai/orca
Length of output: 6503
🏁 Script executed:
node - <<'JS'
const pattern = /powershell(\.exe)?/i
for (const value of ['powershell', 'powershell.exe', 'pwsh', 'pwsh.exe']) {
console.log(`${value}: ${pattern.test(value)}`)
}
JSRepository: stablyai/orca
Length of output: 217
Reject pwsh.exe as a PowerShell interpreter.
The regex matches only powershell and powershell.exe. A script that invokes pwsh.exe would pass this test. Match both executable names.
…s per event (#14828) Grok runs a hook `command` containing a space as `pwsh -Command <cmd>`. Orca registered the encoded PowerShell launcher, whose command line is full of spaces, so every status event walked grok.exe -> pwsh.exe -> powershell.exe -> cmd.exe -> curl.exe before reaching a script whose entire job is one loopback POST. Measured against Grok 1.0.5's own dispatcher on Windows 11, that is 518-719ms per event (mean 607ms). The same script registered as its bare path is spawned directly as `grok.exe -> cmd.exe` and costs 43-213ms (mean 114ms). Orca installs nine Grok events, and a single one-tool-call prompt dispatches roughly ten of them, so this is the difference between a hook chain that is continuously resident during a turn and one that is not. It is also how long the console the agent allocates for a hook can stay on screen, which is the mechanism #15520 fixed for Antigravity -- Grok was worse, paying two interpreters rather than one. Use the shared `wrapWindowsCmdHookCommand`, the same registration Codex, Devin and Antigravity already use (#8430). A profile path that is not cmd-safe still falls back to the encoded launcher, so #6078 stays covered. Tradeoff carried over from those agents: a bare path cannot hold the launcher's missing-script guard, so a deleted script surfaces as a per-event `command not found` in Grok's log rather than a silent stdin drain. Verified that Grok fails open there -- the tool still runs, including on PreToolUse, which Grok declares a blocking event. Verified end to end against the real Grok CLI: 9/9 status posts delivered with full payloads through the bare path, and 12/12 in a controlled A/B spawning both shapes the way Grok does. Also confirmed Grok creates hook processes with CREATE_NO_WINDOW rather than DETACHED_PROCESS, which is the mode where a bare .cmd would have been worse than the launcher.
…Shell on every event (stablyai#15520) Antigravity was the last agent posting hook status through Windows PowerShell 5.1. Every hook event — roughly one every 2-6s during an active session — paid a ~300ms interpreter cold start, which is what made the console the agent allocates for each hook last long enough to be seen as continuous flashing. Move the Windows POST to the shared curl.exe builder every other agent already uses, via the `extraFormLines` escape hatch for the `hook_event_name` field Antigravity uniquely needs. Measured on Windows 11: 326ms -> 134ms per event. Because the curl line percent-expands its arguments, the script also needs `setlocal DisableDelayedExpansion` (stablyai#9358/stablyai#9941) so a `!` in a pane key or worktree path is not eaten as a delayed reference. curl omits a `--data-urlencode name@-` field entirely when stdin is empty, so accept an absent or blank Antigravity payload as `{}` at the ingest boundary — the POSIX script substitutes `{}` before posting and PowerShell did the same, and without this a payload-less event lost the status transition its `hook_event_name` still carried. Scoped to that source; every other agent keeps rejecting a body it cannot parse. Adds a cross-agent guard asserting the invariant the original drift violated: a managed Windows .cmd hook posts through fully-qualified curl.exe and spawns no interpreter. Generated under a mocked win32 platform so the POSIX CI legs guard it too. Validated on a real Windows 11 host, not an emulated platform check. Fixes stablyai#15117
…Shell on every event (stablyai#15520) Antigravity was the last agent posting hook status through Windows PowerShell 5.1. Every hook event — roughly one every 2-6s during an active session — paid a ~300ms interpreter cold start, which is what made the console the agent allocates for each hook last long enough to be seen as continuous flashing. Move the Windows POST to the shared curl.exe builder every other agent already uses, via the `extraFormLines` escape hatch for the `hook_event_name` field Antigravity uniquely needs. Measured on Windows 11: 326ms -> 134ms per event. Because the curl line percent-expands its arguments, the script also needs `setlocal DisableDelayedExpansion` (stablyai#9358/stablyai#9941) so a `!` in a pane key or worktree path is not eaten as a delayed reference. curl omits a `--data-urlencode name@-` field entirely when stdin is empty, so accept an absent or blank Antigravity payload as `{}` at the ingest boundary — the POSIX script substitutes `{}` before posting and PowerShell did the same, and without this a payload-less event lost the status transition its `hook_event_name` still carried. Scoped to that source; every other agent keeps rejecting a body it cannot parse. Adds a cross-agent guard asserting the invariant the original drift violated: a managed Windows .cmd hook posts through fully-qualified curl.exe and spawns no interpreter. Generated under a mocked win32 platform so the POSIX CI legs guard it too. Validated on a real Windows 11 host, not an emulated platform check. Fixes stablyai#15117
…Shell on every event (stablyai#15520) Antigravity was the last agent posting hook status through Windows PowerShell 5.1. Every hook event — roughly one every 2-6s during an active session — paid a ~300ms interpreter cold start, which is what made the console the agent allocates for each hook last long enough to be seen as continuous flashing. Move the Windows POST to the shared curl.exe builder every other agent already uses, via the `extraFormLines` escape hatch for the `hook_event_name` field Antigravity uniquely needs. Measured on Windows 11: 326ms -> 134ms per event. Because the curl line percent-expands its arguments, the script also needs `setlocal DisableDelayedExpansion` (stablyai#9358/stablyai#9941) so a `!` in a pane key or worktree path is not eaten as a delayed reference. curl omits a `--data-urlencode name@-` field entirely when stdin is empty, so accept an absent or blank Antigravity payload as `{}` at the ingest boundary — the POSIX script substitutes `{}` before posting and PowerShell did the same, and without this a payload-less event lost the status transition its `hook_event_name` still carried. Scoped to that source; every other agent keeps rejecting a body it cannot parse. Adds a cross-agent guard asserting the invariant the original drift violated: a managed Windows .cmd hook posts through fully-qualified curl.exe and spawns no interpreter. Generated under a mocked win32 platform so the POSIX CI legs guard it too. Validated on a real Windows 11 host, not an emulated platform check. Fixes stablyai#15117
ELI5
On Windows, the Antigravity agent fired a hook every few seconds, and each one started a
whole Windows PowerShell just to send one small status message to Orca. PowerShell takes
about a third of a second to boot, and the black console window the agent opens for the
hook stays on screen that entire time — so users saw it flashing all session long. Orca
now sends that message with
curl.exeinstead, which every other agent already uses. Thework still happens, it just finishes fast enough that there is nothing to see.
What Changed
src/main/antigravity/hook-script.ts— the Windows managed hook posts through the sharedbuildWindowsAgentHookPostCommand('antigravity', …)curl builder instead of a bespokepowershell.exe -Command "… Invoke-WebRequest …". The event name rides along as the sametop-level
hook_event_nameform field the POSIX branch already sends.setlocalbecomessetlocal DisableDelayedExpansion. The curl linepercent-expands
paneKey/worktreeId, and inherited delayed expansion eats a!out ofthose values ([windows] Managed grok-hook.cmd fails with exit code 1 (syntax error) when GROK_HOME is unset #9358 / Windows: grok-hook.cmd syntax error when GROK_HOME is empty (SessionStart fails) #9941). The old PowerShell line read
$env:at runtime and wasimmune; the curl line is not.
src/shared/agent-hook-listener.ts— accept an absent or empty Antigravitypayloadas{}. The POSIX script substitutes{}before posting and PowerShell did the same forempty stdin, but curl omits a
--data-urlencode name@-field entirely when stdin isempty. Without this, payload-less events were dropped and lost the status transition their
hook_event_namestill carried. Scoped toantigravity; every other source keepsrejecting a body it cannot parse.
src/main/antigravity/windows-hook-payload-delivery.test.ts(live, Windows)plus listener and shape coverage.
No change to the POSIX script, the remote/SSH installer, the WSL relay path, the registered
hook command, or the wrapper
.cmdfiles.Why
Antigravity was the last agent still posting hook status through Windows PowerShell 5.1
(
git greponmainfinds the interpreter insrc/main/antigravity/hook-script.tsandnowhere else). Claude, Codex, Cursor, Devin, Droid, Gemini, Grok, and Command Code all moved
to
curl.exebehind the shared builders ininstaller-utils.ts, whose own comment recordsthe reason: "PowerShell per-post costs ~300ms startup and mangles UTF-8 via code-page
translation."
Antigravity spawns its hooks itself, so Orca cannot suppress the console Windows allocates
for them — but it fully controls how long that console lives. Removing the interpreter takes
the visible window from a third of a second to a flicker, which is the same state the other
bare-
.cmdagents (Codex, Devin) are already in and which nobody reports.Measured on Windows 11, 20 runs per variant against a local listener, identical harness:
Both figures include Git Bash harness overhead, so the ~192 ms delta is the honest number.
At one event every 2–6 s that is the difference between continuous flashing and nothing.
Secondary wins that fall out of the same change: UTF-8 no longer round-trips through the
console code page, the timeout tightens from
-TimeoutSec 2to--connect-timeout 0.5 --max-time 1.5, and each event drops a ~50 MB .NET process for a~4 MB one.
How it drifted
Worth recording, because it explains why no test caught it and what stops the next one.
buildWindowsAgentHookPostCommand(source)— no extension point — and Antigravity is the one agent whose event name comes from the wrapper's env rather than the piped payload. It could not call the shared builder, so it forked a private copy. That fork is the root cause.curl.exe, motivated by latency (two PowerShell processes ≈ 650 ms/hook). Every agent that called it was fixed for free; the private copy silently was not.extraFormLinesadded so Grok could attachgrokHome— precisely the extension point Antigravity needed in May, arriving after the fork had set. This PR uses it.So the original code was not wrong when written; a missing extension point forced a copy, and copies do not receive fixes.
Note for the reporter: the issue infers a regression on 2026-08-14 from file mtimes. That is a rewrite, not an introduction — the PowerShell POST has been in the core script since May 19 and executing since the wrapper/core split on May 22 (#2645). The "did not used to happen" is most likely #13378 (Aug 10, "refresh existing Orca launchers when agent CLIs are unavailable"): before it, a host where the Antigravity CLI was not detected never got its core script refreshed, so the wrappers'
if exist "%ORCA_ANTIGRAVITY_CORE%"check failed and they fell through to the harmlessecho {}path — exactly as described. That switched on a dormant code path. Inferred from the commit's stated purpose, not reproduced.Stopping the next one
New
src/main/agent-hooks/windows-hook-post-interpreter.test.tsasserts the invariant the drift violated, across all ten batch-script agents at once: a managed Windows.cmdhook posts through fully-qualifiedcurl.exe, pipes its payload viapayload@-, and spawns no interpreter. It generates the scripts under a mockedwin32platform instead of executing them, so the POSIX CI legs guard it too — otherwise this class is only visible on a Windows runner.Confirmed to be a real guard rather than a tautology: reverting
hook-script.tstomainmakes it fail withantigravity-hook.cmd must not spawn an interpreter, and restoring the fix makes it pass. Copilot (.ps1) and Kimi (.sh) are excluded with a stated reason — their interpreter is the host, not a per-event child.Linked Issue
Fixes #15117
Visual Proof
N/Afor rendered Orca UI — no Orca view, layout, or in-app control changes. The symptom isan OS console window belonging to the agent's own process tree, not an Orca surface, so
there is no tab-switchable Orca screenshot pair to attach. The measurable before/after is the
process-level evidence in Why and Testing; the interpreter's removal is asserted
directly by
expect(script).not.toMatch(/powershell/i).Testing
Validated on a real Windows 11 host, not an emulated platform check.
Windows (live) —
src/main/antigravity/,src/shared/agent-hook-listener-antigravity.test.ts:25 passed | 3 skipped. Includes a suite that installs the hooks for real, spawns each ofthe five event wrappers the way Antigravity does (
cmd /c <bare .cmd path>, matching theissue's process trace), pipes a 4 KB payload containing
café 日本語 😀, and follows it to alive listener:
hook_event_namecorrect for all five eventspaneKeyandworktreeIdcontaining!survive intact (delayed-expansion guard)PreToolUsestill answers{"decision":"ask"}— Antigravity reads silence as deny ([Bug]: Can not use antigravity cli in orac (ssh) #2426)application/x-www-form-urlencodedWindows baseline comparison — ran
src/main/agent-hooks/onorigin/mainon the samehost first: 6 pre-existing failures (3 ×
installer-utilssymlink tests, 2 × Claudemanaged-hook-stdin-lifecycle, 1 × Claudewindows-hook-payload-delivery) — allenvironment-specific to that box and all in Claude's PowerShell path, none touched here. My
branch reproduces exactly those 6 and adds none.
That comparison also caught a real defect mid-review: the first cut of the listener fix only
handled
payload="", but curl actually omits the field entirely, so the event still dropped.Fixed and re-validated on hardware.
macOS —
src/shared/ src/main/agent-hooks/ src/main/antigravity/: 5853 passed, 0failures (includes the new cross-agent interpreter guard, which runs on every platform).
pnpm typecheck,pnpm build,oxlint --deny-warnings,oxfmt --checkall clean.Review
curl.exeis fully qualified as%SystemRoot%\System32\curl.exe, preservingthe same repo-local-binary-hijack protection the qualified
powershell.exepath had. Thepayload stays off the command line via
payload@-. One honest note: the hook token movesfrom a runtime
$env:read into a percent-expanded-Hargument, so it is briefly visiblein the curl process command line. That is the existing posture for all eight other agents
using these shared builders (
installer-utils.ts:153,:172) — Antigravity was theoutlier — and the token is loopback-only and per-session. Called out rather than buried.
curl.exeis Win10 1803+, already a hard dependency of every other agent hook, so no new floor.
getManagedScript('posix')(
hook-service.ts:193) — untouched. WSL uses the POSIX script via the relay. The hook postis loopback within the host that runs the agent, so there is no client/host version skew.
contract.
refreshManagedScriptIfPresentrewrites the script in place on upgrade; theregistered command and wrapper
.cmdfiles are unchanged, so no stale-registration path.Downgrade restores the old script cleanly.
event, tighter timeouts.
Agent skill upstream boundary
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)