{"record":{"id":"fec338389ff2a950","repo":"ruvnet/ruflo","slug":"sona-adaptation-failed-error","errorCode":null,"errorMessage":"SONA adaptation failed: ${error}","messagePattern":"SONA adaptation failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/neural/src/sona-integration.ts","lineNumber":237,"sourceCode":"      const patterns = this.engine.findPatterns(\n        Array.from(context.queryEmbedding),\n        5\n      );\n\n      // Determine suggested route from patterns\n      const suggestedRoute = this.inferRoute(patterns, context);\n      const confidence = patterns.length > 0 ? patterns[0].avgQuality : 0.5;\n\n      this.adaptationTimeMs = performance.now() - startTime;\n\n      return {\n        transformedQuery: new Float32Array(transformedQuery),\n        patterns,\n        suggestedRoute,\n        confidence,\n      };\n    } catch (error) {\n      throw new Error(`SONA adaptation failed: ${error}`);\n    }\n  }\n\n  /**\n   * Get last adaptation time\n   *\n   * @returns Adaptation time in milliseconds\n   */\n  getAdaptationTime(): number {\n    return this.adaptationTimeMs;\n  }\n\n  /**\n   * Get last learning time\n   *\n   * @returns Learning time in milliseconds\n   */\n  getLearningTime(): number {","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/neural/src/sona-integration.ts#L219-L255","documentation":"Thrown by the SONA query-adaptation path in @claude-flow/neural: the whole adaptQuery body (query transform, pattern retrieval, route inference, confidence scoring) is wrapped in one try/catch, and any lower-level failure is re-thrown as this umbrella error with the original message appended after the colon. The prefix is only an annotation; the suffix is the real cause. The adaptation-time metric is only recorded on success, so this throw also means no timing was captured.","triggerScenarios":"Any exception raised inside the try block: calling adaptQuery before the integration/pattern store is initialized, passing a query vector with non-finite values or wrong dimensionality, corrupted or version-skewed persisted patterns making transformQuery or pattern retrieval throw, or inferRoute failing on inconsistent mode/EWC state.","commonSituations":"Reusing a SonaIntegration instance after the underlying neural store was closed or reloaded mid-flight; loading SONA state written by a different package version so internal shape checks fail; passing Float64Array or a plain array where a Float32Array is expected; concurrent close() during an in-flight adaptation.","solutions":["Read the text after 'SONA adaptation failed:' — it names the actual failing operation; debug that, not the wrapper","Ensure initialization (pattern store load, mode implementation) has completed before the first adaptQuery call","Validate the query up front: finite values, expected dimensionality, Float32Array","If the inner error indicates corrupted state, rebuild patterns from trajectories or re-serialize with the current package version","Reproduce with logging around the transform/pattern-retrieval steps to pinpoint the throw site"],"exampleFix":"// before\nconst r = await sona.adaptQuery(anyOldVector, ctx);\n// after\nif (!(query instanceof Float32Array) || !query.every(Number.isFinite)) {\n  throw new TypeError('query must be a finite Float32Array');\n}\ntry {\n  const r = await sona.adaptQuery(query, ctx);\n} catch (e) {\n  throw new Error(String(e).replace('SONA adaptation failed: ', ''), { cause: e });\n}","handlingStrategy":"try-catch","validationCode":"// validate the query before adaptation\nconst ok =\n  query instanceof Float32Array &&\n  query.length > 0 &&\n  query.every(Number.isFinite);\nif (!ok) throw new TypeError('query must be a non-empty finite Float32Array');\nconst r = await sona.adaptQuery(query, ctx);","typeGuard":"function isFiniteVector(v: unknown): v is Float32Array {\n  return v instanceof Float32Array && v.every(Number.isFinite);\n}","tryCatchPattern":"try {\n  const r = await sona.adaptQuery(query, ctx);\n} catch (e) {\n  const msg = e instanceof Error ? e.message : String(e);\n  if (msg.startsWith('SONA adaptation failed:')) {\n    // the suffix is the real cause — surface it, keep the original as cause\n    throw new Error(msg.slice('SONA adaptation failed:'.length).trim(), { cause: e });\n  }\n  throw e;\n}","preventionTips":["Complete initialization and pattern-store loading before the first adaptQuery call","Validate vector type, length, and finiteness at the call boundary","Keep persisted SONA state on the same package version as the code using it","Log the unwrapped inner message, not just the SONA prefix, when it throws"],"tags":["neural","error-wrapping","runtime"],"backgroundTag":"wrapped-exception","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","contentChangedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}