Skip to content

[Bug]: MarketplaceStager silently stages empty skill dirs when source repository is lazy, breaking sandbox skill scripts #3373

Closed

Description

@BeginnerCong

Describe the bug

MarketplaceStager materialises skill resources exclusively from AgentSkill.getResources() (agentscope-harness/src/main/java/io/agentscope/harness/agent/skill/runtime/MarketplaceStager.java, materializeIfChanged). When the skill comes from a FileSystemSkillRepository constructed with lazy=true, the resource map is intentionally empty (only SKILL.md is read; support files are resolved on demand through originDir).

In that case materializeIfChanged() creates the staged directory but writes zero files, while stageAll() still returns StageResult.Cached unconditionally. Consequences:

  1. ShellPathPolicy renders a <files-root> in the system prompt pointing to a directory that is permanently empty (silent failure — no WARN/ERROR anywhere in the staging path).
  2. For sandboxed harness agents, workspace projection hydrates the empty .skills-cache/<scope>/<ns>/<skill>/ subtree into the container, so skill scripts (scripts/*.py etc.) are never reachable in the sandbox, even though the skill is advertised as available.

To Reproduce

@Test
void lazyFileSystemRepo_stagesNothingButReportsCached(@TempDir Path tmp) throws Exception {
    Path library = Files.createDirectories(tmp.resolve("library/my-skill/scripts"));
    Files.writeString(tmp.resolve("library/my-skill/SKILL.md"),
            "---\nname: my-skill\ndescription: demo\n---\nbody\n");
    Files.writeString(library.resolve("gen.py"), "print('hi')\n");

    var repo = new FileSystemSkillRepository(tmp.resolve("library"), false, null, /* lazy */ true);
    var stager = new MarketplaceStager(tmp.resolve("workspace"));
    Files.createDirectories(tmp.resolve("workspace"));

    AgentSkill skill = repo.getAllSkills().get(0);
    assertTrue(skill.getResources().isEmpty()); // lazy by design

    var ns = new IdentityHashMap<AgentSkillRepository, String>();
    ns.put(repo, repo.getSource());
    var results = stager.stage(List.of(new RepoBound(skill, repo)), ns, "session-1");

    Path stagedDir = tmp.resolve("workspace/.skills-cache/session-1/" + repo.getSource() + "/my-skill");
    // BUG: result claims "Cached" and files-root will be rendered into the prompt,
    // but the staged directory contains no files at all:
    assertInstanceOf(StageResult.Cached.class, results.get("my-skill"));
    try (var s = Files.walk(stagedDir)) {
        assertEquals(1, s.filter(Files::isRegularFile).count()); // fails: 0 regular files
    }
}

Expected behavior

Either of:

  • MarketplaceStager falls back to copying from AgentSkill.getOriginDir() (recursively, preserving relative paths) when the in-memory resource map is empty — this would also preserve binary content and exec bits better than the current String-based materialisation; or
  • stage() returns StageResult.NONE when nothing was materialised, so <files-root> is not rendered and the failure is not silent.

Reporting Cached for an empty directory is the worst of both outcomes: the model is told a path exists, and shell tools in the sandbox fail with "Path does not exist".

Error messages

None during staging (that's part of the bug). The failure only surfaces later inside the sandbox as a tool-level error, e.g.:

Error: Path does not exist: .skills-cache/<session-id>/filesystem-<ns>/my-skill

Environment

  • AgentScope-Java Version: 2.0.3
  • Java Version: 21
  • OS: Windows 11 / Linux (platform-independent)

Additional context

There is a design mismatch between the two skill delivery paths:

  • core side: SkillBox.uploadSkillFiles() explicitly skips copying for skills with a populated originDir (agentscope-core/src/main/java/io/agentscope/core/skill/SkillBox.java) — the assumption being the shell can access the host path directly via <files-root>;
  • harness side: for sandboxed agents the host originDir is unreachable from inside the container, and .skills-cache staging from getResources() is the only delivery route — which degenerates to an empty directory for lazy repositories.

So any lazy-mode filesystem repository + Docker/remote sandbox combination silently loses all skill script files.

Activity

  1. added
    bug
    on Sep 30, 2026
  2. oss-maintainer commented on Sep 30, 2026

    @oss-maintainer
    Collaborator

    Issue Evaluation

    Category: bug | Status: Confirmed (verified against main @ 01da9e6fb, 2.0.4-SNAPSHOT)

    All six claims hold on the current code. This is a real, silent failure on the harness skill path.

    Confirmed

    Claim Evidence
    Staging reads only AgentSkill.getResources() MarketplaceStager.java:238 → materializeIfChanged(stagedDir, skill.getResources()); the method body (:272-302) writes one file per map entry. originDir does not appear anywhere under agentscope-harness/src/main
    Lazy FS repository yields an empty resource map with originDir set FileSystemSkillRepository.java:124 (4-arg ctor), :203-204 → SkillFileSystemHelper.loadSkillFromDirectory(dir, source, !lazy); SkillFileSystemHelper.java:114-117 sets resources = null and originDir(...), and AgentSkill.java:170 turns null into an empty map
    Empty dir created, zero files, Cached returned, no log MarketplaceStager.java:274-277 — Files.createDirectories(stagedDir) then `if (resources == null
    <files-root> still points at the empty dir ShellPathPolicy.java:100-111 resolves any Cached to a path with no emptiness check; SkillPromptBuilder.java:175-177 emits <files-root> whenever non-blank, and :149-155 (template :76-92) tells the model to ls and run scripts under it
    Sandbox never receives the scripts WorkspaceProjectionApplier.java:121 tars only Files::isRegularFile, so an empty skill dir contributes zero tar entries; AbstractBaseSandbox.java:277 hydrates only when payload.fileCount() > 0. Projection roots include .skills-cache (SandboxFilesystemSpec.java:41-42)
    Core skips originDir skills SkillBox.java:694-707 — if (skill.getOriginDir().isPresent()) continue;, coherent with core-side AgentSkillPromptProvider.java:316-319 and SkillToolFactory.java:293-308

    Corrections / refinements to the report

    1. Sandbox wording: it is not that the empty subtree gets hydrated — literally nothing is hydrated for it (only regular files are tarred). Same outcome, slightly different mechanism.
    2. The failure is not sandbox-only. With LocalFilesystemWithShell the same empty host path is advertised (HarnessAgent.java:2874-2911, ShellPathPolicy.java:140-148), so ls <files-root> shows an empty directory without any container involved.
    3. The defect is broader than staging: SkillToolFactory / AgentSkillPromptProvider originDir fallbacks are core-only, and HarnessAgent.java:2933 calls inner.dynamicSkillsEnabled(false), so none of that machinery runs under HarnessAgent. FileSystemSkillRepository also does not implement LazyResourceCapable, so load_skill_through_path(skillId, "scripts/run.sh") fails too (SkillLoadTool.java:195-219, HarnessSkillMiddleware.java:289-299). The premise in LazyResourceCapable.java:30-34 ("the in-memory map already covers every path") is exactly what lazy=true breaks.
    4. Minor side effect: because materializeIfChanged returns before removeUnexpected (:301), a dir that already has files from an earlier eager configuration is left partially stale.
    5. Your repro is executable as written: the ctor (FileSystemSkillRepository.java:124), stage(List<RepoBound>, Map<AgentSkillRepository,String>, String) (MarketplaceStager.java:147, RepoBound at :576) and the path workspace/.skills-cache/session-1/<ns>/<skill> (:164, :189-206, :236) all match. One caveat: with source == null, repo.getSource() is "filesystem-<parentDir>_<dirName>" (:264-281), so read it from the repo instead of hardcoding.

    Impact: any HarnessAgent with a shell filesystem plus a lazy repository — sandboxed or local. Skill scripts are advertised as available and unreachable. Severity: high — it is silent by construction (no WARN, and Cached asserts success), and it breaks the primary delivery channel for skill code.

    Fix direction

    1. Primary: MarketplaceStager.materializeIfChanged (:272-302) — when resources is empty and skill.getOriginDir() is present, copy that tree, reusing the existing path-safety checks (:286-294) and the exec-bit heuristic (:304-351). Pass the skill (or its originDir) in from stageAll (:236-244). This keeps Cached truthful and needs no ShellPathPolicy change, and fixes both sandbox and local paths at once.
    2. Secondary: give HarnessSkillMiddleware (:289-302) a SkillResources adapter over originDir for non-LazyResourceCapable repos so load_skill_through_path works too, and correct the stale LazyResourceCapable javadoc.
    3. Reporting StageResult.NONE instead of Cached (as you suggested) only stops advertising the empty path; it does not restore script access, so we would treat it as a fallback if (1) is judged too invasive.

    Test gap: no existing test stages a lazy repository — MarketplaceStagerOrphanGcTest, MarketplaceStagerExecBitTest, SharedWorkspaceSkillStagingE2ETest, SkillRuntimeTest, SandboxLifecycleMiddlewareCallbackTest all use eager/stub resources, and FileSystemSkillRepositoryLazyTest never stages. Note SharedWorkspaceSkillStagingE2ETest.java:121-134 only asserts Files.isDirectory(advertised) — an empty directory passes it, which is why the E2E guard never caught this.

    Next step: we are not opening a PR unconditionally here. Fix (1) is self-contained and we are confident about it; fix (2) changes LazyResourceCapable / SkillResources semantics, which is a maintainer call. @BeginnerCong if you plan to send the PR yourself we will review it — otherwise reply here and we will turn fix (1) plus tests into a proposal.


    Automated evaluation by github-manager-bot

  3. added
    area/harness
    area/core/tool
    on Sep 30, 2026
  4. xihongshichaojidan8 commented on Sep 30, 2026

    @xihongshichaojidan8
    Contributor

    我已独立复现:同一技能在 eager 模式能缓存脚本,在 lazy 模式返回 Cached,但缓存目录为空。请问你是否已经在实现修复?如果还没有,我愿意先处理 originDir 支持文件的缓存问题,并注意与 #3314 的路径安全改动兼容。

  5. oss-maintainer commented on Sep 30, 2026

    @oss-maintainer
    Collaborator

    Evaluation follow-up | bug | root cause confirmed — fix is now owned by the community

    Answering the question raised above: we are not implementing this fix ourselves, and we will not open a competing PR. Review stays on the PRs below.

    Three open PRs currently modify the same class, agentscope-harness/src/main/java/io/agentscope/harness/agent/skill/runtime/MarketplaceStager.java:

    PR Author Approach Size Scope notes
    #3314 @25344xiaoning harden staging paths (fixes #3313) +624/-45 different root cause, same file and the same two docs/v2/{en,zh}/docs/harness/skill.md files
    #3374 @hermanrous report StageResult.NONE when nothing was materialised +234/-5 makes the failure non-silent; explicitly does not restore script access
    #3376 @xihongshichaojidan8 copy support files from AgentSkill.getOriginDir() when the resource map is empty +372/-1 restores access; also updates the en/zh skill docs

    Mapped against the fix directions in the original evaluation: #3376 is option (1) (the primary fix), #3374 is option (3) (the fallback). That ranking still holds — recovering the files is what actually makes skill scripts reachable with lazy=true plus a shell filesystem; returning NONE on its own only stops advertising an empty <files-root>. The two are composable: an "only report Cached when something was actually written" check is still worth keeping inside option (1), for skills that have neither in-memory resources nor an originDir.

    Coordination points for whichever PR lands first:

    1. Merge order matters. All three touch MarketplaceStager.java, and fix(harness): prevent skill staging path traversal #3314 and fix(harness): stage lazy skill resources from origin directories #3376 touch the same two documentation files, so two of the three will need a rebase regardless of the decision. Merging fix(harness): prevent skill staging path traversal #3314 first is preferable: any originDir-based recursive copy has to respect the path/namespace validation it introduces. fix(harness): stage lazy skill resources from origin directories #3376 states that symlinks inside the cache are rejected and that source/target overlap is detected through real paths — that logic should be reviewed against fix(harness): prevent skill staging path traversal #3314's rules rather than independently of them.
    2. The second gap from the evaluation is still unaddressed by any open PR. load_skill_through_path() keeps failing for repositories that are not LazyResourceCapable (SkillLoadTool.java:195-219, HarnessSkillMiddleware.java:289-302), so a lazy=true skill stays unreadable through that tool even once staging is fixed. Closing it changes SkillResources / LazyResourceCapable semantics, so leaving it out of both PRs was the right call — it deserves its own issue.
    3. Close the test gap, not only the code gap. SharedWorkspaceSkillStagingE2ETest.java:127 validates the advertised path with Files.isDirectory(advertised) only, which an empty directory satisfies — that is why this shipped unnoticed. Whichever PR is merged should additionally assert at least one staged regular file under the advertised root. (Re-checked against current main @ addf82b89: MarketplaceStager.java:275 still returns early on an empty resource map, :238/:244 still report Cached, and FileSystemSkillRepository is still not a LazyResourceCapable implementor.)

    @xihongshichaojidan8 thanks for confirming the reproduction independently. Since #3376 already covers the originDir route, we will treat the two submissions as complementary options for the maintainers to choose between rather than adding a third.


    Automated follow-up by github-manager-bot

  6. added a commit that references this issue on Oct 12, 2026
    44ec9e7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/core/toolarea/harnessbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions