agentscope-ai/agentscope · warning · FileNotFoundError
File {path_file} does not exist.
Error message
File {path_file} does not exist. What it means
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.
Source
Thrown at src/agentscope/embedding/_file_cache.py:124
return np.load(os.path.join(self.cache_dir, filename)).tolist()
return None
async def remove(self, identifier: JSONSerializableObject) -> None:
"""Remove the embeddings with the given identifier.
Args:
identifier (`JSONSerializableObject`):
The identifiers to remove the embeddings, which will be
used to generate a hashable filename, so it should be
JSON serializable (e.g. a string, number, list, dict).
"""
filename = self._get_filename(identifier)
path_file = os.path.join(self.cache_dir, filename)
if os.path.exists(path_file):
os.remove(path_file)
else:
raise FileNotFoundError(f"File {path_file} does not exist.")
async def clear(self) -> None:
"""Clear the cache directory by removing all files."""
for filename in os.listdir(self.cache_dir):
if filename.endswith(".npy"):
os.remove(os.path.join(self.cache_dir, filename))
def _get_cache_size(self) -> float:
"""Get the current size of the cache directory in MB."""
total_size = 0
for filename in os.listdir(self.cache_dir):
if filename.endswith(".npy"):
path_file = os.path.join(self.cache_dir, filename)
if os.path.isfile(path_file):
total_size += os.path.getsize(path_file)
return total_size / (1024.0 * 1024.0)
@staticmethodView on GitHub (pinned to e90f1c7592)
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
Example fix
# before
await cache.remove(identifier) # raises if already gone
# after
try:
await cache.remove(identifier)
except FileNotFoundError:
pass # already removed Defensive patterns
Strategy: try-catch
Validate before calling
import os
path_file = os.path.join(cache.cache_dir, cache._get_filename(identifier))
if not os.path.isfile(path_file):
pass # nothing to remove Try / catch
try:
await cache.remove(identifier)
except FileNotFoundError:
pass # idempotent removal Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- Path {path_file} exists but is not a file.
- host_cache_dir must be a directory.
- host_cache_dir must not be a symbolic link.
- host_cache_dir must be a real directory.
- Credential {credential_id!r} for owner {owner_id!r} disappea
AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28).
Data as JSON: /api/errors/d5a9cf9c851db1c8.
Report an issue: GitHub.