agentscope-ai/agentscope · critical · RuntimeError

host_cache_dir was removed or replaced before execution.

Error message

host_cache_dir was removed or replaced before execution.

What it means

The same removal/replacement guard applied specifically to host_cache_dir: at execution time, _directory_identity on the cache dir raised ValueError (it is now a symlink or missing), so the backend refuses to build the bwrap invocation.

Source

Thrown at src/agentscope/workspace/_bubblewrap/_bubblewrap_backend.py:491

                identity = self._directory_identity(path, label=label)
            except ValueError as exc:
                raise RuntimeError(
                    f"{label} was removed or replaced before execution.",
                ) from exc
            if identity != expected_identity:
                raise RuntimeError(
                    f"{label} was replaced before execution.",
                )

        if self._host_cache_dir is None:
            return
        try:
            identity = self._directory_identity(
                self._host_cache_dir,
                label="host_cache_dir",
            )
        except ValueError as exc:
            raise RuntimeError(
                "host_cache_dir was removed or replaced before execution.",
            ) from exc
        if identity != self._host_cache_identity:
            raise RuntimeError(
                "host_cache_dir was replaced before execution.",
            )

    @staticmethod
    def _directory_identity(
        path: str,
        *,
        label: str,
    ) -> tuple[int, int]:
        """Return a stable identity for a real directory mount source."""
        if os.path.islink(path) or not os.path.isdir(path):
            raise ValueError(f"{label} must be a real directory: {path}")
        stat_result = os.stat(path, follow_symlinks=False)
        return stat_result.st_dev, stat_result.st_ino

View on GitHub (pinned to e90f1c7592)

Solutions

  1. Exclude the library's cache dir from cache-cleaners/tmp-cleaners, or move it to a stable location
  2. Reconstruct the workspace after external cache wipes
  3. Pre-create the cache dir with 0700 perms owned by the app and document it as persistent state
Defensive patterns

Strategy: fallback

Validate before calling

null

Type guard

null

Try / catch

except RuntimeError as e:
    if 'host_cache_dir was removed' in str(e):
        await rebuild_workspace_with_fresh_cache()

Prevention

When it happens

Trigger: host_cache_dir being deleted, replaced by a symlink, or turned into a non-directory while the workspace object is still in use.

Common situations: Cache-cleaning scripts (e.g. `find /cache -delete`) running against the library's cache directory mid-session; cache dirs placed under /tmp subject to cleanup.

Related errors


AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28). Data as JSON: /api/errors/97f9f9d712a90d90. Report an issue: GitHub.