Skip to content

fix(redis-session): clear shutdown interrupted state correctly#1318

Closed
JGoP-L wants to merge 6 commits into
agentscope-ai:mainfrom
JGoP-L:fix-redis-session-key-delete
Closed

fix(redis-session): clear shutdown interrupted state correctly#1318
JGoP-L wants to merge 6 commits into
agentscope-ai:mainfrom
JGoP-L:fix-redis-session-key-delete

Conversation

@JGoP-L

@JGoP-L JGoP-L commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

1.0.12-SNAPSHOT

Description

This PR fixes a Redis session persistence bug where per-key session deletion was not implemented for RedisSession.

Background:

  • GracefulShutdownManager.checkAndClearShutdownInterrupted(...) relies on session.delete(sessionKey, "shutdown_interrupted") to clear the shutdown interruption flag after it is read.
  • RedisSession previously inherited the default no-op implementation of Session.delete(SessionKey, String).
  • As a result, the shutdown_interrupted flag could remain persisted in Redis and be repeatedly detected on later runs.

Changes made:

  • Implemented RedisSession.delete(SessionKey, String) to delete a single persisted state key.
  • Added removeFromSet(...) support to Redis client adapters so deleted state keys are also removed from the session tracking set.
  • Implemented set member removal for Jedis, Lettuce, and Redisson adapters.
  • Added regression tests covering Redis single-state key deletion and GracefulShutdownManager clearing shutdown_interrupted only once.

How to test:

mvn -pl agentscope-extensions/agentscope-extensions-session-redis -am -Dtest=JedisSessionTest#testDeleteSingleStateKey+testDeleteSingleStateKeyRemovesPersistedValue+testManagerCheckAndClearShutdownInterruptedWithRedisSession test
mvn -pl agentscope-extensions/agentscope-extensions-session-redis -am test

Closes #1315

Checklist

Please check the following items before code is ready to be reviewed.

  • Code has been formatted with mvn spotless:apply
  • All relevant tests are passing (mvn -pl agentscope-extensions/agentscope-extensions-session-redis -am test)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated or is not required
  • Code is ready for review

@JGoP-L JGoP-L requested review from a team and Copilot April 29, 2026 10:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes Redis-backed session persistence so that per-key state deletion works (specifically enabling GracefulShutdownManager to clear the persisted shutdown_interrupted flag after it is read), preventing repeated “shutdown-interrupted retry” behavior across restarts.

Changes:

  • Implemented RedisSession.delete(SessionKey, String) to delete an individual persisted state key and remove it from the session tracking set.
  • Added removeFromSet(...) support to the Redis client adapter abstraction and implemented it for Jedis, Lettuce, and Redisson adapters.
  • Added regression tests validating single-key deletion behavior and the one-time clearing behavior in GracefulShutdownManager.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
agentscope-extensions/agentscope-extensions-session-redis/src/main/java/io/agentscope/core/session/redis/RedisSession.java Implements per-key deletion and updates session key-tracking metadata accordingly.
agentscope-extensions/agentscope-extensions-session-redis/src/main/java/io/agentscope/core/session/redis/RedisClientAdapter.java Extends the adapter contract with removeFromSet (default no-op) to support metadata cleanup.
agentscope-extensions/agentscope-extensions-session-redis/src/main/java/io/agentscope/core/session/redis/jedis/JedisClientAdapter.java Implements set member removal via srem.
agentscope-extensions/agentscope-extensions-session-redis/src/main/java/io/agentscope/core/session/redis/lettuce/LettuceClientAdapter.java Implements set member removal for both standalone and cluster command paths.
agentscope-extensions/agentscope-extensions-session-redis/src/main/java/io/agentscope/core/session/redis/redisson/RedissonClientAdapter.java Implements set member removal using RSet.remove.
agentscope-extensions/agentscope-extensions-session-redis/src/test/java/io/agentscope/core/session/redis/JedisSessionTest.java Adds regression tests for per-key deletion and shutdown flag clearing behavior.

@Override
public void deleteKeys(String... keys) {
for (String key : keys) {
values.remove(key);

Copilot AI Apr 29, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StatefulRedisClientAdapter.deleteKeys(...) currently only removes entries from the values map. Since RedisClientAdapter.deleteKeys is used to delete any Redis key (including the session _keys set), this test adapter can become inconsistent if a test ever deletes set keys via deleteKeys. Consider removing deleted keys from both values and sets (and optionally dropping the set entry when it becomes empty to better mimic Redis behavior).

Suggested change
values.remove(key);
values.remove(key);
sets.remove(key);

Copilot uses AI. Check for mistakes.
@codecov

codecov Bot commented Apr 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...io/agentscope/core/session/redis/RedisSession.java 75.00% 2 Missing ⚠️
...ntscope/core/session/redis/RedisClientAdapter.java 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@JGoP-L JGoP-L closed this May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]:Session.delete(sessionKey, key) no-op causes repeated empty input after graceful shutdown retry`

2 participants