shutdown callback is not called when the outbound ...
# ask-ai
n
shutdown callback is not called when the outbound phone call is not picked up
t
Thanks for reaching out, Tareq. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m responding about the shutdown callback not firing when an outbound phone call is not picked up. What’s happening: the shutdown callback only runs when the agent session/room is explicitly shut down or disconnected. An unanswered outbound SIP call can time out or fail without automatically disconnecting the room or calling
session.shutdown()
, so the registered shutdown callback won’t run. What you can do (short checklist): • Confirm you registered the shutdown callback with
ctx.add_shutdown_callback(...)
. • If you use
create_sip_participant(..., wait_until_answered=True)
, handle the timeout/error from that call and explicitly disconnect the room or shutdown the session in the exception path. • If you don’t wait for answer, monitor the SIP participant’s
sip.callStatus
(or equivalent) and trigger cleanup when it reaches an unconnected/failure state. • Add an explicit timeout: after N seconds of no answer, call
await ctx.room.disconnect()
or
await session.shutdown()
to ensure callbacks run. If you’d like, paste the snippet where you dial (the
create_sip_participant
call and how you register the shutdown callback) and I’ll point out exactly where to add the explicit cleanup and an example try/except. Sources: SIP Lifecycle Management Agent | LiveKit docs | Agents telephony integration | LiveKit docs
n
I call ctx.shutdown() but still the shutdown callback is not called
t
Thanks — I’m following up on your note that you call
ctx.shutdown()
but the shutdown callback still isn’t running. To diagnose this quickly, please paste these three small snippets (or confirm them): 1. Where and how you register the shutdown callback (the
ctx.add_shutdown_callback(...)
code). 2. The exact line(s) where you call
ctx.shutdown()
(or `session.shutdown()`/`ctx.room.disconnect()`), and whether that call runs inside the same task that registered the callback. 3. Any logs or exceptions around shutdown (including startup logs showing the callback was registered, and any timeout/errors after calling shutdown). Common causes to check while you paste code: • The callback is registered after you call
ctx.shutdown()
(order issue). • The callback raises an exception immediately when run (check logs for stack trace). • The shutdown call is in a different context/object than the one where the callback was registered (different `ctx`/session). • A shutdown timeout is hit and the hook is aborted — look for timeout logs. If you share those snippets/logs I’ll point out the exact fix (ordering, try/except around the hook, or calling the correct shutdown function). Sources: Job lifecycle | LiveKit docs