fix(memory): return relations connected to requested nodes in openNodes/searchNodes

Previously, `openNodes` and `searchNodes` only returned relations where
BOTH endpoints were in the result set (using `&&`). This silently
dropped all relations to/from nodes outside the set — making it
impossible to discover a node's connections without calling `read_graph`
and filtering the entire dataset client-side.

Changed the filter from `&&` to `||` so that any relation with at least
one endpoint in the result set is included. This matches the expected
graph-query semantics: when you open a node, you should see all its
edges, not just edges to other opened nodes.

Fixes #3137

Tests updated and new cases added covering:
- Outgoing relations to nodes not in the open set
- Incoming relations from nodes not in the open set
- Relations connected to a single opened node
- searchNodes returning outgoing relations to unmatched entities

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
DukeDeSouth 2026-02-06 20:14:27 -05:00
commit ca7ea2253e

View file

@ -197,9 +197,10 @@ export class KnowledgeGraphManager {
// Create a Set of filtered entity names for quick lookup
const filteredEntityNames = new Set(filteredEntities.map(e => e.name));
// Filter relations to only include those between filtered entities
// Include relations where at least one endpoint matches the search results.
// This lets callers discover connections to nodes outside the result set.
const filteredRelations = graph.relations.filter(r =>
filteredEntityNames.has(r.from) && filteredEntityNames.has(r.to)
filteredEntityNames.has(r.from) || filteredEntityNames.has(r.to)
);
const filteredGraph: KnowledgeGraph = {
@ -219,9 +220,12 @@ export class KnowledgeGraphManager {
// Create a Set of filtered entity names for quick lookup
const filteredEntityNames = new Set(filteredEntities.map(e => e.name));
// Filter relations to only include those between filtered entities
// Include relations where at least one endpoint is in the requested set.
// Previously this required BOTH endpoints, which meant relations from a
// requested node to an unrequested node were silently dropped — making it
// impossible to discover a node's connections without reading the full graph.
const filteredRelations = graph.relations.filter(r =>
filteredEntityNames.has(r.from) && filteredEntityNames.has(r.to)
filteredEntityNames.has(r.from) || filteredEntityNames.has(r.to)
);
const filteredGraph: KnowledgeGraph = {