# How to Prevent Duplicate LiveKit Room Creation During Reconnection?

**URL:** <https://community.livekit.io/t/how-to-prevent-duplicate-livekit-room-creation-during-reconnection/2257>\
**Category:** Agents\
**Tags:** livekit-cloud\
**Created:** [October 14, 2026, 6:44am UTC](https://community.livekit.io/t/how-to-prevent-duplicate-livekit-room-creation-during-reconnection/2257 "2026-10-14T06:44:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![G\_Madhabananda\_Patra](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/g_madhabananda_patra/32/1841_2.png) [@G\_Madhabananda\_Patra](https://community.livekit.io/u/G_Madhabananda_Patra)\
**Post date:** [October 14, 2026, 6:44am UTC](https://community.livekit.io/t/how-to-prevent-duplicate-livekit-room-creation-during-reconnection/2257/1 "2026-10-14T06:44:14Z")

</div>

We are facing an issue with LiveKit room lifecycle management

1. A participant joins the room, followed by the AI agent and egress service.
2. If the participant disconnects due to CONNECTION\_TIMEOUT and since no “standard” participant is left, LiveKit triggers “session.close” event causing the agent to leave as well which in turn triggers room tear down manually overriding the default empty timeout.
3. After approximately 1 or 2 mins, the participant reconnects, and we observe a different room ID with same room name and only same participant that joins the room due to reconnect. In this new room the agent and egress never joins.

**Room ids with same room name:**  
RM\_ZABB75iE5zKc  
RM\_bkcnLNWWXDXR  
RM\_PgoNRr7xUTJQ

For context:  
We generate participant access tokens with a **TTL of 10 minutes**.

 ![image](https://us1.discourse-cdn.com/flex001/uploads/livekit2/original/2X/1/13103dffbc860e4ccc6f1a045b27b87251e99ff6.jpeg)

\*\*  
Questions:\*\*

- Is it possible to generate participant tokens using a unique room ID instead of a room name?

- What is the recommended approach to prevent duplicate room creation?

Any guidance on LiveKit room lifecycle management and production best practices would be appreciated.

---

<div class="post-metadata">

**Author:** ![darryncampbell](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/darryncampbell/32/20_2.png) [@darryncampbell](https://community.livekit.io/u/darryncampbell)\
**Post date:** [October 14, 2026, 8:42am UTC](https://community.livekit.io/t/how-to-prevent-duplicate-livekit-room-creation-during-reconnection/2257/2 "2026-10-14T08:42:35Z")

</div>

Hi, you can’t specify the room ID as part of the token, you need to specify the room name.

You really want the user joining the same room, rather than create a new one, since then you retain the conversation context with the agent.

If this happens regularly, that a participant reconnects after 1 or 2 minutes, then I think you want to keep the room alive by specifying a `departure_timeout` on the RoomConfiguration of the token (it defaults to 20 seconds), [Room service API | LiveKit Documentation](https://docs.livekit.io/reference/other/roomservice-api/#room). To prevent the agent from leaving you would also need to specify `close_on_disconnect` as false: [Agent session | LiveKit Documentation](https://docs.livekit.io/agents/logic/sessions/#close_on_disconnect).

Another option, if you don’t want the participant to be able to reconnect is to listen for a `participant_disconnected` webhook, and when the participant disconnects, revoke their token, [Access tokens & grants | LiveKit Documentation](https://docs.livekit.io/frontends/reference/tokens-grants/#token-revocation), which would prevent the room being re-created when they reconnect.

---

<div class="post-metadata">

**Author:** ![G\_Madhabananda\_Patra](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/g_madhabananda_patra/32/1841_2.png) [@G\_Madhabananda\_Patra](https://community.livekit.io/u/G_Madhabananda_Patra)\
**Post date:** [October 14, 2026, 11:25am UTC](https://community.livekit.io/t/how-to-prevent-duplicate-livekit-room-creation-during-reconnection/2257/3 "2026-10-14T11:25:38Z")

</div>

> [@darryncampbell](#):
>
> If this happens regularly, that a participant reconnects after 1 or 2 minutes, then I think you want to keep the room alive by specifying a `departure_timeout` on the RoomConfiguration of the token (it defaults to 20 seconds)

We haven’t observed the default 20-second `departure_timeout` behaviour when all participants leave the room.

Could this be because we don’t explicitly create rooms using the LiveKit Room Service API? Currently, the room is created automatically when we dispatch the agent with the room name specified.

Am I correct in understanding that we should explicitly create the room using the Room Service API, configure `departure_timeout` in the room configuration, and then dispatch the agent using the same room name?

Would this ensure the room remains available for participant reconnection, even if all participants temporarily disconnect?

---

<div class="post-metadata">

**Author:** ![darryncampbell](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/darryncampbell/32/20_2.png) [@darryncampbell](https://community.livekit.io/u/darryncampbell)\
**Post date:** [October 14, 2026, 1:16pm UTC](https://community.livekit.io/t/how-to-prevent-duplicate-livekit-room-creation-during-reconnection/2257/4 "2026-10-14T13:16:27Z")

</div>

> [@G\_Madhabananda\_Patra](#):
>
> Am I correct in understanding that we should explicitly create the room using the Room Service API, configure `departure_timeout` in the room configuration, and then dispatch the agent using the same room name?

I wasn’t suggesting that - that would give you more control but it would be a large change on your part.

I was referring to the room configuration on the token, [Access tokens & grants | LiveKit Documentation](https://docs.livekit.io/frontends/reference/tokens-grants/#room-configuration) , but that docs page doesn’t list every parameter, it directs you to [Room service API | LiveKit Documentation](https://docs.livekit.io/reference/other/roomservice-api/#roomconfiguration). I only provided the second link in my response above, which in retrospect was confusing - sorry about that. You should be able to define `departure_timeout` as part of the token room\_config, based on those docs. I haven’t tested it to be 100% sure, so let me know if you see any issues - If you specify a high value, say 3 minutes, I wouldn’t expect the room to end for 3 minutes after the participant leaves.

---

<div class="post-metadata">

**Author:** ![G\_Madhabananda\_Patra](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/g_madhabananda_patra/32/1841_2.png) [@G\_Madhabananda\_Patra](https://community.livekit.io/u/G_Madhabananda_Patra)\
**Post date:** [October 16, 2026, 8:24am UTC](https://community.livekit.io/t/how-to-prevent-duplicate-livekit-room-creation-during-reconnection/2257/6 "2026-10-16T08:24:54Z")

</div>

> [@darryncampbell](#):
>
> You should be able to define `departure_timeout` as part of the token room\_config, based on those docs.

Thank you, Darryn. We tested departure\_timeout: 60 in the token’s room\_config, but the room still closed about 22 seconds after the participant left. We dispatch the agent with createDispatch before the participant joins, so the room already exists when the token is used. Is there a way to pass departure\_timeout through createDispatch or agent side, so the room it creates uses it?

---

<div class="post-metadata">

**Author:** ![darryncampbell](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/darryncampbell/32/20_2.png) [@darryncampbell](https://community.livekit.io/u/darryncampbell)\
**Post date:** [October 16, 2026, 9:50am UTC](https://community.livekit.io/t/how-to-prevent-duplicate-livekit-room-creation-during-reconnection/2257/7 "2026-10-16T09:50:31Z")

</div>

I misunderstood (again) 🤦

No, you can’t control the departure timeout if you are creating the room automatically via `createDispatch`. You would need to create the room first, through the createRoom API, then dispatch the agent to that created room.

> [@G\_Madhabananda\_Patra](#):
>
> Am I correct in understanding that we should explicitly create the room using the Room Service API, configure `departure_timeout` in the room configuration, and then dispatch the agent using the same room name?

So, a corrected answer to this question, “yes”. Sorry for all the confusion

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/system/32/26_2.png) [@system](https://community.livekit.io/u/system)\
**Post date:** [October 18, 2026, 9:50am UTC](https://community.livekit.io/t/how-to-prevent-duplicate-livekit-room-creation-during-reconnection/2257/8 "2026-10-18T09:50:49Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
