Skip to content

fix(memory): stop OpenSearch long-term memory indexes colliding across users - #1215

Open
eric7h wants to merge 1 commit into
volcengine:mainfrom
eric7h:fix/opensearch-ltm-index-user-collision
Open

eric7h wants to merge 1 commit into
volcengine:mainfrom
eric7h:fix/opensearch-ltm-index-user-collision

Conversation

@eric7h

@eric7h eric7h commented Nov 7, 2026

Copy link
Copy Markdown

Summary

OpensearchLTMBackend built per-user OpenSearch indexes as f"{self.index}_{user_id}". That join is ambiguous whenever index or user_id contains _:

backend index user_id OpenSearch index
app u1_x app_u1_x
app_u1 x app_u1_x

Two distinct (index, user_id) pairs therefore share one index and leak memories. This is the OpenSearch counterpart of the Redis prefix collision fixed in #1201 (RediSearch prefix matching); here the collision is an exact index-name clash.

Fix

Introduce _user_scoped_index(user_id):

  • sanitize each of self.index / user_id for OpenSearch naming rules
  • append a short SHA-256 digest of the raw value so pairs that sanitize alike (e.g. u1_x vs u1-x) stay distinct
  • join as veadk-ltm-{index_part}-{user_part}

save_memory / search_memory both use that helper.

Note: existing memories stored under the old {index}_{user_id} names will not be found after this change; re-ingest or rename indexes if you rely on prior OpenSearch LTM data.

How to reproduce

# On main, both pairs resolve to the same OpenSearch index name:
assert f"{'app'}_{'u1_x'}" == f"{'app_u1'}_{'x'}" == "app_u1_x"

# With the fix, scoped names differ (digests omitted below for brevity):
#   app / u1_x  -> veadk-ltm-app_<digest>-u1-x_<digest>
#   app_u1 / x  -> veadk-ltm-app-u1_<digest>-x_<digest>

New tests in tests/memory/long_term_memory_backends/test_opensearch_ltm_backend.py fail on main (collision assertion) and pass with this change (6 passed). Related memory suite: 68 passed.

Test plan

  • pytest tests/memory/long_term_memory_backends/test_opensearch_ltm_backend.py — 6 passed
  • pytest tests/memory/long_term_memory_backends/ tests/test_long_term_memory.py tests/test_openviking_long_term_memory.py — 68 passed
  • pre-commit (ruff check/format, gitleaks) on touched files

…s users

f"{index}_{user_id}" is ambiguous: index="app"/user="u1_x" and
index="app_u1"/user="x" both become app_u1_x and share memories.
Scope each user with a sanitized, digest-tagged OpenSearch index name.

This branch has not been deployed

No deployments
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.

1 participant