I am still running into the issue where if I conne...
# ask-ai
g
I am still running into the issue where if I connect <20 seconds after the last user session ended, then the agent doesn't rejoin. I believe it takes 20 seconds for the agent to leave the room when the session is ended, so if you join before this job can finish, the agent doesn't respond. Help me diagnose what is going wrong
t
Thanks for reaching out, Sohum. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'd love to help you get to the bottom of this! Could you share a bit more about your setup? For example: • Are you using a custom agent implementation or one of LiveKit's built-in features? • What usually causes the agent to join or leave the room in your setup? • Have you noticed any logs or error messages when the agent has trouble rejoining? Knowing these details will really help us figure out what's going on together.
g
I am using a custom agent and self hosted livekit server in GKE with STUnner. Once this log
deleting room state
comes after the user leaves, then it works. But if the user tries to join before then, it fails
t
I understand how frustrating this issue can be! What’s happening is that the room cleanup process after a user leaves takes a little time. If a new user joins before this cleanup finishes (which you can see from the "deleting room state" log), the system might reuse the previous room's state, leading to those inconsistencies you’re experiencing. Here are some ways to help resolve this: • Try using unique room names when creating rooms by adding a timestamp, UUID, or counter. This way, each room is fresh and doesn’t depend on the previous one’s cleanup. • Another option is to wait about 1-2 minutes after you see the "deleting room state" log before creating a room with the same name. This gives the system enough time to finish cleaning up. • Also, make sure your custom agent listens for disconnection events and only tries to reconnect once the room is confirmed to exist or has been recreated. If you’d like, I’m here to help guide you through implementing any of these solutions in your setup. Just let me know! Sources: Avoiding Room ID Reuse When Re-Creating Rooms With the Same Name | examples/warm-transfer/warm_transfer.py | agents/src/job.ts | Connecting to LiveKit | LiveKit Docs
g
The thing is, I don't want to create a product that has this downtime
t
I completely understand how important it is to avoid downtime, and I’m here to help you with that! One effective way is to separate the room cleanup process from the creation of new rooms. Here are a few friendly suggestions you might find useful: • Use unique room names: Instead of reusing the same room name, try generating a unique name for each session (like adding a timestamp or UUID). This way, a new room can be created right away without waiting for the previous one to finish cleaning up. • Implement a fallback mechanism: If your agent notices the room is still cleaning up, it can gently redirect users to a waiting room or placeholder until the new session is ready. This helps keep things smooth and seamless for everyone. • Optimize agent reconnection logic: Consider tweaking your custom agent so it checks the room’s status before joining. This can help it reconnect gracefully and avoid hiccups during transitions. If you’d like, I’d be happy to walk you through any of these options in more detail to help you get rid of downtime completely. Just let me know!