Repository navigation
Conversation
…dout Hidden PowerShell cannot give a .cmd an inheritable console, so invoking the script with the call operator opens a titled conhost on every Grok tool event. Launch System32\cmd.exe through ProcessStartInfo with CreateNoWindow, relay stdout/stderr, and keep .ps1 on the in-process call operator. Fixes #14828
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughWindows Merge Risk: ⚪ Minimal · up to The Windows hook launcher change is localized and preserves hook output and exit-code behavior; no actionable merge-blocking risk remains beyond normal checks and review. 🚥 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (3)
src/main/agent-hooks/windows-powershell-hook-launcher.ts (1)
50-58: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winSet the redirected stream encodings, and do not block on the stdin write.
Two points on the relay:
- No
StandardOutputEncodingorStandardErrorEncodingis set. The childcmd.exewrites in the console OEM codepage. Non-ASCII hook JSON can be corrupted before[Console]::Out.Write. Set the encodings on$psito match[Console]::OutputEncoding.$p.StandardInput.Write($stdin)blocks once the payload exceeds the pipe buffer and the hook does not read stdin. The child still exits and the broken pipe raises the caughtIOException, so this delays rather than hangs, but an async write removes the stall.♻️ Proposed encoding and non-blocking write
'$psi.RedirectStandardError = $true', + '$psi.StandardOutputEncoding = [Console]::OutputEncoding', + '$psi.StandardErrorEncoding = [Console]::OutputEncoding', `$psi.EnvironmentVariables['ORCA_WINDOWS_HOOK_CMD'] = ${quotedScriptPath}`, '$stdin = [Console]::In.ReadToEnd()', '$p = [System.Diagnostics.Process]::Start($psi)', '$outTask = $p.StandardOutput.ReadToEndAsync()', '$errTask = $p.StandardError.ReadToEndAsync()', - 'try { $p.StandardInput.Write($stdin); $p.StandardInput.Close() } catch [System.IO.IOException] {}', + 'try { $null = $p.StandardInput.WriteAsync($stdin).ContinueWith({ param($t) $p.StandardInput.Close() }) } catch [System.IO.IOException] {}',
StandardOutputEncodingrequiresRedirectStandardOutput = $true, which is already set. Confirm the property is available on Windows PowerShell 5.1, which is the launcher target.src/main/agent-hooks/installer-utils.test.ts (1)
622-640: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winPin the launcher argument string with a literal assertion.
Line 635 compares the decoded command with a string that
buildWindowsNoWindowCmdHookInvocationproduced, so that assertion passes for any launcher body. ThetoContainchecks at 636-639 cover only the window flag, the executable path, and the variable name. A regression in$psi.Argumentsor in the exit-code relay still passes.Add literal assertions for the parts that carry the fix.
♻️ Proposed additional assertions
expect(decoded).toContain("EnvironmentVariables['ORCA_WINDOWS_HOOK_CMD']") + expect(decoded).toContain('$psi.UseShellExecute = $false') + expect(decoded).toContain('exit $p.ExitCode') expect(decoded).not.toMatch(/& 'C:\\Users\\alice\\.orca\\agent-hooks\\codex-hook\.cmd'/)src/main/agent-hooks/windows-hook-cmd-no-window.test.ts (1)
134-166: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueBound the sampler by the hook lifetime, and observe the hook stderr promise.
Two reliability points in this test:
- The sampler stops after a fixed 5000 ms. PowerShell startup plus
ping -n 4consumes most of that budget, so the sampling window can close before a launcher window would appear. The test then passes without proving the fix. Keep sampling until the hook process closes, or raisetitledWindowSampleMswell above the hook duration.hookOutput.stderris never awaited. A stream error rejects an unobserved promise and surfaces as an unhandled rejection instead of a test failure. Include it in thePromise.all.♻️ Proposed test adjustments
-const titledWindowSampleMs = 5_000 +const titledWindowSampleMs = 12_000- const [hookCode, hookStdout, samplerStdout] = await Promise.all([ + const [hookCode, hookStdout, , samplerStdout] = await Promise.all([ hookOutput.close, hookOutput.stdout, + hookOutput.stderr, samplerOutput.stdout, samplerOutput.close ])
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: a3a7825c-012a-4754-afeb-3d4aea96c57d
📒 Files selected for processing (4)
src/main/agent-hooks/installer-utils.test.tssrc/main/agent-hooks/installer-utils.tssrc/main/agent-hooks/windows-hook-cmd-no-window.test.tssrc/main/agent-hooks/windows-powershell-hook-launcher.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Keep /v:on only to expand the quoted script path, then nest cmd /v:off so literal ! in hook bodies, env values, and paths is not eaten. Pin UseShellExecute/exit-code shape, sample titled windows until the hook exits, and cover bang characters in live Windows tests.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/agent-hooks/windows-powershell-hook-launcher.ts (1)
38-40: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse a Node path utility for the
cmd.exepath.Line 39 converts assumed
/separators to\. Usepath.win32.normalize()or construct this path withpath.win32.join()instead.Proposed change
+import { win32 } from 'node:path' + const quotedCmd = quotePowerShellSingleQuoted( - getWindowsSystem32Path('cmd.exe').replaceAll('/', '\\') + win32.normalize(getWindowsSystem32Path('cmd.exe')) )As per coding guidelines: “Use
path.joinor Electron/Node path utilities for file paths; never assume/or\.”Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 18da8ab1-46d8-4ce0-a0ea-9ff8c2b5f01f
📒 Files selected for processing (3)
src/main/agent-hooks/installer-utils.test.tssrc/main/agent-hooks/windows-hook-cmd-no-window.test.tssrc/main/agent-hooks/windows-powershell-hook-launcher.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.
CreateProcess still needs a backslash System32 cmd.exe path. Use path.win32.normalize on the existing forward-slash System32 helper instead of replacing separators by hand.
|
Closing in favor of #15595, which registers the cmd-safe |
…ed flag pair (STA-5237) `-WindowStyle Hidden` + `-EncodedCommand` is denied at CreateProcess by Kaspersky on Windows 11, whatever the payload decodes to. Bash reports it as `Permission denied` and every managed hook event fails, so agent status never arrives; the parent shell also briefly cannot spawn anything afterwards, so a denied hook can take the user's next command down with it. Measured on the reporting host (#16003), with a harmless `exit 0` payload: -NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -EncodedCommand 126 -NoProfile -WindowStyle Hidden -EncodedCommand 126 -WindowStyle Hidden -EncodedCommand 126 -NoProfile -EncodedCommand 0 (5/5) #16576 removed `-ExecutionPolicy Bypass`, which is the one flag of the three NOT in the signature, so hooks kept failing after that fix. The pair that has to stop being spelled is `-WindowStyle Hidden` + `-EncodedCommand`. Because the change is to the shared switch constant, it covers every site that spells the denied pair in one edit: Claude via `wrapWindowsPowerShellEncodedCommand`, gemini/cursor/droid/command-code/copilot via `wrapWindowsHookCommand`, the `runtime-home-hook-command` unsafe-HOME fallback, and the spaced-path fallback for codex/grok/devin/antigravity. Only a flag is removed, so parser and payload compatibility is unchanged for every executor: the string is still a PowerShell command line, still one self-contained token, still base64-shielded. The tradeoff, recorded rather than hidden: `-WindowStyle Hidden` was the shipped fix for #14815 (+#14828, #15117, #15447, #15767), and this removes it. Its suppression was never measured — #14825 confirmed it visually, #16576's author stated it "remains unverified on a real box", and #15506's author argued it cannot help a `.cmd` child with no console to inherit. The console is allocated by the parent chain, not by this command line. A live window measurement is still outstanding and is called out in the PR. Also adds `windows-hook-payload-delivery.test.ts` to the PR CI Windows leg, which had never run it.
…ed flag pair (STA-5237) `-WindowStyle Hidden` + `-EncodedCommand` is denied at CreateProcess by Kaspersky on Windows 11, whatever the payload decodes to. Bash reports it as `Permission denied` and every managed hook event fails, so agent status never arrives; the parent shell also briefly cannot spawn anything afterwards, so a denied hook can take the user's next command down with it. Measured on the reporting host (#16003), with a harmless `exit 0` payload: -NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -EncodedCommand 126 -NoProfile -WindowStyle Hidden -EncodedCommand 126 -WindowStyle Hidden -EncodedCommand 126 -NoProfile -EncodedCommand 0 (5/5) #16576 removed `-ExecutionPolicy Bypass`, which is the one flag of the three NOT in the signature, so hooks kept failing after that fix. The pair that has to stop being spelled is `-WindowStyle Hidden` + `-EncodedCommand`. Because the change is to the shared switch constant, it covers every site that spells the denied pair in one edit: Claude via `wrapWindowsPowerShellEncodedCommand`, gemini/cursor/droid/command-code/copilot via `wrapWindowsHookCommand`, the `runtime-home-hook-command` unsafe-HOME fallback, and the spaced-path fallback for codex/grok/devin/antigravity. Only a flag is removed, so parser and payload compatibility is unchanged for every executor: the string is still a PowerShell command line, still one self-contained token, still base64-shielded. The tradeoff, recorded rather than hidden: `-WindowStyle Hidden` was the shipped fix for #14815 (+#14828, #15117, #15447, #15767), and this removes it. Its suppression was never measured — #14825 confirmed it visually, #16576's author stated it "remains unverified on a real box", and #15506's author argued it cannot help a `.cmd` child with no console to inherit. The console is allocated by the parent chain, not by this command line. A live window measurement is still outstanding and is called out in the PR. Also adds `windows-hook-payload-delivery.test.ts` to the PR CI Windows leg, which had never run it.
…ed flag pair (STA-5237) (#16739) * fix(agent-hooks): stop the Windows hook launcher spelling the AV-denied flag pair (STA-5237) `-WindowStyle Hidden` + `-EncodedCommand` is denied at CreateProcess by Kaspersky on Windows 11, whatever the payload decodes to. Bash reports it as `Permission denied` and every managed hook event fails, so agent status never arrives; the parent shell also briefly cannot spawn anything afterwards, so a denied hook can take the user's next command down with it. Measured on the reporting host (#16003), with a harmless `exit 0` payload: -NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -EncodedCommand 126 -NoProfile -WindowStyle Hidden -EncodedCommand 126 -WindowStyle Hidden -EncodedCommand 126 -NoProfile -EncodedCommand 0 (5/5) #16576 removed `-ExecutionPolicy Bypass`, which is the one flag of the three NOT in the signature, so hooks kept failing after that fix. The pair that has to stop being spelled is `-WindowStyle Hidden` + `-EncodedCommand`. Because the change is to the shared switch constant, it covers every site that spells the denied pair in one edit: Claude via `wrapWindowsPowerShellEncodedCommand`, gemini/cursor/droid/command-code/copilot via `wrapWindowsHookCommand`, the `runtime-home-hook-command` unsafe-HOME fallback, and the spaced-path fallback for codex/grok/devin/antigravity. Only a flag is removed, so parser and payload compatibility is unchanged for every executor: the string is still a PowerShell command line, still one self-contained token, still base64-shielded. The tradeoff, recorded rather than hidden: `-WindowStyle Hidden` was the shipped fix for #14815 (+#14828, #15117, #15447, #15767), and this removes it. Its suppression was never measured — #14825 confirmed it visually, #16576's author stated it "remains unverified on a real box", and #15506's author argued it cannot help a `.cmd` child with no console to inherit. The console is allocated by the parent chain, not by this command line. A live window measurement is still outstanding and is called out in the PR. Also adds `windows-hook-payload-delivery.test.ts` to the PR CI Windows leg, which had never run it. * test(agent-hooks): keep launcher token out of source grep
…ed flag pair (STA-5237) (stablyai#16739) * fix(agent-hooks): stop the Windows hook launcher spelling the AV-denied flag pair (STA-5237) `-WindowStyle Hidden` + `-EncodedCommand` is denied at CreateProcess by Kaspersky on Windows 11, whatever the payload decodes to. Bash reports it as `Permission denied` and every managed hook event fails, so agent status never arrives; the parent shell also briefly cannot spawn anything afterwards, so a denied hook can take the user's next command down with it. Measured on the reporting host (stablyai#16003), with a harmless `exit 0` payload: -NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -EncodedCommand 126 -NoProfile -WindowStyle Hidden -EncodedCommand 126 -WindowStyle Hidden -EncodedCommand 126 -NoProfile -EncodedCommand 0 (5/5) NOT in the signature, so hooks kept failing after that fix. The pair that has to stop being spelled is `-WindowStyle Hidden` + `-EncodedCommand`. Because the change is to the shared switch constant, it covers every site that spells the denied pair in one edit: Claude via `wrapWindowsPowerShellEncodedCommand`, gemini/cursor/droid/command-code/copilot via `wrapWindowsHookCommand`, the `runtime-home-hook-command` unsafe-HOME fallback, and the spaced-path fallback for codex/grok/devin/antigravity. Only a flag is removed, so parser and payload compatibility is unchanged for every executor: the string is still a PowerShell command line, still one self-contained token, still base64-shielded. The tradeoff, recorded rather than hidden: `-WindowStyle Hidden` was the shipped fix for stablyai#14815 (+stablyai#14828, stablyai#15117, stablyai#15447, stablyai#15767), and this removes it. Its suppression was never measured — stablyai#14825 confirmed it visually, stablyai#16576's author stated it "remains unverified on a real box", and stablyai#15506's author argued it cannot help a `.cmd` child with no console to inherit. The console is allocated by the parent chain, not by this command line. A live window measurement is still outstanding and is called out in the PR. Also adds `windows-hook-payload-delivery.test.ts` to the PR CI Windows leg, which had never run it. * test(agent-hooks): keep launcher token out of source grep (cherry picked from commit 928d306)
…ed flag pair (STA-5237) (stablyai#16739) * fix(agent-hooks): stop the Windows hook launcher spelling the AV-denied flag pair (STA-5237) `-WindowStyle Hidden` + `-EncodedCommand` is denied at CreateProcess by Kaspersky on Windows 11, whatever the payload decodes to. Bash reports it as `Permission denied` and every managed hook event fails, so agent status never arrives; the parent shell also briefly cannot spawn anything afterwards, so a denied hook can take the user's next command down with it. Measured on the reporting host (stablyai#16003), with a harmless `exit 0` payload: -NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -EncodedCommand 126 -NoProfile -WindowStyle Hidden -EncodedCommand 126 -WindowStyle Hidden -EncodedCommand 126 -NoProfile -EncodedCommand 0 (5/5) stablyai#16576 removed `-ExecutionPolicy Bypass`, which is the one flag of the three NOT in the signature, so hooks kept failing after that fix. The pair that has to stop being spelled is `-WindowStyle Hidden` + `-EncodedCommand`. Because the change is to the shared switch constant, it covers every site that spells the denied pair in one edit: Claude via `wrapWindowsPowerShellEncodedCommand`, gemini/cursor/droid/command-code/copilot via `wrapWindowsHookCommand`, the `runtime-home-hook-command` unsafe-HOME fallback, and the spaced-path fallback for codex/grok/devin/antigravity. Only a flag is removed, so parser and payload compatibility is unchanged for every executor: the string is still a PowerShell command line, still one self-contained token, still base64-shielded. The tradeoff, recorded rather than hidden: `-WindowStyle Hidden` was the shipped fix for stablyai#14815 (+stablyai#14828, stablyai#15117, stablyai#15447, stablyai#15767), and this removes it. Its suppression was never measured — stablyai#14825 confirmed it visually, stablyai#16576's author stated it "remains unverified on a real box", and stablyai#15506's author argued it cannot help a `.cmd` child with no console to inherit. The console is allocated by the parent chain, not by this command line. A live window measurement is still outstanding and is called out in the PR. Also adds `windows-hook-payload-delivery.test.ts` to the PR CI Windows leg, which had never run it. * test(agent-hooks): keep launcher token out of source grep
ELI5
On Windows, every Grok tool call runs Orca's managed hook as a
.cmdfile. The hook is already wrapped in hidden PowerShell, but.cmdcannot inherit that hidden console, so Windows opens a brief titledcmd/conhostwindow and steals focus. This change startsSystem32\cmd.exewithCreateNoWindowand still copies the hook's stdout, stderr, and exit code back to the caller.What Changed
wrapWindowsHookCommandstill uses the existing encoded PowerShell launcher (-WindowStyle Hidden,$ProgressPreference='SilentlyContinue', absolutepowershell.exe)..cmd, it no longer uses& $scriptPath. It starts absoluteSystem32\cmd.exethroughProcessStartInfowithUseShellExecute = $false,CreateNoWindow = $true, redirected stdin/stdout/stderr, writes[Console]::In.ReadToEnd()into the child then closes stdin, writes child stdout/stderr back, andexit $p.ExitCode.%, and^travel in an env var and are expanded with delayed expansion (/v:on+!ORCA_WINDOWS_HOOK_CMD!), so they stay out of the encoded command line ([Bug]: Codex hooks fail on Windows when user path contains spaces #6078) and cmd does not resplit them..ps1, the launcher still calls&in-process.wrapWindowsCmdHookCommand(Codex/Antigravity argv[0] fast path), hook script bodies, terminal daemonOpenConsole.exe, and the Git Bashruntime-home-hook-commandpath are unchanged.Why
#14825 hid the PowerShell wrapper. That is not enough for Grok: Grok's managed entry is
& grok-hook.cmd, and a.cmdwith no console to inherit gets a new one. #14845 tried a native GUI launcher for this issue and was closed unmerged against the same files. This is the small follow-up onmain: one launcher change, stdout preserved so Claude/Cursor do not regress #14818.Evidence for the
.cmdspawn path: #14828 (comment)Linked Issue
Fixes #14828
Visual Proof
N/A — no Orca UI, layout, or in-app control change. The bug is an OS console flash / focus steal (
MainWindowTitleoftenC:\WINDOWS\System32\conhost.exe), so proof is command shape, process tree, and a live Windows test that samples titledcmd/conhostwindows while a Grok-stylepowershell -NoProfile -NonInteractivelaunch runs a sleeping.cmd. Screenshots would not show the flash reliably.Before: decoded payload is
& '...\grok-hook.cmd'; each tool event opens a titled console.After: decoded payload contains
CreateNoWindow = $trueand is not a naked& '...*.cmd'; live sampling on this Windows 11 machine found no new titledcmd/conhostwindow; stdout{"ok":true}and exit 0 still came back.Testing
Platforms actually exercised: Windows 11 (this checkout). macOS/Linux covered by command-shape unit tests (no Windows spawn).
Ran locally:
pnpm exec vitest run --config config/vitest.config.ts src/main/agent-hooks/installer-utils.test.ts src/main/agent-hooks/windows-hook-cmd-no-window.test.ts src/main/claude/hook-service.test.ts src/main/grok/hook-service.test.ts— 84 passed, 7 skippedpowershell -NoProfile -NonInteractive, no Hidden on that outer layer) relays stdout/stderr/exit 7; missing script drains and exits 0; titled-window sampler over a 3s.cmdsaw no newcmd/conhostMainWindowTitle(skipped in CI viaskipIf)pnpm typecheckpassedpnpm lint: oxlint, code-quality native/type-aware, reliability gates, max-lines ratchet, and bundled skill guides passed.verify:skill-bundle-manifestfailed on this worktree with staleresources/skills/*.json; those files are not in this diff (pre-existing generator drift). CI should cover the rest of lint pluspnpm test/pnpm buildDid not run full
pnpm test/pnpm build(too heavy for this launcher-only change).Pre-existing flake not caused by this PR:
managed-hook-stdin-lifecycle.test.tsantigravity-hook.cmdstdinEOFvsEPIPE/ECONNRESET. That case spawns the.cmdas argv[0] viacmd.exe /d /c scriptPath, notwrapWindowsHookCommand(same race noted on #14825).AI Disclosure
Implemented and verified with Grok 4.6.
Review
wrapPosixHookCommand. Command-shape tests run on every CI OS; live window sampling isskipIfWindows-desktop / not CI..shvia SFTP. Local folder workspaces and git worktrees share~/.orca/agent-hooks/*.cmd..cmdentries use this wrapper. Copilot.ps1stays in-process&. Claude Windows lifecycle hooks usegetWindowsManagedLifecycleHook(unchanged). Codex/Antigravity still usewrapWindowsCmdHookCommandbare argv[0] when the path is cmd-safe ([Bug] Windows: Antigravity agent hooks spawn a visible console (cmd.exe + powershell.exe) on every invocation and tool call #15117).$null = ReadToEnd()), so Claude-hooks-compat JSON from [Bug]: Windows shell command failures #14818 is not dropped.cmd.exewithCreateNoWindowinstead of a visible console; no native GUI launcher and no process-tree kill.System32\cmd.exefromgetWindowsSystem32Path, not PATH. Script path is PowerShell-literal and passed through delayed expansion, not interpolated onto an unquoted cmd line.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.Notes
Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)Author