Skip to content

fix(windows): spawn Grok status hooks via a GUI launcher - #15530

Closed
sanshengai wants to merge 1 commit into
stablyai:mainfrom
sanshengai:fix/windows-grok-hook-gui-launcher
Closed

sanshengai wants to merge 1 commit into
stablyai:mainfrom
sanshengai:fix/windows-grok-hook-gui-launcher

Conversation

@sanshengai

Copy link
Copy Markdown

ELI5

On Windows, Grok flashes a console window on every status-hook event (including each time you send a message). Grok treats any hook command that contains a space as pwsh -Command …, so Orca's encoded PowerShell wrapper always pops a window. This PR installs a GUI-subsystem orca-grok-hook.exe with no spaces in the path so Grok CreateProcess-es it directly.

What Changed

  • Added native/windows-grok-hook-launcher (/target:winexe), packaged as bin/orca-grok-hook.exe.
  • Windows Grok hook install copies that launcher next to grok-hook.cmd and writes that single path as the managed command.
  • Profile paths that contain spaces still use the existing encoded PowerShell launcher ([Bug]: Codex hooks fail on Windows when user path contains spaces #6078).
  • Install/status/remove match both the new launcher and stale grok-hook.cmd PowerShell entries.

Why

#14828 is a Grok-on-Windows console flash on every UserPromptSubmit / tool hook. A previous full-agent GUI launcher (#14845) was closed in favor of a small follow-up on current main with a reproduction. This is that Grok-only follow-up.

Grok's HTTP hooks cannot target http://127.0.0.1 (HTTPS-only SSRF policy), so HTTP is not a substitute for the local listener.

Linked Issue

Fixes #14828

Visual Proof

N/A — no rendered UI. The change is how Grok is told to spawn the status hook on Windows (no new window vs a brief console popup).

Testing

  • Compiled orca-grok-hook.exe on Windows; PE subsystem is GUI (2).

  • Updated hook-service and electron-builder tests.

  • Did not run the full pnpm lint && pnpm typecheck && pnpm test && pnpm build locally (fresh clone, no node_modules). CI should cover that.

  • Manual check after merge: install Grok hooks on Windows, send a message in an Orca Grok pane, confirm no console popup. Tool run_terminal_command flashes are out of scope (Grok's own pwsh spawn).

  • Automated tests added/updated, or explained why not below

  • I manually tested these changes locally (launcher compiled; full Orca install path not end-to-end tested in this checkout)

AI Disclosure

Drafted with Grok 4.6 (xAI Grok Build).

Review

  • Cross-platform: launcher is Windows-only; POSIX install path unchanged.
  • SSH/remote: installRemote still uses wrapPosixHookCommand.
  • Other agents: unchanged.
  • Performance: copy of a ~6 KiB exe into ~/.orca/agent-hooks on install.
  • Security: fail-open; launcher swallows child errors and always exits 0, matching grok-hook.cmd.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Author

Grok treats a hook command with spaces as pwsh -Command, which pops a
console on every UserPromptSubmit and tool event (#14828). Install a
space-free GUI-subsystem orca-grok-hook.exe next to grok-hook.cmd so
Grok CreateProcess-es it directly. Profile paths with spaces still use
the encoded PowerShell launcher (#6078).
@sanshengai

Copy link
Copy Markdown
Author

Reproduction on Windows 11 + Orca 1.4.185 + Grok Build 1.0.5 (GUI host): every UserPromptSubmit (sending a message) and tool-hook event spawns pwsh -Command and flashes a console. Grok treats any hook command containing a space as a shell string, so the existing encoded PowerShell wrapper always pops a window. HTTP hooks cannot target http://127.0.0.1 (HTTPS-only). This PR is the small Grok-only GUI launcher follow-up requested when #14845 was closed.

@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The change adds a C# Windows launcher for grok-hook.cmd. A Node.js script compiles the launcher, and the Windows packaging flow runs that script before native dependency rebuilding. Electron Builder packages the executable under bin/orca-grok-hook.exe. The Grok hook service publishes the bundled executable to the agent-hooks directory, uses it for Windows commands when possible, and recognizes both executable and PowerShell command forms. Tests cover packaging, build ordering, installation, and preservation.

Merge Risk: 🟠 High · up to c7bd2

The Windows hook change can still cause failed hook events, broken status reporting, and removal of unrelated user-authored hooks because status checks mutate the installed executable, stale commands are not recognized, stdin may close prematurely, and launcher matching is too broad. These current-head correctness and configuration-safety risks should be fixed before merging.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. 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 describes the Windows Grok hook launcher change that prevents console windows during status-hook execution.
Description check ✅ Passed The description covers the required sections, linked issue, behavior change, testing status, scope considerations, and checklist items.
Linked Issues check ✅ Passed The changes directly address issue #14828 by using a Windows GUI-subsystem launcher to prevent repeated console flashes and focus theft.
Out of Scope Changes check ✅ Passed The packaging, build, installation, matching, and test changes are all related to the Windows Grok hook console-flash fix.

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.

Warning

⚠️ This pull request shows signs of AI-generated slop (defensive_cruft). It has been flagged by CodeRabbit slop detection and should be reviewed carefully.

@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: 4


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 63d18e4f-85fb-4f18-b019-a7e4636ab23c

📥 Commits

Reviewing files that changed from the base of the PR and between 0b8107a and c7bd249.

📒 Files selected for processing (9)
  • config/electron-builder.config.cjs
  • config/scripts/build-windows-grok-hook-launcher.mjs
  • config/scripts/electron-builder-config.test.mjs
  • config/scripts/electron-builder-native-rebuild.cjs
  • config/scripts/electron-builder-native-rebuild.test.mjs
  • native/windows-grok-hook-launcher/.gitignore
  • native/windows-grok-hook-launcher/OrcaGrokHookLauncher.cs
  • src/main/grok/hook-service.test.ts
  • src/main/grok/hook-service.ts

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

Comment on lines +23 to +26
if (!File.Exists(scriptPath))
{
return 0;
}

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.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Drain stdin before returning when the script is missing.

The existing PowerShell fallback drains stdin for this case. Returning immediately closes the hook input pipe. Grok can then receive a broken-pipe error while it writes the event payload.

Proposed fix
             if (!File.Exists(scriptPath))
             {
+                DrainStandardInput();
                 return 0;
             }

Add DrainStandardInput with the same best-effort Console.OpenStandardInput().CopyTo(Stream.Null) behavior used by the child-input forwarding path.

Comment on lines +108 to +113
function isGrokManagedCommand(command: string | undefined): boolean {
if (createManagedCommandMatcher(getManagedScriptFileName())(command)) {
return true
}
return Boolean(command?.replaceAll('\\', '/').includes(WINDOWS_GROK_HOOK_LAUNCHER_NAME))
}

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Restrict launcher matching to the managed launcher path.

Line 112 matches any command that contains orca-grok-hook.exe. removeManagedCommands can then remove a user-authored hook that only references that executable name. Match the normalized managed path, such as agent-hooks/orca-grok-hook.exe, instead.

Proposed fix
-  return Boolean(command?.replaceAll('\\', '/').includes(WINDOWS_GROK_HOOK_LAUNCHER_NAME))
+  return Boolean(
+    command
+      ?.replaceAll('\\', '/')
+      .endsWith(`/agent-hooks/${WINDOWS_GROK_HOOK_LAUNCHER_NAME}`)
+  )
📝 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
function isGrokManagedCommand(command: string | undefined): boolean {
if (createManagedCommandMatcher(getManagedScriptFileName())(command)) {
return true
}
return Boolean(command?.replaceAll('\\', '/').includes(WINDOWS_GROK_HOOK_LAUNCHER_NAME))
}
function isGrokManagedCommand(command: string | undefined): boolean {
if (createManagedCommandMatcher(getManagedScriptFileName())(command)) {
return true
}
return Boolean(
command
?.replaceAll('\\', '/')
.endsWith(`/agent-hooks/${WINDOWS_GROK_HOOK_LAUNCHER_NAME}`)
)
}

Comment on lines +125 to +133
function publishWindowsGrokHookLauncher(): string | null {
const source = bundledWindowsGrokHookLauncherPath()
if (!source) {
return null
}
const destination = join(homedir(), '.orca', 'agent-hooks', WINDOWS_GROK_HOOK_LAUNCHER_NAME)
mkdirSync(dirname(destination), { recursive: true })
copyFileSync(source, destination)
return destination

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.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Do not overwrite the launcher during status checks.

getStatus() calls getManagedCommand(), so this function copies the executable on every status read. If a hook is running, Windows can reject the overwrite with a sharing violation. The uncaught error then makes status reporting fail. Publish only during install or use a non-mutating status path that reuses an existing destination.

Comment on lines 136 to +148
function getManagedCommand(scriptPath: string): string {
return process.platform === 'win32'
? wrapWindowsHookCommand(scriptPath)
: wrapPosixHookCommand(scriptPath)
if (process.platform !== 'win32') {
return wrapPosixHookCommand(scriptPath)
}
// Why: Grok treats a command string with spaces as a pwsh -Command script
// (#14828). A single space-free GUI-subsystem exe is spawned directly, so
// no console window appears. Profile paths with spaces still need the
// encoded PowerShell launcher (#6078).
const launcher = publishWindowsGrokHookLauncher()
if (launcher && !/\s/.test(launcher)) {
return launcher.replaceAll('\\', '/')
}
return wrapWindowsHookCommand(scriptPath)

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 | 🟠 Major | ⚡ Quick win

Recognize stale PowerShell commands in getStatus().

When the executable is available, this function returns its path. Lines 252-254 then use exact equality, so existing encoded PowerShell hook commands report not_installed even though isGrokManagedCommand preserves and removes them. Use the managed-command predicate for status detection and add a stale-PowerShell status test.

@ynjmxn

ynjmxn commented Aug 20, 2026

Copy link
Copy Markdown

Thanks for sending a Grok-only follow-up.

This overlaps with #15506, which already Fixes #14828 (shared .cmd CreateNoWindow path, opened a few hours earlier). I left a short comparison on #14828 so maintainers can pick one; the two should not both merge.

@hoonysis

Copy link
Copy Markdown

I end-to-end tested the current GUI-launcher direction on Windows 11 with Orca 1.4.185 and Grok Build 1.0.5. There are two separate paths to account for.

1. A GUI launcher that re-invokes grok-hook.cmd still flashes

My first implementation used a GUI-subsystem orca-grok-hook.exe, but had it start the existing grok-hook.cmd. Process tracing still showed:

grok.exe
  orca-grok-hook.exe
    cmd.exe
      conhost.exe

The visible flash remained. The version that passed the real-session test does not start PowerShell, cmd.exe, curl.exe, or the existing script at all. The GUI executable:

  • reads the Grok event JSON from stdin;
  • loads ORCA_AGENT_HOOK_PORT, token, pane/tab/launch/worktree identity from the environment, with ORCA_AGENT_HOOK_ENDPOINT as fallback;
  • sends the same application/x-www-form-urlencoded body directly to http://127.0.0.1:<port>/hook/grok;
  • sets X-Orca-Agent-Hook-Token;
  • uses a short timeout and always fails open.

This is not a Grok HTTP hook, so Grok's HTTPS-only hook URL policy does not apply. Grok only launches a space-free GUI executable; that executable talks to Orca's already-existing local listener.

With this direct-POST launcher, all nine Orca-managed Grok events remained installed and Orca status updates continued working, with no new titled cmd/conhost windows.

This means the current PR launcher still needs one architectural change: post directly instead of forwarding stdin to grok-hook.cmd.

2. Grok also imports Orca's Claude hook

After fixing the native Grok path, I still saw flashes. Grok's Claude compatibility imported the Orca-managed entries from %USERPROFILE%\.claude\settings.json as global/settings, alongside the native global/orca-status hooks.

Observed hook counts before filtering the duplicate route:

  • UserPromptSubmit: 3
  • tool events: 4
  • Stop: 2

Setting only [compat.claude] hooks = false in Grok config, while leaving Claude skills/rules/agents/MCP compatibility intact, reduced those counts to 1/2/1. A fresh Grok session then completed prompt, read-file pre/post, and stop events with Orca status source grok and zero visible console flashes.

I recommend adding an end-to-end test case where both Orca's Grok hooks and Orca's Claude managed hooks are installed. Otherwise the native launcher can appear fixed while the imported Claude route still flashes.

I have the tested direct-POST C# launcher and can adapt it into this PR if that direction is acceptable.

@sanshengai

Copy link
Copy Markdown
Author

Closing as superseded by #15595, which merged the lower-complexity bare .cmd launch path after measuring Grok's real CREATE_NO_WINDOW behavior and credited this PR's whitespace-trigger diagnosis. The current branch is no longer the preferred fix.

@sanshengai sanshengai closed this Aug 28, 2026
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.

[Bug] Windows: Grok agent hooks flash a visible console and steal keyboard focus on every tool call

3 participants