Skip to content

fix(client): fail WebRTC setup when the initiation payload cannot be published - #939

Open
chinmayv095 wants to merge 1 commit into
elevenlabs:mainfrom
chinmayv095:fix/webrtc-required-init-publish
Open

fix(client): fail WebRTC setup when the initiation payload cannot be published#939
chinmayv095 wants to merge 1 commit into
elevenlabs:mainfrom
chinmayv095:fix/webrtc-required-init-publish

Conversation

@chinmayv095

@chinmayv095 chinmayv095 commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Fixes #916.

Problem

WebRTCConnection.create() sends the mandatory conversation_initiation_client_data through sendMessage(), which is best effort in two ways:

  • it returns early, with only a console.warn, when the room is no longer connected
  • it catches and swallows a localParticipant.publishData() rejection

Either case lets create() resolve. Conversation.startSession() then fires onConnect and 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 existing catch already calls room.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 LiveKit Room so connect and mic setup succeed and only the initiation send fails:

Test Without this change
fails setup when the initiation payload cannot be published fails — create() resolves
fails setup when the room disconnects before the payload is sent fails — create() resolves
keeps mid-session sends best effort when publishing fails passes — guards against over-fixing

The first also asserts room.disconnect() ran, so a failed setup cannot leave the room and microphone live.

Full @elevenlabs/client suite: 182 passing (179 before). lint:es, lint:prettier and tsc --build clean. Changeset included per agents.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 and sendMessage.


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 mandatory conversation_initiation_client_data never reaches the server. That payload is sent through sendRequiredMessage() instead of best-effort sendMessage(), so a disconnected room or a failed publishData() rejects setup and flows through the existing catch that calls room.disconnect() and rethrows.

Ordinary mid-session data messages still use sendMessage() (warn/return or log and swallow errors). Publishing is factored into shared publishMessage() used by both paths.

Tests cover publish failure during setup (including disconnect), disconnect before send without calling publishData, and unchanged best-effort behavior after a successful create(). 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.

…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

Copy link
Copy Markdown
Member

Thanks a lot @chinmayv095 for the fix 👍

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.

[@elevenlabs/client][WebRTC] conversation-init publish failures are swallowed, allowing silent sessions

2 participants