{"record":{"id":"7733d023cf9c69e2","repo":"abhigyanpatwari/GitNexus","slug":"label-directory-target-has-the-wrong-type-rela","errorCode":null,"errorMessage":"{label} directory target has the wrong type: {relative}","messagePattern":"(.+?) directory target has the wrong type: (.+?)","errorType":"exception","errorClass":"SandboxError","httpStatus":null,"severity":"error","filePath":"eval/workflow_bench/proposer_sandbox.py","lineNumber":617,"sourceCode":"            try:\n                next_fd = os.open(part, flags | nofollow, dir_fd=current_fd)\n            except OSError as exc:\n                raise SandboxError(f\"{label} target has a non-directory or symlink parent: {relative}\") from exc\n            os.close(current_fd)\n            current_fd = next_fd\n\n        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,","sourceCodeStart":599,"sourceCodeEnd":635,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/d540b00184d71a896261ee02670da9a92d59d8f7/eval/workflow_bench/proposer_sandbox.py#L599-L635","documentation":"Raised by _prepare_clone_target when the caller asked for a directory target (directory=True) and the leaf already exists but is not a directory (e.g. a regular file, socket, or device). The harness refuses to overwrite or follow it; the mount placeholder must be a real directory, so a type mismatch aborts staging.","triggerScenarios":"_prepare_clone_target(..., directory=True) finds an existing leaf whose mode fails stat.S_ISDIR — for example a task declares a directory-shaped dependency mount but a regular file already sits at that path in the clone.","commonSituations":"A dependency-snapshot directory path collides with a tracked regular file; a prior run left a file where a directory is now expected; task authoring changed a target from file to directory without clearing the old artifact.","solutions":["Check the leaf type at the path in the error: `stat -c '%F' <worktree>/<leaf>`.","If a tracked file is colliding, remove it from the repo or change the task target path so the directory placeholder does not overlap the file.","If the collision is generated state, ensure the worktree is freshly created and setup does not write a file at that path.","Reconcile the task's declared target type with what actually lives at that path."],"exampleFix":"// before — task wants a directory but a file is tracked there\ntarget: .vite-temp   # directory=True, but a file .vite-temp exists\n// after — remove the tracked file so the dir placeholder can be created\ngit rm .vite-temp","handlingStrategy":"validation","validationCode":"import os, stat\nfrom pathlib import PurePosixPath\n\ndef dir_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_ISDIR(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=True, label='dep')\nexcept SandboxError:\n    # leaf exists but is not a directory; clear or reroute\n    raise","preventionTips":["Keep task target types stable across changes (don't flip file<->directory).","Use clean worktrees so stale artifacts cannot collide.","Document each target's expected type next to its declaration."],"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"}