On_shutdown node

Livekit team, is there official documentation on on_shutdown anywhere? Kind of confusing, as it’s an async function, but it seems like I can’t trust it to execute all my code. I have 3 async functions within on_shutdown, one makes a db call, another makes an llm chat completion call (standalone), and then one more fast db insert call.

should all execute in <5s

How should I think about on_shutdown vs on_exit?

Seems like the only way I can trust it is by moving all code to an api endpoint and then doing a fire-and-forget in on_shutdown. What about dirty stops, as in, client’s computer powers off mid-session?

Did you see this? Job lifecycle | LiveKit Documentation

You can adjust this value in the ServerOptions (code here: agents/livekit-agents/livekit/agents/worker.py at main · livekit/agents · GitHub)

e.g. server = AgentServer(shutdown_process_timeout=10)

yeah I read that doc a few times, but didn’t realize there’s a ServerOptions config. Very helpful. It looks like when running the agent locally I get Cannot write to closing transport error, but I’m deploying with lk agents create now and I expect it to work. This is very helpful, thank you!