Skip to content

fix(generate_response): Fix flaky concurrent tests for generate_response#1011

Merged
LearningGp merged 7 commits intoagentscope-ai:mainfrom
xuhuafeifei:fix_issue_1009
Mar 26, 2026
Merged

fix(generate_response): Fix flaky concurrent tests for generate_response#1011
LearningGp merged 7 commits intoagentscope-ai:mainfrom
xuhuafeifei:fix_issue_1009

Conversation

@xuhuafeifei
Copy link
Contributor

@xuhuafeifei xuhuafeifei commented Mar 21, 2026

AgentScope-Java Version

[The version of AgentScope-Java you are working on, e.g. 1.0.9, check your pom.xml dependency version or run mvn dependency:tree | grep agentscope-parent:pom(only mac/linux)]

Description

Background

The unit test code testConcurrencyConflictStructuredOutput contains two agent.call actions.

The first thread's agent.call writes generate_response into the Toolkit and then clears it in the doFinally block.

The second thread's agent.call also writes generate_response into the Toolkit and then clears it in the doFinally block.

Problem

The issue occurs when the first thread executes doFinally later than the second thread writes generate_response. In this case, the first thread will clear the content written by the second thread into the Toolkit, causing the second thread to fail to retrieve generate_response.

Objective

Avoid "late cleanup" mistakenly deleting a tool with the same name that has already been overwritten by another call.

Implementation Approach

Use Java's ConcurrentHashMap.remove(Object key, Object value) to ensure only the tool written by the current thread is removed, while preventing race conditions.

How to Verify

Add a new test method: io.agentscope.core.agent.ReActAgentStructuredOutputTest#testConcurrencyConflictStructuredOutput_repeated.

Test the same method 25,000 times. If no exceptions occur, it can be considered basically problem-free.

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

@xuhuafeifei xuhuafeifei requested a review from a team March 21, 2026 11:30
@xuhuafeifei xuhuafeifei changed the title Fix issue 1009 Fix issue #1009 Mar 21, 2026
@codecov
Copy link

codecov bot commented Mar 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Collaborator

@LearningGp LearningGp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@LearningGp LearningGp changed the title Fix issue #1009 fix(generate_response): Fix flaky concurrent tests for generate_response Mar 26, 2026
@LearningGp LearningGp merged commit 58e1b4b into agentscope-ai:main Mar 26, 2026
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.

2 participants