{"record":{"id":"d5a9cf9c851db1c8","repo":"agentscope-ai/agentscope","slug":"file-path-file-does-not-exist","errorCode":null,"errorMessage":"File {path_file} does not exist.","messagePattern":"File (.+?) does not exist\\.","errorType":"exception","errorClass":"FileNotFoundError","httpStatus":null,"severity":"warning","filePath":"src/agentscope/embedding/_file_cache.py","lineNumber":124,"sourceCode":"            return np.load(os.path.join(self.cache_dir, filename)).tolist()\n        return None\n\n    async def remove(self, identifier: JSONSerializableObject) -> None:\n        \"\"\"Remove the embeddings with the given identifier.\n\n        Args:\n            identifier (`JSONSerializableObject`):\n                The identifiers to remove the embeddings, which will be\n                used to generate a hashable filename, so it should be\n                JSON serializable (e.g. a string, number, list, dict).\n        \"\"\"\n        filename = self._get_filename(identifier)\n        path_file = os.path.join(self.cache_dir, filename)\n\n        if os.path.exists(path_file):\n            os.remove(path_file)\n        else:\n            raise FileNotFoundError(f\"File {path_file} does not exist.\")\n\n    async def clear(self) -> None:\n        \"\"\"Clear the cache directory by removing all files.\"\"\"\n        for filename in os.listdir(self.cache_dir):\n            if filename.endswith(\".npy\"):\n                os.remove(os.path.join(self.cache_dir, filename))\n\n    def _get_cache_size(self) -> float:\n        \"\"\"Get the current size of the cache directory in MB.\"\"\"\n        total_size = 0\n        for filename in os.listdir(self.cache_dir):\n            if filename.endswith(\".npy\"):\n                path_file = os.path.join(self.cache_dir, filename)\n                if os.path.isfile(path_file):\n                    total_size += os.path.getsize(path_file)\n        return total_size / (1024.0 * 1024.0)\n\n    @staticmethod","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/embedding/_file_cache.py#L106-L142","documentation":"Raised by FileCache.remove when trying to delete a cached embedding whose file does not exist on disk. remove() is also invoked by clear() and _maintain_cache_dir(), so eviction or clearing can surface this if the file vanished between listing and removal.","triggerScenarios":"Calling await cache.remove(identifier) twice; calling remove for an identifier never stored; or a race where another process/thread deletes the .npy file (or the whole cache dir) between os.listdir/os.path.exists and the delete.","commonSituations":"Multiple workers or async tasks sharing one cache directory; cache dir wiped externally (tmp cleaner, container restart) while the process holds stale expectations; retry logic that removes an entry then retries and removes again.","solutions":["Check existence (or track stored identifiers) before calling remove","Catch FileNotFoundError and treat it as success (idempotent delete)","Ensure only one owner process manages a given cache_dir, or add file locking","If the whole cache dir was removed externally, recreate/restore it or reset in-memory state"],"exampleFix":"# before\nawait cache.remove(identifier)  # raises if already gone\n\n# after\ntry:\n    await cache.remove(identifier)\nexcept FileNotFoundError:\n    pass  # already removed","handlingStrategy":"try-catch","validationCode":"import os\npath_file = os.path.join(cache.cache_dir, cache._get_filename(identifier))\nif not os.path.isfile(path_file):\n    pass  # nothing to remove","typeGuard":null,"tryCatchPattern":"try:\n    await cache.remove(identifier)\nexcept FileNotFoundError:\n    pass  # idempotent removal","preventionTips":["Treat remove as idempotent; always catch FileNotFoundError","Track stored identifiers in a set to avoid double removes","Avoid concurrent processes deleting from the same cache dir"],"tags":["cache","filesystem","embedding","race-condition"],"backgroundTag":"file-not-found","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}