ruvnet/ruflo · error

ruvLLM bridge not initialized. Call with config first.

Error message

ruvLLM bridge not initialized. Call with config first.

What it means

getRuvllmBridge() is a lazy singleton: the first call must carry a RuvllmConfig (with modelsDir) to construct the instance; subsequent argument-less calls return it. This throw means the getter ran with no argument while `instance` is still null — no module ever performed the configuring call, or resetRuvllmBridge() cleared it (typical between tests) and a later bare getter call had no config.

Solutions

  1. Create the singleton explicitly at boot: getRuvllmBridge({ modelsDir: '...' }) before any consumer runs
  2. In tests, call getRuvllmBridge(config) inside beforeEach after resetRuvllmBridge()
  3. Keep a single bootstrap module that owns the configuring call and is imported first
  4. If it appears mid-session, search for resetRuvllmBridge() calls that may have cleared the instance

Example fix

// before — consumer assumes the singleton exists
const bridge = getRuvllmBridge(); // throws if nothing configured it

// after — always hand the config through; first call configures, later calls reuse
const bridge = getRuvllmBridge({ modelsDir: process.env.MODELS_DIR ?? './models' });
Defensive patterns

Strategy: validation

Validate before calling

import { getRuvllmBridge, type RuvllmConfig, type RuvllmBridge } from './ruvllm-bridge.js';

let configured = false;
export function ensureBridge(config: RuvllmConfig): RuvllmBridge {
  if (!configured) {
    getRuvllmBridge(config); // first call constructs the singleton
    configured = true;
  }
  return getRuvllmBridge(); // safe now — instance exists
}

Try / catch

let bridge: RuvllmBridge;
try {
  bridge = getRuvllmBridge();
} catch {
  // nothing configured the singleton yet — this call carries the config
  bridge = getRuvllmBridge({ modelsDir: process.env.MODELS_DIR ?? './models' });
}

Prevention

When it happens

Trigger: `getRuvllmBridge()` before any `getRuvllmBridge(config)`; calling the getter after `resetRuvllmBridge()` (test teardown) without re-creating; a consumer module invoking the getter at import time before the bootstrap module configures it.

Common situations: Tests that reset the singleton per case but forget to rebuild it in beforeEach; import-order problems where consumer code loads before configuration; refactors that removed the one configuring call site.

Related errors


AI-assisted analysis of ruvnet/ruflo@fa13ee4ad6 (2026-08-18). Data as JSON: /api/errors/dbbf36ae36399cfb. Report an issue: GitHub.

Appendix: source

Thrown at v3/@claude-flow/cli/src/appliance/ruvllm-bridge.ts:335

    if (/^(convert|change)\s+(var|let)\s+to\s+const$/i.test(t)) {
      return 'Use the Edit tool to replace `var`/`let` declarations with `const`.';
    }
    if (/^remove\s+console\.(log|warn|error|debug|info)$/i.test(t)) {
      const m = t.toLowerCase().match(/console\.(\w+)/)?.[1] ?? 'log';
      return `Use the Edit tool to remove all \`console.${m}\` calls.`;
    }
    return null;
  }
}

// ── Singleton accessor ──────────────────────────────────────

let instance: RuvllmBridge | null = null;

/** Get or create the singleton RuvllmBridge. Config required on first call. */
export function getRuvllmBridge(config?: RuvllmConfig): RuvllmBridge {
  if (!instance && config) instance = new RuvllmBridge(config);
  if (!instance) throw new Error('ruvLLM bridge not initialized. Call with config first.');
  return instance;
}

/** Reset the singleton (useful for tests). */
export function resetRuvllmBridge(): void { instance = null; }

/** Check whether @ruvector/core is importable without loading the bridge. */
export async function isRuvllmAvailable(): Promise<boolean> {
  try { await import('@ruvector/core'); return true; } catch { return false; }
}

View on GitHub (pinned to fa13ee4ad6)