From a7122a50e33fa71a679c8445d5d04613fe3e03f3 Mon Sep 17 00:00:00 2001 From: rUv Date: Tue, 5 May 2026 22:05:38 -0400 Subject: [PATCH] fix(intelligence): make Flash Attention + ruvllm coordinator stats truthful (#1770) (#1771) Fix 1: neural_status.flashAttention was hardcoded false (neural-tools.ts:699). Now probes ../ruvector/flash-attention.js loader so it agrees with hooks_intelligence_stats on a single source of truth. Fix 2: ruvllm SonaCoordinator reported unavailable despite @ruvector/ruvllm being resolvable. Root cause: getIntelligenceStats() read ruvllmCoordinator synchronously but it was populated only by an async init path the MCP dashboard never awaits. Fix: lazy-init on stats query via sync createRequire, gated on ruvllmLoaded. Cost: 7.7ms first call, 0.24us steady-state. Also: CLAUDE_FLOW_DEBUG-gated log at the catch site so future regressions of this shape do not disappear silently. Verified: neural_status.features.flashAttention=true (was false); hooks_intelligence_stats.ruvllm.coordinator=active (was unavailable); 769 cli tests pass. Bumps all three packages to 3.7.0-alpha.4. Closes #1770 Co-authored-by: Reuven --- package.json | 2 +- ruflo/package.json | 2 +- v3/@claude-flow/cli/package.json | 2 +- .../cli/src/mcp-tools/neural-tools.ts | 13 +++++++- .../cli/src/memory/intelligence.ts | 32 +++++++++++++++++-- 5 files changed, 44 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 7ddf6da39e..9bc76e7c6f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "claude-flow", - "version": "3.7.0-alpha.3", + "version": "3.7.0-alpha.4", "description": "Ruflo - Enterprise AI agent orchestration for Claude Code. Deploy 60+ specialized agents in coordinated swarms with self-learning, fault-tolerant consensus, vector memory, and MCP integration", "main": "dist/index.js", "type": "module", diff --git a/ruflo/package.json b/ruflo/package.json index 0553560723..345967ec10 100644 --- a/ruflo/package.json +++ b/ruflo/package.json @@ -1,6 +1,6 @@ { "name": "ruflo", - "version": "3.7.0-alpha.3", + "version": "3.7.0-alpha.4", "description": "Ruflo - Enterprise AI agent orchestration platform. Deploy 60+ specialized agents in coordinated swarms with self-learning, fault-tolerant consensus, vector memory, and MCP integration", "main": "bin/ruflo.js", "type": "module", diff --git a/v3/@claude-flow/cli/package.json b/v3/@claude-flow/cli/package.json index 5fe4d2e35b..e17339443e 100644 --- a/v3/@claude-flow/cli/package.json +++ b/v3/@claude-flow/cli/package.json @@ -1,6 +1,6 @@ { "name": "@claude-flow/cli", - "version": "3.7.0-alpha.3", + "version": "3.7.0-alpha.4", "type": "module", "description": "Ruflo CLI - Enterprise AI agent orchestration with 60+ specialized agents, swarm coordination, MCP server, self-learning hooks, and vector memory for Claude Code", "main": "dist/src/index.js", diff --git a/v3/@claude-flow/cli/src/mcp-tools/neural-tools.ts b/v3/@claude-flow/cli/src/mcp-tools/neural-tools.ts index 2a5c68678c..822a218404 100644 --- a/v3/@claude-flow/cli/src/mcp-tools/neural-tools.ts +++ b/v3/@claude-flow/cli/src/mcp-tools/neural-tools.ts @@ -696,7 +696,18 @@ export const neuralTools: MCPTool[] = [ features: { hnsw: true, quantization: true, - flashAttention: false, + // #1770: probe the real loader instead of returning a literal false. + // Was hardcoded false, which contradicted hooks_intelligence_stats's + // simultaneous claim of `implementation: real-flash-attention`. + // The two surfaces now agree on a single source of truth. + flashAttention: await (async () => { + try { + const { getFlashAttention } = await import('../ruvector/flash-attention.js'); + return getFlashAttention() !== null; + } catch { + return false; + } + })(), reasoningBank: true, }, }; diff --git a/v3/@claude-flow/cli/src/memory/intelligence.ts b/v3/@claude-flow/cli/src/memory/intelligence.ts index dad0cd2f67..79061bfd2b 100644 --- a/v3/@claude-flow/cli/src/memory/intelligence.ts +++ b/v3/@claude-flow/cli/src/memory/intelligence.ts @@ -13,6 +13,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'; import { homedir } from 'node:os'; +import { createRequire } from 'node:module'; import { dirname, join } from 'node:path'; // ============================================================================ @@ -717,20 +718,37 @@ class LocalReasoningBank { let ruvllmCoordinator: any = null; let ruvllmLoaded = false; -async function loadRuvllmCoordinator(): Promise { +/** + * Synchronously load the @ruvector/ruvllm SonaCoordinator. Used both by the + * async init path (initializeIntelligence) and by sync stat readers like + * getIntelligenceStats — the dashboard would otherwise report "unavailable" + * when stats are queried before any async init has fired (#1770). + */ +function loadRuvllmCoordinatorSync(): any { if (ruvllmLoaded) return ruvllmCoordinator; ruvllmLoaded = true; try { - const { createRequire } = await import('module'); const requireCjs = createRequire(import.meta.url); const ruvllm = requireCjs('@ruvector/ruvllm'); ruvllmCoordinator = new ruvllm.SonaCoordinator(ruvllm.DEFAULT_SONA_CONFIG); return ruvllmCoordinator; - } catch { + } catch (err) { + // Surface the reason on debug builds so future regressions of #1770 don't + // disappear silently. Stays quiet by default to avoid noise on the cli's + // hot path (e.g., npx invocations). + if (process.env.CLAUDE_FLOW_DEBUG) { + // eslint-disable-next-line no-console + console.error('[ruvllm] SonaCoordinator load failed, falling back to JS:', (err as Error).message); + } + ruvllmCoordinator = null; return null; } } +async function loadRuvllmCoordinator(): Promise { + return loadRuvllmCoordinatorSync(); +} + // ============================================================================ // Module State // ============================================================================ @@ -1078,6 +1096,14 @@ export function getIntelligenceStats(): IntelligenceStats & { const sonaStats = sonaCoordinator?.stats(); const bankStats = reasoningBank?.stats(); + // Lazy-init the ruvllm coordinator if it hasn't been loaded yet. The MCP + // dashboard (`hooks_intelligence_stats`) hits this path before any + // initializeIntelligence() call has fired, so the coordinator field would + // otherwise stay null and the dashboard would report "unavailable" even + // when @ruvector/ruvllm is fully resolvable. Sync require — cheap, idempotent. + if (!ruvllmLoaded) { + loadRuvllmCoordinatorSync(); + } const ruvllmStats = ruvllmCoordinator?.stats?.() || null; // Fetch cross-module stats for unified reporting