I am using the following setup as recommended, and I have also shifted my API call from on_session_end to @session.on("close"):
-
session.shutdown(drain=True) -
delete_room_on_close=False
What is happening:
When the AI calls the end_interview function, it triggers session.shutdown(drain=True). After this, I can see in the LiveKit dashboard that the agent disconnects successfully, but the user remains in the room with a stuck UI. The user has no idea what happened and thinks the interface has frozen.
What I need:
Could you please suggest a reliable solution that handles this cleanly? I need the user to be properly disconnected or shown a clear end state when the agent shuts down.
This is running in production and I cannot afford unexpected behavior like this. A solution that is stable and has no edge cases would be greatly appreciated.
Code Sample:
@llm.function_tool(description=end_interview_instruction)
async def end_interview():
logger.info("\n 🛑 TOOL CALLED: end_interview")
ctx.agent.end_reason = "assistant-said-end-call-phrase"
await session.say("Thank you for your time. Goodbye!", allow_interruptions=False)
session.shutdown(drain=True)
await session.start(
room=ctx.room,
agent=InterviewAgent(instructions=instructions, ctx=ctx),
room_options=room_io.RoomOptions(
audio_input=room_io.AudioInputOptions(
noise_cancellation=noise_cancellation.BVC(),
),
#forcefully close room and monitor sync API Call
delete_room_on_close=False,
),
# record=True, // it is recording file in server
)
You can see in image
- agent-AJ_a4vv4RoXScHB left at “Mar 23, 2026, 3:06:48 PM“
- Why Room ended at “Mar 23, 2026, 3:22:01 PM“
The issue started from today
