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

Stop-review-gate hook masks the real failure: Node 24 DEP0190 warning displaces the actual error in stderr-first reporting

Open Reveludden opened this issue 4 months ago • 4 comments

Labels (suggestion): bug, windows

Summary When the stop-time review task fails on Windows with Node 24, the hook reports only a Node DeprecationWarning instead of the actual failure cause. The real error (in our case: ChatGPT usage limit reached) is only discoverable by manually reading the job logs under CLAUDE_PLUGIN_DATA/state//jobs/*.log.

Environment Windows 11 Pro (10.0.26200) Node v24.14.1 codex-cli 0.142.5 (logged in via ChatGPT) Claude Code 2.1.202 codex plugin 1.0.5 What happens At turn end with stopReviewGate enabled, Claude Code shows:

Stop hook blocking error: The stop-time Codex review task failed: (node:98328) [DEP0190] DeprecationWarning: Passing args to a child process with shell option true can lead to security vulnerabilities, as the arguments are not escaped, only concatenated. The actual failure (quota exhausted — "You've hit your usage limit...") never reaches the user. We initially chased the deprecation warning as the root cause; the real error was only visible in the companion job log.

Root-cause chain scripts/lib/app-server.mjs — SpawnedCodexAppServerClient.initialize():

this.proc = spawn("codex", ["app-server"], { ... shell: process.platform === "win32" ? (process.env.SHELL || true) : false, }); shell: true (introduced to fix #85, spawn ENOENT for .cmd shims) combined with an args array makes Node 24 emit DEP0190 on the hook process's stderr.

scripts/stop-review-gate-hook.mjs — runStopReview():

if (result.status !== 0) { const detail = String(result.stderr || result.stdout || "").trim(); return { ok: false, reason: detail ? The stop-time Codex review task failed: ${detail} : ... }; } stderr is preferred over stdout. Since stderr now always starts with the DEP0190 warning on Windows/Node 24, the warning displaces whatever useful diagnostics exist. The companion's structured JSON (with rawOutput, threadId) goes to stdout and is never shown.

Impact Every stop-gate failure on Windows + Node 24 presents as a deprecation warning, regardless of the true cause (quota, auth, network, app-server crash). Users debug the wrong thing. This also compounds #248 (gate blocking on infrastructure errors) by making those errors undiagnosable from the hook output.

Suggested fixes (any one of these helps) Filter warning noise from stderr before building the failure reason: drop lines matching /^(node:\d+) [DEP\d+]|DeprecationWarning|ExperimentalWarning/. Silence the warning at the source: spawn the companion/app-server child with NODE_OPTIONS=--no-deprecation (or pass a single command string when shell: true, which avoids DEP0190 entirely). Prefer structured output: when stdout parses as the companion's JSON, report rawOutput/job-log error content instead of raw stderr; fall back to stderr only when stdout is empty. Happy to provide the full job log excerpt if useful.

Reveludden avatar Jul 08 '26 07:07 Reveludden

+1 reproducing this on Windows 11 / Node v24.16.0 / codex-cli 0.144.6 / plugin 1.0.4.

Concrete reproduction: our stop-review-gate task returned this to Claude Code as the "failure" message, even though our SQL validator hotfix (the code under review) was actually fine:

The stop-time Codex review task failed: (node:27912) [DEP0190] DeprecationWarning: Passing args to a child process with shell option true can lead to security vulnerabilities, as the arguments are not escaped, only concatenated.

Additional data point: the DEP0190 can be fixed at source, not just masked

The three currently-proposed fixes (regex filter / NODE_OPTIONS=--no-deprecation / parse stdout) all treat the symptom. There's a 4th option that fixes the actual DEP0190 warning at its origin — the spawn call in scripts/lib/app-server.mjs:189-195:

this.proc = spawn("codex", ["app-server"], {
  cwd: this.cwd,
  env: this.options.env ?? process.env,
  stdio: ["pipe", "pipe", "pipe"],
  shell: process.platform === "win32" ? (process.env.SHELL || true) : false,
  windowsHide: true
});

Per Node.js DEP0190, passing an args array when shell: true is now deprecated — the command should be a single string.

The original need for shell: true on Windows was resolving .cmd shims via PATHEXT (see closed issue #85). A cleaner
fix is to resolve the shim explicitly and skip the shell entirely:

// Resolve .cmd/.bat on Windows so shell isn't needed
const command = process.platform === "win32" ? "codex.cmd" : "codex";
this.proc = spawn(command, ["app-server"], {
  cwd: this.cwd,
  env: this.options.env ?? process.env,
  stdio: ["pipe", "pipe", "pipe"],
  shell: false,
  windowsHide: true
});

If the deployment can't guarantee .cmd extension, which-cli / which module or a manual PATHEXT scan works.

Fixing at source has two benefits:
1. Eliminates the stderr noise entirely (the hook doesn't need to filter/parse around it)
2. Fixes the underlying security concern DEP0190 is warning about (arg injection via shell escape)

haocyclone avatar Jul 20 '26 04:07 haocyclone

Confirming this still reproduces on a current setup — not the stop-review-gate variant, but the same root cause surfacing as plain stdout/stderr noise on every codex-companion.mjs invocation (not just at stop-gate time):

Environment

  • Windows 11 (10.0.26200)
  • Node v24.13.0
  • codex-cli 0.145.0 (ChatGPT login)
  • codex plugin 1.0.6

Repro

node scripts/codex-companion.mjs task --wait --effort low "..."

prints, before any real output:

(node:35340) [DEP0190] DeprecationWarning: Passing args to a child process with shell option true can lead to security vulnerabilities, as the arguments are not escaped, only concatenated.
(Use `node --trace-deprecation ...` to show where the warning was created)

Traced it to the same two call sites already named here:

  • lib/app-server.mjs SpawnedCodexAppServerClient.initialize() — spawn("codex", ["app-server"], { shell: process.platform === "win32" ? (process.env.SHELL || true) : false, ... })
  • lib/process.mjs runCommand() — same shell: options.shell ?? (win32 ? (process.env.SHELL || true) : false) pattern, used by binaryAvailable (the setup/--version check) and by terminateProcessTree's taskkill call.

Worth noting this compounds with #525: on this machine SHELL is unset (not Git Bash), so it resolves to bare shell: true, which is what triggers DEP0190 specifically — git.mjs already sidesteps this correctly with a hardcoded shell: false per its comment ("Repository-derived arguments must never pass through a shell"). Of the fixes suggested above, "pass a single command string when shell: true" or gating on NODE_OPTIONS=--no-deprecation for the spawned child both look like they'd fix this at the source for every call site at once, not just the stop-gate reporting path.

Mikeymichs avatar Aug 02 '26 06:08 Mikeymichs

Follow-up with a resolved Windows-specific root cause from a separate failure path:

I later reproduced a CreateProcessAsUserW failed error while Codex was running commands inside the Windows read-only sandbox. Initially this looked like a sandbox/helper regression, because:

  • read-only and workspace-write both failed
  • danger-full-access succeeded
  • the companion/app-server path failed while direct unrestricted execution worked

The actual cause was the pwsh.exe being resolved from the Microsoft Store / WindowsApps location rather than the normal PowerShell 7 installation.

After changing resolution to:

C:\Program Files\PowerShell\7\pwsh.exe

the same read-only sandbox commands all completed with exit code 0, CreateProcessAsUserW failed disappeared, and the companion/plugin path worked again.

So the corrected diagnosis for that failure is:

The Windows sandbox itself was not generally broken; it could not successfully spawn the Store/WindowsApps pwsh.exe through CreateProcessAsUserW. Using the regular PowerShell 7 executable fixed it.

This does not change the original DEP0190 finding in this issue: shell: true with an args array still emits the deprecation warning on Node 24, and stderr-first reporting can still mask the actual underlying failure. It does add another concrete example of why surfacing the structured stdout/job-log error is important: the visible warning may have little or nothing to do with the real root cause.

haocyclone avatar Aug 06 '26 08:08 haocyclone

Another data point that I think widens this beyond Windows/Node 24: on macOS with Node 26 the hook reports an empty payload — no DEP0190, no error text at all. Same underlying failure (quota exhausted), same file, but the proposed DEP0190 filters would not have helped here.

Environment

  • macOS 15 (Darwin 25.6.0), Apple Silicon
  • Node v26.7.0
  • codex-cli 0.152.0 (ChatGPT login, codex login status reports "Logged in using ChatGPT" throughout)
  • codex plugin 1.0.6

What Claude Code showed, identically, three turns running:

The stop-time Codex review task failed: {
  "status": 1,
  "threadId": "01a061ac-0588-71f1-a348-491c0f53dc36",
  "rawOutput": "",
  "touchedFiles": [],
  "reasoningSummary": []
}

rawOutput is empty. There is no DeprecationWarning to filter out and no detail of any kind — so on this platform the reporting path fails in a way that produces strictly less information than the Windows case, where at least a wrong string appears.

The actual cause, found only by invoking codex exec by hand:

ERROR: You've hit your usage limit. Visit https://chatgpt.com/codex/settings/usage
to purchase more credits or try again at Sep 6th, 2026 10:26 PM.

Why this is worth separating from the DEP0190 symptom

The three fixes floated above (regex-filter DEP0190 / NODE_OPTIONS=--no-deprecation / parse stdout) all address stderr carrying the wrong content. They do not address stderr carrying nothing, which is what happens here. Whatever the platform-specific mechanism, the shared defect is that runStopReview() surfaces a single opaque status: 1 for every failure class, so a recoverable billing condition and a genuine review failure are indistinguishable to the reader.

Two things made this expensive to diagnose:

  1. codex login status keeps reporting a healthy ChatGPT login when the quota is exhausted, so the obvious first check points away from the real cause.
  2. The gate re-fires every turn. With no usable error text it produced three identical blocking failures before I thought to probe codex exec directly. Since quota resets can be days out (mine: Sep 6), that is potentially days of identical false alarms — and any genuine stop-hook failure in that window would be buried among them.

Suggested handling for the quota class specifically

Quota exhaustion is knowable, recoverable, and carries a reset timestamp. Rather than only widening what stderr captures, it would help to detect it and return a distinct status the hook can act on — e.g. report "Codex quota exhausted, resets <date>; stop-review skipped" and skip rather than block. A gate that cannot run is not the same as a review that failed, and blocking on the former gives the user no action they can take for four days except disable the gate (which is what I ended up doing via /codex:setup --disable-review-gate).

Happy to test a patch on macOS/Node 26 if that's useful.

bhavenmurji avatar Sep 02 '26 12:09 bhavenmurji