Skip to content

fix(memory): keep sessionless memories separate from a session named __unknown_session_id__ - #7753

Open
tonmoy-y wants to merge 1 commit into
google:mainfrom
tonmoy-y:fix/in-memory-memory-sessionless-bucket
Open

tonmoy-y wants to merge 1 commit into
google:mainfrom
tonmoy-y:fix/in-memory-memory-sessionless-bucket

Conversation

@tonmoy-y

Copy link
Copy Markdown

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

Problem:
InMemoryMemoryService.add_events_to_memory() stores events added without a session ID under the string __unknown_session_id__. InMemorySessionService accepts that literal as an ordinary session ID, so add_session_to_memory() for such a session replaces the sessionless bucket and silently removes earlier sessionless memories.

Solution:
Key the private sessionless bucket by None instead of a string. Caller-provided session IDs are always str, so they can no longer alias it. Ordinary session IDs, replacement and deletion behave as before, and empty/omitted IDs still map to the same bucket. Only InMemoryMemoryService is changed; the SQLite and MongoDB services use the same string constant but are out of scope for this issue.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Added test_add_session_to_memory_keeps_sessionless_memories (parametrized with ordinary-session and __unknown_session_id__). The __unknown_session_id__ case fails on main and passes with this change.

$ pytest tests/unittests/memory -q
178 passed, 1 warning

Manual End-to-End (E2E) Tests:

Ran the reproduction script from #7711 (Python 3.12):

before: ordinary-session: before=1, after=1
        __unknown_session_id__: before=1, after=0
after:  ordinary-session: before=1, after=1
        __unknown_session_id__: before=1, after=1

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Additional context

@widechaos commented on #7711 asking to take it on. I found no PR or branch for it and no maintainer reply, so I opened this; happy to close it in favour of theirs if they already have one in progress. Tested on Python 3.12 only; full supported-version tox run not done.

…__unknown_session_id__

InMemoryMemoryService stored events added without a session ID under the
string '__unknown_session_id__'. A session with that literal ID shared the
bucket, so add_session_to_memory replaced the sessionless memories. Key the
sessionless bucket by None, which no session ID can alias.
@widechaos

Copy link
Copy Markdown

Please keep this PR open. I have a local candidate for #7711, but I haven't submitted a PR. I'll leave the implementation with you and won't open a competing one. I haven't independently reviewed or tested your patch.

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.

InMemoryMemoryService loses sessionless memories when a session ID equals its fallback bucket name

3 participants