From 9e4e7017256158da9b0b18ff19dbb2b5e1cd2f57 Mon Sep 17 00:00:00 2001 From: rUv Date: Sun, 8 Feb 2026 03:37:10 +0000 Subject: [PATCH] Checkpoint: File edits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Automatic checkpoint created by Claude Code - Branch: rebrand/ruvflow-umbrella - Timestamp: 2026-02-08T03:37:10Z - Changes: 1 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- v3/@claude-flow/memory/src/memory-graph.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/v3/@claude-flow/memory/src/memory-graph.ts b/v3/@claude-flow/memory/src/memory-graph.ts index 813fcf3d3e..134b1d7280 100644 --- a/v3/@claude-flow/memory/src/memory-graph.ts +++ b/v3/@claude-flow/memory/src/memory-graph.ts @@ -264,6 +264,8 @@ export class MemoryGraph extends EventEmitter { /** * Compute PageRank scores using the power iteration method. + * Handles dangling nodes (no outgoing edges) by redistributing their + * rank mass equally across all nodes. * Returns a map of node ID to PageRank score. */ computePageRank(): Map { @@ -282,11 +284,26 @@ export class MemoryGraph extends EventEmitter { this.pageRanks.set(nodeId, initialRank); } + // Identify dangling nodes (no outgoing edges) + const danglingNodes: string[] = []; + for (const nodeId of this.nodes.keys()) { + const outEdges = this.edges.get(nodeId); + if (!outEdges || outEdges.length === 0) { + danglingNodes.push(nodeId); + } + } + let iterations = 0; for (let iter = 0; iter < this.config.pageRankIterations; iter++) { let maxDelta = 0; const newRanks = new Map(); + // Compute dangling node rank sum for redistribution + let danglingSum = 0; + for (const nodeId of danglingNodes) { + danglingSum += this.pageRanks.get(nodeId) || 0; + } + for (const nodeId of this.nodes.keys()) { let sum = 0; const incoming = this.reverseEdges.get(nodeId); @@ -297,7 +314,8 @@ export class MemoryGraph extends EventEmitter { } } - const newRank = (1 - d) / N + d * sum; + // Redistribute dangling rank mass equally + const newRank = (1 - d) / N + d * (sum + danglingSum / N); newRanks.set(nodeId, newRank); maxDelta = Math.max(maxDelta, Math.abs(newRank - (this.pageRanks.get(nodeId) || 0))); }