{"record":{"id":"f695c11bb7531e62","repo":"moeru-ai/airi","slug":"the-motion-sequence-must-contain-at-least-one-valu","errorCode":null,"errorMessage":"The motion sequence must contain at least one value.","messagePattern":"The motion sequence must contain at least one value\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/motion-driver-magic/src/shared/var.ts","lineNumber":79,"sourceCode":"  const residuals: number[][] = []\n  for (let frameIndex = order; frameIndex < frames.length; frameIndex++) {\n    const feature = createAutoregressiveFeature(frames, order, channelCount, frameIndex)\n    const prediction = predictAutoregressiveValues(coefficients, feature)\n    residuals.push(frames[frameIndex].map((value, channel) => value - prediction[channel]))\n  }\n  return residuals\n}\n\n/** Fits the VAR parameters that both public methods use. */\nexport function fitVarParameters(sequence: TrainingSequence, options: VarFitOptions): VarParameters {\n  if (!Number.isFinite(sequence.sampleRateHz) || sequence.sampleRateHz <= 0)\n    throw new Error('The motion sample rate must be positive.')\n  if (options.order < 1 || !Number.isInteger(options.order))\n    throw new Error('The VAR order must be a positive integer.')\n\n  const frames = sequence.frames\n  if (frames.length === 0 || frames[0].length === 0)\n    throw new Error('The motion sequence must contain at least one value.')\n  if (frames.some(frame => frame.length !== frames[0].length))\n    throw new Error('Every motion frame must have the same number of values.')\n\n  const channels = createMotionChannels(frames)\n  if (channels.length === 0)\n    throw new Error('The current motion has no changing channels.')\n  if (frames.length <= options.order + 1)\n    throw new Error('The current motion is too short for this VAR order.')\n\n  const baselineFrame = createBaselineFrame(frames)\n  const trainingFrames = frames.map(frame => channels.map(\n    channel => (frame[channel.valueIndices[0]] - channel.mean) / channel.scale,\n  ))\n  const coefficients = fitCoefficients(trainingFrames, options)\n  const residuals = createResiduals(trainingFrames, coefficients, options.order)\n  const squaredResidualSum = residuals.reduce(\n    (sum, residual) => sum + residual.reduce((channelSum, value) => channelSum + value ** 2, 0),\n    0,","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/moeru-ai/airi/blob/9c213115f8bd0fff9e6eabab02b077ac32da21be/packages/motion-driver-magic/src/shared/var.ts#L61-L97","documentation":"VAR fitting needs at least one frame with at least one value per frame; an empty `sequence.frames` array or frames of length 0 have nothing to model. The check runs before any matrix construction so failures are immediate and clear.","triggerScenarios":"Passing a TrainingSequence with `frames: []`, or `frames: [[]]` — e.g. a recording that captured zero frames, a filter that removed all frames, or a channel-selection step that dropped every value.","commonSituations":"Recording started after capture stopped (empty buffer); upstream filtering dropped everything (all frames below a threshold); deserializing a saved motion file that failed partially; slicing a frame range with wrong indices producing empty arrays.","solutions":["Verify the recording actually captured frames before fitting; check `frames.length` upstream.","Fix the slicing/filtering logic that emptied the frame list.","Reject empty sequences at the ingestion boundary with your own clearer message.","Ensure the capture pipeline (device open -> frame callback -> buffer) ran end-to-end before training."],"exampleFix":"// before\nfitVarParameters({ frames: recorded, sampleRateHz: 30 }, opts)\n// after\nif (recorded.length === 0 || recorded[0].length === 0)\n  throw new Error('No motion frames captured')\nfitVarParameters({ frames: recorded, sampleRateHz: 30 }, opts)","handlingStrategy":"validation","validationCode":"function hasFrames(seq: TrainingSequence): boolean {\n  return seq.frames.length > 0 && seq.frames[0].length > 0\n}","typeGuard":null,"tryCatchPattern":"try {\n  fitVarParameters(seq, options)\n} catch (error) {\n  if (error instanceof Error && error.message.includes('at least one value')) {\n    console.error('Empty motion sequence; check the capture pipeline')\n    return null\n  }\n  throw error\n}","preventionTips":["Check recorded.length after capture ends; never fit on empty buffers.","Validate sequence shape (non-empty frames, non-empty rows) at ingestion.","Ensure range slicing/filtering cannot produce zero frames silently.","Fail fast in the capture pipeline when no frames arrive within a timeout."],"tags":["validation","empty-input","var","motion"],"backgroundTag":"empty-input-data","analyzedSha":"9c213115f8bd0fff9e6eabab02b077ac32da21be","analyzedAt":"2026-09-02T04:27:24.639Z","contentChangedAt":"2026-09-02T04:27:24.639Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}