Skip to content

fix(statestore): 修复 saveIfVersion 中的反序列化异常 - #1

Open
hulincup wants to merge 2 commits into
mainfrom
fix/statestore-saveifversion-deserialization
Open

hulincup wants to merge 2 commits into
mainfrom
fix/statestore-saveifversion-deserialization

Conversation

@hulincup

@hulincup hulincup commented Sep 9, 2026

Copy link
Copy Markdown
Owner

问题描述

当 expectedVersion 为 UNVERSIONED 时,所有 AgentStateStore 实现都试图通过
getVersioned(userId, sessionId, key, State.class) 获取版本号。但 State 是接口,
Jackson 无法直接反序列化接口类型,导致 InvalidDefinitionException。

错误堆栈:

java.lang.IllegalArgumentException: Class io.agentscope.state.State is not a concrete class
  at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObject(...)

解决方案

为每个 AgentStateStore 实现添加私有的 readVersionOnly 方法:

  • 直接查询版本号字段,不反序列化 state_data
  • 避免 Jackson 尝试将 JSON 反序列化为 State 接口

修改的文件

  • JdbcAgentStateStore.java
  • MysqlAgentStateStore.java
  • PostgresAgentStateStore.java
  • RedisAgentStateStore.java
  • JedisAgentStateStore.java
  • RedissonAgentStateStore.java

测试建议

  1. 单元测试:验证 saveIfVersion 在 expectedVersion = UNVERSIONED 时能正确返回新版本号
  2. 集成测试:在 Redis/JDBC/MySQL/PostgreSQL 环境中验证修复效果
  3. 回归测试:确保其他 AgentStateStore 方法不受影响

关联 Issue

Fixes agentscope-ai#3047

当 expectedVersion 为 UNVERSIONED 时,所有 StateStore 实现都试图通过
getVersioned(..., State.class) 获取版本号,但 State 是接口,
Jackson 无法直接反序列化接口类型,导致 InvalidDefinitionException。

修复方案:
- 为每个 StateStore 实现添加私有的 readVersionOnly 方法
- 该方法直接查询版本号字段,不反序列化 state_data
- 避免 Jackson 尝试将 JSON 反序列化为 State 接口

修改的实现:
- JdbcAgentStateStore
- MysqlAgentStateStore
- PostgresAgentStateStore
- RedisAgentStateStore
- JedisAgentStateStore
- RedissonAgentStateStore

Fixes agentscope-ai#3047
补充修复 JedisAgentStateStore 和 RedissonAgentStateStore 中
saveIfVersion 方法在 expectedVersion 为 UNVERSIONED 时的反序列化问题。

Fixes agentscope-ai#3047
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: saveIfVersion() passes State.class to getVersioned() , causing Jackson InvalidDefinitionException on deserialization

1 participant