Repository navigation
Description
[Bug]: OssAgentStateStore can persist large Base64 media but cannot reload the resulting AgentState
Describe the bug
With AgentScope-Java 2.0.3 and Jackson 2.21.4, an AgentState containing a large Base64 VideoBlock can be serialized and persisted successfully, but cannot be deserialized with the same default codec.
We encountered this with OssAgentStateStore. Loading the saved state fails before model invocation, so subsequent turns in the same session fail repeatedly, including text-only messages.
The issue is a persistence round-trip inconsistency: the writer accepts a state that the reader cannot restore under its current constraints. This is not a request to remove Jackson's safety limits.
To Reproduce
- Create a directory containing the following
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>example</groupId>
<artifactId>agentscope-state-roundtrip-repro</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-bom</artifactId>
<version>2.21.4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.agentscope</groupId>
<artifactId>agentscope-core</artifactId>
<version>2.0.3</version>
</dependency>
</dependencies>
</project>- Save the following as
AgentStateRoundTripRepro.javain that directory. This isolates the codec path used by the OSS store; it requires no OSS credentials, real video, or model API.
import com.fasterxml.jackson.core.StreamReadConstraints;
import io.agentscope.core.message.Base64Source;
import io.agentscope.core.message.UserMessage;
import io.agentscope.core.message.VideoBlock;
import io.agentscope.core.state.AgentState;
import io.agentscope.core.util.JacksonJsonCodec;
import java.util.List;
public class AgentStateRoundTripRepro {
public static void main(String[] args) {
// Synthetic Base64 only; no real video or model request is needed.
int sourceBytes = 25_172_915;
int base64Chars = 4 * ((sourceBytes + 2) / 3);
String data = "A".repeat(base64Chars - 1) + "=";
AgentState state = AgentState.builder()
.userId("test-user")
.sessionId("test-session")
.context(List.of(new UserMessage(List.of(
new VideoBlock(new Base64Source("video/mp4", data))))))
.build();
JacksonJsonCodec codec = new JacksonJsonCodec();
String json = codec.toJson(state); // Succeeds.
System.out.println("Serialization succeeded; Base64 chars=" + base64Chars);
try {
codec.fromJson(json, AgentState.class); // Fails with default constraints.
throw new AssertionError("Expected the default reader to reject the payload");
} catch (io.agentscope.core.util.JsonException expected) {
Throwable root = expected;
while (root.getCause() != null) root = root.getCause();
System.out.println(root.getClass().getName() + ": " + root.getMessage());
}
// Diagnostic control, not a recommendation to disable limits globally.
JacksonJsonCodec scopedCodec = new JacksonJsonCodec();
scopedCodec.getObjectMapper().getFactory().setStreamReadConstraints(
StreamReadConstraints.builder()
.maxStringLength(64 * 1024 * 1024)
.build());
AgentState restored = scopedCodec.fromJson(json, AgentState.class);
VideoBlock video = (VideoBlock) restored.getContext().getFirst()
.getContent().getFirst();
if (!data.equals(((Base64Source) video.getSource()).getData())) {
throw new AssertionError("Restored payload differs");
}
System.out.println("Scoped larger-limit reader: round trip succeeded");
}
}- With JDK 21 selected, execute:
mvn dependency:copy-dependencies -DincludeScope=runtime
java -Xmx512m --class-path "target/dependency/*" AgentStateRoundTripRepro.javaThe Base64 field contains 33,563,888 characters. Serialization succeeds, default deserialization fails, and the diagnostic reader with a larger scoped limit restores the same payload unchanged.
In the OSS-backed application, the corresponding sequence is to save an AgentState with this media payload and then restore the session in a new agent instance. The local reproducer above isolates serialization/deserialization rather than accessing OSS.
Expected behavior
State accepted by the persistence layer should be readable by that layer under the same configuration.
If an embedded media field exceeds supported limits, saving should fail with a clear, actionable error before replacing a previously valid state. Alternatively, the store should offer a documented, bounded codec/constraint configuration or persist large media separately by reference.
Error messages
Minimal reproducer:
Serialization succeeded; Base64 chars=33563888
com.fasterxml.jackson.core.exc.StreamConstraintsException: String value length (20054016) exceeds the maximum allowed (20000000, from `StreamReadConstraints.getMaxStringLength()`)
Scoped larger-limit reader: round trip succeeded
Relevant excerpt from the OSS-backed failure; unrelated application frames and identifiers are omitted:
java.lang.RuntimeException: Failed to get state: agent_state
at io.agentscope.extensions.oss.OssAgentStateStore.get(OssAgentStateStore.java:145)
at io.agentscope.core.state.AgentStateStore.getVersioned(AgentStateStore.java:106)
at io.agentscope.core.ReActAgent.loadOrCreateAgentStateForSlot(ReActAgent.java:433)
...
Caused by: io.agentscope.core.util.JsonException:
Failed to deserialize JSON to io.agentscope.core.state.AgentState
at io.agentscope.core.util.JacksonJsonCodec.fromJson(JacksonJsonCodec.java:112)
...
Caused by: com.fasterxml.jackson.databind.JsonMappingException:
String value length (20054016) exceeds the maximum allowed
(20000000, from `StreamReadConstraints.getMaxStringLength()`)
(through reference chain:
io.agentscope.core.state.AgentState["context"]
->java.util.ArrayList[146]
->io.agentscope.core.message.UserMessage["content"]
->java.util.ArrayList[1]
->io.agentscope.core.message.VideoBlock["source"]
->io.agentscope.core.message.Base64Source["data"])
The reported 20,054,016 is the length observed when parsing fails, not the full Base64 payload length.
Environment (please complete the following information):
- AgentScope-Java Version: 2.0.3 (
agentscope-coreandagentscope-extensions-oss) - Java Version: Amazon Corretto 21.0.4 for the standalone reproduction
- OS: Windows for the standalone reproduction; the original OSS-backed failure occurred in a Linux container
- Jackson:
jackson-core/jackson-databind2.21.4;jackson-annotations2.21 - The issue and diagnostic control were reproduced with 2.0.3. Later AgentScope releases have not been tested.
Additional context
The v2.0.3 sources show that:
- OssAgentStateStore serializes state using the global AgentScope codec and reads it back through that codec, without checking read compatibility before persisting.
- JacksonJsonCodec creates its own ObjectMapper. Changing only a Spring-managed ObjectMapper does not change this codec.
A separate codec configured with a 64 Mi-character string limit passed the synthetic round-trip check. This is diagnostic evidence, not a proposed unlimited/global production setting. Whole-state size, concurrent reads, and memory usage also need bounds.
A regression test covering save/serialize followed by restore/deserialize of large multimodal state would help prevent this class of failure. All payload data in the reproducer is synthetic.
Activity
fix(core): let JacksonJsonCodec read back every string it can write
fix(core): let JacksonJsonCodec read back every string it can write
fix(core): let JacksonJsonCodec read back every string it can write (a…