agentscope-java icon indicating copy to clipboard operation
agentscope-java copied to clipboard

[Discussion] `.skills-cache` grows unbounded on sandbox volumes and inflates `glob_files`/`grep_files` cost

Open chcodex opened this issue 1 month ago • 0 comments

Summary

With a marketplace skill repository and a sandbox filesystem, MarketplaceStager materialises skill resources to <hostWsRoot>/.skills-cache/<scope>/<source>/<skill>/ on the host before each reasoning step, and .skills-cache is part of the default workspace projection (SandboxFilesystemSpec.DEFAULT_WORKSPACE_PROJECTION_ROOTS), so it is hydrated into the container's workspace root.

On E2B the workspace root is a persistent volume mount (e.g. /root/workspace), so the cache lands on the volume and survives sandbox destruction. With IsolationScope.SESSION each session gets its own subtree under .skills-cache/, but the orphan GC only sweeps the current scope root (MarketplaceStager.garbageCollectOrphans(scopeRoot, ...)), so subtrees from finished sessions are never revisited and never deleted. The volume grows with the number of sessions.

The growth then shows up directly in the search tools. The sandbox implementations shell out without any exclusion:

  • BaseSandboxFilesystem.glob → find <path> -type f -name <pattern>
  • BaseSandboxFilesystem.grep → grep -rHnF ... <path>

so glob_files / grep_files walk the whole cache tree and their cost grows linearly with past session count. (LocalFilesystem.glob has the same problem via Files.walkFileTree; local grep goes through ripgrep, which skips hidden directories by default, so it is unaffected.)

Proposed directions

Three orthogonal fixes. I'm happy to implement any/all, but would like to hear which fits the roadmap first.

  1. Prune the cache from search traversal (smallest, immediate win). find <path> -name .skills-cache -prune -o -type f -name <pattern> -print, grep --exclude-dir=.skills-cache, and a preVisitDirectory skip in LocalFilesystem.glob. Question: should this be modelled as a general "derived/ephemeral dirs" concept in the filesystem layer so other generated trees can opt in later, or is a targeted .skills-cache exclusion preferable? Note the prune must not apply when the caller explicitly passes a path inside .skills-cache (e.g. an agent grepping its own cached skill sources).

  2. Age-based sweep across scopes (what actually caps the volume). MarketplaceStager.sweepStaleScopes(): delete subtrees under .skills-cache/*/ whose mtime is older than orphanGrace (default 30 min), regardless of the current scope key. The existing grace window was already sized to outlast the longest call that could still shell out to a staged script, so it should be safe for the cross-scope case too.

  3. Decouple the in-container cache location from the workspace root (root fix). Add a targetRoot to WorkspaceProjectionEntry so .skills-cache can hydrate to something like /tmp/agentscope/skills-cache inside the sandbox, and let ShellPathPolicy render <files-root> against that prefix. This needs WorkspaceProjectionApplier to group payloads by target root (the content hash must include it) and a per-target hydrate path in each backend, so it is the largest change of the three.

Questions

  • Which of the three do you prefer? Is (1) acceptable as a default behaviour?
  • For E2B specifically, is (3) the right shape, or would you rather keep the paths coupled and handle the volume some other way?
  • Anything already in flight for this?

Environment

  • agentscope-harness, 2.1.0-SNAPSHOT (154fbabc2)
  • Sandbox: E2B, workspace root mounted at /root/workspace
  • Filesystem mode: sandbox-backed; marketplace skills served from a database-backed repository

chcodex avatar Oct 27 '26 07:10 chcodex