lemon-fall-20150
02/16/2026, 11:04 PMtall-airline-16756
02/16/2026, 11:04 PMtall-airline-16756
02/16/2026, 11:04 PMshutdown_callback doesn't run if you call aclose() on an agent session. Short answer: yes, that's expected.
Explanation:
• Shutdown callbacks are executed during the session's shutdown phase. Calling session.shutdown() (or ctx.shutdown(drain=True)) triggers those hooks and begins a graceful shutdown (draining pending work if requested).
• Calling session.aclose() directly closes the session immediately and does not run the shutdown callbacks. That means pending operations may not be drained and callbacks registered with ctx.add_shutdown_callback() or session.add_shutdown_callback() won't run.
Recommended sequence to ensure callbacks run:
1. Call session.shutdown(drain=True) to initiate graceful shutdown and run shutdown hooks.
2. Then await session.aclose() to finalize the session closure.
If you want, tell me which language/runtime you’re using (Python, Node.js, etc.) and I can show the exact code snippet for the proper shutdown flow.
Sources: Job lifecycle | LiveKit Documentationlemon-fall-20150
02/17/2026, 12:06 AMtall-airline-16756
02/17/2026, 12:06 AMshutdown() first, then aclose().
• shutdown() initiates a graceful shutdown and runs shutdown callbacks. aclose() finalizes and closes the session. If you call aclose() directly, shutdown callbacks will not run.
2) What drain=True vs drain=False means
• `drain=True`: The shutdown will wait for pending work (for example, any in-progress or queued speech output) to complete before finishing shutdown. This ensures work is delivered before the session fully closes.
• `drain=False`: The shutdown will not wait for pending work to finish; it will stop immediately (or as quickly as the shutdown process allows) and callbacks will run without waiting for ongoing tasks to be drained.
Recommended pattern (example):
1. Call session.shutdown(drain=True) to run callbacks and let pending work finish.
2. Await session.aclose() to complete the closure.
If you tell me which runtime you’re using (Python or Node.js), I can provide a short code example showing the exact sequence.