Skip to content

fix(agent-hooks): make Windows cmd hook launcher directly spawnable (#8430 regression) - #8737

Merged
OrcaWin merged 1 commit into
mainfrom
OrcaWin/windows-codex-hook-issue
Jul 14, 2026
Merged

OrcaWin merged 1 commit into
mainfrom
OrcaWin/windows-codex-hook-issue

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Problem

On Windows, every Codex agent hook failed with hook exited with code 1 starting in v1.4.138:

• SessionStart hook (failed)   error: hook exited with code 1
• UserPromptSubmit hook (failed)  error: hook exited with code 1
• Stop hook (failed)  error: hook exited with code 1

Root cause

PR #8430 rewrote wrapWindowsCmdHookCommand so the hook command became a cmd compound:

if exist "path\." (drain) else if exist "path" (call "path") else (drain)

Codex/Antigravity/Devin launch the hook command as a program (argv[0]), not through cmd.exe. The compound's argv[0] is the cmd builtin if, which is not an executable, so the launch fails every time. Verified empirically on Windows: a bare .cmd is directly spawnable (exit 0) via the CreateProcess family these agents use, while the if-led form throws ENOENT. cmd /c interprets the compound fine — which is exactly why it slipped through (tests exercised it via cmd /c, not direct spawn).

Affected all three direct-spawn agents (Codex, Antigravity, Devin); Codex is just the one that got reported.

Fix

Revert the cmd-safe fast path to the bare, directly-spawnable .cmd path — the proven pre-#8430 form. A cmd-builtin drain and direct-spawnability are mutually exclusive, and nesting cmd.exe /d /c breaks large-payload draining. The missing-script stdin drain stays on the encoded-PowerShell fallback (used for spaced/non-ASCII paths).

Zero-regression review

  • Faithful revert: character-for-character the line fix(agent-hooks): drain stdin before hook script early exits so agents never hit EPIPE #8430 changed; bare-path behavior is proven-in-production.
  • Upgrade self-heals: startup install() unconditionally rewrites the command + Codex trust entry and sweeps the old compound (matcher is wrapper-agnostic); no user left with a broken hook.
  • Scope: Windows-local only; SSH/WSL/remote (POSIX) untouched. Claude (Git Bash) and Copilot/Droid (PowerShell) launchers unaffected.
  • Trade-off (accepted): the fast path no longer drains a stale/missing managed script — a rare edge that was itself the regression vector; the encoded fallback still drains.

Tests

  • installer-utils.test.ts: bare-path contract + a platform-independent regression guard (launcher must resolve to a real file, never a cmd-builtin fragment).
  • Updated the lifecycle test + agent-hook-stdin-lifecycle.md doc, fixed a stale Devin comment.
  • tsc + oxlint clean.

@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: df90699d-c40c-4644-bc1f-fc833f439a39

📥 Commits

Reviewing files that changed from the base of the PR and between d0ad118 and 954b430.

📒 Files selected for processing (5)
  • docs/reference/agent-hook-stdin-lifecycle.md
  • src/main/agent-hooks/installer-utils.test.ts
  • src/main/agent-hooks/installer-utils.ts
  • src/main/agent-hooks/managed-hook-stdin-lifecycle.test.ts
  • src/main/devin/hook-settings.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/main/devin/hook-settings.ts
  • src/main/agent-hooks/managed-hook-stdin-lifecycle.test.ts
  • src/main/agent-hooks/installer-utils.test.ts
  • docs/reference/agent-hook-stdin-lifecycle.md
  • src/main/agent-hooks/installer-utils.ts

📝 Walkthrough

Walkthrough

Updated Windows hook command wrapping so safe .cmd paths are directly spawnable and non-safe paths use the encoded launcher. Removed the Windows drain contract from this wrapper, adjusted missing-script lifecycle tests, and documented that bare .cmd launches surface missing scripts as launch failures while interpreter-based launchers handle stdin draining.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the fix and tests, but it misses required template sections and explicit cross-platform/security review details. Add the missing Screenshots, AI Review Report, Security Audit, and Notes sections, and explicitly confirm macOS/Linux/Windows compatibility checks.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: making the Windows cmd hook launcher directly spawnable to fix the regression.
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.
✨ Finishing Touches
📝 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.

…8430 regression)

Codex, Antigravity, and Devin launch their agent-hook `command` as a program
(argv[0]), not through cmd.exe. PR #8430 changed wrapWindowsCmdHookCommand to
emit an `if exist "path\." (drain) else if exist "path" (call "path") else
(drain)` compound whose argv[0] is the cmd builtin `if` — unspawnable — so every
Codex/Antigravity/Devin hook (SessionStart, UserPromptSubmit, Stop, ...) failed
with "hook exited with code 1" on Windows starting in v1.4.138.

Revert the cmd-safe fast path to the bare, directly-spawnable .cmd path (the
proven pre-#8430 form). A cmd-builtin drain and direct-spawnability are mutually
exclusive, and nesting cmd.exe /d /c breaks large-payload draining; the
missing-script stdin drain stays on the encoded-PowerShell fallback (used for
spaced/non-ASCII paths). Upgrades self-heal on first launch: startup install()
unconditionally rewrites the command and Codex trust entry, sweeping the old
compound form.

Add a platform-independent regression guard (launcher must resolve to a real
file, never a cmd-builtin fragment), update the lifecycle test + docs, and fix a
stale Devin comment.
@OrcaWin
OrcaWin force-pushed the OrcaWin/windows-codex-hook-issue branch from d0ad118 to 954b430 Compare July 14, 2026 12:26
@OrcaWin
OrcaWin merged commit a8a8040 into main Jul 14, 2026
1 check passed
@nwparker nwparker mentioned this pull request Sep 27, 2026
1 of 5 tasks
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…tablyai#8430 regression) (stablyai#8737)

Codex, Antigravity, and Devin launch their agent-hook `command` as a program
(argv[0]), not through cmd.exe. PR stablyai#8430 changed wrapWindowsCmdHookCommand to
emit an `if exist "path\." (drain) else if exist "path" (call "path") else
(drain)` compound whose argv[0] is the cmd builtin `if` — unspawnable — so every
Codex/Antigravity/Devin hook (SessionStart, UserPromptSubmit, Stop, ...) failed
with "hook exited with code 1" on Windows starting in v1.4.138.

Revert the cmd-safe fast path to the bare, directly-spawnable .cmd path (the
proven pre-stablyai#8430 form). A cmd-builtin drain and direct-spawnability are mutually
exclusive, and nesting cmd.exe /d /c breaks large-payload draining; the
missing-script stdin drain stays on the encoded-PowerShell fallback (used for
spaced/non-ASCII paths). Upgrades self-heal on first launch: startup install()
unconditionally rewrites the command and Codex trust entry, sweeping the old
compound form.

Add a platform-independent regression guard (launcher must resolve to a real
file, never a cmd-builtin fragment), update the lifecycle test + docs, and fix a
stale Devin comment.
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