[Bug]:Session.delete(sessionKey, key) no-op causes repeated empty input after graceful shutdown retry`
Title
Session.delete(sessionKey, key) default no-op causes shutdown_interrupted flag to persist and repeated empty input after graceful shutdown retry
AgentScope-Java is an open-source project. To involve a broader community, we recommend asking your questions in English.
Describe the bug
Session.delete(SessionKey sessionKey, String key) has a default no-op implementation.
default void delete(SessionKey sessionKey, String key) {
// Default no-op; implementations should override if they support per-key deletion
}
Currently, InMemorySession and JsonSession override this per-key delete method, but RedisSession does not. Other custom Session implementations may also inherit the default no-op behavior.
This breaks the graceful shutdown resume logic.
During shutdown interruption, ActiveRequestContext.saveToSession() persists the agent state and writes the shutdown_interrupted flag:
agent.saveTo(session, sessionKey);
session.save(sessionKey, SHUTDOWN_INTERRUPTED_KEY, new ShutdownInterruptedState(true));
On the next request, GracefulShutdownHook handles PreCallEvent and calls checkAndClearShutdownInterrupted(...). If the flag exists, it tries to clear it:
binding.session()
.delete(binding.sessionKey(), ActiveRequestContext.SHUTDOWN_INTERRUPTED_KEY);
return true;
However, when the underlying Session implementation does not override delete(sessionKey, key), the flag is never removed. checkAndClearShutdownInterrupted(...) still returns true, so every following request is treated as a shutdown-interrupted retry.
GracefulShutdownHook then discards the current user input:
event.setInputMessages(List.of());
As a result, the user input becomes empty repeatedly, and the agent may keep generating the same response again and again from the saved memory context.
To Reproduce Steps to reproduce the behavior:
- Use a
Sessionimplementation that does not overridedelete(SessionKey sessionKey, String key), for exampleRedisSession. - Create an agent with session persistence enabled.
- Start a request and trigger graceful shutdown while the request is active.
- The shutdown logic saves the agent state and writes
shutdown_interrupted = trueinto the session. - Restart the application or retry the same client request.
GracefulShutdownHookreceivesPreCallEventand callscheckAndClearShutdownInterrupted(...).checkAndClearShutdownInterrupted(...)reads the flag and callssession.delete(sessionKey, "shutdown_interrupted").- Because
delete(sessionKey, key)is a no-op for this session implementation, the flag remains. - The hook calls
event.setInputMessages(List.of()), clearing the user input. - Retry or continue the conversation again.
- The same flag is detected again, user input is cleared again, and the agent repeatedly outputs the same content.
Expected behavior
The shutdown_interrupted flag should be removed after it is detected once.
After checkAndClearShutdownInterrupted(...) returns true, subsequent requests should not be treated as shutdown-interrupted retries unless a new shutdown interruption actually occurs.
Session.delete(sessionKey, key) should either:
- be implemented by all built-in
Sessionimplementations, includingRedisSession; or - not have a silent no-op default implementation; or
checkAndClearShutdownInterrupted(...)should verify that the flag was actually removed before returningtrue.
Error messages No exception is thrown.
Observed behavior:
shutdown_interruptedremains in session storage.- User input is repeatedly cleared by
event.setInputMessages(List.of()). - The agent repeatedly generates the same or similar output.
- The issue is silent because the default
delete(sessionKey, key)implementation does nothing and does not fail.
Environment (please complete the following information):
- AgentScope-Java Version: 1.0.11
- Java Version: [please fill in, e.g. 17 / 21 / 25]
- OS: Windows
Additional context
The issue is caused by a mismatch between the graceful shutdown logic and the Session contract.
GracefulShutdownManager.checkAndClearShutdownInterrupted(...) assumes per-key deletion works:
if (flag.isPresent() && flag.get().interrupted()) {
binding.session()
.delete(binding.sessionKey(), ActiveRequestContext.SHUTDOWN_INTERRUPTED_KEY);
return true;
}
But Session.delete(sessionKey, key) is optional in practice because the interface provides a no-op default implementation.
This is especially problematic for persistent or distributed sessions such as RedisSession, where the flag survives process restarts and causes every retry to be treated as a shutdown resume.
Possible fixes:
- Implement
delete(SessionKey sessionKey, String key)inRedisSessionand other built-in session implementations. - Consider making
delete(SessionKey sessionKey, String key)a required interface method instead of a default no-op. - Add a regression test using a non-memory session implementation to verify that
shutdown_interruptedis cleared after the first retry. - Optionally make
checkAndClearShutdownInterrupted(...)re-read the flag after deletion or log a warning if the flag still exists.