Skip to content

[Bug]: After upgrading to version 2.0.3, there was an error when writing to the Redis cluster. #3085

Closed

Description

@1065609785

After upgrading to version 2.0.3, there was an error when writing to the Redis cluster.
Describe the bug
The AgentScope 2.0.2 version is operating normally. Only upgrading AgentScope to 2.0.3 without modifying any business or Redis cluster-related configurations resulted in errors when writing to the Redis cluster after the upgrade.

To Reproduce
The store is using this: DistributedStore store = RedisDistributedStore.fromJedis(getJedisCluster(), agentScopeProperties.getRedis().getKeyPrefix());

Expected behavior
A clear and concise description of what you expected to happen.

Error messages
系统异常

java.lang.RuntimeException: Failed to save state if version: agent_state
at io.agentscope.extensions.redis.state.RedisAgentStateStore.saveIfVersion(RedisAgentStateStore.java:289)
at io.agentscope.core.ReActAgent.persistAgentStateCas(ReActAgent.java:557)
at io.agentscope.core.ReActAgent.lambda$saveStateToSession$1(ReActAgent.java:485)
at reactor.core.publisher.MonoRunnable.subscribe(MonoRunnable.java:49)
at reactor.core.publisher.Mono.subscribe(Mono.java:4569)
at reactor.core.publisher.MonoSubscribeOn$SubscribeOnSubscriber.run(MonoSubscribeOn.java:127)
at io.opentelemetry.instrumentation.reactor.v3_1.ContextPropagationOperator$RunnableWrapper.run(ContextPropagationOperator.java:374)
at reactor.core.scheduler.WorkerTask.call(WorkerTask.java:90)
at reactor.core.scheduler.WorkerTask.call(WorkerTask.java:37)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:328)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:309)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1090)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:614)
at java.base/java.lang.Thread.run(Thread.java:1474)
Caused by: redis.clients.jedis.exceptions.JedisClusterOperationException: Keys must belong to same hashslot.
at redis.clients.jedis.ClusterCommandArguments.processKey(ClusterCommandArguments.java:36)
at redis.clients.jedis.CommandArguments.key(CommandArguments.java:131)
at java.base/java.lang.Iterable.forEach(Iterable.java:75)
at redis.clients.jedis.CommandArguments.keys(CommandArguments.java:161)
at redis.clients.jedis.CommandObjects.eval(CommandObjects.java:3114)
at redis.clients.jedis.UnifiedJedis.eval(UnifiedJedis.java:4019)
at io.agentscope.extensions.redis.state.jedis.JedisClientAdapter.evalScript(JedisClientAdapter.java:173)
at io.agentscope.extensions.redis.state.RedisAgentStateStore.saveIfVersion(RedisAgentStateStore.java:283)
... 13 common frames omitted

Environment (please complete the following information):

  • AgentScope-Java Version: [2.0.3]
  • Java Version: [21]
  • OS: [ windows10]

Activity

  1. added
    bug
    on Sep 10, 2026
  2. HaleBos commented on Sep 10, 2026

    @HaleBos

    I have same problem
    java.lang.RuntimeException: Failed to save state if version: agent_state
    ....
    Caused by: redis.clients.jedis.exceptions.JedisDataException: CROSSSLOT Keys in request don't hash to the same slot
    at redis.clients.jedis.Protocol.processError(Protocol.java:110) ~[jedis-7.4.1.jar!/:?]
    at redis.clients.jedis.Protocol.process(Protocol.java:158) ~[jedis-7.4.1.jar!/:?]
    at redis.clients.jedis.Protocol.read(Protocol.java:221) ~[jedis-7.4.1.jar!/:?]
    at redis.clients.jedis.Connection.protocolRead(Connection.java:430) ~[jedis-7.4.1.jar!/:?]
    at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:443) ~[jedis-7.4.1.jar!/:?]
    at redis.clients.jedis.Connection.getOne(Connection.java:416) ~[jedis-7.4.1.jar!/:?]
    at redis.clients.jedis.Connection.executeCommand(Connection.java:212) ~[jedis-7.4.1.jar!/:?]
    at redis.clients.jedis.executors.DefaultCommandExecutor.executeCommand(DefaultCommandExecutor.java:24) ~[jedis-7.4.1.jar!/:?]
    at redis.clients.jedis.UnifiedJedis.executeCommand(UnifiedJedis.java:317) ~[jedis-7.4.1.jar!/:?]
    at redis.clients.jedis.UnifiedJedis.eval(UnifiedJedis.java:4019) ~[jedis-7.4.1.jar!/:?]
    at io.agentscope.extensions.redis.state.jedis.JedisClientAdapter.evalScript(JedisClientAdapter.java:173) ~
    at io.agentscope.extensions.redis.state.RedisAgentStateStore.saveIfVersion(RedisAgentStateStore.java:283) ~
    ... 12 more

  3. rudy2steiner commented on Sep 10, 2026

    @rudy2steiner
    Contributor

    I‘ll fix it later

  4. oss-maintainer commented on Sep 11, 2026

    @oss-maintainer
    Collaborator

    Issue Evaluation

    Category: bug | Status: Needs Info (strong cluster-mode suspect identified)

    Checked against main @ c5db8f7:

    • agentscope-extensions/agentscope-extensions-redis/.../state/RedisAgentStateStore.java:270-293 — saveIfVersion() wraps any failure into RuntimeException("Failed to save state if version: " + key, e), which is the outer exception in your trace; the cause is what matters here and it is not present in the report.
    • RedisStateVersionSupport.SAVE_SCRIPT runs a multi-key Lua script with KEYS = [payloadKey, payloadKey+":ver", prefix+slotId+":_keys"] (saveScriptKeys, lines 90-93). None of these keys carries a Redis hash tag, so in cluster mode the three keys are not guaranteed to map to the same slot and the EVAL is rejected (CROSSSLOT / "keys must in same slot").
    • JedisClientAdapter#evalScript (line 172-178) calls unifiedJedis.eval(...) directly, i.e. the cluster path is exercised as-is.
    • slotId() (line 446-451) produces user/sessionId, and key builders at 486-509 concatenate the raw prefix — again no {...} tag.

    The 2.0.2 → 2.0.3 difference is consistent with the versioned CAS write path being introduced in that range, which is why the same configuration works on 2.0.2.

    To confirm, please paste:

    • The cause of the exception (the Caused by: block under Failed to save state if version) — we need the actual Redis error string.
    • Your Redis topology (real cluster / proxy-based cluster such as Tair/Corvus / Sentinel / standalone) and the Jedis version.
    • Whether agentscope-core is also 2.0.3 (i.e. the upgrade did not leave a mixed version on the classpath).

    Recommended fix direction once confirmed: include a common hash tag in the session-scoped keys (e.g. {prefix:userId/sessionId} for payload, version and _keys) so all KEYS land in one slot, or fall back to a non-atomic read/CAS path when the client is a cluster.


    Automated evaluation by github-manager-bot

  5. added
    area/ext/memory
    on Sep 11, 2026
  6. xzxiaoshan commented on Oct 10, 2026

    @xzxiaoshan
    Collaborator

    complated as #3129

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/ext/memorybug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions