{"record":{"id":"e149c3991f90576f","repo":"moeru-ai/airi","slug":"kokoro-worker-unknown-message-type","errorCode":null,"errorMessage":"[Kokoro Worker] Unknown message type:","messagePattern":"\\[Kokoro Worker\\] Unknown message type:","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/stage-ui/src/workers/kokoro/worker.ts","lineNumber":302,"sourceCode":"\n  switch (message.type) {\n    case 'load-model':\n      await loadModel(message)\n      break\n    case 'run-inference':\n      await runInference(message as RunInferenceRequest<KokoroInferenceInput>)\n      break\n    case 'unload-model':\n      ttsModel = null\n      currentQuantization = null\n      currentDevice = null\n      globalThis.postMessage({ type: 'model-unloaded', requestId: message.requestId })\n      break\n    case 'cancel':\n      markCancelled(message.targetRequestId)\n      break\n    default:\n      console.warn('[Kokoro Worker] Unknown message type:', (message as any).type)\n  }\n})\n","sourceCodeStart":284,"sourceCodeEnd":305,"githubUrl":"https://github.com/moeru-ai/airi/blob/677329427f32468c74b17f3ec47eeca4e05bec65/packages/stage-ui/src/workers/kokoro/worker.ts#L284-L305","documentation":"The Kokoro TTS worker's inbound message switch handles exactly 'load-model', 'run-inference', 'unload-model', and 'cancel'. Any other message.type falls into default, logs this warning with the received type, and is then dropped - no reply and no error is sent, so a caller awaiting that requestId would hang until its timeout.","triggerScenarios":"Main thread and worker built from different versions after a deploy (new message type exists on one side only); raw postMessage with a typo'd or renamed type; dev HMR leaving a stale worker alive that receives new-protocol messages; external code posting into the worker.","commonSituations":"Version skew between bundles after upgrades without a hard reload; developing a new worker message and forgetting the worker-side case; recorded/replayed messages with outdated shapes.","solutions":["Compare the logged type against the WorkerInboundMessage union in the worker protocol module","Hard-reload or restart the app so main thread and worker come from the same bundle","Add the missing case in the worker switch (or reply with an error) if you extended the protocol","Use the typed request helpers instead of hand-built postMessage payloads"],"exampleFix":"// before\nswitch (message.type) {\n  case 'load-model': ...\n  default: console.warn('[Kokoro Worker] Unknown message type:', (message as any).type)\n}\n\n// after - compile-time exhaustiveness plus an error reply so callers do not hang\ndefault: {\n  const _exhaustive: never = message\n  sendError(message.requestId, new Error(`Unknown message type: ${(message as any).type}`), 'protocol')\n}","handlingStrategy":"type-guard","validationCode":"if (!isKnownKokoroMessage(message)) {\n  console.warn('dropping unknown worker message:', message)\n  return\n}","typeGuard":"type KnownKokoroMessage =\n  | { type: 'load-model' }\n  | { type: 'run-inference' }\n  | { type: 'unload-model' }\n  | { type: 'cancel' }\nfunction isKnownKokoroMessage(m: unknown): m is KnownKokoroMessage {\n  return typeof m === 'object' && m !== null\n    && ['load-model', 'run-inference', 'unload-model', 'cancel'].includes((m as { type: unknown }).type as string)\n}","tryCatchPattern":"default: {\n  const _exhaustive: never = message\n  sendError(message.requestId, new Error(`Unknown message type: ${(message as any).type}`), 'protocol')\n}","preventionTips":["Define the message union in one shared protocol module imported by both sides","Use exhaustive never checks in the switch so new types fail compilation","Reply with an error for unknown requests so awaiting callers time out with a reason","Hard-reload after deployments to avoid main/worker version skew"],"tags":["web-worker","message-protocol","type-dispatch","version-skew"],"backgroundTag":"unknown-message-type","analyzedSha":"677329427f32468c74b17f3ec47eeca4e05bec65","analyzedAt":"2026-08-18T17:29:58.153Z","contentChangedAt":"2026-08-18T17:29:58.153Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}