{"record":{"id":"2f17a7932b2e82f8","repo":"abhigyanpatwari/GitNexus","slug":"evidence-destination-already-exists-destination","errorCode":null,"errorMessage":"evidence destination already exists: {destination}","messagePattern":"evidence destination already exists: (.+?)","errorType":"exception","errorClass":"SandboxError","httpStatus":null,"severity":"error","filePath":"eval/workflow_bench/proposer_sandbox.py","lineNumber":222,"sourceCode":"        raw = value\n    elif isinstance(value, str):\n        raw = value.encode()\n    else:\n        raw = (json.dumps(value, sort_keys=True, separators=(\",\", \":\")) + \"\\n\").encode()\n    return redact_text(raw.decode(errors=\"replace\"), secrets).encode()\n\n\ndef stage_evidence_bundle(\n    destination: Path,\n    entries: Mapping[str, Any],\n    *,\n    secrets: Sequence[str] = (),\n) -> Path:\n    \"\"\"Write a redacted owner-only evidence bundle with hard byte caps.\"\"\"\n\n    destination = destination.resolve()\n    if destination.exists():\n        raise SandboxError(f\"evidence destination already exists: {destination}\")\n    destination.mkdir(parents=True, mode=0o700)\n    destination.chmod(0o700)\n    total = 0\n    try:\n        for name, value in entries.items():\n            relative = PurePosixPath(name)\n            if len(relative.parts) != 1 or relative.name in {\"\", \".\", \"..\"}:\n                raise SandboxError(f\"evidence names must be simple relative files: {name!r}\")\n            payload = _evidence_bytes(value, secrets)\n            if len(payload) > MAX_EVIDENCE_FILE_BYTES:\n                raise SandboxError(f\"evidence exceeds the per-file limit: {name}\")\n            total += len(payload)\n            if total > MAX_BUNDLE_BYTES:\n                raise SandboxError(\"evidence bundle exceeds the total byte limit\")\n            path = destination / relative.name\n            path.write_bytes(payload)\n            path.chmod(0o600)\n    except BaseException:","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/d540b00184d71a896261ee02670da9a92d59d8f7/eval/workflow_bench/proposer_sandbox.py#L204-L240","documentation":"Raised by stage_evidence_bundle when the destination directory already exists (destination.resolve().exists() is true). The writer wants to mkdir(parents=True, mode=0o700) into a fresh path and treats a pre-existing destination as a collision it must not silently overwrite, since clobbering could mix old unredacted bytes with new evidence.","triggerScenarios":"Calling stage_evidence_bundle with a destination Path that already exists on disk (file or directory), including a leftover bundle from a previous run or retry.","commonSituations":"A retry reuses the same destination path after a prior run crashed mid-stage; the destination sits under a temp base whose name is deterministic per task and the prior artifact was not cleaned; two concurrent tasks share a staging root without per-run names; a SIGKILL beat the failure-path rmtree.","solutions":["Pass a fresh per-run destination: append a unique suffix (uuid, timestamp, pid) or use tempfile.mkdtemp as the parent and a new leaf name.","Delete the existing destination before staging if you are sure it is stale: shutil.rmtree(destination, ignore_errors=True) then retry.","On retry, generate a new destination under the session private_root rather than reusing the literal same path.","Ensure the orchestrator cleans the staging root at session end so retries start clean."],"exampleFix":"// before\ndest = Path(\"/tmp/wfbench/task-7/evidence\")  # exists from prior crash\nstage_evidence_bundle(dest, entries)\n// after\ndest = Path(tempfile.mkdtemp(prefix=\"evidence-\")) / \"evidence\"\nstage_evidence_bundle(dest, entries)","handlingStrategy":"validation","validationCode":"from pathlib import Path\nimport tempfile, uuid\n\ndef fresh_destination(base: Path) -> Path:\n    return base / f'evidence-{uuid.uuid4().hex}' if base.exists() else base\n\ndest = fresh_destination(Path(tempfile.mkdtemp(prefix='wfbench-'))) / 'bundle'","typeGuard":"null","tryCatchPattern":"try:\n    stage_evidence_bundle(dest, entries, secrets=secrets)\nexcept SandboxError as exc:\n    if 'already exists' in str(exc):\n        import shutil\n        shutil.rmtree(dest, ignore_errors=True)\n        stage_evidence_bundle(dest, entries, secrets=secrets)\n    raise","preventionTips":["Use a unique destination per run (uuid/timestamp/pid suffix).","Clean the staging root at the start of each run.","Never reuse a destination across retries.","Use tempfile.mkdtemp so the parent is always fresh."],"tags":["evidence","filesystem","idempotency","sandbox"],"backgroundTag":null,"analyzedSha":"d540b00184d71a896261ee02670da9a92d59d8f7","analyzedAt":"2026-08-12T19:50:25.132Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}