Skip to content

fix(codex): make Windows hooks portable across session shells - #8699

Closed
OrcaWin wants to merge 2 commits into
stablyai:mainfrom
OrcaWin:fix/windows-codex-hook-shell
Closed

OrcaWin wants to merge 2 commits into
stablyai:mainfrom
OrcaWin:fix/windows-codex-hook-shell

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • fix Orca-managed Codex hooks failing with exit code 1 when Windows Codex runs them through PowerShell
  • register shell-safe .cmd paths with forward slashes so CMD, PowerShell, and Git Bash can all execute the same command
  • keep the encoded PowerShell fallback for paths that contain spaces or shell metacharacters
  • add an installed-config regression that sends a 1 MB hook payload through PowerShell and requires a clean exit

This fixes the Windows regression introduced by #8430. That change replaced the direct Codex hook path with a CMD-only if exist (...) guard, but Codex uses the configured session shell when present. PowerShell therefore rejected the hook before Orca's script could read stdin.

Screenshots

No visual change.

Testing

  • pnpm lint — not run in full; targeted Oxlint passed for all four changed files
  • pnpm typecheck — not run in full; pnpm run typecheck:node passed
  • pnpm test — not run in full; focused Vitest run passed 30 tests across the Codex service and cross-shell launcher
  • pnpm build — not run
  • Added or updated high-quality tests that would catch regressions

Additional verification:

  • installed Codex hook command executed successfully with a 1 MB stdin payload through Windows PowerShell
  • the generated direct command was exercised successfully under CMD, Windows PowerShell, and Git for Windows Bash
  • targeted Oxfmt check passed
  • pnpm run check:max-lines-ratchet passed
  • git diff --check passed

A broader managed-hook lifecycle run reached two unchanged failures in the existing CMD-only fast-path tests on this machine (more.com/Node stdin EOF and missing-script exit 1). The fixed Codex installer no longer uses that CMD-only launcher.

AI Review Report

The review traced Codex hook discovery, trust hashing, and command execution through the current upstream implementation. It confirmed that Windows hooks default to cmd.exe only when no session shell is configured; otherwise Codex executes them through the active shell. That made the existing CMD-only guard invalid for Orca sessions hosted by PowerShell.

Main risks checked:

  • Shell compatibility: verified the chosen forward-slash .cmd command under CMD, Windows PowerShell, and Git Bash. Paths that are not safe to execute unquoted retain Orca's existing encoded launcher.
  • Performance: rejected an initial always-encoded PowerShell approach after measuring roughly 2.3 seconds of added startup time per hook on this machine. The final safe-path branch starts no additional interpreter.
  • Trust and cleanup: Codex trust entries continue to hash the exact installed command, and the managed-command matcher already recognizes both direct forward-slash paths and encoded fallback commands.
  • Cross-platform: the new command is selected only under process.platform === 'win32'. macOS/Linux local hooks, WSL runtime hooks, and SSH remote hooks keep their existing POSIX launchers unchanged.
  • Agent scope: only Codex switches away from the CMD-specific helper. Antigravity and Devin behavior is unchanged.
  • UI/Electron: no renderer, shortcut, label, layout, or Electron IPC behavior changed.

No additional correctness changes were needed after review.

Security Audit

  • No dependency, network endpoint, auth flow, IPC channel, or secret handling changed.
  • The direct command is allowed only when the normalized path matches the existing strict shell-safe allowlist. Spaces, quotes, %, ^, &, parentheses, Unicode, and other potentially ambiguous characters fall back to the encoded PowerShell launcher.
  • The managed script path still comes from Orca's controlled ~/.orca/agent-hooks location and is written atomically before hooks.json is published.
  • WSL and SSH commands remain host-scoped and use POSIX paths; no Windows path is sent to a remote host.

No security follow-up is required.

Notes

  • If the managed .cmd is manually deleted after Orca publishes hooks.json, a shell-safe direct entry can report a missing hook until Orca's installer repairs it. Normal install, upgrade, dev/prod switching, and removal flows write the shared script before publishing configuration, so they do not create that state.
  • X handle: not provided.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e2d99d9e-aa87-4e8d-a2c9-0735f8401e6f

📥 Commits

Reviewing files that changed from the base of the PR and between 0490415 and 3e09035.

📒 Files selected for processing (1)
  • src/main/codex/hook-service.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/codex/hook-service.test.ts

📝 Walkthrough

Walkthrough

Adds wrapWindowsCrossShellHookCommand to select a normalized direct Windows path or an encoded PowerShell launcher. Codex managed hooks use this wrapper on Windows, while POSIX behavior remains unchanged. Tests cover both wrapper outcomes and execute the generated Windows command through PowerShell.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: making Windows hooks portable across shells.
Description check ✅ Passed The description follows the template and fills all required sections with a clear summary, testing notes, review, security, and notes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

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: Pro

Run ID: 7a9ecf0d-b093-48a9-97db-df3fe360f466

📥 Commits

Reviewing files that changed from the base of the PR and between 8e0977d and 0490415.

📒 Files selected for processing (4)
  • src/main/agent-hooks/installer-utils.test.ts
  • src/main/agent-hooks/installer-utils.ts
  • src/main/codex/hook-service.test.ts
  • src/main/codex/hook-service.ts

Comment thread src/main/codex/hook-service.test.ts Resolved
@OrcaWin

OrcaWin commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator Author

Live Windows validation passed on commit \3e090350b:\n\n- launched an isolated real \pnpm dev\ Electron instance\n- created a PowerShell terminal with the Orca-managed \CODEX_HOME\n- verified all managed Codex events use \C:/Users/neil/.orca/agent-hooks/codex-hook.cmd\n- launched \codex-cli 0.144.3\ with an initial harmless prompt\n- observed no \SessionStart hook (failed), \UserPromptSubmit hook (failed), or \hook exited with code 1\n- observed \UserPromptSubmit\ in Orca's agent-status handling and a completed assistant response\n- stopped the dev/Codex process tree and removed the isolated profile\n\nThe review portability note is addressed by \3e090350b; the focused PowerShell regression test passes.

@brennanb2025

Copy link
Copy Markdown
Contributor

Closing as superseded by #8737, which landed the broader Windows hook launcher fix on main for Codex, Antigravity, and Devin.

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