Skip to content

fix(harness): close test agents before temp workspace cleanup - #2669

Closed
zouyx wants to merge 2 commits into
agentscope-ai:mainfrom
zouyx:featrue/fix-ci-tempdir-race
Closed

fix(harness): close test agents before temp workspace cleanup#2669
zouyx wants to merge 2 commits into
agentscope-ai:mainfrom
zouyx:featrue/fix-ci-tempdir-race

Conversation

@zouyx

@zouyx zouyx commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

AgentScope-Java Version

2.0.1-SNAPSHOT

Description

Fixes flaky GitHub Actions failures in Harness tests caused by JUnit deleting @TempDir workspaces while HarnessAgent background session/transcript writes are still draining.

  • Track each HarnessAgent created by the affected tests.
  • Close tracked agents in @AfterEach before JUnit cleans temporary directories.
  • Preserve restoration of agentscope.state.home in subagent stream tests.

Testing

  • mvn -pl agentscope-harness -am -Dtest=HarnessAgentSubagentStreamTest,HarnessAgentDynamicHookBuilderTest test
  • ./.github/scripts/check-shade-and-bom-sync.sh
  • mvn -T1 clean verify (in progress)

Checklist

  • Code has been formatted with mvn spotless:apply
  • Targeted Harness tests are passing
  • Module shade/BOM synchronization check is passing
  • No documentation update is required for this test lifecycle fix
  • Code is ready for review

Copilot AI lite review requested due to automatic review settings August 11, 2026 16:34
@zouyx

zouyx commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator Author

This PR for fix main CI fail

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.

Pull request overview

This PR addresses flaky Harness test failures where JUnit deletes @TempDir workspaces while HarnessAgent background session/transcript writes are still draining by explicitly closing agents before temp directory cleanup.

Changes:

  • Track HarnessAgent instances created by the affected tests.
  • Close tracked agents in @AfterEach to ensure background writes are drained before @TempDir cleanup.
  • Preserve restoration behavior for agentscope.state.home in the subagent stream tests.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
agentscope-harness/src/test/java/io/agentscope/harness/agent/HarnessAgentSubagentStreamTest.java Track created agents and close them in @AfterEach before restoring agentscope.state.home.
agentscope-harness/src/test/java/io/agentscope/harness/agent/HarnessAgentDynamicHookBuilderTest.java Track created agents and close them in @AfterEach to avoid TempDir deletion races.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +83 to +85
void closeAgents() {
agents.forEach(HarnessAgent::close);
}
Comment on lines +84 to +86
try {
agents.forEach(HarnessAgent::close);
} finally {
@AgentScopeJavaBot AgentScopeJavaBot added bug Something isn't working area/harness agentscope-harness (test/runtime support) labels Aug 12, 2026
@zouyx zouyx closed this Aug 12, 2026
@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 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

area/harness agentscope-harness (test/runtime support) bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants