Skip to content

fix(tools): MemoryGraph no longer crashes on an empty corpus - #2111

Open
pai-scaffolde wants to merge 1 commit into
danielmiessler:mainfrom
pai-scaffolde:fix/k-memorygraph-empty-corpus
Open

fix(tools): MemoryGraph no longer crashes on an empty corpus#2111
pai-scaffolde wants to merge 1 commit into
danielmiessler:mainfrom
pai-scaffolde:fix/k-memorygraph-empty-corpus

Conversation

@pai-scaffolde

Copy link
Copy Markdown

Reproduced on a fresh LifeOS 7.40.4 install (macOS, Claude Code in the Claude desktop app); the fix was applied to that install and run there before filing. (#1605 / PRs #1407, #1408 covered the graphology deps and duplicate slugs, not this.)

Observed

bun LIFEOS/TOOLS/MemoryGraph.ts patterns on a fresh install (empty MEMORY/KNOWLEDGE, empty MEMORY/WORK):

error: graphology-metrics/centrality/pagerank: failed to converge.
      at build (LIFEOS/TOOLS/MemoryGraph.ts:552:13)
exit 1

Root cause

computePatterns() calls pagerank.assign(graph, ...) unconditionally. graphology-metrics 2.4.2's power iteration checks error < N * tolerance; with N = 0 that is 0 < 0, never true, so it exits the loop unconverged and throws. Measured boundary (probe against the shipped node_modules): 0 nodes throws; 1 node, 2 nodes with or without an edge, 3-node path all converge. louvain.assign on the empty graph is fine. So the crash is exactly "no notes yet", i.e. every fresh install until the first knowledge note lands.

Fix

Skip pagerank.assign when graph.order === 0. Every downstream reader of the pagerank attribute iterates the node list, which is empty, so PATTERNS.md and graph.json are emitted with 0 nodes instead of a crash. Graphs with nodes take exactly the old path.

How tested

LIFEOS_DIR=<tmp with empty MEMORY/KNOWLEDGE + MEMORY/WORK> bun MemoryGraph.ts patterns: exit 1 with the trace above before; exit 0 after, MEMORY/GRAPH/PATTERNS.md + graph.json written. Also exit 0 for patterns --all on the empty corpus and for a one-note corpus. Verified on the live install as well.

🤖 Generated with Claude Code

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 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant