Skip to content

POSIX xargs Apostrophe Failure Silently Erases Feature Detection #14

Open

Description

@Madhumasa84

Summary

_detect_features_fast feeds a newline-separated file list into xargs grep without -d '\n' or -0. If any file in the target repository has an apostrophe or single quote in its path (e.g. src/don't_crash.js), xargs fails with unmatched single quote and outputs nothing. The recon step silently detects 0 features.

Root Cause

In openhack/deterministic_recon.py:182-190:

cmd = ["xargs", "grep", "-Fl", "--max-count=1", "--binary-files=without-match"]
proc = subprocess.run(cmd, input=file_list, capture_output=True, text=True, timeout=15)

POSIX xargs treats single quotes as quoting characters by default.

Reproduction

touch "don't_break.js"
# xargs grep fails with returncode=1, stderr="xargs: unmatched single quote", stdout=""

Impact

A single apostrophe anywhere in the target repository's filenames completely blacks out deterministic feature detection for all categories.

Proposed Fix

Pass -d '\n' to xargs:

cmd = ["xargs", "-d", "\n", "grep", "-Fl", "--max-count=1", "--binary-files=without-match"]

Activity

  1. mlgxiii commented on Nov 20, 2026

    @mlgxiii

    _detect_features_fast passes newline-separated paths to xargs grep without -0 or -d '\n', so an apostrophe can be treated as shell quoting and leave feature detection empty.
    Every Python invocation that feeds a file list to xargs can be checked for a delimiter.

    a check that keeps it fixed:

    version: 1
    id: xargs-file-list-delimiter
    title: Python code that runs xargs on a file list passes -0 or -d '\n'
    description: Python code that runs xargs on a file list passes -0 or -d '\n', so
      paths with quotes are not parsed as shell quoting
    select:
      glob: openhack/**/*.py
      grep: xargs
    assert:
      - id: delimit-file-paths
        description: Every xargs invocation that consumes a file list uses -0 or -d '\n'.
        error: Pass -0 or -d '\n' to xargs when it consumes a file list.
        decide: Pass if every xargs invocation that consumes a file list passes -0 or -d
          '\n'; fail if any such invocation omits both.

    On main (6a0675e) it flags openhack/deterministic_recon.py. Note the same pattern is also at line 213 (cmd_parts = ["xargs", "grep", "-El", ...]): with only line 182 fixed the check still fails; with both, it passes.

    Run npx agentests run in CI, or --staged as a pre-commit hook. It flags the pattern in new changes; the existing files still need the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions