Skip to content

Fix silent mic race between Room.connect audio publish and setMicrophoneEnabled - #988

Merged
MaxHeimbrock merged 2 commits into
mainfrom
max/fix-connect-audio-publish-race
Jul 31, 2026
Merged

Fix silent mic race between Room.connect audio publish and setMicrophoneEnabled#988
MaxHeimbrock merged 2 commits into
mainfrom
max/fix-connect-audio-publish-race

Conversation

@MaxHeimbrock

@MaxHeimbrock MaxHeimbrock commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Encountered when trying the android agent starter app. 50% of the time I had to mute and unmute again until the agent and transcription reacted to me talking.

Confirmed the fix in the agent starter app, but had to rebase onto 2.26.0 because TokenRequestOptions gained an agentDeployment parameter in released SDK 2.26.1 (#968). Data-class parameter additions change the constructor signature, so components 2.4.0 — compiled against 2.26.0 — crashes on any released SDK ≥ 2.26.1, including 2.27.0. Latest components + latest SDK is a broken pair for every user right now.

Background

When connecting with ConnectOptions.audio = true while the app enables the mic as soon as the room reports CONNECTED, both paths published the same default audio track. Room.connect's publish did not take the per-source publish lock, so the losing path's duplicate publish failed and its failure branch stopped the just-published track, leaving the publication unmuted but sending silence until the mic was toggled.

Changes

  • Route Room.connect's audio/video publishes through setMicrophoneEnabled/ setCameraEnabled so they serialize on the source publish lock, where "already published" unmutes instead of failing.
  • In setTrackEnabled, don't stop a track whose publish was rejected as a duplicate: it is live and owned by the concurrent publisher.
  • Log a warning in publishTrackImpl's previously silent duplicate branch.

…oneEnabled

When connecting with ConnectOptions.audio = true while the app enables the
mic as soon as the room reports CONNECTED, both paths published the same
default audio track. Room.connect's publish did not take the per-source
publish lock, so the losing path's duplicate publish failed and its failure
branch stopped the just-published track, leaving the publication unmuted
but sending silence until the mic was toggled.

- Route Room.connect's audio/video publishes through setMicrophoneEnabled/
  setCameraEnabled so they serialize on the source publish lock, where
  "already published" unmutes instead of failing.
- In setTrackEnabled, don't stop a track whose publish was rejected as a
  duplicate: it is live and owned by the concurrent publisher.
- Log a warning in publishTrackImpl's previously silent duplicate branch.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Jul 30, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 66b81b8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
client-sdk-android Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

Copy link
Copy Markdown
Contributor

Diffuse output:

OLD: diffuse-source-file
NEW: livekit-android-sdk-release.aar

 AAR      │ old      │ new      │ diff   
──────────┼──────────┼──────────┼────────
      jar │  2.7 MiB │  2.7 MiB │ -234 B 
 manifest │  1.5 KiB │  1.5 KiB │    0 B 
 lint-jar │ 12.7 KiB │ 12.7 KiB │    0 B 
    other │  1.9 KiB │  1.9 KiB │    0 B 
──────────┼──────────┼──────────┼────────
    total │  2.7 MiB │  2.7 MiB │ -234 B 

 JAR     │ old   │ new   │ diff       
─────────┼───────┼───────┼────────────
 classes │  1504 │  1504 │  0 (+0 -0) 
 methods │ 20221 │ 20222 │ +1 (+1 -0) 
  fields │  5166 │  5166 │  0 (+0 -0)
AAR
 size    │ diff   │ path          
─────────┼────────┼───────────────
 2.7 MiB │ -234 B │ ∆ classes.jar 
─────────┼────────┼───────────────
 2.7 MiB │ -234 B │ (total)
JAR
METHODS:

   old   │ new   │ diff       
  ───────┼───────┼────────────
   20221 │ 20222 │ +1 (+1 -0) 
  
  + io.livekit.android.room.participant.LocalParticipant isTrackPublished(Track) → boolean

@MaxHeimbrock
MaxHeimbrock marked this pull request as ready for review July 30, 2026 15:10

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

@davidliu davidliu 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.

LGTM!

@MaxHeimbrock
MaxHeimbrock merged commit 8047711 into main Jul 31, 2026
6 checks passed
@MaxHeimbrock
MaxHeimbrock deleted the max/fix-connect-audio-publish-race branch July 31, 2026 07:37
@davidliu davidliu mentioned this pull request Jul 31, 2026
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.

2 participants