codex-plugin-cc icon indicating copy to clipboard operation
codex-plugin-cc copied to clipboard

codex-companion cancel taskkill fallback breaks under Git Bash — MSYS translates /PID arg to C:/Program Files/Git/PID

Open lukaskucinski opened this issue 6 months ago • 2 comments

Environment

  • codex plugin v1.0.4
  • Windows 10 Pro 10.0.19045
  • Git Bash (MSYS2) — the default Bash environment for Claude Code on Windows
  • node codex-companion.mjs cancel <job-id> invoked when a job has stalled

Symptom

When codex-companion's soft-cancel IPC fails and the script falls back to taskkill /PID <pid> /T /F, Git Bash's MSYS layer translates the literal /PID argument into a Windows path, mangling the command:

taskkill /PID 34428 /T /F: exit=1: ERROR: Invalid argument/option - 'C:/Program Files/Git/PID'.
Type "TASKKILL /?" for usage.

MSYS sees /PID as a root-level Unix path and prefixes it with the Git for Windows install root. The actual taskkill receives C:/Program Files/Git/PID 34428 /T /F and rejects the bogus argument.

Result: the cancel fallback fails, the wedged codex process keeps running, and the user has to clean up manually via Stop-Process -Id <pid> -Force from PowerShell.

Reproduction

  1. Launch any codex adversarial-review job from Git Bash on Windows
  2. Trigger a stall condition (e.g., the IPC deadlock described in #330; or kill the codex process out-of-band so the broker thinks it's running but it isn't)
  3. Run node codex-companion.mjs cancel <job-id> from Git Bash
  4. Observe the MSYS-mangled taskkill stderr

Suggested fixes (any of these works)

  1. Set MSYS_NO_PATHCONV=1 in the env for the taskkill invocation
  2. Pass //PID (double-slash escape recognized by MSYS as "no translation")
  3. Preferred: on Windows, use powershell.exe -NoProfile -Command "Stop-Process -Id <pid> -Force" instead of taskkill — no MSYS translation, cleaner exit semantics, no dependency on which shell wraps the node invocation

Option 3 is what we recommend to our users in our orchestrator's recovery guidance, so confirmed working.

Reference

Same orchestrator run as the IPC deadlock issue (#330). Job ID review-mpbtwgbj-gswbux, PID 34428.

lukaskucinski avatar May 19 '26 00:05 lukaskucinski

Confirming this on a second environment and adding the exact code location + a tested minimal patch.

Repro env: Windows 11 (26200), codex plugin v1.0.4, launched from Claude Code — whose default SHELL is /bin/bash.exe (Git Bash). So this isn't an exotic config: any Windows user on the Claude Code default shell hits it.

Root cause (one line). terminateProcessTree shells out for the kill, and runCommand spawns through process.env.SHELL on Windows:

plugins/codex/scripts/lib/process.mjs

// runCommand
shell: process.platform === "win32" ? (process.env.SHELL || true) : false,
...
// terminateProcessTree (win32 branch)
runCommandImpl("taskkill", ["/PID", String(pid), "/T", "/F"], {
  cwd: options.cwd,
  env: options.env
});

Because the spawn goes through Git Bash, MSYS path conversion rewrites the first /-flag: /PID → C:/Program Files/Git/PID, so taskkill aborts with ERROR: Invalid argument/option - 'C:/Program Files/Git/PID'.

Scope is broader than the cancel fallback. Since it's in terminateProcessTree, it also fires from the SessionEnd lifecycle hook (teardownBrokerSession) and broker teardown — every process-tree kill fails, leaving orphaned node processes and surfacing as repeated "Background shell failed" noise, not just on /codex:cancel.

Verified minimal fix — disable MSYS conversion for only this spawn, so the existing taskkill path (and its "process not found" handling) is otherwise untouched:

runCommandImpl("taskkill", ["/PID", String(pid), "/T", "/F"], {
  cwd: options.cwd,
  env: { ...(options.env ?? process.env), MSYS_NO_PATHCONV: "1", MSYS2_ARG_CONV_EXCL: "*" }
});

Proof the flags survive once conversion is off:

$ taskkill /PID 999999 /T /F
ERROR: Invalid argument/option - 'C:/Program Files/Git/PID'.   # broken

$ MSYS_NO_PATHCONV=1 taskkill /PID 999999 /T /F
ERROR: The process "999999" not found.                         # flags intact (and this
                                                               # "not found" case is already
                                                               # handled gracefully)

The powershell.exe Stop-Process approach in the original report also works; the env-scoped patch above is just the smallest diff and keeps the current taskkill output parsing. Happy to open a PR if useful.

ryantokam avatar Jun 27 '26 01:06 ryantokam

Duplicate of #525.

dkundel-openai avatar Aug 11 '26 00:08 dkundel-openai