{"record":{"id":"b373c7a49b4ff807","repo":"moeru-ai/airi","slug":"creating-new-recognition-instance-due-to-error","errorCode":null,"errorMessage":"Creating new recognition instance due to error","messagePattern":"Creating new recognition instance due to error","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/stage-ui/src/libs/providers/providers/browser-web-speech-api/provider.ts","lineNumber":402,"sourceCode":"      if (errorMessage.includes('already') || errorMessage.includes('started')) {\n        // Recognition is already running, this is OK\n        console.info('Web Speech API recognition already running')\n        return true\n      }\n\n      if (errorMessage.includes('not-allowed') || errorMessage.includes('permission')) {\n        // Permission denied - user needs to grant microphone access\n        const err = new Error('Microphone permission denied. Please grant microphone access and try again.')\n        console.error('Web Speech API: Microphone permission denied')\n        fullStreamCtrl?.error(err)\n        textStreamCtrl?.error(err)\n        deferredText.reject(err)\n        deferredText.isRejected = true\n        return false\n      }\n\n      // For other errors, try creating a new instance\n      console.warn('Creating new recognition instance due to error')\n      try {\n        createAndStartNewRecognitionInstance(recognition)\n        console.info('Web Speech API recognition restarted successfully with new instance')\n        return true\n      }\n      catch (restartError: any) {\n        const err = new Error(`Failed to start Web Speech API recognition: ${restartError?.message || String(restartError)}`)\n        fullStreamCtrl?.error(err)\n        textStreamCtrl?.error(err)\n        deferredText.reject(err)\n        deferredText.isRejected = true\n        console.error('Web Speech API recognition failed to start after retry:', restartError)\n        return false\n      }\n    }\n  }\n\n  // Add event listeners for debugging before starting","sourceCodeStart":384,"sourceCodeEnd":420,"githubUrl":"https://github.com/moeru-ai/airi/blob/677329427f32468c74b17f3ec47eeca4e05bec65/packages/stage-ui/src/libs/providers/providers/browser-web-speech-api/provider.ts#L384-L420","documentation":"After an unclassified startRecognition() failure (not 'already started', not permission-related), the provider logs this warning and attempts recovery by discarding the current SpeechRecognition object and building a fresh one via createAndStartNewRecognitionInstance(). It is the mid-path of the restart strategy, not a terminal error — terminal failure is the subsequent 'failed to start after retry' path.","triggerScenarios":"recognition.start() threw an error whose message matched neither the 'already started' nor 'not-allowed/permission' branches — e.g. InvalidStateError variants, 'service-not-allowed', or engine-specific exceptions — so the code recreates the instance to reset its lifecycle.","commonSituations":"Browser engine glitch leaving recognition in a bad internal state; switching input devices mid-session; speech service temporarily unavailable; long sessions where the old object stops accepting start().","solutions":["Usually self-healing — confirm the next log line says the new instance started successfully.","If it recurs in a loop, capture the original errorMessage from the preceding 'start failed' log to identify the true cause.","Add a short cooldown or max-restart counter so a permanently failing engine does not recreate instances in a tight loop.","Check OS/browser speech service health and microphone device state when retries keep being needed."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  createAndStartNewRecognitionInstance(recognition)\n}\ncatch (restartError: any) {\n  const err = new Error(`Failed to start Web Speech API recognition: ${errorMessageFrom(restartError)}`)\n  // fail the stream once; surface to user rather than looping retries\n}","preventionTips":["Cap instance-recreation attempts to avoid restart loops.","Log the original start error alongside the recreation attempt for diagnosis.","Cool down between recreation attempts (the provider already delays restarts)."],"tags":["web-speech-api","recovery","instance-recreation"],"backgroundTag":"speech-recognition-start-failure","analyzedSha":"677329427f32468c74b17f3ec47eeca4e05bec65","analyzedAt":"2026-08-18T17:29:58.153Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}