agentscope-ai/agentscope · error · FileNotFoundError
not found in Pod: {path}
Error message
not found in Pod: {path} What it means
Raised by K8sBackend.read_file() when `tar cf - -C <dir> <basename>` inside the Pod fails and its stderr contains 'No such file' or 'not found'. This is the explicit missing-file branch: the requested path does not exist inside the Kubernetes Pod. Note this backend reads files by tar-streaming them out of the container, so tar's error text is the signal.
Source
Thrown at src/agentscope/workspace/_k8s/_k8s_backend.py:235
Returns:
`bytes`:
The raw file contents.
Raises:
`FileNotFoundError`:
If the path does not exist inside the Pod.
"""
dirname = posixpath.dirname(path) or "/"
basename = posixpath.basename(path)
result = await self.exec_shell(
["tar", "cf", "-", "-C", dirname, basename],
cwd="/",
)
if not result.ok():
stderr_text = result.stderr.decode(errors="replace")
if "No such file" in stderr_text or "not found" in stderr_text:
raise FileNotFoundError(
f"not found in Pod: {path}",
)
raise FileNotFoundError(
f"not found in Pod: {path} (tar stderr: {stderr_text})",
)
try:
tar = tarfile.open(fileobj=io.BytesIO(result.stdout), mode="r")
except tarfile.ReadError as exc:
raise FileNotFoundError(
f"not found in Pod: {path}",
) from exc
try:
for member in tar.getmembers():
if member.isfile():
f = tar.extractfile(member)
if f:View on GitHub (pinned to e90f1c7592)
Solutions
- Verify the path exists first: `await backend.exec_shell(["test", "-f", path])` and check exit code
- Fix path construction to use the in-Pod absolute path
- Catch FileNotFoundError and regenerate/recreate the file if it's a transient spill artifact
- Serialize read+delete around shared tempfiles to avoid races
Example fix
// before
data = await backend.read_file(spill_path) # FileNotFoundError
// after
if (await backend.exec_shell(["test", "-f", spill_path])).ok():
data = await backend.read_file(spill_path)
else:
data = b"" Defensive patterns
Strategy: validation
Validate before calling
if (await backend.exec_shell(["test", "-f", path])).ok():
data = await backend.read_file(path)
else:
data = None Try / catch
try:
data = await backend.read_file(path)
except FileNotFoundError:
data = None # treat missing as empty Prevention
- Pre-check with `test -f` inside the Pod for optional files
- Use absolute in-Pod paths
- Avoid racing a concurrent delete_path on the same tempfile
When it happens
Trigger: `await backend.read_file(path)` where path doesn't exist in the Pod — e.g. a tempfile already cleaned up, a gateway body_file spilled and deleted, or a wrong absolute path.
Common situations: Reading a gateway spill file (body_file) that another request already deleted; racing cleanup code; paths built for a different container or the host rather than the Pod; file removed between existence check and read.
Related errors
- not found in Pod: {path} (tar stderr: {stderr_text})
- write to {path!r} failed: {command[0]} exited {exit_code}: {
- {entry.path!r} is larger than its declared {entry.size} byte
- {entry.path!r} declared {entry.size} bytes but sent {written
- not found in container: {path}\nstderr: {result.stderr.decod
AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28).
Data as JSON: /api/errors/48adda2e2b2fed69.
Report an issue: GitHub.