Skip to content

fix(extensions): resolve infinite loop and strategy starvation in AutoContextMemory#994

Open
jujn wants to merge 4 commits intoagentscope-ai:mainfrom
jujn:fix_989
Open

fix(extensions): resolve infinite loop and strategy starvation in AutoContextMemory#994
jujn wants to merge 4 commits intoagentscope-ai:mainfrom
jujn:fix_989

Conversation

@jujn
Copy link

@jujn jujn commented Mar 19, 2026

Description

Close #989

This PR fixes issue989 where skipped tool compressions (due to low tokens) falsely reported success, causing an infinite search loop and blocking subsequent compression strategies. By changing summaryToolsMessages to return a boolean and introducing a search cursor (searchStartIndex), the memory manager now correctly advances past skipped messages. As a result, the full auto-context compression chain (Strategies 1-6) can now execute reliably without getting stuck.

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

@jujn jujn requested review from a team and Copilot March 19, 2026 13:37
@cla-assistant
Copy link

cla-assistant bot commented Mar 19, 2026

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes #989 by ensuring Strategy 1 (tool-invocation compression) only reports success when compression actually occurs, and by adding a cursor to continue scanning past tool groups that were skipped due to low tokens—allowing the full Strategy 1–6 compression chain to proceed without getting stuck.

Changes:

  • Change summaryToolsMessages(...) to return a boolean indicating whether compression actually ran (vs. being skipped due to token threshold).
  • Add a cursor (cursorStartIndex / searchStartIndex) to advance past skipped tool-message ranges and avoid re-selecting the same range repeatedly.
  • Add/adjust unit tests to validate that compression continues when tool compression is skipped and that later tool groups can still be compressed.

Reviewed changes

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

File Description
agentscope-extensions/agentscope-extensions-autocontext-memory/src/main/java/io/agentscope/core/memory/autocontext/AutoContextMemory.java Fix Strategy 1 control flow with a boolean “actually compressed” signal and a cursor-based search to avoid reprocessing skipped tool ranges.
agentscope-extensions/agentscope-extensions-autocontext-memory/src/test/java/io/agentscope/core/memory/autocontext/AutoContextMemoryTest.java Update configs to avoid unintended skipping in existing tests; add targeted tests for “skip due to low tokens but continue” and cursor advancement behavior.

You can also share your feedback on Copilot code review. Take the survey.

@codecov
Copy link

codecov bot commented Mar 19, 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.

[Bug]:AutoContextMemory的策略1 工具调用压缩因 token 不足跳过时,误判为已执行压缩,导致后续策略无法执行

2 participants