quaint-dog-88356
04/02/2026, 6:49 PMtall-airline-16756
04/02/2026, 6:50 PMtall-airline-16756
04/02/2026, 6:50 PMcommit_user_turn(). I’ll explain the role of commit_user_turn(), what could cause duplicate STT connections, and then ask a few targeted questions so I can help you debug this faster.
Short answer
• Yes — calling commit_user_turn() is necessary in manual turn mode to signal the end of a user turn and let the agent finish processing the input (LLM work, TTS, etc.). Not calling it can leave the turn open and prevent normal cleanup.
• However, commit_user_turn() itself is not explicitly documented as opening or closing STT connections. Duplicate STT connections and memory leaks are usually caused by how audio/stream lifecycle and agent tasks are managed, not by the call alone.
What to check next (likely causes and mitigations)
• Ensure you explicitly close or stop any audio/STT streams when a turn ends:
◦ If you create rtc.AudioStream or similar stream objects per turn, make sure they’re closed on commit/clear/interrupt.
• Ensure every commit_user_turn() is paired with proper cleanup:
◦ If you start async tasks to forward audio to STT, cancel/await them when the turn completes or is interrupted.
• Look for orphaned tasks or handlers in lifecycle hooks:
◦ Confirm you don’t leave background listeners, callbacks, or long-lived promises running after a turn finishes.
• Review features that increase resource retention:
◦ Features like enhanced noise cancellation or preemptive_generation can increase CPU/memory; confirm whether those are enabled and whether they spawn extra threads or connections that need teardown.
• Monitor connection reuse in your STT provider integration:
◦ Some STT client libraries may open new websockets/streams per audio session if not reused; ensure your integration reuses connections where intended.
Targeted troubleshooting steps you can run now
1. Add logging around turn lifecycle:
◦ Log when you create/start and when you close/stop STT/audio streams and when you call commit_user_turn().
1. Reproduce with a minimal flow:
◦ Run a short script that opens a turn, sends audio, calls commit_user_turn(), and repeat N times while watching active connections and memory.
1. Check for un-awaited/cancelled tasks:
◦ Search for spawned async tasks that are not awaited or canceled in error/cleanup paths.
1. Temporarily disable preemptive_generation and noise-cancellation features to see whether memory/connection counts stabilize.
2. Inspect your STT client for connection pooling settings:
◦ Ensure you’re not creating a new STT websocket per small audio chunk unless required.
Questions to narrow this down
• Are you using enhanced noise cancellation or preemptive_generation? If so, which?
• Which STT provider and client library are you using (built-in LiveKit STT or an external provider)?
• Do you open a new STT/audio stream for every user turn, or reuse one stream per session/agent?
• Can you share (sanitized) pseudocode showing how you start audio capture, send audio to STT, and where you call commit_user_turn() and any cleanup?
• When you say “duplicate STT connections are being held open,” do you see multiple websocket/stream connections at the STT provider level, or multiple internal objects in your process (e.g., many AudioStream instances)?
If you share the answers or a small pseudocode snippet, I’ll propose concrete code-level changes and the exact places to add cleanup to stop connection growth and eliminate the leak.
Sources: Turns overview | LiveKit Documentation | Self-hosted deployments | LiveKit Documentation | Agent speech and audio | LiveKit Documentation | Video | LiveKit Documentation | Capturing the First Few Seconds of a Call for Processing, with interactive elementsquaint-dog-88356
04/02/2026, 6:51 PMtall-airline-16756
04/02/2026, 6:51 PMquaint-dog-88356
04/02/2026, 6:53 PM