{"record":{"id":"7f563ec9dcc40e6a","repo":"moeru-ai/airi","slug":"mediapipe-backend-not-initialized-call-init-fir","errorCode":null,"errorMessage":"MediaPipe backend not initialized (call init() first)","messagePattern":"MediaPipe backend not initialized \\(call init\\(\\) first\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/model-driver-mediapipe/src/backends/mediapipe.ts","lineNumber":90,"sourceCode":"  }\n\n  async function ensureFaceLandmarker() {\n    if (faceLandmarker)\n      return faceLandmarker\n\n    const { FaceLandmarker } = tasksVision!\n    faceLandmarker = await FaceLandmarker.createFromOptions(vision!, {\n      baseOptions: { modelAssetPath: visionTaskAssets.face },\n      runningMode: 'VIDEO',\n      numFaces: 1,\n    })\n\n    return faceLandmarker\n  }\n\n  async function run(frame: TexImageSource, jobs: MocapJob[], nowMs: number): Promise<PerceptionPartial> {\n    if (!config)\n      throw new Error('MediaPipe backend not initialized (call init() first)')\n\n    await semaphore.acquire()\n    busy = true\n    try {\n      const partial: PerceptionPartial = {}\n\n      for (const job of jobs) {\n        if (!config.enabled[job])\n          continue\n\n        if (job === 'pose') {\n          const landmarker = await ensurePoseLandmarker()\n          const res: PoseLandmarkerResult = landmarker.detectForVideo(frame, nowMs)\n          const firstPose: NormalizedLandmark[] = res.landmarks[0] ?? []\n          const firstWorld: Landmark[] = res.worldLandmarks[0] ?? []\n          partial.pose = {\n            landmarks2d: firstPose,\n            worldLandmarks: firstWorld.map(p => ({","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/moeru-ai/airi/blob/27111382b4a79a7e983289d6e983a06af185ed0f/packages/model-driver-mediapipe/src/backends/mediapipe.ts#L72-L108","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Await backend.init(config) before allowing the scheduler to call backend.run().","Track an isInitialized flag in the engine and drop early frames until init resolves.","Ensure init() does not throw silently; wrap it and surface errors before starting capture."],"exampleFix":"// before\nbackend = createMediaPipeBackend()\nscheduler.start() // calls backend.run before init\n// after\nbackend = createMediaPipeBackend()\nawait backend.init(config)\nscheduler.start()","handlingStrategy":"validation","validationCode":"let initialized = false\nasync function ensureInit(backend: MocapBackend, config: MocapConfig) {\n  if (!initialized) {\n    await backend.init(config)\n    initialized = true\n  }\n}\n\nawait ensureInit(backend, config)\nbackend.run(frame, jobs, now)","typeGuard":null,"tryCatchPattern":"try {\n  await backend.run(frame, jobs, now)\n} catch (error) {\n  if (error instanceof Error && error.message.includes('not initialized')) {\n    await backend.init(config)\n    await backend.run(frame, jobs, now)\n  } else throw error\n}","preventionTips":["Await backend.init(config) before starting the frame scheduler.","Track an isInitialized flag in the engine and drop frames until ready.","Surface init failures before the first frame is dispatched."],"tags":["mediapipe","mocap","lifecycle","initialization-order"],"backgroundTag":null,"analyzedSha":"27111382b4a79a7e983289d6e983a06af185ed0f","analyzedAt":"2026-08-12T18:33:34.132Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}