Skip to content

fix: wait_for_participant waits until participant is fully active - #5271

Merged
davidzhao merged 6 commits into
mainfrom
dz/participant-active
Apr 3, 2026
Merged

davidzhao merged 6 commits into
mainfrom
dz/participant-active

Conversation

@davidzhao

Copy link
Copy Markdown
Member

requires livekit v1.1.4

@davidzhao
davidzhao requested a review from a team March 30, 2026 05:21
devin-ai-integration[bot]

This comment was marked as resolved.

@chenghao-mou chenghao-mou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we update the pyproject and uv lock files?

@davidzhao

Copy link
Copy Markdown
Member Author

should we update the pyproject and uv lock files?

yup, waiting for python sdk release before doing so..

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 new potential issue.

View 6 additional findings in Devin Review.

Open in Devin Review

@davidzhao
davidzhao merged commit 4be45a2 into main Apr 3, 2026
18 of 20 checks passed
@davidzhao
davidzhao deleted the dz/participant-active branch April 3, 2026 20:42
osimhi213 added a commit to de-id/livekit-agents that referenced this pull request Apr 5, 2026
* upstream/main:
  fix: add PARTICIPANT_KIND_CONNECTOR to default participant kinds (livekit#5339)
  feat: expose service_tier in CompletionUsage from OpenAI Responses API (livekit#5341)
  feat: answering machine detection (livekit#4906)
  fix: wait_for_participant waits until participant is fully active (livekit#5271)
  (gemini realtime): add warnings in update_chat_ctx and update_instructions (livekit#5332)
  fix: convert oneOf to anyOf in strict schema for discriminated unions (livekit#5324)
  fix(voice): make function call history preservation configurable in AgentTask (livekit#5288)
osimhi213 added a commit to de-id/livekit-agents that referenced this pull request Apr 5, 2026
* fix(voice): make function call history preservation configurable in AgentTask (livekit#5288)

* fix: convert oneOf to anyOf in strict schema for discriminated unions (livekit#5324)

* (gemini realtime): add warnings in update_chat_ctx and update_instructions (livekit#5332)

* fix: wait_for_participant waits until participant is fully active (livekit#5271)

* feat: answering machine detection (livekit#4906)

Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* feat: expose service_tier in CompletionUsage from OpenAI Responses API (livekit#5341)

* fix: add PARTICIPANT_KIND_CONNECTOR to default participant kinds (livekit#5339)

---------

Co-authored-by: Gopal Bagaswar <[email protected]>
Co-authored-by: Long Chen <[email protected]>
Co-authored-by: Tina Nguyen <[email protected]>
Co-authored-by: David Zhao <[email protected]>
Co-authored-by: Chenghao Mou <[email protected]>
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Piyush Gambhir <[email protected]>
Co-authored-by: Anunay Maheshwari <[email protected]>
@IngLP

IngLP commented Apr 13, 2026

Copy link
Copy Markdown

hi @davidzhao , this breaks my implementation! I was using wait_for_participant to setup the agent according to participant metadata, and this used to work because I had time to do so, while the telephone was ringing. Now I am losing that precious time to do the setup.

@davidzhao

Copy link
Copy Markdown
Member Author

@IngLP can you clarify what actually happens in your use case? this should introduce less than 500ms of latency to wait_for_participant in the typical case.

@IngLP

IngLP commented Apr 13, 2026

Copy link
Copy Markdown

@davidzhao maybe that's true for incoming calls, but for outgoing calls, it's not. I had plenty of time while the other extension was ringing, now wait_for_participant only unlocks when the callee has actually answered.

@davidzhao

Copy link
Copy Markdown
Member Author

@IngLP can you share a code snippet of what you are doing? and describe the current behavior that you are observing?

@IngLP

IngLP commented Apr 13, 2026

Copy link
Copy Markdown

Before:

  • Outgoing call launched by backend with CreateSIPParticipant, agent config written in sip participant metadata
  • The call starts and it's ringing
  • Agent starts, waits for participant, reads metadata, setups agent and tools
  • Call is still ringing
  • Contact answers and everything is ready

Now:

  • Contact answers and everything has still to be set up, including recording, which cuts part of the call.

@davidzhao

Copy link
Copy Markdown
Member Author

@IngLP please share example code snippet.. that'll make it easier for us to see what's going on. if you are calling specific APIs, include the actual calls with the parameters

@IngLP

IngLP commented Apr 14, 2026

Copy link
Copy Markdown

@davidzhao it's just like this:

@server.rtc_session()
async def entrypoint(ctx: JobContext):
    [other setup code]

    logger.info(f"connecting to room {ctx.room.name}")
    await ctx.connect(auto_subscribe=AutoSubscribe.AUDIO_ONLY)

    try:
        participant = await ctx.wait_for_participant()
    except RuntimeError as exc:
        if _is_expected_participant_wait_disconnect(exc):
            logger.info(
                "Room disconnected before participant joined; ending job without agent startup"
            )
            return
        raise
    
    [setup agent according to participant metadata, other code]

    agent_session = AgentSessionExt(
        **components,
    )
    await agent_session.start_session(agent, participant, room=ctx.room)

@davidzhao

Copy link
Copy Markdown
Member Author

@IngLP where do you perform the outbound dial?

@IngLP

IngLP commented Apr 15, 2026

Copy link
Copy Markdown

@davidzhao in the backend, a separate deployment from the agents runner.

@decafdennis

Copy link
Copy Markdown

This change also hangs the wait_for_participant call in console mode, because create_mock_room does not mock out the participant state and so the participant never becomes active.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants