Room ended reason

Hi LiveKit Team,

I need to detect the exact reason why a room ended so I can handle each case differently on my backend. Specifically I need to distinguish between the following scenarios:

  1. User ended the call — user clicked the end call button and the frontend called room.disconnect()

  2. AI ended the interview — the agent called room.disconnect() from the Python server via a tool function

  3. User lost internet connection — user disconnected due to network issues

  4. User closed the browser tab or page — without explicitly clicking end call

  5. System or agent error — any other unexpected failure such as LLM, TTS, STT, agent crash, stream failure, socket error, or token expiry

Could you help me understand:

  1. Is there a way to detect and differentiate between all of the above reasons when a room ends?
  2. What is the recommended approach to handle and log each of these cases separately?

You will probably need to using a combination of webhooks and self reporting from your agents (it could send to your webhook interface too if you like):slight_smile:

See if these resources help you: