Skip to content

fix(harness): avoid duplicating GracefulShutdownMiddleware in fromAgent#1952

Merged
chickenlj merged 1 commit into
agentscope-ai:mainfrom
zouyx:fixHanessAgent
Jun 29, 2026
Merged

fix(harness): avoid duplicating GracefulShutdownMiddleware in fromAgent#1952
chickenlj merged 1 commit into
agentscope-ai:mainfrom
zouyx:fixHanessAgent

Conversation

@zouyx

@zouyx zouyx commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.0.0-SNAPSHOT

Description

This PR fixes #1950.

Background:
When HarnessAgent.Builder.fromAgent(ReActAgent) is used to wrap an existing ReActAgent, the source agent's middleware chain currently gets copied into the harness builder. Since ReActAgent always adds a system-level GracefulShutdownMiddleware during construction, copying that middleware causes the final harness delegate to contain two GracefulShutdownMiddleware instances.

Purpose:
Ensure GracefulShutdownMiddleware appears exactly once after cloning a ReActAgent into a HarnessAgent.

Changes made:

  • Updated HarnessAgent.Builder.filterCopyableMiddlewares(...) to exclude GracefulShutdownMiddleware
  • Added a regression assertion in HarnessAgentTest to verify the cloned delegate contains exactly one GracefulShutdownMiddleware

How to test:

  • Run mvn -T1 -pl agentscope-harness -am -Dtest=HarnessAgentTest test
  • Confirm fromAgent_filtersRuntimeMiddlewareAndStillPropagatesUserMiddleware passes and the cloned delegate keeps only one GracefulShutdownMiddleware

Checklist

Please check the following items before code is ready to be reviewed.

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

@zouyx zouyx requested review from a team and Copilot June 28, 2026 06:43

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 fixes issue #1950 by preventing GracefulShutdownMiddleware from being duplicated when cloning a ReActAgent into a HarnessAgent via HarnessAgent.Builder.fromAgent(...). It ensures the cloned delegate ends up with exactly one system-level graceful-shutdown middleware while still propagating user-provided middleware.

Changes:

  • Exclude GracefulShutdownMiddleware from the middleware list copied from the source agent during fromAgent(...).
  • Add a regression assertion to verify the cloned delegate contains exactly one GracefulShutdownMiddleware.

Reviewed changes

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

File Description
agentscope-harness/src/main/java/io/agentscope/harness/agent/HarnessAgent.java Filters out GracefulShutdownMiddleware from copyable middlewares during fromAgent(...) cloning.
agentscope-harness/src/test/java/io/agentscope/harness/agent/HarnessAgentTest.java Adds regression coverage asserting the cloned delegate has exactly one GracefulShutdownMiddleware.

@codecov

codecov Bot commented Jun 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...java/io/agentscope/harness/agent/HarnessAgent.java 0.00% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@zouyx

zouyx commented Jun 28, 2026

Copy link
Copy Markdown
Contributor Author
  • codecov/patch

I think it doesn't matter.

Because if i don't change this line, there is two GracefulShutdownMiddleware in child.getDelegate().getMiddlewares() .

@chickenlj chickenlj merged commit 156eaff into agentscope-ai:main Jun 29, 2026
5 of 6 checks passed
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]: HarnessAgent.Builder.fromAgent() duplicates GracefulShutdownMiddleware in middleware chain

3 participants