ruvnet/ruflo · error · Error
Trajectory buffer not initialized
Error message
Trajectory buffer not initialized
What it means
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).
Source
Thrown at v3/@claude-flow/cli/src/services/ruvector-training.ts:545
} else if (microLoRA) {
microLoRA.adapt_with_reward(improvement);
}
totalAdaptations++;
}
/**
* Record a learning trajectory
*/
export function recordTrajectory(
embedding: Float32Array,
operatorType: number,
attentionType: number,
executionMs: number,
baselineMs: number
): void {
if (!trajectoryBuffer) {
throw new Error('Trajectory buffer not initialized');
}
trajectoryBuffer.record(
embedding,
operatorType,
attentionType,
executionMs,
baselineMs
);
}
/**
* Get trajectory statistics
*/
export function getTrajectoryStats(): {
successRate: number;
meanImprovement: number;
bestImprovement: number;View on GitHub (pinned to fa13ee4ad6)
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.
Example fix
// before
instrumentation.on('step', (ev) => {
recordTrajectory(ev.embedding, ev.op, ev.attn, ev.ms, ev.base); // pre-init → throws
});
// after
const ready = initializeTraining({ trajectoryCapacity: 50_000 });
instrumentation.on('step', async (ev) => {
await ready;
recordTrajectory(ev.embedding, ev.op, ev.attn, ev.ms, ev.base);
}); Defensive patterns
Strategy: validation
Validate before calling
const ready = initializeTraining({ trajectoryCapacity: 50_000 }); // awaited later, started once
instrumentation.on('step', async (ev) => {
await ready; // guarantees trajectoryBuffer exists (WASM or JS fallback)
recordTrajectory(ev.embedding, ev.op, ev.attn, ev.executionMs, ev.baselineMs);
}); Try / catch
try {
recordTrajectory(emb, op, attn, execMs, baseMs);
} catch (e) {
if (e instanceof Error && e.message === 'Trajectory buffer not initialized') {
await initializeTraining();
recordTrajectory(emb, op, attn, execMs, baseMs);
return;
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Training system not initialized
- SSRF guard: invalid URL — ${rawUrl}
- ruvLLM bridge not initialized. Call with config first.
- Flash attention not initialized
- MoE attention not initialized
AI-assisted analysis of ruvnet/ruflo@fa13ee4ad6 (2026-08-18).
Data as JSON: /api/errors/d398922f132de2c9.
Report an issue: GitHub.