abhigyanpatwari/GitNexus · critical · ValueError

clone HEAD is not an immutable commit

Error message

clone HEAD is not an immutable commit

What it means

Raised by sanitize_clone_for_hidden_oracles when `git rev-parse --verify HEAD^{commit}` does not return a string of exactly 40 or 64 hexadecimal characters (i.e. a SHA-1 or SHA-256 object id). Without a valid immutable commit at HEAD, the sanitizer cannot record the original HEAD for later update-ref and cannot guarantee a known starting point for history rewriting.

Source

Thrown at eval/workflow_bench/oracle_assets.py:272

    try:
        root_metadata = root.lstat()
        git_metadata = (root / ".git").lstat()
    except OSError as exc:
        raise ValueError(f"oracle sanitization requires a self-contained clone: {root}") from exc
    if (
        stat.S_ISLNK(root_metadata.st_mode)
        or not stat.S_ISDIR(root_metadata.st_mode)
        or root.resolve(strict=True) != root
        or stat.S_ISLNK(git_metadata.st_mode)
        or not stat.S_ISDIR(git_metadata.st_mode)
    ):
        raise ValueError(f"oracle sanitization requires a real self-contained clone: {root}")

    original_head = _git_checked(root, ["rev-parse", "--verify", "HEAD^{commit}"])
    if len(original_head) not in {40, 64} or any(
        character not in "0123456789abcdefABCDEF" for character in original_head
    ):
        raise ValueError("clone HEAD is not an immutable commit")

    hidden_tree_result = run_managed(
        [
            "git",
            "-C",
            str(root),
            "ls-tree",
            "-d",
            "--format=%(objectname)",
            "HEAD",
            "--",
            HIDDEN_HARNESS_PATH.as_posix(),
        ],
        timeout=60,
        tail_bytes=1024,
    )
    if not hidden_tree_result.ok:
        raise ValueError("cannot inspect the clone for committed benchmark harness data")

View on GitHub (pinned to d540b00184)

Solutions

  1. Ensure the clone has at least one real commit on HEAD before sanitizing.
  2. Re-clone from the source to get a valid HEAD commit.
  3. Run `git -C <clone> rev-parse --verify HEAD^{commit}` manually and confirm it prints a 40- or 64-char hex SHA.
  4. Check the clone is not shallow/corrupted with `git fsck`.
Defensive patterns

Strategy: validation

Validate before calling

import re
from eval.workflow_bench.oracle_assets import _git_checked

def assert_head_commit(clone) -> None:
    head = _git_checked(clone, ["rev-parse", "--verify", "HEAD^{commit}"])
    if not re.fullmatch(r"[0-9a-fA-F]{40}|[0-9a-fA-F]{64}", head):
        raise ValueError(f"HEAD is not a valid commit SHA: {head!r}")

Type guard

def head_is_immutable_commit(clone) -> bool:
    import re
    from eval.workflow_bench.oracle_assets import _git_checked
    try:
        head = _git_checked(clone, ["rev-parse", "--verify", "HEAD^{commit}"])
    except Exception:
        return False
    return bool(re.fullmatch(r"[0-9a-fA-F]{40}|[0-9a-fA-F]{64}", head))

Try / catch

try:
    head = sanitize_clone_for_hidden_oracles(clone)
except ValueError as exc:
    if "not an immutable commit" in str(exc):
        raise SystemExit("Clone HEAD is unborn/invalid; commit at least once or re-clone") from exc
    raise

Prevention

When it happens

Trigger: The clone has no commits (unborn HEAD, fresh `git init` with nothing committed); HEAD is detached at a tag or non-commit object; git rev-parse output is malformed/empty; a corrupted repository where HEAD is not resolvable to a commit.

Common situations: Sanitizing a brand-new empty repo; a clone that failed to fetch any commits; a shallow clone with a broken HEAD; repository corruption; an unusual git version producing unexpected rev-parse output.

Related errors


AI-assisted analysis of abhigyanpatwari/GitNexus@d540b00184 (2026-08-12). Data as JSON: /api/errors/7167208ccbfd34f8. Report an issue: GitHub.