If a participant disconnects and my shutdown hook ...
# ask-ai
p
If a participant disconnects and my shutdown hook callback is executed, is there a way to pass the session.userdata, even if the data has been closed (on disconnect)?
t
Thanks for reaching out, Mario. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hello! Our team is operating on reduced capacity over the holidays, so our responses may be delayed. If your issue is critical/urgent, please react to your original message above with the ‼️ emoji and your issue will be escalated with our team. Happy Holidays!
Thanks — you're asking whether a shutdown hook can still read
session.userdata
after a participant disconnects. Yes. Shutdown hooks run during session teardown before the session's resources are fully cleared, so
session.userdata
remains available inside those callbacks. You can read (and persist) userdata in the shutdown hook to perform final cleanup or save state. If you plan to modify userdata in the hook, confirm your hook runs synchronously (or await async cleanup) so changes complete before the session fully closes. Do you want an example in your language (Go/JS/Rust) or details about registering the shutdown callback? Sources: Job lifecycle | LiveKit docs
p
if the agent is not running, would I be able to access its userdata?
t
You're asking whether you can access an agent's
userdata
when the agent is not running. You cannot access an agent's
userdata
once the agent/session has stopped.
userdata
lives in the AgentSession/JobProcess during the agent's lifecycle and is cleared when the session ends. If you need the data after shutdown, persist it before the agent stops (for example, in a shutdown hook that saves to a database or file). Would you like a short example in your preferred language showing how to persist
userdata
in a shutdown hook? Sources: Agents (Node.js) | livekit/livekit_composite | DeepWiki | Job lifecycle | LiveKit docs
p
are session.userdata the same as agent.userdata?
t
You're asking whether
session.userdata
and
agent.userdata
are the same. Yes — they refer to the same userdata object. When an AgentSession is created, the
userdata
is attached to the session and is accessible from the agent via the session (e.g.,
self.session.userdata
or
agent.session.userdata
). Any data stored there is shared between the session and the agent during the session's lifecycle. Sources: Agents and handoffs | LiveKit docs
p
So, if the agent is not running, but the session is, would I be able to still access the userdata?
t
Yes — if the AgentSession is still active,
session.userdata
remains accessible even when no agent is currently running.
userdata
is attached to the session (not the agent), so it persists across agent handoffs and while the session is live. If you need the data after the session ends, save it to external storage in a shutdown hook before the session stops. Sources: Agents and handoffs | LiveKit docs | Agent session | LiveKit docs