"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(memory): fix duplicate title index clobber
Lanre Shittu03ec4b3d807d
diff --git a/agent/src/memory/persistent.py b/agent/src/memory/persistent.pyindex 6496fe180..01504fd59 100644--- a/agent/src/memory/persistent.py+++ b/agent/src/memory/persistent.py@@ -630,7 +630,12 @@ class PersistentMemory:if self._index_path.exists():lines = self._index_path.read_text(encoding="utf-8").split("\n")updated = False- target_prefix = f"- [{title}]("+ # Match on the filename, not just the title: two different+ # memory_types produce two different files for the same title+ # (add() names the file "{memory_type}_{slug}.md"), and matching+ # on title alone made the second add() silently clobber the+ # first entry's index row even though both files exist on disk.+ target_prefix = f"- [{title}]({filename})"for i, line in enumerate(lines):if line.startswith(target_prefix):lines[i] = new_linediff --git a/agent/tests/test_persistent_memory.py b/agent/tests/test_persistent_memory.pyindex 160f960cc..52dd32bf4 100644--- a/agent/tests/test_persistent_memory.py+++ b/agent/tests/test_persistent_memory.py@@ -195,6 +195,27 @@ class TestAdd:index = (tmp_path / "MEMORY.md").read_text(encoding="utf-8")assert index.count("[dup-check]") == 1+ def test_same_title_different_types_keep_separate_index_rows(+ self, tmp_path: Path+ ) -> None:+ # Same title, different memory_type: add() writes two distinct+ # files ("reference_kb-entry.md", "user_kb-entry.md"), so the index+ # must keep two rows rather than the second add() clobbering the+ # first entry's row just because the title matches.+ pm = PersistentMemory(memory_dir=tmp_path)+ pm.add(+ "kb-entry", "raw material notes", "reference", description="reference doc"+ )+ pm.add("kb-entry", "user preference notes", "user", description="user pref")++ assert (tmp_path / "reference_kb-entry.md").exists()+ assert (tmp_path / "user_kb-entry.md").exists()++ index = (tmp_path / "MEMORY.md").read_text(encoding="utf-8")+ assert index.count("[kb-entry]") == 2+ assert "reference_kb-entry.md" in index+ assert "user_kb-entry.md" in index+def test_cjk_names_get_distinct_filenames(self, tmp_path: Path) -> None:# Regression: previously every non-ASCII char was replaced with `_`, so# any two CJK-only names of the same length collapsed to the same slug