Skip to content

fix(redis): isolate chat memory key prefixes per repository - #71

Merged
yuluo-yx merged 1 commit into
agentic-ai-java:mainfrom
logicwu0:fix/50-redis-instance-key-prefix
Oct 30, 2026
Merged

yuluo-yx merged 1 commit into
agentic-ai-java:mainfrom
logicwu0:fix/50-redis-instance-key-prefix

Conversation

@logicwu0

Copy link
Copy Markdown
Contributor

Describe what this PR does / why we need it

Redis chat-memory repositories currently share a mutable static key prefix. Constructing a second Jedis, Lettuce, or Redisson repository changes the keys used by an existing repository; even a failed build can change its namespace.

This PR captures the prefix in an immutable instance field so each repository consistently uses its configured namespace.

Does this pull request fix one issue?

Fixes #50

Describe how you did it

  • Pass the builder prefix to the base constructor for all three clients, including Redisson's custom-config path, instead of writing a shared static field.
  • Preserve the default argi_chat_memory:<conversationId> format, null-to-default behavior, explicitly empty prefixes, and intentional sharing between instances with the same prefix.
  • Add offline regression tests for all client pairings, failed and concurrent construction, builder reuse, custom Redisson configuration, and the retained no-argument base constructor.
  • Add real Redis tests for the actual keys used by read/write/list/delete operations, default and shared prefixes, all nine client pairings, and concurrent construction.
  • Add compatibility, data-audit, migration, and rollback guidance to the existing module README. No stored data is moved or deleted by the fix.

Describe how to verify it

With an isolated Redis available on port 16379:

mvn -B -ntp -pl memory-repository/argi-model-chat-memory-repository-redis -am \
  -Dtest=RedisKeyPrefixIsolationTest,RedisKeyPrefixIntegrationTest \
  -Dredis.test.port=16379 -Dcheckstyle.skip=false test

The integration suite alternatively starts a Redis container when Docker is available. Test keys use unique IDs; the suite does not flush the database.

Verified locally with JDK 21 and a temporary standalone Redis 7.0.15 server:

  • Before the production fix, the initial 23 offline cases all exposed the defect (22 assertion failures and one execution exception caused by the concurrent assertion failure). All nine real Redis client-pairing cases also failed because expected namespace keys were absent.
  • After the fix, all 34 new cases passed: 24 offline and 10 real-backend cases, with no skips in either new suite.
  • The module test run reported 91 tests, zero failures/errors, and 57 skips. The skipped cases are the existing Docker-based suites, including TLS tests; Docker is unavailable locally.
  • Checkstyle reported zero violations; git diff --check passed.

Special notes for reviews

Seven files change: four production classes, two test classes, and the existing README. No changes to serialization, SSL, or saveAll atomicity are included.

The protected mutable static CUSTOM_KEY_PREFIX field is removed. External subclasses using that field must migrate to super(keyPrefix) and recompile. The public no-argument base constructor and protected getKeyPrefix() method remain available; public builder methods are unchanged.

Applications previously affected by cross-instance prefix changes should audit known namespaces against authoritative ownership records before migrating any data. Prefixes are not an authorization boundary. The real-backend verification covers standalone Redis, not TLS, Redis Cluster, or high availability.

Capture each repository's prefix at construction instead of mutating shared static configuration. Cover all client pairings, failed and parallel builds, builder reuse, and actual Redis keys. Document compatibility and migration considerations.

Fixes agentic-ai-java#50

@yuluo-yx yuluo-yx 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.

lgtm

@yuluo-yx
yuluo-yx merged commit 399c674 into agentic-ai-java:main Oct 30, 2026
6 checks passed
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] Redis 聊天记忆 key 前缀应属于实例,避免多仓库相互覆盖

2 participants