Skip to content

fix(antigravity): keep the Windows hook command startable on a spaced profile - #22035

Closed
brennanb2025 wants to merge 2 commits into
mainfrom
brennanb2025/antigravity-windows-hook-stdout
Closed

brennanb2025 wants to merge 2 commits into
mainfrom
brennanb2025/antigravity-windows-hook-stdout

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​85 $\color{#cf222e}{\Huge{\mathbf{−}}}$​13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​72
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​17 $\color{#cf222e}{\Huge{\mathbf{−}}}$​10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​7

What a user hits today

On Windows, if your user profile path contains a space — C:\Users\First Last, the ordinary
shape — Antigravity may refuse every tool call, on a clean install, with nothing deleted.

Antigravity requires a decision on PreToolUse and reads silence as a deny
(src/main/antigravity/hook-events.ts). So a hook command Antigravity cannot start is not a
lost status indicator. It is a deny on every tool call, and there is nothing in the UI that
says so.

The chain, and how much of it I verified

Verified by reading the code at 663d670878:

  1. WINDOWS_CMD_SAFE_PATH (src/main/agent-hooks/installer-utils.ts:151) is
    /^[A-Za-z0-9_.:\\~-]+$/. No space in the character class. Verified.
  2. wrapWindowsCmdHookCommand (:153-156) therefore hands any spaced path to
    wrapWindowsHookCommand, which emits
    …/powershell.exe -NoProfile -EncodedCommand <base64> — a multi-token string.
    Verified, and reproduced in the test run below.
  3. Antigravity starts a hook command as a program, not as a shell line, so a multi-token
    string is not a name it can start. Not verified by me — taken on trust. See below.
  4. getManagedCommand (src/main/antigravity/hook-service.ts:62-67) passed no
    fallbackStdout on either Windows branch, while installer-utils.ts:133 states Windows
    must match POSIX. Verified.

What is still unproven

Link 3 is the load-bearing one and I did not measure it. The repository's own basis for it is
the fix message for #8737 (ee709b02ed), which states plainly that Antigravity launches its
agent-hook command as argv[0], not through cmd.exe, and which reverted an earlier
if exist … (…) else (…) compound after it failed in the field with "hook exited with code 1"
on v1.4.138. Two later changes restate it, and src/main/devin/hook-settings.ts:56 and
src/main/agent-hooks/installer-utils.test.ts:710 both carry it as a comment.

That is a strong, field-grounded claim, but it is still a claim in a commit message, not a
measurement. The nearest contrary-looking evidence is the process trace recorded at
src/main/antigravity/windows-hook-payload-delivery.test.ts:95-98 — cmd /d /c <bare .cmd path>
— which is consistent with the same model: the command string is taken as one program path, and
cmd.exe appears only because the target is a .cmd. Consistent is not the same as proven.

I also fixed a stale comment next to the change that read "Antigravity wraps hook commands in
cmd.exe", because it now reads as evidence against the fix and is not what the trace shows.

What this changes

Antigravity's Windows entry is now the per-event wrapper path itself, for every profile.

That path is the shape Antigravity can start, and it is already the file that answers: the
wrapper Orca writes echoes the ask decision on its own when the core script is missing, which
is exactly what fallbackStdout buys the POSIX command. So the startable path and the
answering path are the same file.

The wrapper path is now derived from the core script's directory, making explicit the %~dp0
lookup the wrapper already depended on.

Why not the existing wrapWindowsDirectCmdHookCommand

src/main/agent-hooks/windows-direct-cmd-hook-command.ts is Orca's shipped, EDR-clean answer
for the Claude lifecycle hook, and it was the first thing I tried. It does not fit here, for
three independent reasons:

  1. It returns null for exactly the paths this bug is about — its own test pins
    C:\Users\Bob Smith\… as declined (windows-direct-cmd-hook-command.test.ts:40). It has
    nothing to offer a spaced profile.
  2. Its output is <path> || echo {}, which is multi-token. Applying it to the cmd-safe
    majority would put every currently-working Windows user onto a string that, under the model
    in link 3, cannot start — turning a minority bug into a universal one.
  3. Its neutral answer is {}, and {} is itself read as a deny on PreToolUse
    (hook-service.test.ts:148). It answers the wrong question for a gate event.

I also did not take the smallest diff — adding fallbackStdout to wrapWindowsCmdHookCommand
— because a fallbackStdout cannot be attached to a bare token, so implementing it that way
would force every user onto the encoded branch. Same universal-exposure trap as (2).

Blast radius

wrapWindowsCmdHookCommand is untouched. Its production consumers before this change were
three: antigravity, devin, grok. After it, two:

  • src/main/devin/hook-settings.ts:58
  • src/main/grok/grok-hook-script.ts:28

Both get byte-identical commands; installer-utils.ts has a zero-line diff. The same
unstartable-fallback exposure plausibly applies to them under link 3, but their events are not
gates — silence there costs status, not tool calls — so that is a separate change, not this one.

Upgrades self-heal: the managed-command matcher decodes the old encoded entry, so the next
install() sweeps it and writes the bare path. getStatus() reports partial until then.

Test evidence: red, then green

New pin: src/main/antigravity/windows-hook-command-spawnability.test.ts.

It installs into a home directory whose path carries a space and asserts that every event's
registered command is a single path that names a real file, and that the PreToolUse one still
echoes the ask decision after the core script is deleted. It opens with a positive control
pinning both sides of the whitelist, so the test cannot silently stop exercising the diverted
class.

Ablated (the fix line reverted to wrapWindowsCmdHookCommand(...), everything else identical):

 × registers a single startable script path for every event on a spaced profile
 × keeps answering the PreToolUse gate from that path when the core script is gone
 Tests  2 failed | 1 passed (3)

AssertionError: PreInvocation: expected
  'C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -NoProfile -EncodedCommand JABQ…'
to be
  '…/orca antigravity spaced 6PgWYq/.orca/agent-hooks/antigravity-pre-invocation.cmd'

The control passed in the red run, so the instrument was live. With the fix restored:
Tests 3 passed (3).

Wider runs: src/main/antigravity/, src/main/agent-hooks/, src/main/devin/,
src/main/grok/, src/main/codex/windows-hook-command.test.ts — 104 files, 1047 passed,
35 skipped. pnpm tc exit 0. pnpm run check:code-quality:changed — 0 new findings across
all seven gates. pnpm-lock.yaml is not in the commit.

Four unrelated failures appeared in a broader sweep
(claude-agent-sdk-exit-proof, claude-structured-real-cli,
claude-tui-resume-real-binary, codex-structured-turn-processes). Two reproduce at a clean
origin/main and the other two passed on re-run; none of the four import any file this PR
touches. They spawn real agent binaries and are flaky in this environment.

What still needs a real Windows host

I did not run anything on Windows. No Windows validation is claimed. Everything above ran
on macOS, where the Windows branch is reached by mocking process.platform.

What a Windows box still has to settle:

  1. Link 3, directly. Install Antigravity hooks under a profile with a space, fire a tool
    call, and capture the process tree. The question is whether the registered string is handed
    over as one program name or as a command line — that is what decides this design, and it is
    the one thing I could not test.
  2. The before state. On the same box at origin/main, confirm the encoded entry really
    does produce no stdout and that Antigravity really does deny. If it turns out the encoded
    entry starts fine, this change is unnecessary and the premise should be retracted.
  3. The after state, both profiles. A spaced profile and a plain ASCII one, all five events,
    checking that PreToolUse prints {"decision":"ask"} and that status still posts.
  4. A non-ASCII profile (CJK, Cyrillic, accented). Those take the same diverted branch as a
    spaced one; the fix covers them by construction, but that is untested.
  5. The upgrade path. Start with an encoded entry already in ~/.gemini/config/hooks.json,
    launch Orca, and confirm install() sweeps it to the bare path and status flips to
    installed.

The Windows-only live legs already in windows-hook-payload-delivery.test.ts cover (3) once
run on a Windows runner; they are skipped everywhere else.

EDR posture

docs/reference/windows-edr-posture.md read first. This change removes an interpreter hop
rather than adding one — the registered command no longer names powershell.exe and no longer
carries -EncodedCommand on the diverted path. No -ExecutionPolicy Bypass, no
cmd.exe /c with escaped free text, no per-operation interpreter spawn, no runtime Add-Type.
No process spawning was added, so nothing here needs src/shared/child-process/.

… profile

Antigravity requires a decision on PreToolUse and reads silence as a deny
(hook-events.ts, #2426). So a hook command it cannot start does not merely lose
status - it denies every tool call.

The Windows branch routed the per-event wrapper path through the shared cmd
wrapper, whose safe-path whitelist excludes spaces. Any profile shaped like
C:\Users\First Last therefore had its entry replaced with a multi-token encoded
PowerShell launcher. Antigravity starts a hook `command` as a program (#8737),
and a multi-token string is not a program name, so that entry never starts, and
the gate hears nothing on a clean install with nothing deleted.

Register the per-event wrapper path itself for every profile. It is the shape
Antigravity can start, and it is already the file that answers: the wrapper
echoes the ask decision on its own when the core script is missing, which is
what fallbackStdout buys the POSIX command. Derive the wrapper path from the
core script's directory so the `%~dp0` lookup the wrapper depends on is
explicit rather than incidental.

The shared cmd wrapper is untouched; its remaining consumers (devin, grok) get
byte-identical commands. The contract test now drives the installer's own
builder instead of a private copy of the Windows branch that had stopped
reflecting what gets registered.
@coderabbitai

coderabbitai Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Understand this PR’s impact

Explore downstream dependencies and potential security impact with Blast Radius.

View blast radius →

Warning

Review limit reached

Next included review available in 1 minute.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 56536103-6f10-439c-9ce0-dd501a1958ff

📥 Commits

Reviewing files that changed from the base of the PR and between cab0a33 and a59943f.

📒 Files selected for processing (3)
  • src/main/agent-hooks/managed-hook-command-contract.test.ts
  • src/main/antigravity/hook-service.ts
  • src/main/antigravity/windows-hook-command-spawnability.test.ts

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 7f9a31d0-d09a-42d9-8478-eb04e2631fd7

📥 Commits

Reviewing files that changed from the base of the PR and between 663d670 and cab0a33.

📒 Files selected for processing (3)
  • src/main/agent-hooks/managed-hook-command-contract.test.ts
  • src/main/antigravity/hook-service.ts
  • src/main/antigravity/windows-hook-command-spawnability.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The Antigravity hook service now creates each Windows event wrapper beside the core managed script and returns that wrapper path directly from getManagedCommand. Installation and refresh use the same path calculation. The managed-hook contract test uses this command builder for all events. New Windows tests verify path classification, wrapper file creation, startable commands, and PreToolUse fallback behavior.

Priority: ⬇️ Low

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description gives detailed user impact, implementation rationale, testing evidence, limitations, and compatibility considerations. However, it omits the required Linked Issue, does not provide the… Add the issue reference under Linked Issue, add before-and-after visual proof or state N/A with a reason if visual proof does not apply, and complete the applicable Testing, Review, Agent skill upstream boundary, and Checklist items.
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the Antigravity Windows hook fix for profiles with spaces. It is concise and directly related to the main change.
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.
Full details: Description check

Explanation

The description gives detailed user impact, implementation rationale, testing evidence, limitations, and compatibility considerations. However, it omits the required Linked Issue, does not provide the required Visual Proof or an explicit N/A statement, and leaves required checklist items unchecked.

✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — Antigravity's Windows hook entry is now the bare per-event wrapper .cmd path for every profile, replacing the cmd-safe helper whose spaced/non-ASCII branch emitted a multi-token PowerShell launcher that Antigravity cannot start.

  • Windows command path — getManagedCommand returns getWindowsWrapperScriptPath(...), and the helper now derives the wrapper from dirname(scriptPath). For cmd-safe profiles this is byte-identical to the previous output, so only the diverted class changes, and the upgrade sweep still matches the old encoded entry.
  • Contract test — the antigravity local builder now drives the installer's own getManagedCommand instead of a private copy of the Windows branch, so it tracks what Antigravity actually registers.
  • New spawnability pin — a spaced-home test asserts every event's command is a single existing file (not a PowerShell launcher) and that PreToolUse still answers from the wrapper once the core script is deleted.

I confirmed the new pin is a live instrument: reverting getManagedCommand to wrapWindowsCmdHookCommand(...) fails 2 of its 3 cases while the whitelist control still passes. The related hook-service, managed-hook-command-contract, managed-hook-stdin-lifecycle, managed-hook-timeout, and remote-hook-service-installers suites all pass on this head.

The one thing this review cannot settle is the PR's own documented open question — Antigravity's launch model (argv[0] vs. cmd.exe) — which the author already flags and which needs a real Windows host to close out.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

…ity-windows-hook-stdout

# Conflicts:
#	src/main/agent-hooks/managed-hook-command-contract.test.ts
@greptile-apps

greptile-apps Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[High risk] Changes how Windows hook commands are built and started.

The PR appears safe to merge, with a non-blocking gap in Windows-host validation of the launch behavior it relies on.

Findings

  1. P2 Spaced-path launch remains untested ▶

Summary

The PR registers Antigravity’s per-event Windows .cmd wrappers directly, including under spaced profiles, and updates command-contract and installation tests.

  • The new tests verify the registered path and missing-core fallback, but not whether the host can launch a spaced path.

Reviews (1) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..."

Comment on lines +60 to +63
// Why: a program name is startable only if it names a file. A multi-token launcher string
// never does, and a hook that never starts writes no stdout at all.
expect(existsSync(command), `${event.eventName} command is not a file`).toBe(true)
expect(command, event.eventName).not.toMatch(/powershell|-EncodedCommand/i)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Spaced-path launch remains untested The test confirms that each registered command names an existing file, but it never launches that command. The live Windows suite launches wrappers without guaranteeing a spaced home directory. As a result, a failure to start the bare .cmd path under a spaced profile could leave these tests green while PreToolUse denies tool calls. Please add Windows-host coverage that launches a command from a guaranteed spaced path and checks its gate response.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Closing: the premise did not hold up when measured.

Antigravity documents that it runs hook commands through cmd /c on Windows. On a Windows machine with a spaced profile path, the command main registers today started correctly under every way cmd can be invoked, while this PR's bare-path command failed under two of the three. So this would have fixed nothing, and could have broken the users it was meant to help.

A real, separate problem remains: if the wrapper script is deleted while Antigravity's hook config survives, every tool call is denied (on main too). That will be fixed at its root by re-deriving the installed hook state, in its own PR.

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.

1 participant