Repository navigation
Description
Describe the bug
In ReActAgent.loadOrCreateAgentStateForSlot (agentscope-core, ReActAgent.java:441-448), the catch (Exception e) around state loading falls back to a brand-new empty AgentState for any exception thrown by the configured AgentStateStore — not just "state not found". A transient backend failure (Redis/MySQL blip, connection timeout, serialization error after an upgrade, etc.) is therefore indistinguishable from a genuinely fresh session: the agent continues this turn with empty conversation history, and on the next successful save it can overwrite the previously persisted state.
The same catch also logs e.getMessage() instead of e, so the stack trace is dropped. For exceptions whose getMessage() is null or terse (NPE, some Jackson JsonMappingException paths, timeout wrappers), the log line gives no place to start from.
Related but distinct: #2702 (onError path does not persist), #2475 (sessionId with / corrupts the slot), #2535 (stale stateCache write-back overwrites newer state). This one is the read-side complement.
To Reproduce
-
Configure a
ReActAgent/HarnessAgentwith anyAgentStateStorewhosegetVersioned(...)throws — e.g. a stub that simulates a transientSQLException/RedisConnectionFailureException:AgentStateStore brokenStore = new AgentStateStore() { @Override public <T> Optional<VersionedState<T>> getVersioned( String userId, String sessionId, String key, Class<T> type) { throw new RuntimeException("simulated transient store failure"); } // ... other methods delegate to a working in-memory store };
-
Put a few turns into a session so history exists in the working backend.
-
Make the backend throw once on the next
agent.call(...)(flip a flag, kill the Redis proxy, etc.). -
Send another message.
Observed behavior
- The turn proceeds as if the session were brand new; no prior messages are visible to the model.
- The only log line is:
No stack trace.
WARN ReActAgent - Failed to load AgentState for slot (userId=alice, sessionId=demo): simulated transient store failure - On the next successful save, the empty in-memory state can overwrite the previously persisted history.
Expected behavior
- A transient backend failure should propagate (or the turn should fail fast) rather than silently treating the session as new — the cost of a failed turn is much lower than the cost of silently wiping memory.
- The "fall back to a fresh state" path should be reserved for the genuine absence case, which the code already distinguishes (
versioned.isPresent()/legacy.found()both return false without throwing). - The log should include the exception itself (
log.warn("...", e)), not juste.getMessage().
Error messages
WARN i.a.core.ReActAgent - Failed to load AgentState for slot (userId=alice, sessionId=demo): simulated transient store failure
Environment (please complete the following information):
- AgentScope-Java Version:
2.0.3-SNAPSHOT(main, commit49cffeb6) - Java Version: 17
- OS: macOS 15.3 (darwin)
Additional context
The offending block is ReActAgent.java:441-448:
} catch (Exception e) {
log.warn(
"Failed to load AgentState for slot (userId={}, sessionId={}): {}",
userId,
sessionId,
e.getMessage());
long version = stateStore.supportsVersioning() ? 0L : AgentStateStore.UNVERSIONED;
return new VersionedState<>(fresh, version);
}Happy to send a PR once we agree on the desired semantics — my one-line hypothesis is that the catch should (a) log e for the stack trace and (b) only return fresh when the exception is a known "not found" signal from the store, letting storage/serialization errors bubble.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
ordinary-s commentedon Aug 18, 2026
Hi, I would like to work on this issue. I have a local fix and regression coverage ready and will open a PR shortly.