{"record":{"id":"15cdeb2b84b938d0","repo":"ruvnet/ruflo","slug":"trajectory-params-trajectoryid-not-found","errorCode":null,"errorMessage":"Trajectory ${params.trajectoryId} not found","messagePattern":"Trajectory (.+?) not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/integration/src/sona-adapter.ts","lineNumber":273,"sourceCode":"    return trajectoryId;\n  }\n\n  /**\n   * Record a step in an active trajectory\n   */\n  async recordTrajectoryStep(params: {\n    trajectoryId: string;\n    stepId?: string;\n    action: string;\n    observation: string;\n    reward: number;\n    embedding?: number[];\n  }): Promise<void> {\n    this.ensureInitialized();\n\n    const trajectory = this.activeTrajectories.get(params.trajectoryId);\n    if (!trajectory) {\n      throw new Error(`Trajectory ${params.trajectoryId} not found`);\n    }\n\n    const step: SONATrajectoryStep = {\n      stepId: params.stepId || this.generateId('step'),\n      action: params.action,\n      observation: params.observation,\n      reward: params.reward,\n      timestamp: Date.now(),\n      embedding: params.embedding,\n    };\n\n    trajectory.steps.push(step);\n    trajectory.totalReward += params.reward;\n\n    this.emit('trajectory-step-recorded', {\n      trajectoryId: params.trajectoryId,\n      step\n    });","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/integration/src/sona-adapter.ts#L255-L291","documentation":"SONAAdapter.recordTrajectoryStep looks up params.trajectoryId in the in-memory activeTrajectories map and throws on a miss. The map is populated only by startTrajectory, and entries are removed by endTrajectory — steps are accepted only for live, started trajectories on the same adapter instance.","triggerScenarios":"Recording a step for an id that was never started, for a trajectory already ended (endTrajectory deletes it from the map), or for a trajectory started on a different adapter instance (the map is per-instance and memory-only).","commonSituations":"Continuing to log steps after calling endTrajectory; a process restart mid-trajectory wiping the in-memory map; splitting start/step/end across serverless invocations or worker processes.","solutions":["Create the trajectory first and use exactly the id returned by startTrajectory for every subsequent step","Stop recording after endTrajectory — the trajectory is closed by design","Keep start/step/end on the same adapter instance and process; after a restart, start a new trajectory rather than resuming the old id"],"exampleFix":"// before\nadapter.recordTrajectoryStep({ trajectoryId: 'traj-42', action, observation, reward }); // never started\n\n// after\nconst trajectoryId = await adapter.startTrajectory({ /* ... */ });\nadapter.recordTrajectoryStep({ trajectoryId, action, observation, reward });","handlingStrategy":"validation","validationCode":"// Track live ids on the caller side (activeTrajectories is private to the adapter)\nconst live = new Set<string>();\nconst trajectoryId = await adapter.startTrajectory(params);\nlive.add(trajectoryId);\nfunction recordStep(p: StepParams) {\n  if (!live.has(p.trajectoryId)) {\n    throw new Error(`trajectory not live: ${p.trajectoryId}`);\n  }\n  return adapter.recordTrajectoryStep(p);\n}","typeGuard":"const isLiveTrajectory = (id: string, live: Set<string>): boolean => live.has(id);","tryCatchPattern":"try {\n  await adapter.recordTrajectoryStep(step);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('not found')) {\n    // start a new trajectory (or drop the step) — never fabricate a resume of a dead id\n  }\n  throw e;\n}","preventionTips":["Derive every step/end call from the value returned by startTrajectory — never hand-write ids","Close trajectories in a finally block so they don't linger half-alive","Assume in-memory trajectories die with the process; design restarts to start anew"],"tags":["trajectory","state","lifecycle","sona"],"backgroundTag":"entity-not-found","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"}