Repository navigation
Description
Describe the bug
MemorySessionManager.delete_all_long_term_memories_in_namespace is documented to delete all long-term memory records in a namespace, but it deletes at most 10. It collects the records with list_long_term_memory_records(namespace=namespace) and does not pass max_results, so it gets the default of 10:
bedrock-agentcore-sdk-python/src/bedrock_agentcore/memory/session.py
Lines 1107 to 1109 in 3707a9f
# Retrieve all memory records in the specified namespace # TODO: revisit after full deprecation of namespace fields memory_records = self.list_long_term_memory_records(namespace=namespace) - (default
bedrock-agentcore-sdk-python/src/bedrock_agentcore/memory/session.py
Lines 964 to 968 in 3707a9f
def list_long_term_memory_records( self, namespace_prefix: Optional[str] = None, strategy_id: Optional[str] = None, max_results: int = 10, max_results=10) - (stops paging and truncates at
bedrock-agentcore-sdk-python/src/bedrock_agentcore/memory/session.py
Lines 1013 to 1021 in 3707a9f
all_records.extend([MemoryRecord(record) for record in memory_records]) # Stop if we've reached max_results if len(all_records) >= max_results: break logger.info(" ✅ Found a total of %d long-term records.", len(all_records)) return all_records[:max_results] max_results)
The return value has 10 successfulRecords and an empty failedRecords, so the caller cannot tell that records were left behind.
To Reproduce
Steps to reproduce the behavior (boto3 client mocked, no AWS calls):
- Mock the data-plane client so
list_memory_recordsreturns 250 records in one namespace, over three pages. - Call
MemorySessionManager(...).delete_all_long_term_memories_in_namespace("actor/123/facts"). - See that 10 records are deleted with a single
batch_delete_memory_recordscall.
Script:
from unittest.mock import MagicMock, patch
from bedrock_agentcore.memory.session import MemorySessionManager
records = [{"memoryRecordId": f"rec-{i:03d}"} for i in range(250)]
client = MagicMock()
paginator = MagicMock()
paginator.paginate.return_value = [{"memoryRecordSummaries": records[i : i + 100]} for i in range(0, 250, 100)]
client.get_paginator.return_value = paginator
client.batch_delete_memory_records.side_effect = lambda memoryId, records: {
"successfulRecords": [{"memoryRecordId": r["memoryRecordId"]} for r in records],
"failedRecords": [],
}
with patch("boto3.Session") as sess:
sess.return_value.client.return_value = client
sess.return_value.region_name = "us-west-2"
mgr = MemorySessionManager(memory_id="mem-1", region_name="us-west-2")
result = mgr.delete_all_long_term_memories_in_namespace("actor/123/facts")
print("deleted:", len(result["successfulRecords"]), "failed:", len(result["failedRecords"]))
print("batch_delete calls:", client.batch_delete_memory_records.call_count)
Output:
deleted: 10 failed: 0
batch_delete calls: 1
Expected behavior
All 250 records are deleted, in three batch_delete_memory_records calls (the method already splits the IDs into chunks of 100).
Screenshots
N/A
Desktop (please complete the following information):
- OS: Linux
- Browser: N/A (Python SDK)
- Version: bedrock-agentcore 1.25.2 (main at 3707a9f), Python 3.12.8, boto3 1.43.123
Smartphone (please complete the following information):
N/A
Additional context
- The limit has been there since the method was added in feat: adding function to delete all memory records in namespace #148. The existing unit tests patch
list_long_term_memory_records, so they never hit the default. - Proposed fix: read every page before deleting, either by passing an unbounded
max_resultsat L1109 or by iterating thelist_memory_recordspaginator in this method, plus a unit test with more than 10 records that mocks only the paginator. - Out of scope: whether this call should use
namespaceornamespace_path(the TODO added in Update DP APIs to support namespace re-design #449). The fix keepsnamespace=namespaceunchanged.
I'd be happy to work on this if confirmed.
Activity