Skip to content

fix(agent-hooks): guard every Windows missing-target fallback before it reads stdin - #19415

Merged
OrcaWin merged 2 commits into
mainfrom
nwparker/linear-windows-hooks
Sep 8, 2026
Merged

OrcaWin merged 2 commits into
mainfrom
nwparker/linear-windows-hooks

Conversation

@nwparker

@nwparker nwparker commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​243 $\color{#cf222e}{\Huge{\mathbf{−}}}$​54 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​189
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​61 $\color{#cf222e}{\Huge{\mathbf{−}}}$​18 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​43

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 .cmd syntax. 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:

without the fix, delayed expansion on  ->  "core not found"   <- broken
with the fix,    delayed expansion on  ->  "core ran"         <- correct

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:

undo this tests that fail
wrapper environment check 5 shape + 1 live (hangs 15s)
wrapper delayed-expansion fix 5 shape + live run posts nothing
PowerShell launcher check 1 shape + 1 live (hangs)
Git Bash launcher check 1 live (hangs)

Verification

Run on real Windows 11, Node 24.

  • Before the fix the launcher hung until killed at 6s. After, it exits in ~17ms.
  • Typecheck, lint, and the changed-code quality gate all pass.
  • Ran 3,347 tests across every agent's hook code, before and after, and diffed the failure lists: no new failures, one pre-existing failure fixed.
  • 8 failures remain on my machine and are identical on 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-time does not bound its read of stdin.

nwparker and others added 2 commits September 7, 2026 17:48
…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.
@OrcaWin OrcaWin changed the title fix(antigravity): guard missing Windows hook cores before draining stdin fix(agent-hooks): guard every Windows missing-target fallback before it reads stdin Sep 8, 2026
@OrcaWin
OrcaWin marked this pull request as ready for review September 8, 2026 05:34
@pullfrog

pullfrog Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

This run was cancelled 🛑

The workflow was cancelled before completion. Please check the link below for details.

Pullfrog  | View workflow run | via Pullfrog | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

📝 Walkthrough

Walkthrough

The 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 4b427

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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 8 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: preventing Windows missing-target fallbacks from reading stdin indefinitely.
Description check ✅ Passed The description is detailed and covers the bug, scope, rationale, implementation, testing, platform coverage, and known limitations. It does not use the template headings and omits an explicit "Fixes …
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 00253f90-39c3-4ea4-a927-4cd6d8054f84

📥 Commits

Reviewing files that changed from the base of the PR and between 102402e and 4b4276e.

📒 Files selected for processing (8)
  • src/main/agent-hooks/hook-stdin-contract.ts
  • src/main/agent-hooks/installer-utils.test.ts
  • src/main/agent-hooks/installer-utils.ts
  • src/main/agent-hooks/managed-hook-stdin-lifecycle.test.ts
  • src/main/agent-hooks/runtime-home-hook-command.ts
  • src/main/antigravity/hook-script.ts
  • src/main/antigravity/windows-hook-payload-delivery.test.ts
  • src/main/copilot/copilot-managed-script.ts

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

Comment on lines +342 to +344
expect(decoded.indexOf("Write-Output '{}'"), `${name} answers first`).toBeLessThan(
decoded.indexOf(WINDOWS_POWERSHELL_HOOK_ENVIRONMENT_GUARD)
)

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.

🎯 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.

Suggested change
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)
)

@OrcaWin
OrcaWin merged commit 15adbd9 into main Sep 8, 2026
64 of 82 checks passed
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.

2 participants