fix(redis): add Redis Cluster support for AgentStateStore - #2587
Open
amyaxy wants to merge 8 commits into
Open
Conversation
…ore (agentscope-ai#2579) - Bind session/namespace keys to the same slot via hash tags to avoid CROSSSLOT errors on multi-key EVAL in cluster mode - Fix cross-node SCAN for Jedis (scanIteration) and Lettuce (iterate all master nodes) so listSessionIds/clearAllSessions no longer miss shards - Escape glob metacharacters in listSessionIds userId - Document key-layout breaking change in class Javadoc - Make the integration test portable (single container + fixed port bindings) so it runs on Windows/macOS/Linux - Add testcontainers dependency; add unit + integration tests (22 cases pass)
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
oss-maintainer
left a comment
Collaborator
There was a problem hiding this comment.
Summary
This PR modifies 12 files with 1160 lines of diff.
Observations
- Files changed: 12
- Test coverage: ✅ Tests included
- CLA: ✅ Signed
Suggestions
- Please ensure all public API changes are backward compatible
- Consider adding unit tests for new logic paths
Automated review by github-manager-bot
Contributor
Author
|
@zouyx 麻烦审核一下,谢谢 |
zouyx
reviewed
Aug 8, 2026
…ectness bugs
Make RedisAgentStateStore safe under Redis Cluster (hash tags) and close several
data-correctness / concurrency / security gaps found in review.
Core correctness & atomicity
- ListHashUtil: hash over ALL elements instead of sampling 5 indices (C1),
fixing silent hash collisions / data loss on non-sampled mutations.
- save(List): single atomic EVAL guarded-append via LIST_SAVE_SCRIPT, removing
the non-atomic multi-step list save (C2 / CN1).
- getVersioned: read payload+version atomically via client.mget (H1).
- save / saveIfVersion: drop the Long.MIN_VALUE sentinel, use an explicit
`unconditional` flag (M1 / L1 / L2); save(value) clears the list form via
SAVE_VALUE_SCRIPT so single-value and list states never coexist (M1 reverse).
- delete / clearAllSessions: atomic per-key delete (PER_KEY_DELETE_SCRIPT, H2)
and atomic read-SMEMBERS + DEL (CLEAR_SESSION_SCRIPT) to close the
save-vs-clearAllSessions race (CN2); only scan *:_keys markers, return the
actual deleted count, and warn that it is destructive (M2 / S3).
Key validation & scope safety
- validateStateKey: reject blank / { } / :list-suffix state keys (S1).
- slotId / validateScopeId: reject '/', ',' and glob metachars in userId /
sessionId to protect the {user/session} hash tag and SCAN patterns (N1);
reject the reserved sentinel "__anon__" to avoid collision with anonymous
sessions (N2). Anonymous (null/blank) sessions keep the existing layout.
- CLEAR_SESSION_SCRIPT: batch DEL via unpack sub-ranges (BATCH=500) to avoid
the Lua varargs C-stack limit on large sessions (N3).
Collaborator
这个变更有点多,需要点时间 |
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 #2579
Checklist
Please check the following items before code is ready to be reviewed.
mvn spotless:applymvn test)