my sesssion has this option set close_on_disconnec...
# ask-ai
e
my sesssion has this option set close_on_disconnect=False await session.start( room=ctx.room, agent=agent, room_input_options=RoomInputOptions( # LiveKit Cloud enhanced noise cancellation # - If self-hosting, omit this parameter # - For telephony applications, use
BVCTelephony
for best results noise_cancellation=noise_cancellation.BVC(), close_on_disconnect=False ), ) When client closes the browser, the participant disconnects and my on_participant_disconnected methid is triggerred which has some final logic to generate a response from llm stream = self._session.llm.chat(chat_ctx=chat_ctx, conn_options=llm_conn_options) parts: list[str] = [] async for chunk in stream: if chunk.delta and chunk.delta.content: parts.append(chunk.delta.content) await stream.aclose() return "".join(parts).strip() but as soon as it reached here, I see the log that 2025-07-30 181937,559 - DEBUG livekit.agents - stream closed {"participant": "688987c3de146499c319e1da", "source": "SOURCE_MICROPHONE", "pid": 28631, "job_id": "AJ_oBmNFx2bKSZT"} 2025-07-30 181940,388 - WARNING livekit - livekit:rtc engine453livekit:rtc_engine - received session close: "signal client closed: \"stream closed\"" UnknownReason Resume {"pid": 28631, "job_id": "AJ_oBmNFx2bKSZT"} 2025-07-30 181940,394 - DEBUG livekit.agents - shutting down job task {"reason": "", "user_initiated": false, "pid": 28631, "job_id": "AJ_oBmNFx2bKSZT"} 2025-07-30 181940,397 - INFO livekit.agents - process exiting {"reason": "", "pid": 28631, "job_id": "AJ_oBmNFx2bKSZT"} 2025-07-30 181940,422 - DEBUG li
t
Thanks for reaching out, Shubhankar. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
When
close_on_disconnect=False
is set, the session should not automatically close when a participant disconnects. However, if your session is still closing, here are some potential causes and solutions: • Other Close Triggers: The session might be closing due to reasons unrelated to participant disconnection, such as room-level events or explicit session closure in your code. • Manual Session Closure: Check if your code is explicitly calling session close methods. • Room-Level Events: Ensure the room itself is not being closed or deleted. To handle participant disconnection while keeping the session active: 1. Ensure
close_on_disconnect=False
is correctly set in your `RoomInputOptions`:
Copy code
await session.start(
    agent=MyAgent(), 
    room=ctx.room,
    input_options=RoomInputOptions(close_on_disconnect=False)
)
1. Manually handle participant disconnection events at the room level:
Copy code
def _on_participant_disconnected(_: rtc.Participant, fut=room_empty_future):
    if len(ctx.room.remote_participants) == 0 and not fut.done():
        fut.set_result(None)

ctx.room.on("participant_disconnected", _on_participant_disconnected)
1. Listen for session close events to debug and handle cleanup:
Copy code
@session.on("close")
def on_close(ev: CloseEvent):
    print(f"Agent Session closed, reason: {ev.reason}")
If the issue persists despite these steps, further investigation into your specific implementation may be required. Sources: examples/voice_agents/realtime_joke_teller.py