Skip to content

Fix issue #1009#1011

Open
xuhuafeifei wants to merge 5 commits intoagentscope-ai:mainfrom
xuhuafeifei:fix_issue_1009
Open

Fix issue #1009#1011
xuhuafeifei wants to merge 5 commits intoagentscope-ai:mainfrom
xuhuafeifei:fix_issue_1009

Conversation

@xuhuafeifei
Copy link

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 runSubscribeOnThenSequentialSecondCallStructuredOutputScenario 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!

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.

1 participant