Skip to content

feat(memory): add session and user memory deletion APIs - #7175

Open
ArulJerald wants to merge 1 commit into
google:mainfrom
ArulJerald:feat/memory-service-delete-7109
Open

ArulJerald wants to merge 1 commit into
google:mainfrom
ArulJerald:feat/memory-service-delete-7109

Conversation

@ArulJerald

Copy link
Copy Markdown

Link to Issue or Description of Change

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

Problem:
Calling BaseSessionService.delete_session() removes session records from the session store, but leaves behind memories copied or synthesized into BaseMemoryService via add_session_to_memory() or add_events_to_memory(). Furthermore, BaseMemoryService offered no removal or purge API, making it impossible to clean up session memory or comply with user-level data retention / right-to-be-forgotten requirements.

Solution:

  1. Added delete_session_memory(*, app_name, user_id, session_id) and delete_user_memory(*, app_name, user_id) to BaseMemoryService with default implementations raising NotImplementedError.
  2. Implemented thread-safe session and user memory deletion in InMemoryMemoryService under self._lock, safely cleaning up empty user buckets.
  3. Added delete_session_memory(session_id=None) (defaulting to the current session) and delete_user_memory() convenience helpers on Context.
  4. Documented memory retention semantics on BaseSessionService.delete_session() and added a Lifecycle & Removal guide in docs/guides/memory/memory_service/index.md.

Testing Plan

Unit Tests:

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

Summary of passed pytest results:

tests/unittests/memory/test_in_memory_memory_service.py: 45 passed
tests/unittests/agents/test_context.py: 44 passed
Total: 89 passed in 1.78s

Tests added:

  • test_delete_session_memory: Verifies session deletion removes matching session memories while leaving other sessions intact.
  • test_delete_session_memory_cleans_up_empty_user_bucket: Verifies user entry cleanup when the last session memory is purged.
  • test_delete_session_memory_nonexistent_is_noop: Verifies idempotent no-op deletion.
  • test_delete_user_memory: Verifies purging all memories for a user across multiple sessions.
  • test_delete_user_memory_nonexistent_is_noop: Verifies idempotent no-op on missing user.
  • test_base_memory_service_default_deletion_methods: Verifies NotImplementedError raised on unimplemented backends.
  • test_delete_memory_is_thread_safe_against_concurrent_searches: Verifies thread safety under concurrent reader and deleter threads.
  • test_delete_session_memory_default_current_session, test_delete_session_memory_explicit_session_id, test_delete_user_memory_success, and no-service error cases in test_context.py.

Checklist

  • 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.

Session deletion in session services leaves previously ingested
conversations in memory services without a removal path.

Add `delete_session_memory` and `delete_user_memory` to
`BaseMemoryService`, implement them in `InMemoryMemoryService`, and
expose corresponding convenience helpers on `Context` for retention
lifecycle management and right-to-be-forgotten / GDPR compliance.

Closes google#7109
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.

Memory has no removal path: delete_session() leaves what add_session_to_memory() copied, and BaseMemoryService exposes no way to remove it

2 participants