{"record":{"id":"29218878966d30cf","repo":"ruvnet/ruflo","slug":"sonaadapter-not-initialized-call-initialize-fir","errorCode":null,"errorMessage":"SONAAdapter not initialized. Call initialize() first.","messagePattern":"SONAAdapter not initialized\\. Call initialize\\(\\) first\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/integration/src/sona-adapter.ts","lineNumber":810,"sourceCode":"    this.stats.averageConfidence = total / this.patterns.size;\n  }\n\n  private estimateMemoryUsage(): number {\n    // Rough estimate: 500 bytes per pattern, 1KB per trajectory step\n    const patternBytes = this.patterns.size * 500;\n    const trajectoryBytes = Array.from(this.activeTrajectories.values())\n      .reduce((sum, t) => sum + t.steps.length * 1024, 0);\n\n    return patternBytes + trajectoryBytes;\n  }\n\n  private generateId(prefix: string): string {\n    return `${prefix}_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;\n  }\n\n  private ensureInitialized(): void {\n    if (!this.initialized) {\n      throw new Error('SONAAdapter not initialized. Call initialize() first.');\n    }\n  }\n}\n\n/**\n * Create and initialize a SONA adapter\n */\nexport async function createSONAAdapter(\n  config?: Partial<SONAConfiguration>\n): Promise<SONAAdapter> {\n  const adapter = new SONAAdapter(config);\n  await adapter.initialize();\n  return adapter;\n}\n","sourceCodeStart":792,"sourceCodeEnd":825,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/integration/src/sona-adapter.ts#L792-L825","documentation":"SONAAdapter uses the standard bridge pattern: methods that depend on runtime state call ensureInitialized(), which throws until initialize() has fully completed. Before that there is no pattern store, no configuration handshake, and no active trajectories.","triggerScenarios":"Calling any adapter method (startTrajectory, recordTrajectoryStep, optimization APIs) on an instance where initialize() was never awaited, or where it failed earlier.","commonSituations":"Constructing with new SONAAdapter(config) and immediately calling methods; a swallowed init failure; multiple modules each constructing their own instance while only one gets initialized.","solutions":["Use the createSONAAdapter(config) factory — it constructs and awaits initialization in one step","If initializing manually, await it before any other call and fail loudly if it rejects","Share one initialized adapter instance across the app instead of constructing per module"],"exampleFix":"// before\nconst adapter = new SONAAdapter(config);\nawait adapter.startTrajectory({ /* ... */ }); // throws: not initialized\n\n// after\nconst adapter = await createSONAAdapter(config);\nawait adapter.startTrajectory({ /* ... */ });","handlingStrategy":"validation","validationCode":"// Shared initialized singleton — every call site awaits the same promise\nlet adapterPromise: Promise<SONAAdapter> | null = null;\nfunction getSONA(): Promise<SONAAdapter> {\n  adapterPromise ??= createSONAAdapter(config);\n  return adapterPromise;\n}","typeGuard":null,"tryCatchPattern":"try {\n  await sona.startTrajectory(params);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('SONAAdapter not initialized')) {\n    const sonaReady = await createSONAAdapter(config); // then retry once with the ready instance\n    return sonaReady.startTrajectory(params);\n  }\n  throw e;\n}","preventionTips":["Construct via createSONAAdapter(config), never new SONAAdapter() followed by immediate use","Share one initialized instance across modules","Fail loudly on initialization rejection — the guard otherwise surfaces much later"],"tags":["initialization","lifecycle","sona","async"],"backgroundTag":"not-initialized","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}