fix(agent): evict persistence-backed session caches#2339
Open
vowor wants to merge 4 commits into
Open
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
vowor
marked this pull request as ready for review
July 21, 2026 09:47
oss-maintainer
approved these changes
Jul 21, 2026
oss-maintainer
left a comment
Collaborator
There was a problem hiding this comment.
LGTM. Changes look good.
Automated review by github-manager-bot
Collaborator
|
This PR has conflicts with the base branch and cannot be merged. Please rebase or merge the base branch into your branch and resolve the conflicts: git fetch origin
git checkout agent/fix-state-cache-eviction
git rebase origin/main
# resolve conflicts, then:
git push --force-with-leaseThis is a one-time reminder. Feel free to @mention me for a re-review after conflicts are resolved. Automated notification by github-manager-bot |
Author
|
@oss-maintainer The merge conflict has been resolved, and the CI formatting issue has also been fixed. Could you please re-review the PR when you have a chance? Thanks! |
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.
AgentScope-Java Version
2.0.1-SNAPSHOT
Summary
Root cause
When an
AgentStateStorewas configured, every session was loaded intostateCacheandpermissionEngineCache, but completed calls never removed those entries. Long-running multi-user services therefore retained one cache entry per observed session indefinitely. Cleanup also could not safely rely on shared agent fields because concurrent calls may have advanced them to a different session.Implementation
AgentBasenow exposes a terminal callback tied to the exact call scope returned bybeforeAgentExecution.ReActAgentuses that scope to conditionally remove only the state and permission-engine instances owned by the completed call. Conditional map removal prevents an older call from evicting a newer replacement for the same slot.The new
evictSessionandevictUsermethods provide explicit host-controlled cleanup, whileclose()clears both caches. Persistence is not deleted; subsequent access reloads state from the configured store.Verification
mvn test(local macOS runner used headless AWT and a preloaded Mockito agent)agentscope-core: 2,222 tests passed, 9 skippedFixes #2261