Live Kit session closing immediately after being c...
# ask-ai
l
Live Kit session closing immediately after being created. Help!
t
Thanks for reaching out, Tigran. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
There are several potential reasons why a LiveKit session might close immediately after being created: • Automatic Room Closure: If no participants remain in the room when the session is created, or if participants disconnect immediately, the room will close after a short delay. • Agent Session Auto-Close Behavior: The session will close automatically when the linked participant disconnects for reasons such as
CLIENT_INITIATED
,
ROOM_DELETED
, or
USER_REJECTED
. • Worker Lifecycle Management: By default, a room is automatically closed when the last non-agent participant leaves. Any remaining agents will also disconnect. To address this issue, you can: 1. Modify the auto-close behavior by setting
RoomInputOptions.close_on_disconnect
to
False
to prevent automatic closure when participants disconnect. 2. Implement a close event handler to debug the issue and understand why the session is closing. For example:
Copy code
@session.on("close")
def on_close(ev: CloseEvent):
    print(f"Agent Session closed, reason: {ev.reason}")
This will help you identify the specific reason for the immediate closure, such as
CLIENT_INITIATED
,
ROOM_DELETED
,
USER_REJECTED
, or
JOB_SHUTDOWN
. Please check the close reason and ensure that participants are properly joining and remaining in the room when the session is created. Sources: Rooms, participants, and tracks | LiveKit Docs | livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/experimental/realti... | Worker lifecycle | LiveKit Docs