abhigyanpatwari/GitNexus · error · SandboxError

{label} target has the wrong type: {relative}

Error message

{label} target has the wrong type: {relative}

What it means

Raised by _prepare_clone_target in the type-agnostic branch (directory=None): the leaf exists and is neither a regular file nor a directory (e.g. a FIFO, socket, character/block device). The harness allows an existing leaf only if it is a plain file or directory; any other node type is rejected because mounting or writing through it is undefined and unsafe.

Source

Thrown at eval/workflow_bench/proposer_sandbox.py:626

            mode = os.stat(leaf, dir_fd=current_fd, follow_symlinks=False).st_mode
        except FileNotFoundError:
            mode = None
        if mode is not None and stat.S_ISLNK(mode):
            raise SandboxError(f"{label} target cannot be a symlink: {relative}")
        if directory is True:
            if mode is None:
                os.mkdir(leaf, mode=0o700, dir_fd=current_fd)
            elif not stat.S_ISDIR(mode):
                raise SandboxError(f"{label} directory target has the wrong type: {relative}")
        elif directory is False:
            if mode is None:
                file_flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL | nofollow
                file_fd = os.open(leaf, file_flags, 0o600, dir_fd=current_fd)
                os.close(file_fd)
            elif not stat.S_ISREG(mode):
                raise SandboxError(f"{label} file target has the wrong type: {relative}")
        elif mode is not None and not (stat.S_ISREG(mode) or stat.S_ISDIR(mode)):
            raise SandboxError(f"{label} target has the wrong type: {relative}")
    finally:
        os.close(current_fd)
    return clone / Path(*relative.parts)


def stage_task_assets(
    task: Mapping[str, Any],
    *,
    repo: Path,
    clone: Path,
) -> list[ReadOnlyMount]:
    """Compatibility wrapper for immutable task-asset staging."""

    # Kept lazy to avoid a module cycle: task_assets uses the sandbox's
    # shared error, mount, and no-follow target primitives.
    from .task_assets import stage_task_assets as stage_immutable_task_assets

    return stage_immutable_task_assets(task, repo=repo, clone=clone)

View on GitHub (pinned to d540b00184)

Solutions

  1. Identify the node type: `stat -c '%F' <worktree>/<leaf>`.
  2. Remove the special file from the repo or reroute the target to a clean path.
  3. Recreate the worktree from a clean detached checkout so no stale special nodes persist.
  4. Audit any setup script for mkfifo/socket/device creation at harness-managed paths.

Example fix

// before — a leftover FIFO occupies the target path
target: eval/workflow_bench/run.fifo
// after — remove the stale special node
rm <worktree>/eval/workflow_bench/run.fifo   # or git rm if tracked
Defensive patterns

Strategy: validation

Validate before calling

import os, stat
from pathlib import PurePosixPath

def leaf_is_file_or_dir_or_absent(clone: Path, relative: str) -> bool:
    parts = PurePosixPath(relative).parts
    pfd = os.open(clone, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW)
    try:
        for p in parts[:-1]:
            nxt = os.open(p, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=pfd)
            os.close(pfd); pfd = nxt
        try:
            mode = os.stat(parts[-1], dir_fd=pfd, follow_symlinks=False).st_mode
            return stat.S_ISREG(mode) or stat.S_ISDIR(mode)
        except FileNotFoundError:
            return True
    finally:
        os.close(pfd)

Try / catch

from .proposer_sandbox import SandboxError

try:
    target = _prepare_clone_target(clone, PurePosixPath(rel), directory=None, label='target')
except SandboxError:
    # leaf is a FIFO/socket/device; remove it or reroute
    raise

Prevention

When it happens

Trigger: _prepare_clone_target(..., directory=None) finds an existing leaf whose mode is neither stat.S_ISREG nor stat.S_ISDIR — for example a leftover FIFO/socket/device node at the target path inside the clone.

Common situations: A previous test or setup step created a FIFO/socket at the target path (common with test fixtures that mkfifo); a tracked special file occupies the path; a malformed artifact from a crashed run was left behind.

Related errors


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