Describe the bug
LocalFilesystemPersonalAssistantExampleTest (agentscope-harness, package io.agentscope.harness.agent.example) intermittently fails in CI with:
org.junit.platform.commons.JUnitException: Failed to close extension context
Caused by: java.io.IOException: Failed to delete temp directory /tmp/junit-... The following paths could not be deleted (see suppressed exceptions for details): <root>, agents, agents/my-local-assistant, agents/my-local-assistant/sessions
Suppressed: java.nio.file.DirectoryNotEmptyException: ...
This happens during JUnit's @TempDir teardown: it walks the temp directory tree to delete it, but a background thread named session-tree-mirror is still writing files into that same directory at teardown time, so the delete hits DirectoryNotEmptyException mid-walk. It's a teardown race between the test's async session-mirroring thread and JUnit's directory cleanup, not a logic bug in the test's assertions.
To Reproduce
Not reliably reproducible on demand — it's timing/scheduler dependent. Observed across multiple unrelated PRs in CI:
Same test class, different failing methods, different OS, inconsistent pass/fail on identical code — consistent with a timing race rather than a deterministic bug.
Expected behavior
The test suite should not intermittently fail due to teardown races. Either:
- The
session-tree-mirror background thread should be joined/stopped before the test method returns (so nothing writes to the temp dir during @TempDir cleanup), or
- The test should use a teardown mechanism that tolerates a still-active writer (e.g. retry-on-
DirectoryNotEmptyException deletion, or an explicit shutdown hook for the mirror thread in an @AfterEach).
Error messages
org.junit.platform.commons.JUnitException: Failed to close extension context
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
Caused by: java.io.IOException: Failed to delete temp directory /tmp/junit-5345473238498555742. The following paths could not be deleted (see suppressed exceptions for details): <root>, agents, agents/my-local-assistant, agents/my-local-assistant/sessions
Suppressed: java.nio.file.DirectoryNotEmptyException: /tmp/junit-5345473238498555742
at java.base/sun.nio.fs.UnixFileSystemProvider.implDelete(UnixFileSystemProvider.java:246)
at java.base/java.nio.file.Files.walkFileTree(Files.java:2828)
Environment (please complete the following information):
- AgentScope-Java Version: 2.0.1-SNAPSHOT
- Java Version: 21
- OS: both observed — ubuntu-latest and windows-latest (GitHub Actions runners)
Additional context
This is a CI-infra flake, not tied to any particular feature change — it has now surfaced on two unrelated PRs touching completely different modules (agentscope-extensions-rag-simple and agentscope-harness middleware). Filing separately so it can be tracked and fixed independently rather than blocking unrelated PRs.
Describe the bug
LocalFilesystemPersonalAssistantExampleTest(agentscope-harness, packageio.agentscope.harness.agent.example) intermittently fails in CI with:This happens during JUnit's
@TempDirteardown: it walks the temp directory tree to delete it, but a background thread namedsession-tree-mirroris still writing files into that same directory at teardown time, so the delete hitsDirectoryNotEmptyExceptionmid-walk. It's a teardown race between the test's async session-mirroring thread and JUnit's directory cleanup, not a logic bug in the test's assertions.To Reproduce
Not reliably reproducible on demand — it's timing/scheduler dependent. Observed across multiple unrelated PRs in CI:
OpenAITextEmbeddingchange): failed onubuntu-latest— run, methodlocalFilesystem_directDiskAccessFromHostProcess.MemoryMaintenanceMiddlewarechange): failed onwindows-latest— run, methodlocalFilesystem_workspaceIsNotPartitionedByUserOrSession. A CI run immediately prior on the exact same code passed cleanly.Same test class, different failing methods, different OS, inconsistent pass/fail on identical code — consistent with a timing race rather than a deterministic bug.
Expected behavior
The test suite should not intermittently fail due to teardown races. Either:
session-tree-mirrorbackground thread should be joined/stopped before the test method returns (so nothing writes to the temp dir during@TempDircleanup), orDirectoryNotEmptyExceptiondeletion, or an explicit shutdown hook for the mirror thread in an@AfterEach).Error messages
Environment (please complete the following information):
Additional context
This is a CI-infra flake, not tied to any particular feature change — it has now surfaced on two unrelated PRs touching completely different modules (
agentscope-extensions-rag-simpleandagentscope-harnessmiddleware). Filing separately so it can be tracked and fixed independently rather than blocking unrelated PRs.