{"record":{"id":"919594b53e7179d5","repo":"ruvnet/ruflo","slug":"sona-learning-failed-error","errorCode":null,"errorMessage":"SONA learning failed: ${error}","messagePattern":"SONA learning failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/neural/src/sona-integration.ts","lineNumber":199,"sourceCode":"          step.reward\n        );\n      }\n\n      // Set context if available\n      if (trajectory.domain) {\n        this.engine.addTrajectoryContext(trajectoryId, trajectory.domain);\n      }\n\n      // Complete trajectory with quality score\n      const quality = this.calculateQuality(trajectory);\n      this.engine.endTrajectory(trajectoryId, quality);\n\n      // Flush instant updates\n      this.engine.flush();\n\n      this.learningTimeMs = performance.now() - startTime;\n    } catch (error) {\n      throw new Error(`SONA learning failed: ${error}`);\n    }\n  }\n\n  /**\n   * Adapt behavior based on context\n   *\n   * @param context - Current context for adaptation\n   * @returns Adapted behavior with transformed embeddings\n   */\n  async adapt(context: Context): Promise<AdaptedBehavior> {\n    const startTime = performance.now();\n\n    try {\n      // Apply micro-LoRA transformation\n      const transformedQuery = this.engine.applyMicroLora(\n        Array.from(context.queryEmbedding)\n      );\n","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/neural/src/sona-integration.ts#L181-L217","documentation":"SONALearningEngine.learn() wraps its entire body — engine.beginTrajectory(), per-step context recording, endTrajectory(id, quality) and flush() — in a try/catch that rethrows everything as 'SONA learning failed: <original error>'. The prefix is generic; the actual cause is the wrapped text, most often trajectory-lifecycle misuse of the underlying SONA engine (already-ended or unknown trajectory id, uninitialized or shut-down engine) or a failure inside the active mode's learn step during flush().","triggerScenarios":"Calling learn() twice with the same trajectory so begin/endTrajectory hit an already-ended id; learn() before initialize() finished or after cleanup() started; flush() throwing because the active SONA mode (balanced/research/edge/batch/real-time) failed its internal learn step; malformed trajectories (missing steps or domain) tripping engine internals.","commonSituations":"Retrying a failed learn() with the same trajectory object; shutting the neural system down while learning is in flight; mode-specific bugs that only surface in research or edge modes.","solutions":["Read the text after 'SONA learning failed:' — it names the real failure; fix that first","Do not learn() the same trajectory twice — track learned ids in a Set","Ensure initialize() has resolved and cleanup() is not running concurrently","Once the underlying cause is fixed, retry with a fresh engine/trajectory if the error was transient (I/O, timing)"],"exampleFix":"// before\nawait engine.learn(trajectory); // 'SONA learning failed: ...' - cause buried\n\n// after\ntry {\n  await engine.learn(trajectory);\n} catch (e) {\n  const cause = (e as Error).message.replace(/^SONA learning failed: /, '');\n  logger.error('learn failed', { cause });\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"const learned = new Set<string>();\nasync function learnOnce(engine: SONALearningEngine, trajectory: Trajectory) {\n  if (learned.has(trajectory.trajectoryId)) return; // avoid double-learn\n  await engine.learn(trajectory);\n  learned.add(trajectory.trajectoryId);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await engine.learn(trajectory);\n} catch (e) {\n  const cause = (e as Error).message.replace(/^SONA learning failed: /, '');\n  // 'cause' is the real error (e.g. trajectory already ended, engine not initialized)\n  logger.error('SONA learn failed', { cause });\n  // classify: lifecycle misuse -> permanent, do not retry; transient -> rebuild and retry once\n}","preventionTips":["Initialize the engine before learning and never clean up mid-flight","Track already-learned trajectory ids to prevent double learn()","Log the unwrapped cause, not just the 'SONA learning failed' prefix","Fix the underlying cause before retrying - a blind retry of the same trajectory repeats the failure"],"tags":["neural","sona","learning","error-wrapping"],"backgroundTag":null,"analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","contentChangedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}