Skip to content

[Bug]: ReActAgent silently resets conversation memory when AgentStateStore throws (and drops the stack trace) #2741

Closed

Description

@hi-neason

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

  1. Configure a ReActAgent / HarnessAgent with any AgentStateStore whose getVersioned(...) throws — e.g. a stub that simulates a transient SQLException/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
    };
  2. Put a few turns into a session so history exists in the working backend.

  3. Make the backend throw once on the next agent.call(...) (flip a flag, kill the Redis proxy, etc.).

  4. 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:
    WARN  ReActAgent - Failed to load AgentState for slot (userId=alice, sessionId=demo): simulated transient store failure
    
    No stack trace.
  • 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 just e.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, commit 49cffeb6)
  • 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.

Activity

  1. added
    bug
    area/core/agent
    area/core/memory
    on Aug 17, 2026
  2. ordinary-s commented on Aug 18, 2026

    @ordinary-s
    Contributor

    Hi, I would like to work on this issue. I have a local fix and regression coverage ready and will open a PR shortly.

  3. moved this from Backlog to In progress in AgentScope Javaon Aug 18, 2026
  4. moved this from In progress to Done in AgentScope Javaon Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/core/agentarea/core/memorybug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions