{"record":{"id":"df4445d66fd458cb","repo":"abhigyanpatwari/GitNexus","slug":"could-not-allocate-a-unique-overlay-staging-file","errorCode":null,"errorMessage":"could not allocate a unique overlay staging file","messagePattern":"could not allocate a unique overlay staging file","errorType":"exception","errorClass":"FileExistsError","httpStatus":null,"severity":"warning","filePath":"eval/workflow_bench/promotion_apply.py","lineNumber":370,"sourceCode":"            try:\n                os.unlink(name, dir_fd=parent_descriptor)\n                os.fsync(parent_descriptor)\n            except OSError as cleanup_exc:\n                raise _StagingCleanupError(name, exc, cleanup_exc) from exc\n            raise\n        else:\n            os.close(descriptor)\n            try:\n                os.fsync(parent_descriptor)\n            except OSError as exc:\n                try:\n                    os.unlink(name, dir_fd=parent_descriptor)\n                    os.fsync(parent_descriptor)\n                except OSError as cleanup_exc:\n                    raise _StagingCleanupError(name, exc, cleanup_exc) from exc\n                raise\n            return name\n    raise FileExistsError(\"could not allocate a unique overlay staging file\")\n\n\ndef _temporary_exists(parent_descriptor: int, name: str) -> bool:\n    try:\n        os.stat(name, dir_fd=parent_descriptor, follow_symlinks=False)\n    except FileNotFoundError:\n        return False\n    return True\n\n\ndef _unlink_temporary(parent_descriptor: int, name: str) -> None:\n    try:\n        os.unlink(name, dir_fd=parent_descriptor)\n    except FileNotFoundError:\n        return\n    os.fsync(parent_descriptor)\n\n","sourceCodeStart":352,"sourceCodeEnd":388,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/d540b00184d71a896261ee02670da9a92d59d8f7/eval/workflow_bench/promotion_apply.py#L352-L388","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. `_stage_replacement_at` loops up to 100 times, each generating a fresh `.wfevolve-<token_hex(16)>` name and opening with `O_CREAT | O_EXCL`. If every attempt raises `FileExistsError`, it gives up with this `FileExistsError`. With 128 bits of randomness a genuine collision is astronomically unlikely, so this almost always indicates a broken filesystem/RNG or a directory flooded with stale `.wfevolve-*` entries.","triggerScenarios":"100 consecutive `O_EXCL` create attempts all collided with an existing entry — either the directory already contains huge numbers of `.wfevolve-*` files, the RNG is degenerate, or the filesystem mis-reports existence.","commonSituations":"Prior crashed promotions left thousands of stale staging files in a mirror dir; `secrets.token_hex` entropy source unavailable in a locked-down container; a filesystem (some FUSE/network mounts) with broken exclusive-create semantics.","solutions":["Remove stale staging files: delete unreferenced `.wfevolve-*` entries from the mirror directories.","Verify the Python RNG works: `len({secrets.token_hex(16) for _ in range(100)}) == 100`.","If the filesystem has broken `O_EXCL`, move the checkout to a POSIX-correct local filesystem and retry."],"exampleFix":"// before\napply_promoted_overlay(overlay, repo_root=root)\n// after\nimport glob\nfor stale in glob.glob(str(root / '**' / '.wfevolve-*'), recursive=True):\n    os.unlink(stale)\napply_promoted_overlay(overlay, repo_root=root)","handlingStrategy":"retry","validationCode":"import glob\nstale = glob.glob(str(root / '**' / '.wfevolve-*'), recursive=True)\nif stale:\n    for s in stale: os.unlink(s)\n# also sanity-check the RNG\nassert len({secrets.token_hex(16) for _ in range(100)}) == 100","typeGuard":null,"tryCatchPattern":"except FileExistsError as exc:\n    if 'could not allocate a unique overlay staging file' in str(exc):\n        log.warning('staging name collision; clearing stale .wfevolve-* and retrying once')\n        clear_stale_wfevolve(root)\n        apply_promoted_overlay(overlay, repo_root=root)","preventionTips":["Clean up `.wfevolve-*` leftovers after any crashed promotion.","Ensure `/dev/urandom` is available in sandboxed/locked-down containers.","Use a POSIX-correct local filesystem for the checkout (not a broken FUSE mount)."],"tags":["filesystem","rng","staging","overlay","cleanup"],"backgroundTag":null,"analyzedSha":"d540b00184d71a896261ee02670da9a92d59d8f7","analyzedAt":"2026-08-12T19:50:25.132Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}