Can i get the reason the call was ended with ctx.a...
# ask-ai
o
Can i get the reason the call was ended with ctx.add_shutdown_callback(write_transcript)?
t
Thanks for reaching out, fernando. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking whether ctx.add_shutdown_callback(write_transcript) is the reason the call ended — quick answer: it isn't the cause; it only registers a task to run after the session shuts down. What it does: • Schedules
write_transcript
to run during post-shutdown cleanup (to save transcripts/logs). • Runs after the session or room has already ended. How to find the actual reason the call ended: • Check server logs for events like
delete_room
,
participant_removed
, or other ROOM_DELETED events. • Search your code for explicit shutdown calls such as
session.shutdown()
or
room.disconnect()
. • If you use session reports (Python agents), view the session report metadata — it includes session end reasons. If you want, tell me: • which agent/service logs you can access (server logs or session reports), • the timestamp or session/room ID for the call, and I’ll suggest the exact log entries or commands to look for. Sources: Job lifecycle | LiveKit docs | Observability data hooks | LiveKit docs | Connecting to LiveKit | LiveKit docs
o
I mean, we are using write_transcript to write the transcript to a file, but it would be helpful if we can get the reason the call ended
t
You're asking how to capture the reason a call ended so you can save it (alongside the transcript) rather than just running
write_transcript
. Good idea — you can record the end reason and save it with your transcript. What to do (Python agent): 1. Listen for the session close event and read its `error`:
Copy code
@session.on("close")
def on_close(event):
    reason = None
    if event.error:
        # contains exception info and `recoverable` flag
        reason = f"error: {event.error}, recoverable: {event.error.recoverable}"
    else:
        reason = "ended gracefully"
    # save reason somewhere (file, DB) or attach to transcript
1. In your shutdown callback, include that reason when writing the transcript:
Copy code
async def write_transcript():
    report = ctx.make_session_report()  # structured session metadata (Python)
    # combine transcript + report or reason and write to file
ctx.add_shutdown_callback(write_transcript)
Additional useful signals: • For SIP calls, check
sip.callStatus
on the participant (e.g.,
hangup
vs
active
). • LiveKit Cloud/dashboard and server logs show disconnect reasons like
STATE_MISMATCH
,
PEER_CONNECTION_DISCONNECT
, or
ROOM_DELETED
— correlate those with your session ID and timestamps. If you want, tell me which environment you run (Python agent, SIP, or LiveKit Cloud) and a sample session or room ID and I’ll give the exact code/log entries to capture and save the end reason with your transcript. Sources: Events and error handling | LiveKit docs | Observability data hooks | LiveKit docs | SIP participant | LiveKit docs | Understanding the STATE_MISMATCH Disconnect Reason | Connecting to LiveKit | LiveKit docs