Skip to content

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

Open
guslegend0510 wants to merge 2 commits into
agentscope-ai:mainfrom
guslegend0510:fix/1979-classpath-skill-repository-jar-fs
Open

fix(core): reuse classpath skill jar file systems#1981
guslegend0510 wants to merge 2 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 84.21053% with 6 lines in your changes missing coverage. Please review.

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

📢 Thoughts on this report? Let us know!

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

2 participants