{"record":{"id":"f2de5022f8f42e6e","repo":"moeru-ai/airi","slug":"the-current-motion-is-too-short-for-this-var-order","errorCode":null,"errorMessage":"The current motion is too short for this VAR order.","messagePattern":"The current motion is too short for this VAR order\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/motion-driver-magic/src/shared/var.ts","lineNumber":87,"sourceCode":"\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,\n  )\n\n  return {\n    options,\n    sampleRateHz: sequence.sampleRateHz,\n    sourceFrameCount: frames.length,\n    channelCount: channels.length,\n    featureCount: coefficients.length,","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/moeru-ai/airi/blob/9c213115f8bd0fff9e6eabab02b077ac32da21be/packages/motion-driver-magic/src/shared/var.ts#L69-L105","documentation":"Fitting a VAR model of order k requires estimating coefficients from at least k+1 consecutive frame pairs (k lagged frames to predict frame k+1). fitVarParameters throws when frames.length <= options.order + 1, because there are fewer usable training transitions than the model needs. A longer sequence (strictly more than order+1 frames) is required.","triggerScenarios":"Calling fitVarParameters with a small options.order check failing: e.g. frames.length = 3 with order = 3 (needs > 4 frames), or any sequence where frame count does not exceed order + 1.","commonSituations":"Setting a high VAR order on short motion clips; trimming clips down to a handful of frames for testing; concatenation logic that produced fewer frames than expected.","solutions":["Reduce options.order so frames.length > order + 1","Trim or extend the motion sequence to contain more frames than order + 1","Concatenate multiple compatible clips to lengthen training data","Validate frame count against the requested order before calling and surface a friendlier message"],"exampleFix":"// before\nfitVarParameters(sequence, { order: 5 }) // sequence.frames.length = 4\n// after\nfitVarParameters(sequence, { order: 2 }) // 4 > 2 + 1, OK\n// or extend the sequence to more than 6 frames","handlingStrategy":"validation","validationCode":"function isLongEnough(frames: number[][], order: number): boolean {\n  return frames.length > order + 1\n}\nif (!isLongEnough(sequence.frames, options.order)) throw new Error('Sequence too short for order')","typeGuard":"function supportsOrder(v: { frames: number[][] }, order: number): boolean {\n  return Array.isArray(v.frames) && v.frames.length > order + 1\n}","tryCatchPattern":"try {\n  const params = fitVarParameters(sequence, { order })\n} catch (e) {\n  if (e instanceof Error && e.message === 'The current motion is too short for this VAR order.') {\n    order = Math.max(1, sequence.frames.length - 2) // retry with a lower order\n  } else throw e\n}","preventionTips":["Compute the maximum supported order as frames.length - 2 and clamp options.order to it","Prefer low orders (1-3) unless the clip is long","Concatenate compatible clips to lengthen training data before raising the order","Validate frame count against order in the UI before starting a fit"],"tags":["validation","motion-data","var"],"backgroundTag":"sequence-too-short","analyzedSha":"9c213115f8bd0fff9e6eabab02b077ac32da21be","analyzedAt":"2026-09-02T04:27:24.639Z","contentChangedAt":"2026-09-02T04:27:24.639Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}