From d7d95c03f7fdf6154ca78f10fa4116acec0b007f Mon Sep 17 00:00:00 2001 From: pai-scaffolde Date: Fri, 11 Sep 2026 16:53:17 -0700 Subject: [PATCH] fix(tools): MemoryGraph no longer crashes on an empty corpus MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit graphology-metrics' PageRank power iteration cannot converge on a graph with zero nodes (error < N * tolerance is never true when N is 0), so pagerank.assign() throws "failed to converge" and `bun MemoryGraph.ts patterns` died with a stack trace on any install whose MEMORY/KNOWLEDGE and MEMORY/WORK are still empty — exactly a fresh install. Measured boundary: one or more nodes converge fine, with or without edges; only the empty graph throws. Skip PageRank when the graph has no nodes; every consumer of the attribute iterates the (empty) node list, so PATTERNS.md and graph.json are emitted with 0 nodes instead of a crash. Co-Authored-By: Claude Fable 5.1 --- LifeOS/install/LIFEOS/TOOLS/MemoryGraph.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/LifeOS/install/LIFEOS/TOOLS/MemoryGraph.ts b/LifeOS/install/LIFEOS/TOOLS/MemoryGraph.ts index b5c0b6dc57..0c8e033e9b 100755 --- a/LifeOS/install/LIFEOS/TOOLS/MemoryGraph.ts +++ b/LifeOS/install/LIFEOS/TOOLS/MemoryGraph.ts @@ -410,8 +410,10 @@ function computePatterns(graph: Graph) { // Communities (Louvain) louvain.assign(graph, { resolution: 1 }); - // PageRank (influence) + degree - pagerank.assign(graph, { getEdgeWeight: "weight" }); + // PageRank (influence) + degree. graphology's power iteration never converges + // on an empty graph (it throws "failed to converge"), and a fresh install has + // no notes yet — skip it there; every reader below iterates zero nodes. + if (graph.order > 0) pagerank.assign(graph, { getEdgeWeight: "weight" }); const degree = new Map(); graph.forEachNode((n) => degree.set(n, graph.degree(n)));