affaan-m/ECC · error · Error

Codex review failed ` : ''}

Error message

Codex review failed${detail ? `: ${detail}` : ''}

What it means

When the spawned Codex process finishes but exits with a non-zero status code (result.status !== 0, with no result.error), the library treats it as a review failure. It takes the last line of the process's stderr as detail and throws 'Codex review failed: <detail>'.

Solutions

  1. Read the detail appended to the error message — it is the final stderr line from Codex and names the real cause.
  2. Verify Codex authentication (run `codex` interactively or check its auth/config; re-login if needed).
  3. Update the Codex CLI to the version this script targets (`npm update -g @openai/codex`) — flag mismatches after upgrades are common.
  4. Check quota/rate limits if the detail mentions 429/limit.
  5. Re-run with a smaller prompt if the detail suggests payload or content issues.

Example fix

// before
throw new Error(`Codex review failed: ${detail}`); // e.g. 'Unauthorized: invalid api key'
// after (user side)
codex auth login   # refresh credentials, then re-run the review
Defensive patterns

Strategy: try-catch

Try / catch

try {
  return runReview(opts);
} catch (e) {
  if (e.message.startsWith('Codex review failed')) {
    const detail = e.message.replace('Codex review failed: ', '');
    if (/auth|unauthorized|api key/i.test(detail)) await refreshCodexAuth();
    else if (/429|rate limit/i.test(detail)) await backoff();
  }
  throw e;
}

Prevention

When it happens

Trigger: The codex CLI runs to completion but exits non-zero — invalid/missing API key, refused request, malformed invocation arguments the library passed, or an internal Codex error — with no spawn-level error object.

Common situations: Expired or missing OpenAI credentials; Codex CLI version changed its CLI flags so the constructed arguments are rejected; rate limit or quota exhaustion printing an error to stderr; the review prompt triggering a content refusal.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of affaan-m/ECC@8321021c54 (2026-09-16). Data as JSON: /api/errors/eab73efbbc96188f. Report an issue: GitHub.

Appendix: source

Thrown at skills/council-multi-model/scripts/review-with-codex.js:219

  try {
    const result = spawn('codex', buildCodexArgs(tempDir, outputFile), {
      cwd: tempDir,
      env: environment,
      input: prompt,
      encoding: 'utf8',
      timeout: options.timeoutMs,
      maxBuffer: 1024 * 1024,
      windowsHide: true,
    });

    if (result.error) {
      if (result.error.code === 'ETIMEDOUT') throw new Error('Codex review timed out');
      if (result.error.code === 'ENOENT') throw new Error('Codex CLI is not installed');
      throw new Error(`Codex invocation failed: ${result.error.message}`);
    }
    if (result.status !== 0) {
      const detail = (result.stderr || '').trim().split('\n').slice(-1)[0];
      throw new Error(`Codex review failed${detail ? `: ${detail}` : ''}`);
    }

    let text;
    try {
      text = readFile(outputFile, 'utf8').trim();
    } catch (error) {
      throw new Error(`Codex returned no final response: ${error.message}`);
    }
    if (!text) throw new Error('Codex returned an empty final response');
    return `${providerLabel(options.hostProvider)}\n${text}`;
  } finally {
    remove(tempDir, { recursive: true, force: true });
  }
}

function runStdinReview(options, dependencies = {}) {
  const stdin = dependencies.stdin || process.stdin;
  const stdout = dependencies.stdout || process.stdout;

View on GitHub (pinned to 8321021c54)