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

EISDIR crash in working-tree review when untracked directories exist

Open cheickmec opened this issue 8 months ago • 0 comments

Bug

/codex:adversarial-review --scope working-tree (and likely /codex:review --scope working-tree) crashes with EISDIR: illegal operation on a directory, read when the working tree contains untracked directories.

Reproduction

  1. Have any untracked directory in your repo (e.g., .claude/worktrees/agent-*/, or any mkdir foo && git status)
  2. Run: node scripts/codex-companion.mjs adversarial-review --wait --scope working-tree "any prompt"
  3. Result: EISDIR: illegal operation on a directory, read

Root Cause

In scripts/lib/git.mjs, formatUntrackedFile() (line ~136) does not check stat.isDirectory() before calling fs.readFileSync():

function formatUntrackedFile(cwd, relativePath) {
  const absolutePath = path.join(cwd, relativePath);
  const stat = fs.statSync(absolutePath);
  if (stat.size > MAX_UNTRACKED_BYTES) {
    return `...skipped...`;
  }
  const buffer = fs.readFileSync(absolutePath);  // CRASHES here when absolutePath is a directory
  ...
}

The untracked file list comes from git ls-files --others --exclude-standard (line ~64), which can return directory paths.

Suggested Fix

Add a directory check before the read:

function formatUntrackedFile(cwd, relativePath) {
  const absolutePath = path.join(cwd, relativePath);
  const stat = fs.statSync(absolutePath);
  if (stat.isDirectory()) {
    return `### ${relativePath}\n(skipped: directory)`;
  }
  // ... rest of function
}

Environment

  • codex-plugin-cc 1.0.0
  • Codex CLI 0.117.0
  • macOS 15 (Darwin 25.3.0)
  • Node.js v20.19.0

cheickmec avatar Mar 30 '26 21:03 cheickmec