Skip to content

fix: resolve three bugs in core agent and tool management (#1164 #1165 #1166)#1167

Open
Fruank4 wants to merge 5 commits intoagentscope-ai:mainfrom
Fruank4:fix/bug-1164-1165-1166
Open

fix: resolve three bugs in core agent and tool management (#1164 #1165 #1166)#1167
Fruank4 wants to merge 5 commits intoagentscope-ai:mainfrom
Fruank4:fix/bug-1164-1165-1166

Conversation

@Fruank4
Copy link
Copy Markdown

@Fruank4 Fruank4 commented Apr 8, 2026

Summary

This PR fixes three bugs identified in the core library:

Changes

Fix #1164StaticLongTermMemoryHook.java

Swap the insertion order so the memory SYSTEM message is prepended before the input messages:

// Before
enhancedMessages.addAll(inputMessages);
enhancedMessages.add(memoryMsg);           // memory appended at end

// After
enhancedMessages.add(memoryMsg);           // memory at beginning
enhancedMessages.addAll(inputMessages);

Fix #1165ToolGroupManager.java

Replace the non-thread-safe ArrayList with CopyOnWriteArrayList and update setActiveGroups() / copyTo() to mutate in-place rather than reassign the field:

// Before
private List<String> activeGroups = new ArrayList<>();
// ...
this.activeGroups = new ArrayList<>(activeGroups);   // unsafe reassignment
target.activeGroups = new ArrayList<>(this.activeGroups);

// After
private final List<String> activeGroups = new CopyOnWriteArrayList<>();
// ...
this.activeGroups.clear();
this.activeGroups.addAll(activeGroups);
target.activeGroups.clear();
target.activeGroups.addAll(this.activeGroups);

Fix #1166MessageUtils.java

Replace msg.getName().equals(agentName) with Objects.equals() to safely handle null names:

// Before
if (msg.getRole() == MsgRole.ASSISTANT && msg.getName().equals(agentName)) {

// After
if (msg.getRole() == MsgRole.ASSISTANT && Objects.equals(msg.getName(), agentName)) {

Test plan

  • Existing unit tests pass (mvn test -pl agentscope-core)
  • Verify RAG memory context appears before user query in message list
  • Verify no ConcurrentModificationException when multiple agents modify tool groups concurrently
  • Verify no NullPointerException when assistant messages without names are present in memory

@Fruank4 Fruank4 requested a review from a team April 8, 2026 13:28
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 8, 2026

CLA assistant check
All committers have signed the CLA.

Fruank4 added 2 commits April 8, 2026 21:34
- StaticLongTermMemoryHook: inject retrieved memory at the beginning of
  the message list instead of appending it at the end, so the LLM
  receives context before the user query (fixes agentscope-ai#1164)

- ToolGroupManager: replace non-thread-safe ArrayList with
  CopyOnWriteArrayList for activeGroups, and update setActiveGroups()
  and copyTo() to mutate the list in-place rather than reassigning the
  field, preventing race conditions in concurrent agent scenarios
  (fixes agentscope-ai#1165)

- MessageUtils.extractRecentToolCalls: replace msg.getName().equals()
  with Objects.equals() to avoid NullPointerException when an assistant
  message has no name set (fixes agentscope-ai#1166)
The test was asserting memory message at index 1 (end), which matched
the old buggy behavior. Update to assert index 0 (beginning) to align
with the fix in agentscope-ai#1164.
@Fruank4 Fruank4 force-pushed the fix/bug-1164-1165-1166 branch from 4fcddee to 5317598 Compare April 8, 2026 13:34
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 8, 2026

Codecov Report

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

Files with missing lines Patch % Lines
...ain/java/io/agentscope/core/util/MessageUtils.java 0.00% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@Fruank4
Copy link
Copy Markdown
Author

Fruank4 commented Apr 9, 2026

三个问题:空指针,并发安全,记忆反序

@Fruank4
Copy link
Copy Markdown
Author

Fruank4 commented Apr 10, 2026

给孩子过了吧 呜呜呜

@LearningGp
Copy link
Copy Markdown
Collaborator

lichuang34 这个账号没有签署 CLA,要不用Fruank4这个账号提交下后两个commit

@Fruank4
Copy link
Copy Markdown
Author

Fruank4 commented Apr 14, 2026

CLA验证了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants