{"record":{"id":"71d4a57e6c68a56d","repo":"abhigyanpatwari/GitNexus","slug":"task-asset-cache-is-already-closed","errorCode":null,"errorMessage":"task asset cache is already closed","messagePattern":"task asset cache is already closed","errorType":"exception","errorClass":"SandboxError","httpStatus":null,"severity":"error","filePath":"eval/workflow_bench/task_assets.py","lineNumber":216,"sourceCode":"\n    def __enter__(self) -> TaskAssetCache:\n        return self\n\n    def __exit__(self, _exc_type: object, _exc: object, _traceback: object) -> None:\n        self.close()\n\n    def prepare(\n        self,\n        task: Mapping[str, Any],\n        *,\n        repo: Path,\n        resolved_sha: str,\n        expected_dependency_binding: Mapping[str, Any] | None = None,\n    ) -> TaskAssetSnapshot:\n        \"\"\"Capture or reuse all copied and mounted task bytes in one snapshot.\"\"\"\n\n        if self._closed:\n            raise SandboxError(\"task asset cache is already closed\")\n        repo_identity = _real_directory(repo, label=\"task asset repository\")\n        declarations, relative_paths = _sandbox_copy_declarations(task)\n        dependency_declarations = _sandbox_dependency_declarations(task)\n        dependency_identity = tuple((declaration.source, declaration.target) for declaration in dependency_declarations)\n        definition = (str(repo_identity), resolved_sha, declarations, dependency_identity)\n        existing = self._by_definition.get(definition)\n        if existing is not None:\n            if expected_dependency_binding is not None:\n                existing.validate_dependency_binding(expected_dependency_binding)\n            return existing\n\n        building = Path(tempfile.mkdtemp(prefix=\".building-\", dir=self.root))\n        try:\n            copy_root = building / \"sandbox-copy\"\n            dependency_root = building / \"dependencies\"\n            copy_root.mkdir(mode=0o700)\n            dependency_root.mkdir(mode=0o700)\n            budget = _SnapshotBudget()","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/d540b00184d71a896261ee02670da9a92d59d8f7/eval/workflow_bench/task_assets.py#L198-L234","documentation":"TaskAssetCache.prepare refuses to run after close() (or context-manager __exit__). The cache root has been deleted, so any new snapshot would be written into a removed tree.","triggerScenarios":"Calling cache.prepare(...) after the 'with TaskAssetCache(...)' block exited, or after an explicit cache.close().","commonSituations":"A refactor that moved the prepare call outside the with block; reusing a closed cache across functions; holding a stale cache reference.","solutions":["Move all cache.prepare / materialize / dependency_mounts usage inside the 'with TaskAssetCache(...) as cache:' block.","If you need the cache longer, widen the with scope or delay close() until every arm has consumed the snapshot.","Do not retain or reuse a reference to a cache after close()."],"exampleFix":"# before\nwith TaskAssetCache(root) as cache:\n    snapshot = cache.prepare(task, repo=repo, resolved_sha=sha)\n# later, outside the with-block:\ncache.prepare(other_task, repo=repo, resolved_sha=sha)   # raises: cache closed\n\n# after\nwith TaskAssetCache(root) as cache:\n    snapshot = cache.prepare(task, repo=repo, resolved_sha=sha)\n    other = cache.prepare(other_task, repo=repo, resolved_sha=sha)\nsnapshot.materialize(clone)   # snapshot survives the cache","handlingStrategy":"validation","validationCode":"def assert_cache_open(cache):\n    if getattr(cache, \"_closed\", True):\n        raise RuntimeError(\"TaskAssetCache is closed; call prepare within its with-block\")","typeGuard":"def is_cache_open(cache) -> bool:\n    return not getattr(cache, \"_closed\", True)","tryCatchPattern":null,"preventionTips":["Keep all prepare/materialize/dependency_mounts calls inside the 'with TaskAssetCache(...) as cache:' block.","Widen the with-scope rather than reusing a cache after close().","Do not retain a cache reference past its context-manager exit."],"tags":["state","workflow-bench","lifecycle"],"backgroundTag":null,"analyzedSha":"d540b00184d71a896261ee02670da9a92d59d8f7","analyzedAt":"2026-08-12T19:50:25.132Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}