Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(memory): remove() resolves filename stem like find() does

Lanre Shittu41c3a406a8e8
diff --git a/agent/src/memory/persistent.py b/agent/src/memory/persistent.py
index c66a8836a..d8803bb9c 100644
--- a/agent/src/memory/persistent.py
+++ b/agent/src/memory/persistent.py
@@ -626,13 +626,18 @@ class PersistentMemory:
return path
def remove(self, name: str, memory_type: str | None = None) -> bool:
- """Remove a memory entry by name.
+ """Remove a memory entry by title or filename stem.
One title can exist under several memory types, each in its own file
(``{memory_type}_{slug}.md``, #1525), so a bare title can be ambiguous.
+ Falls back to filename-stem resolution (matching ``find()``) when no
+ title matches, so a name that resolves via ``find()`` or the CLI's
+ ``memory forget`` command also resolves here instead of silently
+ reporting "not found" for the same entry.
+
Args:
- name: Title of the entry to remove.
+ name: Title or filename stem of the entry to remove.
memory_type: The entry's type; needed only when the title exists
under more than one type.
@@ -645,11 +650,19 @@ class PersistentMemory:
"""
from src.config.accessor import get_env_config
+ entries = self._scan_entries()
matches = [
entry
- for entry in self._scan_entries()
+ for entry in entries
if entry.title == name and (memory_type is None or entry.memory_type == memory_type)
]
+ if not matches:
+ matches = [
+ entry
+ for entry in entries
+ if (entry.path.stem == name or entry.path.stem.endswith(f"_{name}"))
+ and (memory_type is None or entry.memory_type == memory_type)
+ ]
if not matches:
return False
if len(matches) > 1:
diff --git a/agent/tests/test_persistent_memory.py b/agent/tests/test_persistent_memory.py
index 5f713ccb6..8a05da56b 100644
--- a/agent/tests/test_persistent_memory.py
+++ b/agent/tests/test_persistent_memory.py
@@ -472,6 +472,14 @@ class TestRemove:
results = pm.find_relevant("temporary")
assert len(results) == 0
+ def test_remove_by_filename_stem(self, tmp_path: Path) -> None:
+ """remove() should resolve a filename stem the same way find() does,
+ not just an exact title match."""
+ pm = PersistentMemory(memory_dir=tmp_path)
+ pm.add("Q2 Planning", "roadmap notes", "project")
+ assert pm.remove("project_q2_planning") is True
+ assert pm.find("Q2 Planning") is None
+
# ---------------------------------------------------------------------------
# PersistentMemory.snapshot