early-afternoon-97327
11/21/2025, 12:50 PMtall-airline-16756
11/21/2025, 12:50 PMtall-airline-16756
11/21/2025, 12:51 PMFallbackAdapter to route to a backup STT provider if Deepgram disconnects frequently.
• Review logs around the disconnect time to see whether the room/participant was being torn down or if there’s a preceding network error.
Quick diagnostic info I need to help further
1. Does this error only occur when you intentionally end the session, or also during ongoing calls?
2. Any recent changes to network, firewall, or API keys?
3. Which LiveKit Agents/Deepgram plugin version are you running (or your repo commit/requirements)?
Tell me answers to those and I’ll suggest precise next steps or code-level changes.
Sources: Deepgram STT plugin guide | LiveKit docs | Events and error handling | LiveKit docs | Understanding the STATE_MISMATCH Disconnect Reason | AI Service Plugin Ecosystem | livekit/livekit_composite | DeepWikiearly-afternoon-97327
11/21/2025, 12:52 PMtall-airline-16756
11/21/2025, 12:52 PMstt_stream.end_input() then await stt_stream.aclose() so Deepgram can finalize transcription.
1. Drain pending work with a graceful shutdown
• Use the session/ctx shutdown that waits for in-flight tasks to finish:
◦ Python: await session.shutdown(drain=True)
◦ Node: ctx.shutdown('Session ended')
1. Cancel background tasks in a shutdown hook
• Stop any silence monitors or background loops before/while shutting down to avoid post-disconnect activity.
1. Prefer shutdown(drain=True) over immediate close
• Don’t call immediate close/`aclose()` on the session without draining — that causes abrupt disconnects and the error you saw.
1. (Optional) Use a fallback or retries
• Add retry logic for transient STT disconnects and consider the Agents FallbackAdapter to switch providers if Deepgram disconnects frequently.
If you want, share which code path you call to end the session (your shutdown snippet or where you currently call aclose()), your STT stream calls, and the LiveKit/Deepgram plugin version — I’ll suggest exact code edits.
Sources: Job lifecycle | LiveKit docs | How to detect and handle silence during calls