{"record":{"id":"433333975b07b792","repo":"moeru-ai/airi","slug":"kokoroadapter-devicelosscount-device-loss-eve","errorCode":null,"errorMessage":"[KokoroAdapter] ${deviceLossCount} device-loss events recorded, promoting load from webgpu to wasm.","messagePattern":"\\[KokoroAdapter\\] (.+?) device-loss events recorded, promoting load from webgpu to wasm\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/stage-ui/src/libs/inference/adapters/kokoro.ts","lineNumber":332,"sourceCode":"\n  async function loadModel(\n    quantization: string,\n    device: string,\n    options?: {\n      onProgress?: (p: ProgressPayload) => void\n      signal?: AbortSignal\n    },\n  ): Promise<Voices> {\n    // NOTICE: Proactive WASM promotion. If this adapter has suffered repeated\n    // WebGPU device-loss events, webgpu is unreliable on this device and we\n    // should not keep retrying. The worker's per-load dtype/device fallback\n    // chain handles transient failures; this guard handles persistent ones.\n    let effectiveDevice = device\n    if (\n      device === 'webgpu'\n      && deviceLossCount >= DEVICE_LOSS_WASM_THRESHOLD\n    ) {\n      console.warn(\n        `[KokoroAdapter] ${deviceLossCount} device-loss events recorded, `\n        + `promoting load from webgpu to wasm.`,\n      )\n      effectiveDevice = 'wasm'\n    }\n    throwIfAborted(options?.signal)\n    await ensureStarted()\n\n    return defaultPerfTracer.withMeasure('inference', 'kokoro-load-model', () => operationMutex.runExclusive(async () => {\n      throwIfAborted(options?.signal)\n      state = 'loading'\n      const modelStatusId = `kokoro-${quantization}`\n\n      // Clear previous model status when switching models\n      if (currentModelStatusId && currentModelStatusId !== modelStatusId)\n        removeInferenceStatus(currentModelStatusId)\n      currentModelStatusId = modelStatusId\n","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/moeru-ai/airi/blob/677329427f32468c74b17f3ec47eeca4e05bec65/packages/stage-ui/src/libs/inference/adapters/kokoro.ts#L314-L350","documentation":"The Kokoro adapter counts WebGPU 'device-lost' events; once deviceLossCount reaches DEVICE_LOSS_WASM_THRESHOLD, load() no longer honors a requested 'webgpu' device and silently substitutes 'wasm', warning first. This is proactive degradation: per-load fallback chains inside the worker handle one-off losses, while this guard stops retrying a GPU that is persistently unstable on this machine.","triggerScenarios":"Repeated WebGPU device loss (driver reset, GPU hung, browser WebGPU implementation bugs) during kokoro loads on the same session; hardware/driver combos where webgpu init succeeds but compute dies mid-run.","commonSituations":"Laptops with hybrid graphics and flaky drivers; older browser versions with immature WebGPU; long sessions that eventually trigger a driver-level reset.","solutions":["Accept the wasm promotion — inference continues, only slower.","Update GPU drivers and the browser (WebGPU stability improves release over release).","If you control the request path, request device: 'wasm' from the start on machines known to be unstable, avoiding the warn entirely.","Report persistent device-loss patterns to the browser vendor if tied to a specific GPU."],"exampleFix":"// before\nawait kokoro.load(progress, { signal }) // device: 'webgpu' default, flaky GPU\n\n// after\nawait kokoro.loadDevice?.({ device: 'wasm' }, progress, { signal }) // or pass wasm explicitly per adapter API","handlingStrategy":"fallback","validationCode":"if (navigator.gpu) {\n  // still expect possible promotion; device-loss counter decides\n} else {\n  requestWasmFromStart()\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Expose a device preference so users on flaky GPUs can pre-select wasm.","Track device-loss counts per session to detect pathological machines early.","Treat wasm as a first-class target in tests, not just a fallback."],"tags":["kokoro","webgpu","device-lost","wasm-fallback","inference"],"backgroundTag":"webgpu-device-lost","analyzedSha":"677329427f32468c74b17f3ec47eeca4e05bec65","analyzedAt":"2026-08-18T17:29:58.153Z","schemaVersion":2},"datasetVersion":"2026-08-23T13:39:53.451Z"}