moeru-ai/airi · error · Error

The current motion is too short for this VAR order.

Error message

The current motion is too short for this VAR order.

What it means

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.

Source

Thrown at packages/motion-driver-magic/src/shared/var.ts:87

/** Fits the VAR parameters that both public methods use. */
export function fitVarParameters(sequence: TrainingSequence, options: VarFitOptions): VarParameters {
  if (!Number.isFinite(sequence.sampleRateHz) || sequence.sampleRateHz <= 0)
    throw new Error('The motion sample rate must be positive.')
  if (options.order < 1 || !Number.isInteger(options.order))
    throw new Error('The VAR order must be a positive integer.')

  const frames = sequence.frames
  if (frames.length === 0 || frames[0].length === 0)
    throw new Error('The motion sequence must contain at least one value.')
  if (frames.some(frame => frame.length !== frames[0].length))
    throw new Error('Every motion frame must have the same number of values.')

  const channels = createMotionChannels(frames)
  if (channels.length === 0)
    throw new Error('The current motion has no changing channels.')
  if (frames.length <= options.order + 1)
    throw new Error('The current motion is too short for this VAR order.')

  const baselineFrame = createBaselineFrame(frames)
  const trainingFrames = frames.map(frame => channels.map(
    channel => (frame[channel.valueIndices[0]] - channel.mean) / channel.scale,
  ))
  const coefficients = fitCoefficients(trainingFrames, options)
  const residuals = createResiduals(trainingFrames, coefficients, options.order)
  const squaredResidualSum = residuals.reduce(
    (sum, residual) => sum + residual.reduce((channelSum, value) => channelSum + value ** 2, 0),
    0,
  )

  return {
    options,
    sampleRateHz: sequence.sampleRateHz,
    sourceFrameCount: frames.length,
    channelCount: channels.length,
    featureCount: coefficients.length,

View on GitHub (pinned to 9c213115f8)

Solutions

  1. Reduce options.order so frames.length > order + 1
  2. Trim or extend the motion sequence to contain more frames than order + 1
  3. Concatenate multiple compatible clips to lengthen training data
  4. Validate frame count against the requested order before calling and surface a friendlier message

Example fix

// before
fitVarParameters(sequence, { order: 5 }) // sequence.frames.length = 4
// after
fitVarParameters(sequence, { order: 2 }) // 4 > 2 + 1, OK
// or extend the sequence to more than 6 frames
Defensive patterns

Strategy: validation

Validate before calling

function isLongEnough(frames: number[][], order: number): boolean {
  return frames.length > order + 1
}
if (!isLongEnough(sequence.frames, options.order)) throw new Error('Sequence too short for order')

Type guard

function supportsOrder(v: { frames: number[][] }, order: number): boolean {
  return Array.isArray(v.frames) && v.frames.length > order + 1
}

Try / catch

try {
  const params = fitVarParameters(sequence, { order })
} catch (e) {
  if (e instanceof Error && e.message === 'The current motion is too short for this VAR order.') {
    order = Math.max(1, sequence.frames.length - 2) // retry with a lower order
  } else throw e
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of moeru-ai/airi@9c213115f8 (2026-09-02). Data as JSON: /api/errors/f2de5022f8f42e6e. Report an issue: GitHub.