Skip to content

fix(core): reuse classpath skill jar file systems#1981

Merged
chickenlj merged 4 commits into
agentscope-ai:mainfrom
guslegend0510:fix/1979-classpath-skill-repository-jar-fs
Jul 6, 2026
Merged

fix(core): reuse classpath skill jar file systems#1981
chickenlj merged 4 commits into
agentscope-ai:mainfrom
guslegend0510:fix/1979-classpath-skill-repository-jar-fs

Conversation

@guslegend0510

Copy link
Copy Markdown
Contributor

Summary

Fixes #1979.

ClasspathSkillRepository failed in jar deployments when the same classpath skill location was initialized more than once in the same JVM. The second repository instance could throw FileSystemAlreadyExistsException because the jar FileSystem was always created with FileSystems.newFileSystem(...).

This change makes jar-backed classpath repositories reuse the same mounted FileSystem and only close it when the last repository referencing it is released.

Root Cause

In jar environments, ClasspathSkillRepository created a new ZipFS for every instance, even when the target jar URI had already been mounted. That caused:

  • FileSystemAlreadyExistsException on repeated initialization
  • unsafe close behavior if multiple repositories shared the same jar-backed resource lifecycle

Changes

  • reuse existing jar FileSystem instances by URI
  • add reference counting for jar-backed shared file systems
  • only close jar FileSystem when the last repository releases it
  • keep non-jar classpath behavior unchanged
  • add regression tests for repeated repository initialization

Tests

Ran:

mvn -pl agentscope-core -Dtest=ClasspathSkillRepositoryTest test

Added coverage for:
repeated ClasspathSkillRepository creation against the same normal jar
repeated ClasspathSkillRepository creation against the same Spring Boot nested jar
repository close ordering, ensuring one repository closing does not break another still using the same shared jar FileSystem

@guslegend0510 guslegend0510 requested a review from a team July 1, 2026 12:25
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.81818% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ore/skill/repository/ClasspathSkillRepository.java 81.81% 4 Missing and 4 partials ⚠️

📢 Thoughts on this report? Let us know!

@jujn jujn 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.

LGTM

@chickenlj chickenlj merged commit 2841863 into agentscope-ai:main Jul 6, 2026
6 checks passed
zouyx pushed a commit to zouyx/agentscope-java that referenced this pull request Jul 6, 2026
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]: ClasspathSkillRepository failed to load skills in jar application

4 participants