Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated

fix(neural): #2549 β€” status no longer misreports native ruvllm training path as Unavailable (#2554)

rUv9b504d2299ba
diff --git a/v3/@claude-flow/cli/__tests__/neural-status-training-backend-2549.test.ts b/v3/@claude-flow/cli/__tests__/neural-status-training-backend-2549.test.ts
new file mode 100644
index 0000000000..4194896e8a
--- /dev/null
+++ b/v3/@claude-flow/cli/__tests__/neural-status-training-backend-2549.test.ts
@@ -0,0 +1,57 @@
+/**
+ * #2549 regression β€” `neural status` misreported the native @ruvector/ruvllm
+ * training path as Unavailable.
+ *
+ * Two defects: `_trainingBackend` was a dead variable (declared 'unavailable',
+ * returned, never assigned), and contrastive availability was read only from
+ * an in-process global that a fresh read-only status process never populates.
+ * Both made a bundled, working module invisible β€” with a remediation hint
+ * ("Install @ruvector/ruvllm") that was actively wrong.
+ *
+ * These tests pin the capability contract: when @ruvector/ruvllm RESOLVES,
+ * the stats layer must never report the training path as unavailable.
+ */
+import { describe, it, expect } from 'vitest';
+import { createRequire } from 'node:module';
+import { resolveTrainingBackend } from '../src/ruvector/lora-adapter.js';
+import { getIntelligenceStats } from '../src/memory/intelligence.js';
+
+function ruvllmResolves(): boolean {
+ try {
+ createRequire(import.meta.url).resolve('@ruvector/ruvllm');
+ return true;
+ } catch {
+ return false;
+ }
+}
+
+describe('#2549 β€” training backend capability reporting', () => {
+ it('resolveTrainingBackend reflects module resolution, not in-process load state', () => {
+ // The probe must not depend on a prior in-process train having run.
+ const backend = resolveTrainingBackend();
+ if (ruvllmResolves()) {
+ expect(backend).toBe('ruvllm');
+ } else {
+ expect(backend).toBe('js-fallback');
+ }
+ });
+
+ it('getIntelligenceStats populates _trainingBackend (the dead-variable regression)', () => {
+ const stats = getIntelligenceStats() as { _trainingBackend?: string };
+ // Whatever the environment, the field must carry a real verdict β€”
+ // 'unavailable' is only legitimate when the probe itself threw.
+ if (ruvllmResolves()) {
+ expect(stats._trainingBackend).toBe('ruvllm');
+ } else {
+ expect(stats._trainingBackend).toBe('js-fallback');
+ }
+ });
+
+ it('contrastive trainer reads available (not unavailable) in a fresh process when the module resolves', () => {
+ const stats = getIntelligenceStats() as { _contrastiveTrainer?: unknown };
+ if (!ruvllmResolves()) return; // nothing to assert without the module
+ // Fresh process β‡’ no __claudeFlowSonaStats global β‡’ must fall back to
+ // the capability probe, never to 'unavailable'.
+ expect(stats._contrastiveTrainer).not.toBe('unavailable');
+ });
+});
diff --git a/v3/@claude-flow/cli/src/commands/neural.ts b/v3/@claude-flow/cli/src/commands/neural.ts
index 12b63dc1e6..857d32b591 100644
--- a/v3/@claude-flow/cli/src/commands/neural.ts
+++ b/v3/@claude-flow/cli/src/commands/neural.ts
@@ -525,17 +525,27 @@ const statusCommand: Command = {
},
{
component: 'Contrastive Trainer',
- status: stats._contrastiveTrainer && stats._contrastiveTrainer !== 'unavailable' ? output.success('Active') : output.dim('Unavailable'),
- details: stats._contrastiveTrainer && stats._contrastiveTrainer !== 'unavailable'
+ // #2549 β€” three states: live session (object with counts),
+ // 'available' (module resolves, no in-process session β€” the
+ // normal case for a read-only status process), 'unavailable'
+ // (module genuinely does not resolve).
+ status: typeof stats._contrastiveTrainer === 'object'
+ ? output.success('Active')
+ : stats._contrastiveTrainer === 'available'
+ ? output.success('Available')
+ : output.dim('Unavailable'),
+ details: typeof stats._contrastiveTrainer === 'object'
? `${(stats._contrastiveTrainer as any).triplets ?? 0} triplets, ${(stats._contrastiveTrainer as any).agents ?? 0} agents`
- : 'Install @ruvector/ruvllm',
+ : stats._contrastiveTrainer === 'available'
+ ? 'ready β€” trains in-process on demand'
+ : 'Install @ruvector/ruvllm',
},
{
component: 'Training Pipeline',
- status: stats._trainingBackend === 'ruvllm' ? output.success('Active') : output.dim(stats._trainingBackend || 'Unavailable'),
+ status: stats._trainingBackend === 'ruvllm' ? output.success('Available') : output.dim(stats._trainingBackend || 'Unavailable'),
details: stats._trainingBackend === 'ruvllm'
- ? 'ruvllm checkpoints enabled'
- : 'JS fallback (no checkpoints)',
+ ? 'native @ruvector/ruvllm pipeline'
+ : 'JS fallback',
},
await (async () => {
try {
diff --git a/v3/@claude-flow/cli/src/memory/intelligence.ts b/v3/@claude-flow/cli/src/memory/intelligence.ts
index eec8814681..067e30d314 100644
--- a/v3/@claude-flow/cli/src/memory/intelligence.ts
+++ b/v3/@claude-flow/cli/src/memory/intelligence.ts
@@ -15,6 +15,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';
+import { resolveTrainingBackend } from '../ruvector/lora-adapter.js';
// ============================================================================
// Persistence Configuration
@@ -1261,15 +1262,27 @@ export function getIntelligenceStats(): IntelligenceStats & {
}
const ruvllmStats = ruvllmCoordinator?.stats?.() || null;
- // Fetch cross-module stats for unified reporting
+ // Fetch cross-module stats for unified reporting.
+ //
+ // #2549 β€” two prior defects here: `trainingBackend` was declared and
+ // returned but never assigned (always 'unavailable'), and contrastive
+ // availability was read ONLY from an in-process global that a fresh
+ // read-only `neural status` process never populates. Both made the
+ // native @ruvector/ruvllm path invisible even when installed. Backend
+ // now comes from the lora-adapter's capability probe; the global still
+ // wins when present because it carries live in-process session counts.
let contrastiveTrainer: { triplets: number; agents: number } | string = 'unavailable';
let trainingBackend = 'unavailable';
try {
- // Synchronous check β€” contrastiveTrainer is module-level in sona-optimizer
- // We read it via the SONAOptimizer singleton if available
+ trainingBackend = resolveTrainingBackend();
+ } catch { /* module absent β€” stay 'unavailable' */ }
+ try {
const sonaModule = (globalThis as any).__claudeFlowSonaStats;
- if (sonaModule) {
- contrastiveTrainer = sonaModule._contrastiveTrainer || 'unavailable';
+ if (sonaModule?._contrastiveTrainer) {
+ contrastiveTrainer = sonaModule._contrastiveTrainer;
+ } else if (trainingBackend === 'ruvllm') {
+ // Module resolves but no in-process session β€” available, idle.
+ contrastiveTrainer = 'available';
}
} catch { /* not available */ }
diff --git a/v3/@claude-flow/cli/src/ruvector/lora-adapter.ts b/v3/@claude-flow/cli/src/ruvector/lora-adapter.ts
index 79504b044c..3ea2838018 100644
--- a/v3/@claude-flow/cli/src/ruvector/lora-adapter.ts
+++ b/v3/@claude-flow/cli/src/ruvector/lora-adapter.ts
@@ -20,6 +20,7 @@
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
import { dirname, join } from 'path';
+import { createRequire } from 'module';
// ============================================================================
// Types & Constants
@@ -136,6 +137,24 @@ const DEFAULT_CONFIG: LoRAConfig = {
let ruvllmPipeline: any = null;
let pipelineLoaded = false;
+/**
+ * Which training backend a train call would use β€” WITHOUT loading the
+ * pipeline (#2549). Before this existed, status surfaces read module state
+ * that only a prior in-process train populates, so a fresh read-only
+ * process always reported 'js-fallback'/'unavailable' even with
+ * @ruvector/ruvllm installed. The pipeline stays lazy: this only probes
+ * module resolution.
+ */
+export function resolveTrainingBackend(): 'ruvllm' | 'js-fallback' {
+ if (pipelineLoaded) return ruvllmPipeline ? 'ruvllm' : 'js-fallback';
+ try {
+ createRequire(import.meta.url).resolve('@ruvector/ruvllm');
+ return 'ruvllm';
+ } catch {
+ return 'js-fallback';
+ }
+}
+
async function loadTrainingPipeline(adapter: LoRAAdapter): Promise<any> {
if (pipelineLoaded) return ruvllmPipeline;
pipelineLoaded = true;
@@ -407,9 +426,7 @@ export class LoRAAdapter {
? this.adaptationNormSum / this.totalAdaptations
: 0,
lastUpdate: this.lastUpdate,
- _trainingBackend: pipelineLoaded
- ? (ruvllmPipeline ? 'ruvllm' : 'js-fallback')
- : 'js-fallback',
+ _trainingBackend: resolveTrainingBackend(),
};
}