fix: memory_recall now finds tree-indexed memories#585
Conversation
memory_recall only matched type='source' results from knowledge_search, but tree-indexed sources return as type='source_section' with the parent source ID in a 'source_id' field. This meant all 84 stored memories were invisible to recall. Now matches both 'source' and 'source_section' types, using the correct parent source ID for metadata lookups.
There was a problem hiding this comment.
Pull request overview
This PR fixes memory_recall returning no memories when retrieval returns tree-indexed results as type="source_section" (with the parent source ID in source_id), ensuring those memories are now discoverable.
Changes:
- Update
memory_recallto collect IDs from bothsourceandsource_sectionresult types. - Deduplicate collected source IDs before batch-fetching metadata.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| item_type = item.get("type") | ||
| if item_type == "source": | ||
| sid = item.get("id") | ||
| elif item_type == "source_section": | ||
| sid = item.get("source_id") |
There was a problem hiding this comment.
This change adds support for type="source_section", but the existing memory_recall tests only cover type="source". Add a unit test case where knowledge_search returns a source_section result with a source_id, and assert the handler fetches metadata for the parent source and returns a memory entry.
| if sid and sid not in source_items: | ||
| source_ids.append(sid) | ||
| source_items[sid] = item |
There was a problem hiding this comment.
sid is coming from knowledge_search results and is a string (see retrieval serializing IDs), but later source_metadata is keyed by row["id"] from psycopg2 which may be a uuid.UUID in some environments. That mismatch would make source_metadata.get(source_id) miss and silently drop otherwise-valid memories. Normalize the DB row key (e.g., str(row["id"])) to match sid (or normalize sid to UUID consistently).
Problem
memory_recallreturned 0 results despite 84 stored memories in the database.Root Cause
Tree-indexed sources are returned from
knowledge_searchastype='source_section'(nottype='source'). The parent source ID is in asource_idfield rather thanid.memory_recallonly matchedtype='source', so all tree-indexed memories were invisible.Fix
Match both
sourceandsource_sectiontypes in the collection loop, using the appropriate ID field for each.Testing
memory_recall('worker timeout')now returns the stored lesson (was returning 0 results)