Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/bedrock_agentcore/memory/controlplane.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,14 @@ def add_strategy(
break

if strategy_id:
return self._wait_for_strategy_active(memory_id, strategy_id, max_wait, poll_interval)
memory = self._wait_for_strategy_active(memory_id, strategy_id, max_wait, poll_interval)
else:
logger.warning("Could not identify newly added strategy %s to wait for activation", strategy_name)

# Also ensure the memory itself has returned to ACTIVE
if memory.get("status") != MemoryStatus.ACTIVE.value:
memory = self._wait_for_memory_active(memory_id, max_wait, poll_interval)

return memory

def get_strategy(self, memory_id: str, strategy_id: str) -> Dict[str, Any]:
Expand Down
26 changes: 26 additions & 0 deletions tests_integ/memory/test_controlplane.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,32 @@ def setup_class(cls):
cls.client = MemoryControlPlaneClient(region_name=cls.region)
cls.test_prefix = f"test_cp_{int(time.time())}"
cls.memory_ids = []
cls._cleanup_stale_memories()

@classmethod
def _cleanup_stale_memories(cls):
"""Delete test memories older than 3 hours. Best-effort; failures won't block tests."""
try:
from datetime import datetime, timedelta, timezone

memories = cls.client.list_memories()
cutoff = datetime.now(timezone.utc) - timedelta(hours=3)
stale = [
m
for m in memories
if m.get("id", "").startswith("test_cp_") and m.get("createdAt") and m["createdAt"] < cutoff
]
print(f"[cleanup] Found {len(memories)} total memories, {len(stale)} stale test_cp_ memories (>3h old)")
deleted = 0
for m in stale:
try:
cls.client.delete_memory(memory_id=m["id"])
deleted += 1
except Exception as e:
print(f"[cleanup] Failed to delete {m['id']}: {e}")
print(f"[cleanup] Deleted {deleted}/{len(stale)} stale memories")
except Exception as e:
print(f"[cleanup] Could not list memories for cleanup: {e}")

@classmethod
def teardown_class(cls):
Expand Down
Loading