Skip to content

fix(harness): report NONE when a lazy repository stages no resources - #3374

Merged
Buktal merged 2 commits into
agentscope-ai:mainfrom
hermanrous:fix/3373-lazy-skill-staging-reports-none
Oct 12, 2026
Merged

Buktal merged 2 commits into
agentscope-ai:mainfrom
hermanrous:fix/3373-lazy-skill-staging-reports-none

Conversation

@hermanrous

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.0.4-SNAPSHOT (main @ 01da9e6)

Description

Closes #3373.

MarketplaceStager.materializeIfChanged() created the staged directory and then returned early
when the resource map was empty, and stageAll() reported StageResult.Cached unconditionally. A
skill from a lazy FileSystemSkillRepository publishes no in-memory resources by design, so it was
advertised with a <files-root> pointing at a directory that stays permanently empty: inside a
sandbox the skill's support files were unreachable, and the only symptom was a later tool error.

materializeIfChanged() now returns whether anything was staged, and leaves no directory behind
when there is nothing to write. stageAll() reports StageResult.NONE in that case, which
ShellPathPolicy.resolve() already maps to "no files-root" — the same graceful-omission path the
class uses when no host workspace is available.

Scope is deliberately minimal: this makes the failure non-silent. Falling back to a recursive copy
from AgentSkill.getOriginDir(), the issue's other suggestion, would restore the missing files, but
that is a larger change and is left out.

How to test:

mvn -T1 -pl agentscope-harness -am -Dtest=MarketplaceStagerLazyRepositoryTest test

lazyRepositoryReportsNone fails on main with
expected: <StageResult.None> but was: <StageResult.Cached> and passes with the change;
nonLazyRepositoryReportsCached pins the non-lazy path so the fix cannot over-correct.

Test evidence

mvn -T1 -pl agentscope-harness -am -Dtest=io.agentscope.harness.**.*Test test on this machine
(OpenJDK 21) reports the same pre-existing baseline with and without the change:

revision Tests run Failures Errors Skipped
main (unchanged) 1081 1 214 18
this branch 1083 1 214 18

The +2 tests are the new ones and they pass; no new failure or error is introduced. The 214 errors
and the 1 failure are pre-existing on main in this environment and are unrelated to this change:
they are IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker
from Mockito self-attaching its inline mock maker on JDK 21 (Mockito is currently self-attaching to enable the inline-mock-maker. This will no longer work in future releases of the JDK). CI on JDK 17
is the authoritative signal; flagging it here rather than ticking the box below unchecked.

Checklist

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test) — see the caveat above: +2 passing tests, no new failures;
    the module's pre-existing Mockito/JDK 21 errors remain
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

MarketplaceStager.materializeIfChanged() created the staged directory before
checking whether there was anything to write, and stageAll() then reported
StageResult.Cached unconditionally. A skill from a lazy FileSystemSkillRepository
publishes no in-memory resources, so it was advertised with a <files-root>
pointing at a directory that stays permanently empty; inside a sandbox its
support files were unreachable, with only a later tool error as the symptom.

materializeIfChanged() now returns whether anything was staged and leaves no
directory behind when there is nothing to write, and stageAll() reports
StageResult.NONE in that case -- the same graceful-omission path the class
already uses when no host workspace is available.

Closes agentscope-ai#3373
Copilot AI balanced review requested due to automatic review settings September 30, 2026 13:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@CLAassistant

CLAassistant commented Sep 30, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@codecov

codecov Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@oss-maintainer oss-maintainer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

materializeIfChanged() now returns whether anything was staged so stageAll() can report StageResult.NONE instead of Cached for a lazy FileSystemSkillRepository, which previously advertised a permanently empty <files-root>. Verified against the PR head: the new test passes at head and fails at HEAD~1 with Cached, and spotless is clean. Correct, narrow, and safe — no must-fix items.

Two things keep this from a straight approve:

  • createDirectories still runs before the entry filter, so an all-rejected resource map creates the directory it just declared it would not stage (inline).
  • This PR competes with #3376, which fixes the same issue #3373 by staging support files from the repository's originDir in the very same method. The two are different contracts — "hide the unusable files-root" versus "make the files actually reachable" — and they touch overlapping lines. Please don't land them blindly in either order; if #3376 merges, the NONE path this PR adds stops being reachable for lazy repositories that have an originDir.

Verified

  • materializeIfChanged is private, so the void -> boolean change is invisible to callers; StageResult and both stage() overloads are unchanged, and NONE was already a legal return (:158, :255). Consumers HarnessSkillMiddleware.java:300-301 and ShellPathPolicy.java:101 need no update.
  • No cross-call cache is broken: the "if changed" behaviour is the per-file SHA in writeIfChanged (:317-322) and unchanged files still enter expected (:307), so repeat calls return Cached, not NONE. Resources appearing later stage immediately (FileSystemSkillRepository.java:194-205).
  • Thread safety: no new fields; roots/retained/expected are per-call locals and StageResult.NONE is an immutable shared record. concurrentCallsWithDifferentVisibleSetsDoNotThrow still passes.

Review scope

Diff-reviewed plus a local test/build run in this checkout only; no CI was triggered from this review. MarketplaceStagerOrphanGcTest.unreadableEntryDoesNotFailStage fails in this container at both revisions because the process runs as root and ignores the stripped permissions — pre-existing and unrelated to this PR.


Automated review by github-manager-bot

// staged skill apart from one whose content is unavailable.
return false;
}
Files.createDirectories(stagedDir);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Warning] createDirectories runs here, before the entries are filtered (:293-304). When a non-empty resource map has every entry rejected (blank name / unsafe path / out-of-tree), the staged directory is still created, then stageAll reports StageResult.NONE (:244) without touching or retaining it — so an empty directory survives until orphan GC reclaims it, and the "no directory when nothing was staged" intent at :283 does not hold. Either move createDirectories after the filter (create lazily on the first accepted entry) or soften the comment. Not blocking: the reported result is now correct, only the on-disk side effect is over-eager.

.get(SKILL_NAME);

assertInstanceOf(StageResult.None.class, result);
assertEquals(0, countRegularFiles(stagedDir(workspace)));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Info] This helper counts regular files only (:110-117), so the test asserts the cache is file-free but never asserts the staged directory is absent. Reverting the createDirectories placement at :287 keeps this suite green. Two assertions would close the gap: (a) the directory does not exist in the all-empty case, and (b) an all-resources-filtered case (non-empty map, every entry rejected) also yields NONE.

}
// Mark as live before GC runs: this is what stops a concurrent call — or
// another replica sharing the volume — from treating it as an orphan.
touch(stagedDir);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Info] Skipping the touch/retain on the NONE path makes a directory staged by an earlier call orphan-GC eligible as soon as the resource map goes empty. That is probably what you want, but worth one sentence in the javadoc (:60-62) so nobody reads NONE as "my cached files are still there".

// render a <files-root> for a directory that stays permanently empty,
// so report NONE and let shell-mode rendering omit the skill.
log.debug("Skill '{}' (source-ns={}) staged no resources", name, ns);
roots.put(name, StageResult.NONE);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Info] Competing fix for the same issue: #3376 changes the same method in stageAll to stage support files from the repository's originDir instead of only reporting NONE. The two are not obviously incompatible, but they touch the same lines and should not land blindly in either order — #3374 makes an unusable files-root invisible, #3376 makes the files actually present. Maintainers should pick the intended contract; if both land, #3374's NONE path stops being reachable for lazy repositories that have an originDir. No action needed from the author.

materializeIfChanged() no longer creates the staged directory up front. The
directory is created by writeIfChanged when the first entry survives the
path-safety filter, so a non-empty map whose entries are all rejected also
returns NONE without leaving a directory behind -- the contract the empty-map
branch already documented.

Also documents that NONE does not retain the skill, so a directory written by an
earlier call becomes orphan-GC eligible, and covers both cases in the test: the
empty-map case now asserts the staged directory is absent rather than merely
file-free, and a new case drives an all-rejected map through stage().

Addresses review feedback on agentscope-ai#3374.
@hermanrous

Copy link
Copy Markdown
Contributor Author

Thanks for the review — both points are addressed in 598eff2:

  • [Warning] createDirectories is gone from materializeIfChanged(): the directory is now created by writeIfChanged() on the first entry that survives the filter, so an all-rejected map leaves nothing behind either.
  • [Info] test gap closed on both sides: the empty-map case now asserts Files.exists(stagedDir) is false (not merely file-free), and a new case drives a non-empty map whose entries are all rejected by the path-safety filter through stage() and asserts NONE plus an absent directory. Reverting the createDirectories placement makes that assertion fail, so it guards the behaviour rather than restating it.
  • [Info] javadoc: StageResult.None now says explicitly that nothing is staged and nothing is retained, so a directory written by an earlier call becomes orphan-GC eligible.

mvn -T1 -pl agentscope-harness -am -Dtest=MarketplaceStagerLazyRepositoryTest test → 3 tests, 0 failures; spotless:check clean.

@oss-maintainer oss-maintainer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Delta re-review of b3f93540..598eff20 (one new commit: stage no directory when every resource is filtered out). It fixes exactly the item the previous review held open, correctly and with a test that pins it. Approving on the code; the overlap with #3376 below is a maintainer call, not a defect here.

Verified at 598eff20

  • Dropping the eager Files.createDirectories(stagedDir) is safe: writeIfChanged creates the parent directory on the first surviving entry, so a partially-rejected resource map still stages normally and a fully-rejected one leaves nothing behind.
  • removeUnexpected(stagedDir, expected) can now be reached with a non-existent stagedDir. That is handled: the walk surfaces NoSuchFileException, which the existing catch (IOException | UncheckedIOException) already covers, so the cleanup is a silent no-op rather than a stage failure — materializeIfChanged still returns false and stageAll reports NONE.
  • Two NONE sub-cases now differ, and both are fine: an empty resource map returns before the cleanup call, so a lazy repository never wipes what an earlier call staged; an all-rejected map runs the cleanup with an empty white-list, so stale files from a previous revision are dropped. The new None javadoc states the consequence (NONE does not mean "the files cached earlier are still there"), which is the right way to close it rather than adding another walk.
  • New test is sound against the real APIs: the 5-arg AgentSkill constructor exists, and StubRepo implements every abstract member of AgentSkillRepository (close() is a default, so it is not required). stagedDir(workspace) mirrors scopeRoot/<ns>/<name> with scopeSegment("session-1") == "session-1", and countRegularFiles already returns 0 for a missing directory, so both new assertions test what they claim.
  • nonLazyRepositoryReportsCached keeps the partially-valid path pinned, so the fix cannot over-correct into dropping real staging.

Not blocking, still worth a maintainer decision

  • Competes with #3376 (same issue #3373, same method, still open). This PR hides the unusable <files-root>; #3376 makes the files reachable from originDir. Both are defensible, but they touch overlapping lines and only one contract should win. If this one lands first, #3376 needs a rebase on the boolean signature; if #3376 lands first, the NONE path added here stops being reachable for lazy repositories that have an originDir.
  • CI was still pending on this HEAD at review time (build ubuntu-latest / windows-latest), mergeStateStatus=blocked; license/cla and Check Module Sync are green. No build or test run was executed locally for this delta — the verification above is static, reading MarketplaceStager.java and the test at 598eff20.

Automated review by github-manager-bot

@Buktal Buktal left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Buktal
Buktal merged commit 44ec9e7 into agentscope-ai:main Oct 12, 2026
6 checks passed
Buktal pushed a commit that referenced this pull request Oct 27, 2026
…rces (#3779)

## AgentScope-Java Version

`2.1.0-SNAPSHOT`, based on upstream `main` at
`16cb024ae62a10db2aedc2371f4d729194ffda82`.

## Description

Closes #3777.

An empty knowledge workspace currently receives instructions to browse a
supposedly populated `knowledge/` tree. A catalog mixing
documentation-only and scripted skills also receives an instruction
claiming that every entry has `<files-root>`. These instructions can
cause reads of paths that were never declared as available.

Collect the knowledge body and file catalog once, then use that snapshot
for both reference material and guidance. Omit Domain Knowledge guidance
when both are empty; keep inline-only knowledge without promising a
directory; include file navigation only when paths were collected,
retaining the existing context-budget fallback. Limit skill file listing
and execution guidance to entries that actually provide `<files-root>`;
documentation-only skills remain discoverable and loadable.

Add regressions for empty knowledge, inline-only references, remote
catalogs, host fallback, failed reads, mixed skill catalogs and rootless
body loading. Adapt the assertions to the current separation between
SYSTEM instructions and REFERENCE material, while preserving memory
behavior. Update the matching English and Chinese workspace/skill
documentation. No POM, public API or staging implementation changes;
#3374 already fixed the zero-resource staging result.

Validation on Java 17/macOS:

- `mvn -B -T1C -pl agentscope-harness -am -DskipTests install`:
dependency/module installation passed locally.
- `mvn -B -T1C -pl agentscope-harness
-Dtest=WorkspaceContextMiddlewareSandboxPromptTest,WorkspaceContextMiddlewareMemoryPromptTest,SkillRuntimeTest
test`: 44 tests, no failures/errors/skips.
- `mvn -B -T1C -pl agentscope-harness test spotless:check`: 1,407 tests,
no failures/errors, 32 skipped; formatting passed.
- Docs: `npm test` (13 passed), `npm run validate` (432 pages, 584
redirects and build validation passed), `npm run broken-links` (no
broken links). Revalidated after the final workspace prose update; no
links changed.
- `git diff --check`: passed.

Follow-up (2026-10-27): Windows CI exposed two platform-specific
assertions in the new catalog tests. Their expected paths used `/`,
while the existing renderer uses native `Path` formatting. Build the
expected catalog entries with `Path.of`, retaining checks for both
reference content and exclusion from SYSTEM instructions. Re-ran the 44
focused tests and Spotless successfully on macOS. Full-repository `clean
verify` now passes on both Ubuntu and Windows in [Java CI run
40464242577](https://github.com/agentscope-ai/agentscope-java/actions/runs/40464242577);
documentation validation, License and Module Sync checks also pass.

The full repository Maven build and tests passed in Ubuntu and Windows
CI. Real sandbox/LLM execution was not run. Skipped tests are not
counted as executed passes.

## Checklist

- [x] Code has been formatted with `mvn spotless:apply` (Harness
module).
- [x] All repository tests are passing — full-repository `clean verify`
passed in Ubuntu and Windows CI; local Harness results and skips are
listed above.
- [x] Javadoc comments remain applicable; no public API was added.
- [x] Related documentation has been updated in English and Chinese.
- [x] Code is ready for review.
chickenlj pushed a commit that referenced this pull request Nov 13, 2026
…3374)

Backport the verified fix to the 2.0.x implementation and retain its existing public contracts where the upstream kernel differs.

(cherry picked from commit 44ec9e7)
Backport-review-patch: 1e4bcfdc37479f930e10b349001e688070ef2f4b
Constraint: No AgentScope Service or SDK migration
Confidence: high
Not-tested: Whole-repository verification pending after lane integration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

5 participants