[Bug]: ReActAgent checks shutdown flag on the wrong AgentState in multi-session calls
AgentScope-Java Version
2.0.2
Description
ReActAgent.doCallInner checks the shutdown-interrupted flag through the agent instance:
shutdownManager.checkAndClearShutdownInterrupted(ReActAgent.this)
However, doCallInner runs inside a per-call CallExecution, which already contains the AgentState resolved from the current (userId, sessionId) in RuntimeContext.
GracefulShutdownManager.checkAndClearShutdownInterrupted(Agent) then calls the no-argument AgentBase.getAgentState(). For ReActAgent, this resolves to the default slot (null, defaultSessionId) rather than the current call's state.
As a result, the shutdown retry recovery logic may read and clear a different AgentState from the one that was interrupted and persisted during shutdown.
To Reproduce
- Create one
ReActAgentinstance serving at least two sessions, for examplesession-aandsession-b. - Call the agent with an explicit
RuntimeContext, such as:userId = user-asessionId = session-a
- Let graceful shutdown interrupt the request and persist that session's
AgentStatewithshutdownInterrupted = true. - Restart the application or retry the same request with the same
RuntimeContext. - Observe that
doCallInnerchecks the default agent state instead of theAgentStateforsession-a.
A deterministic unit test can set shutdownInterrupted = true on a non-default session state, invoke the call for that session, and verify that the duplicate input is discarded and only that session's flag is cleared.
Expected Behavior
The shutdown-interrupted flag should be checked and cleared on the current call's CallExecution.state, identified by the current RuntimeContext (userId, sessionId).
Actual Behavior
The no-argument getAgentState() reads the default slot. For non-default users or sessions, the retry may:
- fail to discard the duplicate input;
- leave the interrupted session's flag set; or
- if the default slot is flagged, discard input belonging to another session.
Root Cause
ReActAgent maintains per-session state in stateCache, keyed by (userId, sessionId).
The call lifecycle correctly resolves the active state into CallExecution.state, and AgentBase binds that state to the shutdown request. However, doCallInner calls the legacy agent-level shutdown API.
GracefulShutdownManager.checkAndClearShutdownInterrupted(Agent) effectively does:
AgentState state = agent.getAgentState();
And ReActAgent.getAgentState() delegates to the default session slot:
getAgentState(null, defaultSessionId)
This is inconsistent with the call-scoped state model introduced in AgentScope 2.x.
Suggested Fix
Add a shutdown check overload accepting the resolved AgentState, or otherwise make the check request/call-scoped.
For example:
if (shutdownManager.checkAndClearShutdownInterrupted(state)) {
msgs = List.of();
}
The existing agent-level overload may be retained for compatibility, but the ReActAgent.doCallInner path should use the current call's state.
Environment
- AgentScope-Java: 2.0.2
- JDK: 17+
- Affected module:
agentscope-core - Affected classes:
ReActAgentGracefulShutdownManager