Repository navigation
fix(windows): spawn Grok status hooks via a GUI launcher - #15530
sanshengai wants to merge 1 commit into
Conversation
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).
|
Reproduction on Windows 11 + Orca 1.4.185 + Grok Build 1.0.5 (GUI host): every |
📝 WalkthroughWalkthroughThe change adds a C# Windows launcher for Merge Risk: 🟠 High · up to 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)
✅ Passed checks (4 passed)
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 Warning |
There was a problem hiding this comment.
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
📒 Files selected for processing (9)
config/electron-builder.config.cjsconfig/scripts/build-windows-grok-hook-launcher.mjsconfig/scripts/electron-builder-config.test.mjsconfig/scripts/electron-builder-native-rebuild.cjsconfig/scripts/electron-builder-native-rebuild.test.mjsnative/windows-grok-hook-launcher/.gitignorenative/windows-grok-hook-launcher/OrcaGrokHookLauncher.cssrc/main/grok/hook-service.test.tssrc/main/grok/hook-service.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
| if (!File.Exists(scriptPath)) | ||
| { | ||
| return 0; | ||
| } |
There was a problem hiding this comment.
🩺 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.
| function isGrokManagedCommand(command: string | undefined): boolean { | ||
| if (createManagedCommandMatcher(getManagedScriptFileName())(command)) { | ||
| return true | ||
| } | ||
| return Boolean(command?.replaceAll('\\', '/').includes(WINDOWS_GROK_HOOK_LAUNCHER_NAME)) | ||
| } |
There was a problem hiding this comment.
🗄️ 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.
| 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}`) | |
| ) | |
| } |
| 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 |
There was a problem hiding this comment.
🩺 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.
| 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) |
There was a problem hiding this comment.
🎯 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.
|
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
|
|
Closing as superseded by #15595, which merged the lower-complexity bare |
ELI5
On Windows, Grok flashes a console window on every status-hook event (including each time you send a message). Grok treats any hook
commandthat contains a space aspwsh -Command …, so Orca's encoded PowerShell wrapper always pops a window. This PR installs a GUI-subsystemorca-grok-hook.exewith no spaces in the path so GrokCreateProcess-es it directly.What Changed
native/windows-grok-hook-launcher(/target:winexe), packaged asbin/orca-grok-hook.exe.grok-hook.cmdand writes that single path as the managed command.grok-hook.cmdPowerShell 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 currentmainwith 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.exeon 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 buildlocally (fresh clone, nonode_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_commandflashes are out of scope (Grok's ownpwshspawn).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
installRemotestill useswrapPosixHookCommand.~/.orca/agent-hookson install.grok-hook.cmd.Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)Author