abhigyanpatwari/GitNexus · error · ValueError

overlay snapshot destination already exists: {destination}

Error message

overlay snapshot destination already exists: {destination}

What it means

freeze_overlay writes the authorized overlay payload into a freshly-created, read-only snapshot directory via tempfile.mkdtemp + atomic os.replace. As a transactional safety guard it refuses any pre-existing destination (exists() OR is_symlink()) so it can never clobber or be tricked via a symlink into writing elsewhere.

Source

Thrown at eval/workflow_bench/promotion_apply.py:53

            f"({type(cleanup).__name__}: {cleanup})"
        )


def mirror_targets(relative: PurePosixPath) -> list[PurePosixPath]:
    """Every repo path one overlay file lands on: canonical + shipped mirrors."""
    skill = relative.parts[2]
    rest = PurePosixPath(*relative.parts[3:])
    targets = [relative]
    targets += [PurePosixPath(root, skill, rest) for root in MIRROR_SKILL_ROOTS]
    return targets


def freeze_overlay(overlay: Path, destination: Path) -> str:
    """Copy authorized bytes into a private, read-only benchmark snapshot."""
    digest, payload = candidate_overlay_payload(overlay)
    destination = destination.expanduser().absolute()
    if destination.exists() or destination.is_symlink():
        raise ValueError(f"overlay snapshot destination already exists: {destination}")
    destination.parent.mkdir(parents=True, exist_ok=True)
    staging = Path(tempfile.mkdtemp(prefix=".overlay-snapshot-", dir=destination.parent))
    try:
        for relative, content in payload:
            target = staging / relative
            target.parent.mkdir(parents=True, exist_ok=True, mode=0o700)
            descriptor = os.open(target, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o400)
            try:
                with os.fdopen(descriptor, "wb", closefd=False) as handle:
                    handle.write(content)
                    handle.flush()
                    os.fsync(handle.fileno())
            finally:
                os.close(descriptor)
        for directory in sorted(
            (path for path in staging.rglob("*") if path.is_dir()),
            key=lambda path: len(path.parts),
            reverse=True,

View on GitHub (pinned to d540b00184)

Solutions

  1. Remove the prior destination first (after verifying it is safe) or choose a unique destination name per run.
  2. Audit the destination path: it must not be a symlink and must not pre-exist before freeze_overlay.
  3. If you see a symlink where you expected a directory, treat it as a security incident — do not unlink blindly.
  4. Make the caller idempotent by hashing the overlay into the destination name.

Example fix

// before
freeze_overlay(overlay, dest)  # second run blows up
// after
if dest.exists() or dest.is_symlink():
    raise SystemExit(f'refusing to reuse snapshot {dest}')
freeze_overlay(overlay, dest.with_name(dest.name + '-' + digest[:12]))
Defensive patterns

Strategy: validation

Validate before calling

def ensure_fresh_destination(destination: Path) -> None:
    if destination.exists() or destination.is_symlink():
        raise SystemExit(f'refusing to overwrite existing snapshot {destination}; remove it first')

# call before freeze_overlay(overlay, destination)

Type guard

from pathlib import Path
import stat

def is_safe_unused_destination(p: str | Path) -> bool:
    path = Path(p)
    try:
        meta = path.lstat()
    except FileNotFoundError:
        return True
    # Anything that exists (incl. dangling symlink) is unsafe.
    return False

Try / catch

try:
    freeze_overlay(overlay, destination)
except ValueError as exc:
    if 'already exists' in str(exc):
        destination = destination.with_name(destination.name + '-' + secrets.token_hex(4))
        freeze_overlay(overlay, destination)
    else:
        raise

Prevention

When it happens

Trigger: Calling freeze_overlay(overlay, destination) when destination already exists (file or dir) or is a dangling/present symlink. Re-running a promotion twice, or pointing at a path that another process created.

Common situations: Re-running the promotion pipeline without clearing the prior snapshot; CI retry against the same destination; destination is a symlink (possibly attacker-planted) that would redirect the write.

Related errors


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