cool-queen-46059
02/13/2026, 9:12 PMtall-airline-16756
02/13/2026, 9:13 PMtall-airline-16756
02/13/2026, 9:13 PMsession.shutdown() (or session.shutdown(drain=True) to finish playing outgoing audio) to gracefully end the agent session.
• Call await session.aclose() to immediately close the agent session.
• Delete the room via the server API to remove all participants (recommended when you want to fully terminate the call/room).
• In Node.js, use ctx.shutdown() for the same effect and optionally use RoomServiceClient to delete the room.
• Detect silence/voicemail and trigger one of the above programmatic methods to end the call automatically.
Why agents might seem unable to disconnect
• The agent code never calls the shutdown/close/delete API — it’s not implemented.
• The agent calls `aclose()`/`shutdown()` but does not await it or handle errors, so the disconnect doesn’t complete.
• The process lacks permission or API scope to delete the room.
• Room cleanup options like delete_room_on_close aren’t configured, so the room persists after the agent leaves or the user disconnects.
Problems when only the user can end the call
• Poor user experience: the user can hear silence after the agent finishes speaking because the agent cannot leave cleanly.
• Resource waste: rooms stay active longer, consuming CPU, bandwidth, and possibly incurring costs.
• Recording/egress issues: egress recordings can continue capturing silence or extra audio, resulting in unwanted content and larger recordings.
• Reduced agent autonomy: agents can’t gracefully hang up on voicemail, disconnect from failed calls, or free themselves to handle new calls automatically.
Recommended best practices
1. Have agents explicitly end their session after completing the interaction with session.shutdown() or session.aclose().
2. If you need to end the whole call for everyone, delete the room via the server API.
3. Implement silence/voicemail detection and use it to trigger an agent shutdown or room deletion so agents don’t stay connected unnecessarily.
4. Ensure your code awaits shutdown/close calls and handles errors, and confirm the service account has permission to delete rooms if you use that approach.
If you want, I can:
• Review snippets of your agent disconnect logic to spot missing shutdown/await/error handling.
• Suggest a small flow to detect silence and safely call session.shutdown() or delete_room.
Which would you prefer — a code review of your disconnect sequence, or a short example of a silence-detection → shutdown flow?
Sources: Job lifecycle | LiveKit Documentation | How to detect and handle silence during calls | LiveKit | Why is there extra audio at the end of my recordings of an agent session? |... | Agents telephony integration | LiveKit Documentation | Agent session | LiveKit Documentationcool-queen-46059
02/13/2026, 9:16 PMtall-airline-16756
02/13/2026, 9:16 PMAgentSession may be configured to close when its linked participant leaves (close_on_disconnect=True). That will cause the agent session to end automatically when the user disconnects https://docs.livekit.io/agents/logic/sessions/.
• `delete_room_on_close`: If enabled, an agent session ending (even from an error/crash) will delete the room and disconnect everyone — this can appear like the agent caused the closure https://docs.livekit.io/agents/logic/sessions/.
• Network / transport failures: ICE/DTLS or other connectivity problems may generate disconnect reasons (e.g., STATE_MISMATCH) that end the session without an explicit hangup by your code https://livekit.io/field-guides/guide/understanding-state-mismatch-disconnect-reason.
• Unhandled errors or indirect tool calls: A crash, an unhandled exception, or an LLM/tool invoking a hangup call indirectly could end the agent session even if you didn’t intentionally add hangup logic https://docs.livekit.io/agents/start/telephony/.
What to check next (practical steps)
1. Check session/room options:
◦ Confirm whether close_on_disconnect or delete_room_on_close is enabled for your AgentSession/RoomOptions. If so, those settings explain automatic agent disconnects.
1. Search logs around the disconnect time:
◦ Look for DeleteRoom, close_on_disconnect, or disconnect reason codes like STATE_MISMATCH or transport errors.
1. Verify code paths and tools:
◦ Ensure no background tool, plugin, or function could be calling session.shutdown(), ctx.shutdown(), hangup_call(), or the server DeleteRoom API.
1. Inspect network/infra events:
◦ Check for NAT flaps, load balancer timeouts, or ICE failures at the same timestamp as the disconnect.
1. Confirm SDK versions:
◦ Note the LiveKit SDK versions in use (server and client). We don’t have a documented bug in the provided sources, but matching versions helps rule out known past issues.
If you’d like, I can help dig further — please share:
• SDK version(s) (server & client): e.g., output of pip freeze | grep livekit or package.json versions.
• A few timestamps and room IDs (RM_xxx) for when this happened.
• Relevant log excerpts around a disconnect (server logs, agent logs, and any disconnect reason codes).
• Your AgentSession/RoomOptions settings (whether close_on_disconnect or delete_room_on_close are set).
With those details I can help pinpoint whether this was expected platform behavior or something that needs deeper investigation.
Sources: Agents telephony integration | LiveKit Documentation | Avoiding Room ID Reuse When Re-Creating Rooms With the Same Name | Ensuring Unique Room IDs with Dynamic Room Names | LiveKit | Agent session | LiveKit Documentation | An introduction to WebRTC Simulcastcool-queen-46059
02/13/2026, 9:35 PMtall-airline-16756
02/13/2026, 9:35 PMclose_on_disconnect=True (default behavior for some AgentSession setups), the agent session will end when its linked user leaves. That produces the exact sequence you described.
• delete_room_on_close enabled for the agent session
◦ If set, any agent session close (including one caused by a participant leaving or an error) will trigger room deletion.
• Server-side or orchestration cleanup triggered by your post-call logic
◦ Your backend might listen for client disconnect events and then call DeleteRoom after running post-call analytics. This would appear in logs as room deletion after participant left.
• Race/ordering in log timestamps
◦ Timestamps or log ordering can make events look sequential even if they are near-simultaneous; check correlated timestamps across systems.
• Network/transport issues following participant leave
◦ When the user leaves, ICE/DTLS transitions or a transient transport failure can surface for the agent and cause its session to end; the room may then be cleaned up automatically.
• Unhandled error or crash in agent process after participant leaves
◦ The agent process could hit an exception or plugin/tool triggered action (e.g., an LLM/tool calling a hangup) right after the user disconnected, causing the agent to exit and room deletion to follow.
Concrete checks to run now
1. Confirm AgentSession/RoomOptions:
◦ Is close_on_disconnect set? Is delete_room_on_close set? If yes, that explains automatic agent disconnect + deletion.
1. Compare timestamps:
◦ Pull precise timestamps for: participant leave (client-initiated), agent disconnect, and DeleteRoom call. Check for any small deltas or ordering inconsistencies.
1. Search for explicit DeleteRoom calls:
◦ Look for server API calls to DeleteRoom around that time in your backend logs (not only LiveKit logs).
1. Inspect disconnect reasons:
◦ In LiveKit logs, check disconnect reason codes for the agent (e.g., STATE_MISMATCH, transport error, or ROOM_DELETED). That reason explains whether the agent was forced out by room deletion or disconnected by transport.
1. Check agent process logs:
◦ Look for unhandled exceptions, shutdown hooks, or any function calls to session.shutdown(), ctx.shutdown(), or hangup_call() executed after the participant left.
1. Confirm any post-call cleanup:
◦ Verify whether your post-call analytics or webhooks trigger a DeleteRoom or cleanup job when the user leaves.
1. Verify SDK versions and deployment timing:
◦ Note server/client LiveKit SDK versions and whether any recent deploys or config changes coincide with the event.
What I can help with next
• If you share:
◦ The exact timestamps and room ID for the incident,
◦ The agent disconnect reason from LiveKit logs,
◦ Whether close_on_disconnect or delete_room_on_close is enabled,
◦ Any DeleteRoom API call entries from your backend logs,
I’ll analyze the sequence and point to the most likely trigger and recommended fix.
If you prefer, I can also provide a short checklist and small code snippets to make agent behavior deterministic (e.g., disable close_on_disconnect, only delete room from a single server job, add robust logging around DeleteRoom calls). Which would you like to go through next?