fix(client): fail WebRTC setup when the initiation payload cannot be published - #939
Open
chinmayv095 wants to merge 1 commit into
Open
fix(client): fail WebRTC setup when the initiation payload cannot be published#939chinmayv095 wants to merge 1 commit into
chinmayv095 wants to merge 1 commit into
Conversation
…published WebRTCConnection.create() sent conversation_initiation_client_data through sendMessage(), which returns early when the room is no longer connected and catches publishData() rejections. Both cases let create() resolve, so a caller could report a connected session — firing onConnect and holding a live room and microphone — for a conversation the server never initialized. Send the initiation payload through a path that surfaces those failures. The existing catch in create() already disconnects the room and rethrows, so the caller's normal connection-error handling recovers. Ordinary mid-session sends stay best effort. Fixes elevenlabs#916
kraenhansen
approved these changes
Aug 17, 2026
Member
|
Thanks a lot @chinmayv095 for the fix 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #916.
Problem
WebRTCConnection.create()sends the mandatoryconversation_initiation_client_datathroughsendMessage(), which is best effort in two ways:console.warn, when the room is no longer connectedlocalParticipant.publishData()rejectionEither case lets
create()resolve.Conversation.startSession()then firesonConnectand the caller reports a connected session, while the LiveKit room and the microphone stay live for a conversation the server never initialized — audible to the user as a session that connects and then never speaks.Fix
Send the initiation payload through a path that surfaces those failures instead of absorbing them.
create()'s existingcatchalready callsroom.disconnect()and rethrows, so the caller's normal connection-error handling recovers with no new error plumbing.Ordinary mid-session sends are unchanged and stay best effort — that distinction is the point, so it has its own test.
Tests
Three added to
WebRTCConnection.test.ts, driving the mocked LiveKitRoomso connect and mic setup succeed and only the initiation send fails:fails setup when the initiation payload cannot be publishedcreate()resolvesfails setup when the room disconnects before the payload is sentcreate()resolveskeeps mid-session sends best effort when publishing failsThe first also asserts
room.disconnect()ran, so a failed setup cannot leave the room and microphone live.Full
@elevenlabs/clientsuite: 182 passing (179 before).lint:es,lint:prettierandtsc --buildclean. Changeset included peragents.md.Note
No conflict with #934, which is also in this file — it changes
room.connect()around line 318, while this touches the initiation send andsendMessage.Note
Medium Risk
Touches WebRTC session bootstrap and connection error semantics; behavior change is intentional but affects when callers see connected vs failed sessions.
Overview
WebRTC
create()no longer reports success when mandatoryconversation_initiation_client_datanever reaches the server. That payload is sent throughsendRequiredMessage()instead of best-effortsendMessage(), so a disconnected room or a failedpublishData()rejects setup and flows through the existingcatchthat callsroom.disconnect()and rethrows.Ordinary mid-session data messages still use
sendMessage()(warn/return or log and swallow errors). Publishing is factored into sharedpublishMessage()used by both paths.Tests cover publish failure during setup (including
disconnect), disconnect before send without callingpublishData, and unchanged best-effort behavior after a successfulcreate(). Patch changeset for@elevenlabs/client.Reviewed by Cursor Bugbot for commit f4eec6b. Bugbot is set up for automated code reviews on this repo. Configure here.