{"record":{"id":"375c9f6b5b4f9bdc","repo":"abhigyanpatwari/GitNexus","slug":"repository-root-must-be-a-real-directory-root","errorCode":null,"errorMessage":"repository root must be a real directory: {root}","messagePattern":"repository root must be a real directory: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"eval/workflow_bench/promotion_apply.py","lineNumber":158,"sourceCode":"\n    if (\n        stat.S_ISLNK(final.st_mode)\n        or not stat.S_ISREG(final.st_mode)\n        or not (identity(before) == identity(opened) == identity(after) == identity(final))\n    ):\n        raise ValueError(f\"overlay destination changed while being read: {target}\")\n    return b\"\".join(chunks), opened.st_mode\n\n\ndef _open_repository_root(repo_root: Path) -> tuple[Path, int]:\n    root = repo_root.expanduser().absolute()\n    try:\n        metadata = root.lstat()\n        resolved = root.resolve(strict=True)\n    except OSError as exc:\n        raise ValueError(f\"repository root is unavailable: {root}\") from exc\n    if stat.S_ISLNK(metadata.st_mode) or not stat.S_ISDIR(metadata.st_mode):\n        raise ValueError(f\"repository root must be a real directory: {root}\")\n    if resolved != root:\n        raise ValueError(f\"repository root must not traverse symlinks: {root}\")\n    flags = os.O_RDONLY | os.O_DIRECTORY | getattr(os, \"O_CLOEXEC\", 0) | getattr(os, \"O_NOFOLLOW\", 0)\n    try:\n        descriptor = os.open(root, flags)\n    except OSError as exc:\n        raise ValueError(f\"repository root changed while opening: {root}\") from exc\n    try:\n        opened = os.fstat(descriptor)\n        final = root.lstat()\n        final_resolved = root.resolve(strict=True)\n\n        def identity(value: os.stat_result) -> tuple[int, int, int]:\n            return value.st_dev, value.st_ino, stat.S_IFMT(value.st_mode)\n\n        if (\n            stat.S_ISLNK(final.st_mode)\n            or not stat.S_ISDIR(opened.st_mode)","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/d540b00184d71a896261ee02670da9a92d59d8f7/eval/workflow_bench/promotion_apply.py#L140-L176","documentation":"All errors below are raised by internal helpers of `eval/workflow_bench/promotion_apply.py` and propagate to the caller of the public entry points: `apply_promoted_overlay(overlay, repo_root, *, expected_digest, expected_target_bases)`, `destination_base_digests(overlay, repo_root)`, `committed_destination_base_digests(overlay, repo_root, *, ref)` and `freeze_overlay(overlay, destination)`. The module applies promoted skill overlays across the canonical skill tree plus its shipped mirrors (`gitnexus/skills`, `gitnexus-claude-plugin/skills`) in a TOCTOU-hardened, symlink-rejecting, descriptor-bound transaction. After `lstat`/`resolve` succeed, `_open_repository_root` checks `stat.S_ISLNK(metadata.st_mode) or not stat.S_ISDIR(metadata.st_mode)`. A symlink-to-a-dir, a regular file, a socket, or any non-directory trips the guard. The repository root must be a literal on-disk directory.","triggerScenarios":"Pointing `repo_root` at a symlink (even one targeting a real dir), a regular file, or any non-directory filesystem entry.","commonSituations":"Operator symlinked the checkout for convenience; `repo_root` accidentally resolves to a tarball/sparse-file; default `REPO_ROOT` miscomputed via `parents[N]` after a file move.","solutions":["Inspect the entry: `pathlib.Path(root).lstat()` and confirm `S_ISDIR` and not `S_ISLNK`.","Replace any symlink with a real directory (`readlink` then bind-mount or move).","Re-derive and pass the real checkout directory explicitly."],"exampleFix":"// before\nroot = Path('/repo')  # /repo -> /data/checkout (symlink)\napply_promoted_overlay(overlay, repo_root=root)\n// after\nroot = Path('/data/checkout')  # the real directory\nassert root.is_dir() and not root.is_symlink()\napply_promoted_overlay(overlay, repo_root=root)","handlingStrategy":"validation","validationCode":"def assert_real_dir(p):\n    root = Path(p).expanduser().absolute()\n    st = root.lstat()\n    if stat.S_ISLNK(st.st_mode) or not stat.S_ISDIR(st.st_mode):\n        raise ValueError(f'repo_root must be a real directory, got: {root}')\n    return root","typeGuard":"import stat\ndef is_real_directory(p: str) -> bool:\n    root = Path(p)\n    try:\n        st = root.lstat()\n    except OSError:\n        return False\n    return (not stat.S_ISLNK(st.st_mode)) and stat.S_ISDIR(st.st_mode)","tryCatchPattern":"except ValueError as exc:\n    if 'must be a real directory' in str(exc):\n        raise SystemExit(f'repo_root is a symlink or non-directory: {exc}')","preventionTips":["Never symlink the repository root; promotion rejects symlinks by design.","In CI, clone into a fresh real directory rather than a symlinked cache path.","Unit-test `is_real_directory(repo_root)` in your harness before applying overlays."],"tags":["filesystem","security","symlink","repository-root","validation"],"backgroundTag":null,"analyzedSha":"d540b00184d71a896261ee02670da9a92d59d8f7","analyzedAt":"2026-08-12T19:50:25.132Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}