fix(tools): MemoryGraph no longer crashes on an empty corpus - #2111
Open
pai-scaffolde wants to merge 1 commit into
Open
fix(tools): MemoryGraph no longer crashes on an empty corpus#2111pai-scaffolde wants to merge 1 commit into
pai-scaffolde wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 patternson a fresh install (emptyMEMORY/KNOWLEDGE, emptyMEMORY/WORK):Root cause
computePatterns()callspagerank.assign(graph, ...)unconditionally. graphology-metrics 2.4.2's power iteration checkserror < N * tolerance; withN = 0that is0 < 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.assignon 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.assignwhengraph.order === 0. Every downstream reader of thepagerankattribute iterates the node list, which is empty, soPATTERNS.mdandgraph.jsonare 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.jsonwritten. Also exit 0 forpatterns --allon the empty corpus and for a one-note corpus. Verified on the live install as well.🤖 Generated with Claude Code