{"record":{"id":"22e5129a75b1ddda","repo":"zed-industries/zed","slug":"build-directory-already-exists-but-is-not-ready-r","errorCode":null,"errorMessage":"build directory already exists but is not ready; refusing to overwrite {build_id}","messagePattern":"build directory already exists but is not ready; refusing to overwrite (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"crates/eval_cli/zed_eval/modal_app.py","lineNumber":185,"sourceCode":"    build_info_path = build_dir / \"build-info.json\"\n    # The lease lives outside build_dir so it never interferes with the atomic\n    # move of the finished build directory below.\n    building_path = pathlib.Path(\"/data/build-locks\") / f\"{build_id}.json\"\n    lease_ttl = int(build_request.get(\"build_wait_timeout_secs\") or 7200)\n    owner = uuid.uuid4().hex\n\n    def reuse_existing() -> dict[str, Any]:\n        build_info = load_json(build_info_path) or {}\n        build_info.setdefault(\"build_id\", build_id)\n        build_info[\"reused\"] = True\n        volume.commit()\n        print(f\"Reusing existing build {build_id}\", flush=True)\n        return build_info\n\n    if ready_path.exists() and binary_path.exists():\n        return reuse_existing()\n    if build_dir.exists():\n        raise RuntimeError(\n            f\"build directory already exists but is not ready; refusing to overwrite {build_id}\"\n        )\n\n    # Single-flight lease: if another invocation is already compiling this exact\n    # build, wait for it to finish rather than running a second multi-minute\n    # compile. The lease is best-effort (the volume has no atomic compare-and-swap);\n    # the atomic move below still guarantees correctness if two builds slip through.\n    deadline = time.time() + lease_ttl\n    while True:\n        reload_volume()\n        if ready_path.exists() and binary_path.exists():\n            return reuse_existing()\n        if build_dir.exists():\n            raise RuntimeError(\n                f\"build directory already exists but is not ready; refusing to overwrite {build_id}\"\n            )\n        lease = load_json(building_path)\n        now = time.time()","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/zed-industries/zed/blob/bc538def4545534201bbfcac4e95ac34ea6501b6/crates/eval_cli/zed_eval/modal_app.py#L167-L203","documentation":"Raised as RuntimeError by modal_app.build_eval_cli() at the fast-path check: the build directory /data/builds/{build_id} exists on the Modal volume, but the READY marker and/or the eval-cli binary are missing, so the build is not reusable and the function refuses to overwrite it. This guard protects a half-written or corrupted build from being silently replaced while other runs may reference it.","triggerScenarios":"A previous build of the same id crashed after creating build_dir but before completing (older/non-atomic code paths, a Modal container killed mid-write); someone manually created or partially deleted files under /data/builds/{id}; volume data loss or partial replication leaving the directory without READY; a stale directory left by an interrupted cleanup.","commonSituations":"Retrying a launch after a build timeout where the first attempt died mid-compile before the atomic move; ops scripts touching /data/builds; running two infrastructures (e.g. renamed app/volume) against the same build ids with different layouts.","solutions":["Inspect the directory on the volume (Modal shell or volume tooling): ls /data/builds/<build_id> — check for eval-cli, build-info.json, READY.","If READY is missing but eval-cli and build-info.json are intact and trustworthy, restore the READY marker; otherwise delete the whole directory.","Delete the stale directory and re-run zed-eval build (or the launch) so the build is recreated atomically.","Also clear a leftover lease file /data/build-locks/<build_id>.json if present, so the single-flight wait does not block on a dead owner."],"exampleFix":"# recovery, from a Modal shell on the volume\n# before\nls /data/builds/my-build-abc        # dir exists, no READY -> RuntimeError\n# after\nrm -rf /data/builds/my-build-abc /data/build-locks/my-build-abc.json\nvolume.commit()                       # then re-run zed-eval build","handlingStrategy":"retry","validationCode":"# Before re-running a build whose previous attempt died:\n# (from a Modal shell with the volume mounted)\n# ls /data/builds/<build_id>     -> expect eval-cli, build-info.json, READY\n# If READY is missing, the dir is incomplete and must be removed.","typeGuard":null,"tryCatchPattern":"try:\n    build_info = build_function.remote(build_request)\nexcept RuntimeError as error:\n    if \"refusing to overwrite\" not in str(error):\n        raise\n    # inspect /data/builds/<build_id> on the volume; delete the incomplete\n    # directory (and /data/build-locks/<build_id>.json), commit, retry once","preventionTips":["Check for a reusable build (READY + eval-cli present) before re-launching the same source.","Never manually create or partially delete files under /data/builds/<id>.","After any killed build, clean both the build dir and the lease file so retries start clean."],"tags":["build","volume","modal","state-corruption"],"backgroundTag":null,"analyzedSha":"bc538def4545534201bbfcac4e95ac34ea6501b6","analyzedAt":"2026-08-16T07:30:46.435Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}