Skip to content

fix(redis): add Redis Cluster support for AgentStateStore - #2587

Open
amyaxy wants to merge 8 commits into
agentscope-ai:mainfrom
amyaxy:fix/2579_agentStateStore-support-for-redis-cluster
Open

fix(redis): add Redis Cluster support for AgentStateStore#2587
amyaxy wants to merge 8 commits into
agentscope-ai:mainfrom
amyaxy:fix/2579_agentStateStore-support-for-redis-cluster

Conversation

@amyaxy

@amyaxy amyaxy commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Description

close #2579

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

…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)
@amyaxy amyaxy changed the title fix(redis): add Redis Cluster support for AgentStateStore and RedisSt… fix(redis): add Redis Cluster support for AgentStateStore Aug 6, 2026
@codecov

codecov Bot commented Aug 6, 2026

Copy link
Copy Markdown

@oss-maintainer oss-maintainer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

@amyaxy

amyaxy commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

@zouyx 麻烦审核一下,谢谢

amyaxy and others added 4 commits August 9, 2026 11:00
…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).
@amyaxy
amyaxy requested review from oss-maintainer and zouyx August 9, 2026 09:48
@zouyx

zouyx commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator

@zouyx 麻烦审核一下,谢谢

这个变更有点多,需要点时间

@AgentScopeJavaBot AgentScopeJavaBot added bug Something isn't working area/build Build, CI, BOM, distribution area/core/memory Memory, session, state area/extensions agentscope-extensions (general) labels Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/build Build, CI, BOM, distribution area/core/memory Memory, session, state area/extensions agentscope-extensions (general) bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: agentStateStore does not support Redis Cluster.

4 participants