moeru-ai/airi · error · Error

MediaPipe backend not initialized (call init() first)

Error message

MediaPipe backend not initialized (call init() first)

What it means

Thrown by the MediaPipe backend's run() when the module-local config variable is still undefined, meaning init(nextConfig) was never called (or was called with no arg and did not assign). run() reads config.enabled[job] for every requested job, so a missing config makes the whole pass undefined behavior.

Source

Thrown at packages/model-driver-mediapipe/src/backends/mediapipe.ts:90

  }

  async function ensureFaceLandmarker() {
    if (faceLandmarker)
      return faceLandmarker

    const { FaceLandmarker } = tasksVision!
    faceLandmarker = await FaceLandmarker.createFromOptions(vision!, {
      baseOptions: { modelAssetPath: visionTaskAssets.face },
      runningMode: 'VIDEO',
      numFaces: 1,
    })

    return faceLandmarker
  }

  async function run(frame: TexImageSource, jobs: MocapJob[], nowMs: number): Promise<PerceptionPartial> {
    if (!config)
      throw new Error('MediaPipe backend not initialized (call init() first)')

    await semaphore.acquire()
    busy = true
    try {
      const partial: PerceptionPartial = {}

      for (const job of jobs) {
        if (!config.enabled[job])
          continue

        if (job === 'pose') {
          const landmarker = await ensurePoseLandmarker()
          const res: PoseLandmarkerResult = landmarker.detectForVideo(frame, nowMs)
          const firstPose: NormalizedLandmark[] = res.landmarks[0] ?? []
          const firstWorld: Landmark[] = res.worldLandmarks[0] ?? []
          partial.pose = {
            landmarks2d: firstPose,
            worldLandmarks: firstWorld.map(p => ({

View on GitHub (pinned to 27111382b4)

Solutions

  1. Await backend.init(config) before allowing the scheduler to call backend.run().
  2. Track an isInitialized flag in the engine and drop early frames until init resolves.
  3. Ensure init() does not throw silently; wrap it and surface errors before starting capture.

Example fix

// before
backend = createMediaPipeBackend()
scheduler.start() // calls backend.run before init
// after
backend = createMediaPipeBackend()
await backend.init(config)
scheduler.start()
Defensive patterns

Strategy: validation

Validate before calling

let initialized = false
async function ensureInit(backend: MocapBackend, config: MocapConfig) {
  if (!initialized) {
    await backend.init(config)
    initialized = true
  }
}

await ensureInit(backend, config)
backend.run(frame, jobs, now)

Try / catch

try {
  await backend.run(frame, jobs, now)
} catch (error) {
  if (error instanceof Error && error.message.includes('not initialized')) {
    await backend.init(config)
    await backend.run(frame, jobs, now)
  } else throw error
}

Prevention

When it happens

Trigger: Calling backend.run(frame, jobs, nowMs) before backend.init(config); init() threw partway so config was never assigned; the engine/scheduler started dispatching frames before the backend finished initializing.

Common situations: Mocap engine wired so that frame scheduling starts on camera 'loadedmetadata' but init() is awaited only in a separate effect that has not resolved; a config object that was built asynchronously and the engine raced ahead; hot-reload resetting the backend instance but not the scheduler.

Related errors


AI-assisted analysis of moeru-ai/airi@27111382b4 (2026-08-12). Data as JSON: /api/errors/7f563ec9dcc40e6a. Report an issue: GitHub.