{"record":{"id":"bdd192586e92356e","repo":"abhigyanpatwari/GitNexus","slug":"label-file-target-has-the-wrong-type-relative","errorCode":null,"errorMessage":"{label} file target has the wrong type: {relative}","messagePattern":"(.+?) file target has the wrong type: (.+?)","errorType":"exception","errorClass":"SandboxError","httpStatus":null,"severity":"error","filePath":"eval/workflow_bench/proposer_sandbox.py","lineNumber":624,"sourceCode":"        leaf = relative.parts[-1]\n        try:\n            mode = os.stat(leaf, dir_fd=current_fd, follow_symlinks=False).st_mode\n        except FileNotFoundError:\n            mode = None\n        if mode is not None and stat.S_ISLNK(mode):\n            raise SandboxError(f\"{label} target cannot be a symlink: {relative}\")\n        if directory is True:\n            if mode is None:\n                os.mkdir(leaf, mode=0o700, dir_fd=current_fd)\n            elif not stat.S_ISDIR(mode):\n                raise SandboxError(f\"{label} directory target has the wrong type: {relative}\")\n        elif directory is False:\n            if mode is None:\n                file_flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL | nofollow\n                file_fd = os.open(leaf, file_flags, 0o600, dir_fd=current_fd)\n                os.close(file_fd)\n            elif not stat.S_ISREG(mode):\n                raise SandboxError(f\"{label} file target has the wrong type: {relative}\")\n        elif mode is not None and not (stat.S_ISREG(mode) or stat.S_ISDIR(mode)):\n            raise SandboxError(f\"{label} target has the wrong type: {relative}\")\n    finally:\n        os.close(current_fd)\n    return clone / Path(*relative.parts)\n\n\ndef stage_task_assets(\n    task: Mapping[str, Any],\n    *,\n    repo: Path,\n    clone: Path,\n) -> list[ReadOnlyMount]:\n    \"\"\"Compatibility wrapper for immutable task-asset staging.\"\"\"\n\n    # Kept lazy to avoid a module cycle: task_assets uses the sandbox's\n    # shared error, mount, and no-follow target primitives.\n    from .task_assets import stage_task_assets as stage_immutable_task_assets","sourceCodeStart":606,"sourceCodeEnd":642,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/d540b00184d71a896261ee02670da9a92d59d8f7/eval/workflow_bench/proposer_sandbox.py#L606-L642","documentation":"Raised by _prepare_clone_target when the caller asked for a file target (directory=False), the leaf exists, but it is not a regular file (e.g. it is a directory, socket, or device). The harness creates the file only when absent (O_CREAT|O_EXCL|O_NOFOLLOW) and otherwise requires an existing regular file; any other type is rejected to avoid writing through a non-file node.","triggerScenarios":"_prepare_clone_target(..., directory=False) finds an existing leaf whose mode fails stat.S_ISREG — for instance a task declares a file-shaped target but a directory already occupies that path.","commonSituations":"A task target path was previously used as a directory and is now declared as a file (or vice versa); leftover state from a prior run; a tracked directory sits where a file mount placeholder is wanted.","solutions":["Check the leaf type: `stat -c '%F' <worktree>/<leaf>`.","If a directory is colliding, remove it from the repo or move the file target to a path not occupied by a directory.","Use a clean worktree so generated state from earlier runs cannot collide.","Align the task's declared target type (file vs directory) with the real on-disk type at that path."],"exampleFix":"// before — file target collides with a tracked directory\ntarget: eval/marker   # directory=False, but eval/marker is a dir\n// after — point the file target elsewhere or remove the directory\ngit rm -r eval/marker","handlingStrategy":"validation","validationCode":"import os, stat\nfrom pathlib import PurePosixPath\n\ndef file_target_ok(clone: Path, relative: str) -> bool:\n    parts = PurePosixPath(relative).parts\n    pfd = os.open(clone, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW)\n    try:\n        for p in parts[:-1]:\n            nxt = os.open(p, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=pfd)\n            os.close(pfd); pfd = nxt\n        try:\n            mode = os.stat(parts[-1], dir_fd=pfd, follow_symlinks=False).st_mode\n            return stat.S_ISREG(mode)\n        except FileNotFoundError:\n            return True  # will be created\n    finally:\n        os.close(pfd)","typeGuard":null,"tryCatchPattern":"from .proposer_sandbox import SandboxError\n\ntry:\n    target = _prepare_clone_target(clone, PurePosixPath(rel), directory=False, label='file')\nexcept SandboxError:\n    # leaf exists but is not a regular file; clear or reroute\n    raise","preventionTips":["Do not reuse a path as both a file and directory target across runs.","Use a clean worktree per arm.","Validate leaf types before declaring them as file targets."],"tags":["sandbox","path-validation","trust-boundary","task-assets"],"backgroundTag":null,"analyzedSha":"d540b00184d71a896261ee02670da9a92d59d8f7","analyzedAt":"2026-08-12T19:50:25.132Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}