Skip to content

Expose subscriber-side remote track enable/disable in Python - #977

Open
zhao-xuan wants to merge 7 commits into
livekit:mainfrom
zhao-xuan:feat/remote-track-publication-enabled
Open

zhao-xuan wants to merge 7 commits into
livekit:mainfrom
zhao-xuan:feat/remote-track-publication-enabled

Conversation

@zhao-xuan

@zhao-xuan zhao-xuan commented Dec 3, 2026 •

Copy link
Copy Markdown

Closes #976.

Motivation

Real-time voice and language-learning agents need to pause incoming microphone media between speaking attempts while keeping the subscription intact. Unsubscribing and resubscribing can require negotiation and stream recreation, risking loss of initial speech. Discarding frames in an agent input gate does not stop downstream media transfer. Publisher mute is a separate user-controlled operation.

Changes

  • Expose the existing EnableRemoteTrackPublicationRequest via RemoteTrackPublication.set_enabled(enabled: bool).
  • Reject calls before subscription with a descriptive RuntimeError.
  • Expose publication.enabled as locally requested state, reset on a new subscription. This is not an SFU acknowledgment.
  • Document idempotency against native local state and asynchronous delivery semantics.
  • Add constructor-based unit tests, a server-backed audio RTP pause/resume and resubscription test, and a minor changeset.
  • Clear remote subscription state on room event stream EOS even when native shutdown omits the disconnected event, with a regression test.
# Once the track_subscribed event has arrived:
publication.set_enabled(False)
publication.set_enabled(True)

Native dependencies (not yet fixed in this PR)

Review revealed existing Rust issues. A Python subscription guard does not eliminate the native race. Before merging, the pinned Rust submodule needs fixes for:

  • Concurrent detach/unpublish panic: rust-sdks#1769. The current diff of rust-sdks#1738 removes the unsafe unwrap(); concurrent detach/settings synchronization still needs verification.
  • Out-of-order settings: rust-sdks#1653, proposed fix rust-sdks#1720.
  • Preserving quality and disabled state: rust-sdks#1738.

Validation

  • The initial Build RTC, Test API and Check Types checks passed. Changeset check passed after adding the changeset.
  • Updated unit and integration tests have been added; latest CI and server-backed execution remain to be verified.
  • Native race and simulcast/order regression testing still required.

The API does not remotely unmute the publisher or guarantee immediate media delivery. Repeated calls may not re-send the native setting when local state already matches.

@CLAassistant

CLAassistant commented Dec 3, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

devin-ai-integration[bot]

This comment was marked as resolved.

@xianshijing-lk

Copy link
Copy Markdown
Contributor

@cloudwebrtc , could you please review this PR ?

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

The FFI wiring looks correct: the field names and request oneof match track_publication.proto and the Rust handler. A few concerns about behavior around the new method, plus two test nits.

devin-ai-integration[bot]

This comment was marked as resolved.

Copy link
Copy Markdown
Author

@cloudwebrtc @xianshijing-lk Thanks for the review! The Python-side feedback has been addressed, including subscription validation, the locally observable enabled state, documentation, improved unit tests, an audio RTP integration test, the changeset, and the latest EOS cleanup fix.

The native findings are tracked upstream in livekit/rust-sdks#1720 and livekit/rust-sdks#1738 (with concurrent detach verification tracked in livekit/rust-sdks#1769). I've resolved the discussions as tracked upstream; these Rust fixes are not yet included in the pinned submodule, and native regression validation remains a prerequisite to merging.

Could you please take another look at the Python changes and advise on the preferred integration order for the Rust dependencies? Thank you!

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

Thanks for the thorough follow-up. I went through the new commits and the Python side looks good to me:

  • The subscription guard and the RuntimeError before any FFI request work as expected, and the test covers that no request is sent.
  • enabled as local requested state works well: it is reset on track_subscribed, it reads False when unsubscribed, and it is only updated after the request succeeds.
  • The EOS cleanup in 2fb5239 covers EOS, disconnected and CONN_DISCONNECTED, and the regression test exercises the missing-event case.
  • The tests now go through the real constructor, and the tautological assertion is gone.

Approving the Python changes. Please don't merge yet: the pinned Rust revision still has the native issues. The most important one is that a concurrent unpublish can panic and take down the whole Python process.

On the Rust dependencies, I'd suggest this order:

  1. Land rust-sdks#1720 (ordered/serialized settings updates) first, since #1738 overlaps with it.
  2. Rebase and land rust-sdks#1738 on top. It covers the quality/disabled merge and replaces the repeated lookup + unwrap.
  3. Confirm rust-sdks#1769 is covered by #1738's single-snapshot change, or close the remaining detach gap there.
  4. Cut a livekit-ffi release and bump the rust-sdks submodule in this PR.
  5. Run test_audio_track_enable_disable.py against a real server (it is skipped in CI without credentials) and post the result here.

Merge once the submodule bump is in and the e2e test passes.

This branch has not been deployed

No deployments
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.

Expose subscriber-side RemoteTrackPublication.set_enabled() for audio tracks

4 participants