{"record":{"id":"d398922f132de2c9","repo":"ruvnet/ruflo","slug":"trajectory-buffer-not-initialized","errorCode":null,"errorMessage":"Trajectory buffer not initialized","messagePattern":"Trajectory buffer not initialized","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/cli/src/services/ruvector-training.ts","lineNumber":545,"sourceCode":"  } else if (microLoRA) {\n    microLoRA.adapt_with_reward(improvement);\n  }\n\n  totalAdaptations++;\n}\n\n/**\n * Record a learning trajectory\n */\nexport function recordTrajectory(\n  embedding: Float32Array,\n  operatorType: number,\n  attentionType: number,\n  executionMs: number,\n  baselineMs: number\n): void {\n  if (!trajectoryBuffer) {\n    throw new Error('Trajectory buffer not initialized');\n  }\n\n  trajectoryBuffer.record(\n    embedding,\n    operatorType,\n    attentionType,\n    executionMs,\n    baselineMs\n  );\n}\n\n/**\n * Get trajectory statistics\n */\nexport function getTrajectoryStats(): {\n  successRate: number;\n  meanImprovement: number;\n  bestImprovement: number;","sourceCodeStart":527,"sourceCodeEnd":563,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/cli/src/services/ruvector-training.ts#L527-L563","documentation":"Thrown by recordTrajectory() when the module-level trajectoryBuffer is null. initializeTraining() always constructs a trajectory buffer on success (WASM WasmTrajectoryBuffer or the JsTrajectoryBuffer fallback), so a null buffer means initializeTraining() never completed in this process — or cleanup() freed and nulled it. Capacity defaults to 10000 entries and dim to 256 (max).","triggerScenarios":"Recording execution-vs-baseline trajectories before awaiting initializeTraining(); calling recordTrajectory after cleanup() in test teardown; trajectory hooks registered in a worker process whose parent alone ran init.","commonSituations":"Instrumentation installed at module load (decorators, monkey-patched timers) that fires before async init resolves; long-running daemons that cleanup() on SIGHUP then keep serving trajectory events; benchmark harnesses that assume state persists from a previous run.","solutions":["Await initializeTraining() (optionally with trajectoryCapacity sized to your run) before arming any trajectory-recording hooks.","Gate recordTrajectory call sites behind the same ensureInitialized() promise used for training.","After cleanup(), either stop recording or re-initialize first.","Size trajectoryCapacity to your step count if you rely on the stats — recording beyond capacity evicts old entries, but that never causes this error."],"exampleFix":"// before\ninstrumentation.on('step', (ev) => {\n  recordTrajectory(ev.embedding, ev.op, ev.attn, ev.ms, ev.base); // pre-init → throws\n});\n\n// after\nconst ready = initializeTraining({ trajectoryCapacity: 50_000 });\ninstrumentation.on('step', async (ev) => {\n  await ready;\n  recordTrajectory(ev.embedding, ev.op, ev.attn, ev.ms, ev.base);\n});","handlingStrategy":"validation","validationCode":"const ready = initializeTraining({ trajectoryCapacity: 50_000 }); // awaited later, started once\ninstrumentation.on('step', async (ev) => {\n  await ready; // guarantees trajectoryBuffer exists (WASM or JS fallback)\n  recordTrajectory(ev.embedding, ev.op, ev.attn, ev.executionMs, ev.baselineMs);\n});","typeGuard":null,"tryCatchPattern":"try {\n  recordTrajectory(emb, op, attn, execMs, baseMs);\n} catch (e) {\n  if (e instanceof Error && e.message === 'Trajectory buffer not initialized') {\n    await initializeTraining();\n    recordTrajectory(emb, op, attn, execMs, baseMs);\n    return;\n  }\n  throw e;\n}","preventionTips":["Arm trajectory-recording hooks only after the init promise resolves.","Size trajectoryCapacity to your expected step count when you rely on getTrajectoryStats().","Treat cleanup() in test afterEach as paired with re-init in beforeEach if later suites still record.","Prefer dropping a telemetry sample over crashing the measured workload."],"tags":["initialization","ruvector","trajectory","telemetry","lifecycle"],"backgroundTag":"component-not-initialized","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}