{"record":{"id":"c3c79409131c35a9","repo":"ruvnet/ruflo","slug":"flash-attention-not-initialized","errorCode":null,"errorMessage":"Flash attention not initialized","messagePattern":"Flash attention not initialized","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/cli/src/services/ruvector-training.ts","lineNumber":591,"sourceCode":"    successRate: trajectoryBuffer.success_rate(),\n    meanImprovement: trajectoryBuffer.mean_improvement(),\n    bestImprovement: trajectoryBuffer.best_improvement(),\n    totalCount: trajectoryBuffer.total_count(),\n    highQualityCount: trajectoryBuffer.high_quality_count(0.1),\n    variance: trajectoryBuffer.variance(),\n  };\n}\n\n/**\n * Compute attention with Flash Attention (2.49x-7.47x faster)\n */\nexport function computeFlashAttention(\n  query: Float32Array,\n  keys: Float32Array[],\n  values: Float32Array[]\n): Float32Array {\n  if (!flashAttention) {\n    throw new Error('Flash attention not initialized');\n  }\n\n  return flashAttention.computeRaw(query, keys, values);\n}\n\n/**\n * Compute MoE routing\n */\nexport function computeMoEAttention(\n  query: Float32Array,\n  keys: Float32Array[],\n  values: Float32Array[]\n): Float32Array {\n  if (!moeAttention) {\n    throw new Error('MoE attention not initialized');\n  }\n\n  return moeAttention.computeRaw(query, keys, values);","sourceCodeStart":573,"sourceCodeEnd":609,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/cli/src/services/ruvector-training.ts#L573-L609","documentation":"Thrown by computeFlashAttention() when the module-level flashAttention is null. It is set by initializeTraining() only when (a) the optional @ruvector/attention package imports successfully AND (b) config.useFlashAttention !== false (it is on by default). So the error means either init never ran, the attention package is missing/unresolvable in your install, flash attention was explicitly disabled, or cleanup() nulled it.","triggerScenarios":"Calling computeFlashAttention before initializeTraining; initializing with { useFlashAttention: false } and still calling the function; running in an install where the optional @ruvector/attention dependency was pruned (npm ci with --omit=optional, partial install, wrong package manager resolution) — init logs '[ruvector] @ruvector/attention unavailable …, attention features disabled' and continues without it.","commonSituations":"Production images that strip optionalDependencies to slim the bundle; pnpm/yarn hoisting differences leaving @ruvector/attention unresolvable; a config preset that disables flash attention for reproducibility while legacy code still calls the fast path; init warnings scrolling past unnoticed in verbose logs.","solutions":["Run initializeTraining() (flash attention is enabled by default — just don't pass useFlashAttention: false) and assert 'FlashAttention' appears in the returned features array.","Install/restore the optional dependency: npm install (without --omit=optional) or explicitly add @ruvector/attention, then re-check node_modules.","Remove the disabling flag from your TrainingConfig if you intentionally turned it off but still call computeFlashAttention.","After cleanup(), re-initialize before using attention again."],"exampleFix":"// before\nconst { initializeTraining } = await import('./services/ruvector-training.js');\nawait initializeTraining({ useFlashAttention: false }); // preset disables it\nconst out = computeFlashAttention(q, keys, values); // throws 'Flash attention not initialized'\n\n// after\nconst init = await initializeTraining({}); // default enables flash attention\nif (!init.features.includes('FlashAttention')) {\n  throw new Error(`@ruvector/attention missing — got features: ${init.features.join(', ')}`);\n}\nconst out = computeFlashAttention(q, keys, values);","handlingStrategy":"validation","validationCode":"const init = await initializeTraining({}); // flash attention defaults ON — do not pass false\nif (!init.features.includes('FlashAttention')) {\n  throw new Error(`FlashAttention unavailable — install @ruvector/attention. Features: ${init.features.join(', ')}`);\n}\n// safe to call now:\nconst out = computeFlashAttention(query, keys, values);","typeGuard":"type AttentionReady = { hasFlash: boolean };\nasync function probeAttentionFeatures(cfg: TrainingConfig = {}): Promise<AttentionReady> {\n  const init = await initializeTraining(cfg);\n  return { hasFlash: init.features.includes('FlashAttention') };\n}","tryCatchPattern":"try {\n  return computeFlashAttention(q, keys, values);\n} catch (e) {\n  if (e instanceof Error && e.message === 'Flash attention not initialized') {\n    // fall back to plain scaled dot-product or re-init with defaults, then retry\n    return scaledDotProduct(q, keys, values);\n  }\n  throw e;\n}","preventionTips":["Assert on the features array returned by initializeTraining() at startup — it is the module's own capability manifest.","Don't set useFlashAttention: false in shared configs while any code path still calls computeFlashAttention.","Install optional dependencies in production images (no --omit=optional) or vendor @ruvector/attention explicitly.","Watch init logs for '[ruvector] @ruvector/attention unavailable' — it silently disables several functions."],"tags":["initialization","ruvector","flash-attention","optional-dependency","attention"],"backgroundTag":"component-not-initialized","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}