From 703ff095179495442d0c16e4e9b307aa8b6dc837 Mon Sep 17 00:00:00 2001 From: Vorflux AI Date: Sat, 28 Mar 2026 23:50:16 +0000 Subject: [PATCH] fix: maxNodes now correctly limits total nodes (documents + memories) Previously maxNodes limited only the number of documents, ignoring their memories. With ~2-6 memories per document, setting maxNodes=200 could result in 600-1400+ actual nodes, defeating the performance guard. Now iterates documents and accumulates total node count (1 doc + N memories), stopping when the limit would be exceeded. This matches the documented behavior of 'Max nodes to display'. Addresses Sentry review comment on memory-graph.tsx#L62. --- .../memory-graph/src/components/memory-graph.tsx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/memory-graph/src/components/memory-graph.tsx b/packages/memory-graph/src/components/memory-graph.tsx index 0a66487c..cf35e234 100644 --- a/packages/memory-graph/src/components/memory-graph.tsx +++ b/packages/memory-graph/src/components/memory-graph.tsx @@ -55,10 +55,20 @@ export function MemoryGraph({ // Used as a dependency proxy to recalculate popover positions const [viewportVersion, setViewportVersion] = useState(0) - // Limit documents if maxNodes is set + // Limit documents so total node count (documents + their memories) stays under maxNodes const limitedDocuments = useMemo(() => { - if (!maxNodes || documents.length <= maxNodes) return documents - return documents.slice(0, maxNodes) + if (!maxNodes || documents.length === 0) return documents + let totalNodes = 0 + let cutoff = documents.length + for (let i = 0; i < documents.length; i++) { + const docNodes = 1 + (documents[i]?.memories?.length ?? 0) + if (totalNodes + docNodes > maxNodes) { + cutoff = i + break + } + totalNodes += docNodes + } + return cutoff === documents.length ? documents : documents.slice(0, cutoff) }, [documents, maxNodes]) const { nodes, edges } = useGraphData(