fix(extensions): resolve infinite loop and strategy starvation in AutoContextMemory#994
Open
jujn wants to merge 4 commits intoagentscope-ai:mainfrom
Open
fix(extensions): resolve infinite loop and strategy starvation in AutoContextMemory#994jujn wants to merge 4 commits intoagentscope-ai:mainfrom
jujn wants to merge 4 commits intoagentscope-ai:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
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.
...utocontext-memory/src/main/java/io/agentscope/core/memory/autocontext/AutoContextMemory.java
Outdated
Show resolved
Hide resolved
...utocontext-memory/src/main/java/io/agentscope/core/memory/autocontext/AutoContextMemory.java
Show resolved
Hide resolved
...utocontext-memory/src/main/java/io/agentscope/core/memory/autocontext/AutoContextMemory.java
Outdated
Show resolved
Hide resolved
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
mvn spotless:applymvn test)