fix: memory recall crashes on a non-dict row from the vector store (#1705)

This commit is contained in:
Afonso Coutinho
2026-06-03 05:35:09 +01:00
committed by GitHub
parent 86d3af743a
commit 9dd9bb8a3f
2 changed files with 27 additions and 0 deletions

View File

@@ -103,6 +103,7 @@ class MemoryService:
metadata=r.get("metadata", {}),
)
for r in results
if isinstance(r, dict)
]
return MemorySearchResult(memories=memories, query=query, total=len(memories))

View File

@@ -0,0 +1,26 @@
import asyncio
from services.memory.service import MemoryService
class _FakeVectorStore:
"""Stands in for MemoryVectorStore.search, which reconstructs rows from a
vector index + metadata store. A stale or corrupt index can yield a
non-dict row mixed in with the good ones."""
def search(self, query, k=5):
return [
{"id": "1", "text": "real memory", "timestamp": 5},
"corrupt-row",
None,
]
def test_recall_skips_non_dict_vector_rows(tmp_path):
svc = MemoryService(str(tmp_path))
svc.vector_store = _FakeVectorStore()
res = asyncio.run(svc.recall("anything"))
# old code did r.get(...) on the str/None rows and raised AttributeError,
# losing the whole recall; now only the well-formed row survives.
assert [m.id for m in res.memories] == ["1"]
assert res.total == 1