Skip to content

Room closes after another participant joins if the agent leaves with ctx.shutdown(reason="Session ended") after a short time #3597

Closed

Description

@Andhs-eff

In our scenario, we connect another human participant to the room via an outbound call and disconnect the agent (as per this). If the agent disconnects immediately or after a short time (even 60 seconds), the call ends just as the agent disconnects.

Example code:

async def entrypoint(ctx: agents.JobContext):
    await ctx.connect()

    session = AgentSession(
        stt=deepgram.STT(),
        llm=openai.LLM(model="gpt-4o-mini"),
        tts=openai.TTS(),
        vad=silero.VAD.load(),
    )

    await session.start(
        room=ctx.room,
        agent=Agent(instructions="You are a helpful voice AI assistant. Your replies are relevant but brief."),
    )

    # Instruct the agent to speak first
    await session.generate_reply()

    # Add another human to replace the agent
    request = CreateSIPParticipantRequest(
        sip_trunk_id = "XXXXXXX",
        sip_call_to = "+XXXXXXX",
        room_name = ctx.room.name,
        participant_identity = "another-human",
        participant_name = "Another Human",
        play_dialtone = True,
        krisp_enabled = True,
        dtmf = "XXXXXXX", 
        wait_until_answered = True
    )

    await ctx.api.sip.create_sip_participant(request)

    await session.say("Thank you for using our service.", allow_interruptions=False, add_to_chat_ctx=False)

    await asyncio.sleep(20)

    ctx.shutdown(reason="Session ended")

In the agent's web console, we see the message could not createOffer with closed peer connection.

Strangely, if we set a sufficiently long time (await asyncio.sleep(120)), the call continues normally with human participants and without the agent.

How can it be that call retention depends on the time it takes for the agent to disconnect? Normally the call should be retained even if the agent disconnects immediately.

P.S. If there is only one participant in the room (the second participant is not added) and the agent disconnects, the room is retained.

Activity

  1. added
    bug
    on Oct 7, 2025
  2. tinalenguyen commented on Oct 7, 2025

    @tinalenguyen
    Member

    Hi, what version of livekit-agents are you using? It might be related to a new param we introduced, delete_room_on_close. Maybe try setting it to False in RoomInputOptions

  3. Andhs-eff commented on Oct 8, 2025

    @Andhs-eff
    Author

    We checked with version 1.2.14. And yes, delete_room_on_close=False fixed the issue. The room is retained even if the agent disconnects immediately after another human joins.

    Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions