Repository navigation
Description
Describe the bug
When saveIfVersion(userId, sessionId, key, value, UNVERSIONED) is called,
the implementation saves the state and then calls getVersioned(userId, sessionId, key, State.class)
to retrieve the version. However, State is a marker interface, and Jackson cannot deserialize
JSON into an interface type without additional type information.
Calling AgentStateStore.saveIfVersion(..., AgentStateStore.UNVERSIONED) on any optimistic-concurrency (versioning) backend — JDBC, MySQL, PostgreSQL, or Redis (Jedis/Redisson/unified) — throws InvalidDefinitionException because the implementation tries to deserialize the state back as the State marker interface to obtain the version number.
This produces the following exception:
com.fasterxml.jackson.databind.exc.InvalidDefinitionException:
Cannot construct instance of io.agentscope.core.state.State (no Creators, like default constructor, exist): abstract types either need to be
mapped to concrete types, have custom deserializer, or contain additional type information
To Reproduce
Steps to reproduce the behavior:
- Use any
AgentStateStoreimplementation that overridessaveIfVersion()
with versioning support (Redis, MySQL, PostgreSQL, JDBC). - Save an agent state with
UNVERSIONEDexpected version. - The internal call to
getVersioned(..., State.class)will fail.
Expected behavior
The method should write the state unconditionally and return the new version number (e.g. 2L), exactly as described in the AgentStateStore#saveIfVersion contract. It must not attempt to deserialize the payload into the State marker interface.
Error messages
Detailed error messages.
Original Stack Trace:
at io.agentscope.extensions.mysql.state.MysqlAgentStateStore.getVersioned(MysqlAgentStateStore.java:419)
at io.agentscope.extensions.mysql.state.MysqlAgentStateStore.saveIfVersion(MysqlAgentStateStore.java:428)
at io.agentscope.core.ReActAgent.persistAgentStateCas(ReActAgent.java:567)
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.javaagent.shaded.instrumentation.reactor.v3_1.ContextPropagationOperator$RunnableWrapper.run(ContextPropagationOperator.java:373)
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$$$capture(FutureTask.java:317)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: io.agentscope.core.util.JsonException: Failed to deserialize JSON to io.agentscope.core.state.State
at io.agentscope.core.util.JacksonJsonCodec.fromJson(JacksonJsonCodec.java:112)
at io.agentscope.extensions.mysql.state.MysqlAgentStateStore.getVersioned(MysqlAgentStateStore.java:415)
at io.agentscope.extensions.mysql.state.MysqlAgentStateStore.saveIfVersion(MysqlAgentStateStore.java:428)
at io.agentscope.core.ReActAgent.persistAgentStateCas(ReActAgent.java:567)
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.javaagent.shaded.instrumentation.reactor.v3_1.ContextPropagationOperator$RunnableWrapper.run(ContextPropagationOperator.java:373)
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$$$capture(FutureTask.java:317)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of io.agentscope.core.state.State (no Creators, like default constructor, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information
at [Source: REDACTED (StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION disabled); line: 1, column: 1]
Environment (please complete the following information):
- AgentScope-Java Version: 2.0.3
- Java Version: [21]
- OS: windows
Additional context
Root cause: State is a marker interface (public interface State {}), so Jackson cannot construct an instance of it. Six saveIfVersion implementations — JdbcAgentStateStore, MysqlAgentStateStore, PostgresAgentStateStore, JedisAgentStateStore, RedissonAgentStateStore, RedisAgentStateStore — call getVersioned(..., State.class).version() in the UNVERSIONED branch solely to read a version number, which forces full deserialization into the abstract interface. The fix reads the version without deserializing the payload (version-only read for SQL stores; return the Lua script result directly for Redis stores).
The OssAgentStateStore, CosAgentStateStore, JpaAgentStateStore, and JsonFileAgentStateStore
do not override saveIfVersion() and use the default implementation from the AgentStateStore
interface, so they are not affected.
Activity
amyaxy commentedon Sep 8, 2026
I'll submit a PR to fix it.
fix(statestore): 修复 Jedis/Redisson StateStore 中的反序列化异常
fix(state): avoid deserializing the State marker interface in saveIfV…