Repository navigation
Description
Describe the bug
When multiple HarnessAgent calls share one workspace root but have different visible skill sets per call (e.g. per-user skill visibility), every call runs HarnessSkillMiddleware.onSystemPrompt → MarketplaceStager.stage(...), which ends with garbageCollectOrphans() deleting cached skill directories that are not in this call's retained set.
Two defects combine to fail the entire agent call:
-
Exception-handling gap.
garbageCollectOrphans/deleteRecursively/removeUnexpectedtraverse directories withFiles.walk(...), whose lazy stream throwsUncheckedIOException(aRuntimeException) when an entry disappears mid-iteration. All three methods onlycatch (IOException ...), so the wrappedNoSuchFileExceptionescapes. For per-skillmaterializeIfChangedthe outercatch (Exception)instage()contains the damage, butgarbageCollectOrphans(cacheRoot, retained)is called outside that try-catch, so any failure there propagates up through the middleware chain and terminates the agent execution. -
Per-call GC on a shared cache. The retained white-list is rebuilt from a single call's visible skills. With per-user visibility, a skill directory legitimately staged by concurrent call A is an "orphan" for call B and gets recursively deleted — potentially while A is walking/materializing the same tree (or vice versa). There is no grace period, reference counting, or namespace isolation for
.skills-cache(unlike runtime data paths, which are prefixed viaNamespaceFactory/IsolationScope).
To Reproduce
Steps to reproduce the behavior:
- Build a
HarnessAgentwith.workspace(<sharedRoot>)and a skill repository whose visible skill set varies per call (e.g. filtered byRuntimeContext.getUserId()), where at least one skill contains a subdirectory (e.g.scripts/). - Run two concurrent calls against the same workspace root where the skill is visible to call A but not to call B (sandbox disabled, plain local workspace).
- Call B's
stage()reachesgarbageCollectOrphansanddeleteRecursively(skillDir)while call A is concurrently staging/walking the same skill directory (or call A'sremoveUnexpectedprunes a subdirectory another call is enumerating).
Expected behavior
- Directory traversal during staging/GC should tolerate entries deleted by concurrent calls (skip vanished paths instead of failing).
- Orphan GC on a shared workspace cache should not delete directories that other in-flight calls may still use (e.g. mtime grace period, ref-counting, or per-isolation-scope cache namespaces consistent with
resolveRuntimeDataPath). - At minimum, a staging/GC failure should degrade gracefully (as the per-skill
catch (Exception)already does), never fail the whole agent call.
Error messages
ERROR ... UncheckedIOException: java.nio.file.NoSuchFileException:
<workspace>/.skills-cache/<source-ns>/<skill-name>/scripts
Observed production signature: the call fails within ~3 s, before the first model round completes (totalEvents=1, no tool execution). The failing path is always a subdirectory of a staged skill that was being deleted concurrently. No sandbox involved (filesystem/shell tools disabled, local workspace only).
Environment (please complete the following information):
- AgentScope-Java Version: 2.0.1 (
agentscope-harness) - Java Version: 17
- OS: Linux (production, shared workspace volume; also reproducible single-node with concurrent threads)
Additional context
Suggested fixes (any combination):
- Widen the catch scope in
MarketplaceStager:garbageCollectOrphans/deleteRecursively/removeUnexpectedshould catchRuntimeException(or explicitlyUncheckedIOException) and log-and-continue, matching the per-skill fault tolerance instage(). - Make
deleteRecursivelyrace-safe: iterate withdeleteIfExistsand tolerateNoSuchFileExceptionper entry instead of relying on a singleFiles.walksnapshot. - Design-level: don't GC a shared cache based on one call's visibility snapshot — add a grace period (delete only entries untouched for N minutes) or prefix
.skills-cachewith the same namespaceIsolationScopeapplies to runtime data, so different users never stage/GC into the same tree.
Relevant code (v2.0.1): agentscope-harness/.../skill/runtime/MarketplaceStager.java — stage(), garbageCollectOrphans(), deleteRecursively(), removeUnexpected(); trigger path: HarnessSkillMiddleware.onSystemPrompt().
Activity
fix(harness): stop orphan GC from deleting skills other calls still use
fix(harness): stop orphan GC from deleting skills other calls still use
fix(harness): stop skill-cache orphan GC from deleting live directori…