abhigyanpatwari/GitNexus · error · RuntimeError

ref {ref!r} not found in clone of {repo}

Error message

ref {ref!r} not found in clone of {repo}

What it means

Thrown by make_worktree after it tries `git checkout --detach` for both the bare ref and the origin/-prefixed ref. If neither checkout succeeds, the requested ref does not exist in the freshly cloned repository, so the arm cannot start from the intended baseline.

Source

Thrown at eval/workflow_bench/runner_artifacts.py:332

                str(repo),
                str(target),
            ],
            timeout=600,
        )
        alternates = target / ".git" / "objects" / "info" / "alternates"
        if alternates.exists():
            raise RuntimeError(f"clone unexpectedly has an external object alternate: {alternates}")
        for obj in (target / ".git" / "objects").rglob("*"):
            if obj.is_file() and obj.stat().st_nlink > 1:
                raise RuntimeError(f"clone object is hardlinked to host storage: {obj}")
        for candidate in (ref, f"origin/{ref}"):
            proc = run_managed(
                ["git", "-C", str(target), "checkout", "--detach", "--quiet", candidate],
                timeout=60,
            )
            if proc.ok:
                return target
        raise RuntimeError(f"ref {ref!r} not found in clone of {repo}")
    except BaseException as primary:
        if target.exists():
            try:
                shutil.rmtree(target)
            except OSError as cleanup:
                primary.add_note(f"clone cleanup also failed: {type(cleanup).__name__}: {cleanup}")
        raise


def remove_clone(clone: Path) -> None:
    """Delete one throwaway arm clone (created by make_worktree)."""

    shutil.rmtree(clone)


def parse_shortstat(text: str) -> dict[str, int]:
    """Parse `git diff --shortstat` output into churn counters."""

View on GitHub (pinned to d540b00184)

Solutions

  1. Verify the ref exists on the source: `git ls-remote --heads --tags <repo> | grep <ref>`.
  2. Correct the `ref` field in the task definition to an existing branch or tag (or its full refs/heads/... / refs/tags/... form).
  3. If the ref is a tag, note the harness clones with --no-tags; fetch it explicitly or use a branch ref.
  4. Ensure the clone is not shallow/partial for the ref you need.

Example fix

// before — task ref points at a non-existent branch
{"id": "t1", "repo": "...", "ref": "feature/old-name", ...}

// after — use a ref that exists on the remote
{"id": "t1", "repo": "...", "ref": "main", ...}
Defensive patterns

Strategy: validation

Validate before calling

import subprocess

def ref_exists(repo: str, ref: str) -> bool:
    out = subprocess.run(['git', 'ls-remote', '--heads', '--tags', repo],
                         capture_output=True, text=True)
    refs = {line.split()[-1] for line in out.stdout.splitlines()}
    return f'refs/heads/{ref}' in refs or f'refs/tags/{ref}' in refs or ref in refs

Type guard

null

Try / catch

try:
    make_worktree(repo, ref, parent)
except RuntimeError as e:
    if 'not found in clone' in str(e):
        print('ref missing on remote; pick an existing branch/tag')
        raise
    raise

Prevention

When it happens

Trigger: For candidate in [ref, f'origin/{ref}'], `run_managed([... 'checkout','--detach', candidate]).ok` is False for both. The ref was not fetched, was misspelled, or only exists as a remote-tracking ref under a different name.

Common situations: The task config's `ref` field points to a branch/tag that does not exist on the source remote; `--no-tags` stripped a tag-only ref; the ref is local to a fork not configured as origin; typo in the ref name; shallow/partial clone excluded the ref.

Related errors


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