Skip to content

fix(codex): remove redundant Windows hook launcher for Unicode profiles - #20952

Merged
nwparker merged 4 commits into
mainfrom
neil/sta-7381-bug-windows-codex-hooks-cjk-profile-paths-force-a-costly
Sep 16, 2026
Merged

nwparker merged 4 commits into
mainfrom
neil/sta-7381-bug-windows-codex-hooks-cjk-profile-paths-force-a-costly

Conversation

@nwparker

@nwparker nwparker commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​270 $\color{#cf222e}{\Huge{\mathbf{−}}}$​24 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​246
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​25 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​18

ELI5

Windows Codex hooks under a CJK or spaced profile started a second PowerShell process for every event. Reuse the PowerShell host Codex already provides, keeping the quoted script invocation, missing-file check, environment guard, and stdin drain.

What Changed

Extract the existing PowerShell command body from its encoded launcher and use that body for native Windows Codex paths that previously required the launcher. ASCII fast paths, other agents' launchers, POSIX/SSH/WSL commands, hook payloads, and the 10-second timeout retain their existing behavior. Reinstallation replaces the old commands and refreshes trust without duplicating hooks or removing user hooks.

Why

The native Windows hook engine passes commands to its selected PowerShell with -NoProfile -Command; it has done so since the hook engine was introduced. The shared helper's historical argv[0] assumption does not describe this consumer. A bare Unicode path loses quoting and missing-script handling; executing the existing guarded body inside the host preserves both while removing the extra interpreter and its execution-policy setup.

Reviewed the reports and discussions in #11496, #18875, and #19187, and cross-referenced #11497, #13442, #18905, and the open #19255. The latter changes Claude's bash/cmd launcher and cannot be applied directly to Codex's PowerShell host.

Linked Issue

Resolves STA-7381.

Visual Proof

N/A — generated hook commands change; no rendered UI or interaction changes. Windows execution and timing evidence follows.

Testing

  • Manually verified on win-lowspec through orca-cli, Windows PowerShell 5.1 and PowerShell 7.6.6.
  • Automated regression coverage added.
  • Windows: 20 tests passed across command/delivery, managed installation, and upgrade suites. All eight events deliver large Unicode JSON exactly once, four concurrent at a time, from a CJK profile containing spaces and an apostrophe. Tests check exact payloads, token and workspace metadata, missing scripts, unreachable receivers, repeated installation, trust refresh, and user-hook preservation.
  • Real Codex CLI 0.152.1: its app-server granted trust for all eight generated hooks. A fresh native session in a folder workspace executed a deterministic Write-Output tool call against a local model-response fixture. SessionStart, UserPromptSubmit, PreToolUse, PostToolUse, and Stop reached the receiver; tool and session exited 0 with empty stderr. No hook-trust bypass was used.
  • macOS: 181 test files passed, 3 skipped; 2,047 tests passed, 15 skipped (src/main/codex, installer-utils, and managed-command contracts).
  • Windows suites are registered in both CI lane lists; all 62 CI registration/change-scope tests passed.
  • pnpm tc, pnpm build, changed-code quality gate, targeted oxlint, formatting, and git diff --check passed.

Paired win-lowspec benchmark: 12 measured runs per shape per host after two warmup rounds, alternating order, the same generated .cmd, and the same 259,044-byte Unicode payload:

Host Old median Fixed median Reduction
Windows PowerShell 5.1 1,039.5 ms 330 ms 68%
PowerShell 7 1,209.5 ms 550 ms 55%

All 56/56 deliveries, including warmups, were byte-exact. No claim is made that this resolves every historical 10-second timeout or unrelated orphan-process report.

Review

Upstream shell boundary checked in local Codex source: build_hooks_for_config always supplies the selected program, so the hooks library's empty-program cmd.exe /C fallback is not used by native sessions. Native shell discovery selects PowerShell; its ultimate cmd fallback requires PowerShell to be absent, which also breaks the old powershell.exe launcher. Shell overrides are test-only apart from disabled, under-development shell_zsh_fork; that experimental native Windows configuration is outside this verification. Orca terminal-shell selection does not configure the Codex hook host.

The shared wrapper still builds the same encoded command for its other callers. Native Windows Codex alone selects the unwrapped body; its ASCII path remains byte-identical. No new process, dependency, runtime detection, polling, wire field, or timeout extension is introduced. Existing sessions may retain their startup hook snapshot; use a fresh Codex session after hook regeneration.

An independently reproduced, pre-existing cmd percent-expansion problem affects literal %VAR% profile segments with both launchers. It is tracked separately as STA-7655.

Agent skill upstream boundary

  • Not applicable.

Checklist

  • Focused change with regression tests
  • Problem, behavior, and measured improvement explained
  • Visual proof applicability explained
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/WSL, and folder-workspace behavior considered
  • Relevant tests, typechecks, build, and changed-code checks passed

@coderabbitai

coderabbitai Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

📝 Walkthrough

Walkthrough

Windows Codex managed hooks now use a shared raw PowerShell command builder for non-safe script paths, while safe paths remain unchanged. The encoded wrapper still handles CMD launcher commands. Tests cover Unicode paths, PowerShell reuse, event delivery, fallback behavior, command contracts, and idempotent hook upgrades. The Windows package workflow now runs the new tests.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to 4e9aa

Windows hooks can fail for UNC profiles or after the managed script is removed; route those cases through the guarded launcher 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%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 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 identifies the main change: removing the redundant Windows hook launcher for Unicode profiles.
Description check ✅ Passed The description is detailed and covers the main template sections, linked issue, testing, scope, compatibility, and checklist. The AI Disclosure and Notes headings are not included, but the descriptio…
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.

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

Important

The new command shape is correct for Codex's default Windows hook shell but is now PowerShell-only, where the previous encoded launcher also ran under Codex's cmd.exe /C fallback. One inline note; everything else looks solid.

Reviewed changes

  • buildWindowsHookPowerShellCommand extracted (installer-utils.ts) — the guarded PowerShell body is now exported and reused; wrapWindowsHookCommand still encodes it for its other callers, so Antigravity/Devin/Grok/Kimi shapes are unchanged.
  • Codex Windows command switched (codex-hook-definition.ts) — getManagedCommand returns the bare .cmd for cmd-safe paths and the unencoded body otherwise, dropping the nested powershell.exe -NoProfile -EncodedCommand on every CJK/spaced-profile event.
  • Command-shape + delivery tests (windows-hook-command.test.ts) — asserts no powershell.exe/EncodedCommand/Set-ExecutionPolicy, pins -LiteralPath '…' -PathType Leaf quoting, and drives all eight events through real PowerShell with large Unicode payloads plus missing-script and unreachable-receiver paths.
  • Upgrade test (windows-hook-upgrade.test.ts) — reinstall twice, asserts exactly one new managed command per event, no old encoded command survives, user hooks and the user hooks.json are untouched, and trust TOML changes.
  • Existing assertions retargeted — hook-service-managed-install.test.ts and the Grok dollar-byte scanner contract now account for the new shape.

ℹ️ Nitpicks

  • src/main/agent-hooks/installer-utils.test.ts:710 and :724 still describe Codex as a wrapWindowsCmdHookCommand argv[0] consumer ("Codex/Antigravity/Devin launch the command as a program"). This PR establishes Codex is not one — the surviving callers are Antigravity, Devin, and Grok — so those comments are now misleading.
  • src/main/codex/windows-hook-upgrade.test.ts:80 asserts expect(readFileSync(tomlPath, 'utf8')).not.toBe(oldTrust), which passes on any byte change. Asserting the new computed trusted hash (or not.toContain(oldHash)) would actually pin the trust refresh.
  • The load-bearing assumption (PowerShell -Command host) is exercised only by describe.skipIf(process.platform !== 'win32'), so Linux CI never runs it. Fine given the manual Windows verification, just noting the coverage boundary.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment thread src/main/codex/codex-hook-definition.ts Resolved

@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 in the follow-up commit. (Not an approval — the prior codex-hook-definition.ts:80 note remains open.)

Reviewed changes

  • CI registration for the new suites (5eb6ac9df1) — src/main/codex/windows-hook-command.test.ts and windows-hook-upgrade.test.ts are now listed in both WINDOWS_PACKAGE_TESTS (config/scripts/pr-code-change-scope.mjs:226-227) and the Test Windows-specific boundaries vitest argv (.github/workflows/pr.yml:891-892). Both are required by config/scripts/win32-test-lane-registration.test.mjs, the relative placement matches the existing classifier list, and the files carry describe.skipIf(process.platform !== 'win32'), so they would otherwise have run on no machine.

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

@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

Reviewed only the delta since the prior pullfrog review (5eb6ac9 → b6da1d3): comment and test-assertion tightening on the already-reviewed command change.

  • Comment accuracy fixed (installer-utils.test.ts, codex-hook-definition.ts) — wrapWindowsCmdHookCommand's comments no longer name Codex as an argv[0] consumer, and the getManagedCommand comment now reads "Codex's default native Windows hook host is PowerShell", scoping the shell assumption instead of asserting it unconditionally.
  • Trust refresh assertion strengthened (windows-hook-upgrade.test.ts) — the setup entry now uses timeoutSec: 10 (was timeout), and the loose not.toBe(oldTrust) byte-diff check is replaced with exact computeTrustedHash assertions: the new command's hash is present and the old command's hash is absent after reinstall.

The remaining prior nitpick (the real-PowerShell delivery test is skipIf non-win32) is an informational coverage boundary, not actionable — the new suites are registered in both Windows CI lanes, so they do run somewhere.

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

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

⚠️ Outside the diff (1)

🟠 Major · Keep UNC and missing paths on the guarded launcher.

src/main/codex/codex-hook-definition.ts:73-80
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Keep UNC and missing paths on the guarded launcher. getManagedCommand returns a bare path when WINDOWS_CMD_SAFE_PATH matches. That predicate accepts UNC paths. Codex runs the command through cmd.exe /C, which does not reliably launch UNC script paths. If the managed script is removed after installation, cmd.exe /C reports a command-not-found failure instead of using the PowerShell wrapper’s missing-file fallback and stdin drain. Restrict the bare branch to drive-letter paths, and route UNC and other paths through buildWindowsHookPowerShellCommand.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 448692d8-e27e-4b96-b63f-41932b7198c3

📥 Commits

Reviewing files that changed from the base of the PR and between b6da1d3 and 4e9aa50.

📒 Files selected for processing (1)
  • src/main/codex/windows-hook-command.test.ts

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

@nwparker
nwparker merged commit d62328a into main Sep 16, 2026
34 checks passed
ivanvykopal pushed a commit to ivanvykopal/orca that referenced this pull request Sep 20, 2026
…es (stablyai#20952)

* fix(codex): reuse the Windows hook shell for Unicode profile paths

* test(codex): register Unicode hook tests in Windows CI

* test(codex): pin trust hash replacement during Windows upgrade

* test(codex): retry transient Windows teardown locks
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