{"record":{"id":"ec61b6720deef3b2","repo":"abhigyanpatwari/GitNexus","slug":"oracle-stage-parent-must-be-a-real-directory-ite","errorCode":null,"errorMessage":"oracle stage parent must be a real directory: {item.target}","messagePattern":"oracle stage parent must be a real directory: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"eval/workflow_bench/oracle_assets.py","lineNumber":470,"sourceCode":"    parents = _git_checked(root, [\"show\", \"-s\", \"--format=%P\", \"HEAD\"], timeout=60)\n    if parents:\n        raise ValueError(\"oracle sanitization snapshot unexpectedly retained parent history\")\n    if _git_checked(root, [\"remote\"], timeout=60):\n        raise ValueError(\"oracle sanitization retained a repository remote\")\n    if logs.exists() or logs.is_symlink():\n        raise ValueError(\"oracle sanitization retained reflog metadata\")\n    return sanitized_head\n\n\ndef _write_stage_file(stage_root: Path, item: OracleFileSnapshot) -> None:\n    destination = stage_root.joinpath(*PurePosixPath(item.target).parts)\n    destination.parent.mkdir(parents=True, mode=0o700, exist_ok=True)\n    current = stage_root\n    for part in PurePosixPath(item.target).parts[:-1]:\n        current /= part\n        metadata = current.lstat()\n        if stat.S_ISLNK(metadata.st_mode) or not stat.S_ISDIR(metadata.st_mode):\n            raise ValueError(f\"oracle stage parent must be a real directory: {item.target}\")\n        current.chmod(0o700)\n    descriptor = os.open(\n        destination,\n        os.O_WRONLY | os.O_CREAT | os.O_EXCL | getattr(os, \"O_NOFOLLOW\", 0),\n        0o400,\n    )\n    try:\n        view = memoryview(item.payload)\n        while view:\n            written = os.write(descriptor, view)\n            if written <= 0:\n                raise OSError(\"short write while staging oracle\")\n            view = view[written:]\n        os.fchmod(descriptor, 0o400)\n        os.fsync(descriptor)\n    finally:\n        os.close(descriptor)\n","sourceCodeStart":452,"sourceCodeEnd":488,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/d540b00184d71a896261ee02670da9a92d59d8f7/eval/workflow_bench/oracle_assets.py#L452-L488","documentation":"Inside _write_stage_file (used by staged_task_oracle to materialize oracle files AFTER the model exits): the harness mkdir's the destination parents, then walks each parent with lstat to confirm it is a real, non-symlink directory before writing the oracle file read-only. A symlink/non-dir parent would indicate a TOCTOU swap (an adversarial model process trying to redirect the oracle write outside the stage root).","triggerScenarios":"Triggered when, between mkdir(parents, exist_ok=True) and the parent walk, one of the parent components of item.target becomes a symlink or non-directory — e.g., a model-launched process racing to replace a directory with a symlink inside .wfbench-oracle-<hex>/.","commonSituations":"A model-under-test that escapes its sandbox and races the oracle staging write; a bug in target path construction producing a path that collides with an existing file; concurrent staged_task_oracle calls sharing a root.","solutions":["Ensure staged_task_oracle's worktree is private to a single task and not writable by the model process.","Inspect `.wfbench-oracle-*/` lineage for symlinks: `find <worktree>/.wfbench-oracle-* -type l`.","Validate item.target does not traverse into existing file paths; ensure the stage root is created fresh each run."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import stat\nfrom pathlib import Path, PurePosixPath\n\ndef stage_parents_are_real(stage_root: Path, target: str) -> bool:\n    cur = stage_root\n    for part in PurePosixPath(target).parts[:-1]:\n        cur = cur / part\n        try:\n            st = cur.lstat()\n        except OSError:\n            return False\n        if stat.S_ISLNK(st.st_mode) or not stat.S_ISDIR(st.st_mode):\n            return False\n    return True\n","typeGuard":"def is_unsafe_stage_parent(exc: BaseException) -> bool:\n    return isinstance(exc, ValueError) and \"stage parent must be a real directory\" in str(exc)\n","tryCatchPattern":"from eval.workflow_bench import oracle_assets\ntry:\n    with oracle_assets.staged_task_oracle(worktree, snapshot) as root:\n        run_command(root)\nexcept ValueError as exc:\n    raise AbortTask(f\"oracle staging failed: {exc}\") from exc\n","preventionTips":["Give each task a private worktree the model cannot write to until staging is complete.","Never reuse a .wfbench-oracle-* directory across runs."],"tags":["staging","toctou","symlink","path-traversal","oracle","security","invariant"],"backgroundTag":null,"analyzedSha":"d540b00184d71a896261ee02670da9a92d59d8f7","analyzedAt":"2026-08-12T19:50:25.132Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}