Skip to content

[FEAT] Unify WebRTC streaming on LiveKit and remove aiortc - #19

Merged
lzx1413 merged 11 commits into
mainfrom
livekit
Jul 28, 2026
Merged

[FEAT] Unify WebRTC streaming on LiveKit and remove aiortc#19
lzx1413 merged 11 commits into
mainfrom
livekit

Conversation

@lzx1413

@lzx1413 lzx1413 commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR makes LiveKit the sole WebRTC transport for TeleFuser streaming.

It adds LiveKit-backed session APIs, admission scheduling, scoped tokens, room workers, native media bridging, reliable control/status messages, bounded telemetry, and browser reconnect handling for both ServerPushService and BidirectionalService.

It removes the legacy direct-aiortc implementation, SDP APIs, duplicate browser clients, and obsolete benchmark assets. It also adds a TeleFuser-owned LiveKit adapter that integrates with AIPerf without modifying or publishing code to the AIPerf repository.

Motivation

TeleFuser previously maintained two WebRTC paths with different session, control, media, and cache-lifecycle behavior. The direct-aiortc path lacked the room lifecycle, reconnection handling, admission control, and operational tooling needed by long-running interactive generation.

LiveKit provides a single transport with explicit ownership:

  • One LiveKit room maps to one model worker and one pipeline session.
  • Controller reconnects do not recreate or mutate pipeline caches.
  • Control and status use reliable tf.control and tf.status topics.
  • Bounded telemetry uses unreliable tf.metrics.
  • Media is transported as native LiveKit video/audio tracks.
  • Session admission, timeout, cleanup, and token issuance share one runtime.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Code refactoring
  • Documentation update
  • Benchmark update

Key Changes

  • Added the LiveKit runtime, session registry, admission scheduler, scoped token service, worker lifecycle, health APIs, and native video/audio bridging.
  • Unified telefuser stream-serve for ServerPushService and BidirectionalService.
  • Added /v1/stream/sessions creation, inspection, viewer-token, deletion, and health APIs.
  • Added the maintained livekit_bidirectional_demo.py browser controller with reconnect handling, TURN relay support, controls, status, and latency telemetry.
  • Preserved LingBot encode, DiT, and decode overlap while separating queue delay, pipeline residence, output cadence, control latency, and stage execution metrics.
  • Removed aiortc, direct SDP routes, the legacy WebRTC runtime, old browser clients, Streamlit streaming UI, and obsolete integration tests.
  • Added a source-loaded telefuser_livekit AIPerf adapter, pinned Git installation helper, LingBot-World v2 workload, benchmark contract, tests, and reproduction documentation.
  • Declared PyAV explicitly and moved the LiveKit SDKs into base dependencies.
  • Updated SageAttention loading to use the standalone sageattention package instead of tf-kernel.
  • Stabilized server CI by preventing subprocess log-pipe deadlocks and bypassing external proxies for loopback health checks.

Breaking Changes

  • telefuser stream-serve now requires LiveKit Cloud or a self-hosted LiveKit Server.
  • /v1/stream/webrtc/* and the direct SDP workflow have been removed.
  • Existing clients must create /v1/stream/sessions sessions and join the returned LiveKit room.
  • The aiortc dependency and legacy WebRTC demos are removed.
  • The maintained browser entrypoint is examples/stream_server/livekit_bidirectional_demo.py.
  • The current runtime supports exactly one in-process model worker. Additional workers require separate service processes.

Validation

Check Result
Ruff 0.9.4 check, format, imports Passed
Python 3.10 unit CI Passed
Python 3.11 unit CI 780 passed
Python 3.12 unit CI 778 passed, 2 CUDA-only skipped
Server CI 62 passed
LiveKit adapter tests 5 passed
MkDocs Python 3.12 build Passed
Changed-file pre-commit hooks Passed
git diff --check main..livekit Passed

Manual end-to-end validation used four H100 80 GB GPUs, local coturn TCP relay, LiveKit Server, LingBot-World v2, forced TURN transport, and the browser control demo.

The validated AIPerf replay completed successfully with 60 chunks and 957 generated frames. The LiveKit client received 947 frames, with 6.253 s first-frame latency, 9.397 client FPS, and 3.399 / 3.901 s mean / p99 chunk pipeline residence.

These measurements distinguish client delivery from target compute and do not claim a model-compute speedup.

Checklist

  • Coding standards and Ruff checks pass
  • Changed-file pre-commit hooks pass
  • Affected and CI unit tests pass
  • Server tests pass
  • New functionality has tests
  • Documentation and benchmark instructions are updated
  • Manual four-GPU end-to-end validation completed
  • Full unfiltered pytest tests/ executed
  • pre-commit run --all-files passes

Additional Notes

The local browser workflow uses development LiveKit credentials, loopback addresses, disabled TURN TLS, --allow-loopback-peers, and forced TCP TURN relay for VS Code Remote SSH. These settings must not be used in production.

AIPerf is installed from a pinned Git commit because the published 0.11.0 wheel does not contain the streaming runner. The LiveKit adapter remains TeleFuser-owned, is loaded from source through PYTHONPATH, and requires no changes to the AIPerf repository.

No CUDA or Triton kernels are added or modified. The end-to-end workflow was validated on SM90 H100 GPUs.

@lzx1413
lzx1413 requested a review from Kaimary July 27, 2026 11:03
lzx1413 added 8 commits July 28, 2026 05:45
Add LiveKit configuration, admission scheduling, token issuance, room workers, media bridging, and session lifecycle APIs. Route stream-serve through the LiveKit runtime while keeping the legacy transport available for the later removal commit.

Verification:
- .venv/bin/python -m pytest tests/unit/service/livekit --ignore=tests/unit/service/livekit/test_demo.py -q
- 42 passed
- git diff --cached --check
Use the standalone sageattention package as the only SageAttention backend source, avoiding the tf-kernel path that triggered CUDA misaligned-address failures.

Verification: PYTHONDONTWRITEBYTECODE=1 .venv/bin/python -m pytest tests/unit/ops/test_attention_backends.py tests/unit/service/livekit -q; ruff check and ruff format --check on the changed attention and LiveKit files; git diff --check.
Add the shared camera-control UI and LiveKit browser adapter with TURN relay configuration, reliable control messages, video playback, and streaming telemetry. Cover the rendered page and LingBot example defaults.

Verification:
- .venv/bin/python -m pytest tests/unit/service/livekit/test_demo.py tests/unit/pipelines/lingbot_world_fast/test_stream_example.py -q
- 7 passed
- git diff --cached --check
Keep actor-stage work asynchronous while reporting queue, pipeline, and applied-control latency separately. Preserve v2 camera intrinsics, rebalance translation controls, and make session stop and cache release behavior deterministic.

Verification:
- .venv/bin/python -m pytest tests/unit/pipelines/lingbot_world_fast/test_service_action_loop.py tests/unit/pipelines/lingbot_world_fast/test_service_metrics.py tests/unit/pipelines/lingbot_world_v2/test_service.py -q
- 52 passed
- git diff --cached --check
Make LiveKit the only stream transport, remove direct SDP and WebRTC API routes, delete the legacy aiortc session implementation and browser clients, and retain server-push support through the unified stream service contract.

Verification:
- .venv/bin/python -m pytest tests/unit/service -q
- 182 passed
- git diff --cached --check
Remove aiortc-specific LingBot stream benchmark contracts, configs, data, and helper scripts. Keep AIPerf documentation explicit that a validated LiveKit client adapter is required before streaming benchmarks are restored.

Verification:
- bash -n scripts/setup_aiperf_repo.sh
- no references to removed stream benchmark assets
- git diff --cached --check
Rewrite the English and Chinese stream guides around LiveKit sessions, data topics, deployment, and lifecycle. Add a root README quickstart that launches coturn, LiveKit, TeleFuser, and the browser controller with VS Code port forwarding, health checks, troubleshooting, and shutdown order.

Verification:
- .venv/bin/mkdocs build --strict --site-dir /tmp/telefuser-docs-livekit-rewrite
- no aiortc, old SDP route, or legacy Demo references remain
- git diff --cached --check
Add PyAV as a direct base dependency because the LiveKit media bridge imports it after aiortc is removed. Stop CI from requesting the deleted webrtc extra and install the standard development dependency set instead.

Verification:
- .venv/bin/python -m pip install --dry-run -e .[dev]
- .venv/bin/python -m pytest tests/unit/service/livekit/test_app.py tests/unit/service/livekit/test_media_bridge.py tests/unit/service/livekit/test_runtime.py tests/unit/service/livekit/test_worker.py -q
- 16 passed
- GitHub Actions workflow YAML parsed successfully
- git diff --cached --check
@lzx1413 lzx1413 mentioned this pull request Jul 28, 2026
27 tasks
lzx1413 added 3 commits July 28, 2026 10:11
- add the TeleFuser-owned LiveKit adapter, pinned GitHub AIPerf installer, LingBot-World v2 one-minute workload, contracts, launchers, and focused adapter tests
- preserve encode, DiT, and decode overlap with bounded directional prefetch and complete latent-chunk duration resolution
- consolidate the user workflow and validated results in the benchmark README and localized docs while removing the retained AIPerf checkout flow

Verification:
- .venv/bin/python -m pytest tests/unit/pipelines/lingbot_world_fast/test_service_action_loop.py tests/unit/pipelines/lingbot_world_fast/test_streaming.py tests/unit/pipelines/lingbot_world_v2/test_service.py
- env PYTHONPATH=benchmarks/telefuser_aiperf .venv-aiperf/bin/python -m pytest benchmarks/telefuser_aiperf/tests/test_livekit_adapter.py
- ruff check benchmarks/telefuser_aiperf/telefuser_aiperf benchmarks/telefuser_aiperf/tests telefuser/pipelines/lingbot_world_fast/service.py tests/unit/pipelines/lingbot_world_fast/test_service_action_loop.py tests/unit/pipelines/lingbot_world_fast/test_streaming.py tests/unit/pipelines/lingbot_world_v2/test_service.py
- ruff format --check benchmarks/telefuser_aiperf/telefuser_aiperf benchmarks/telefuser_aiperf/tests telefuser/pipelines/lingbot_world_fast/service.py tests/unit/pipelines/lingbot_world_fast/test_service_action_loop.py tests/unit/pipelines/lingbot_world_fast/test_streaming.py tests/unit/pipelines/lingbot_world_v2/test_service.py
- bash -n scripts/setup_aiperf.sh benchmarks/telefuser_aiperf/scripts/run_stream_bench.sh
- .venv/bin/python -m mkdocs build --strict
- git diff --cached --check
Write fake-server output to a temporary log file so verbose startup logs cannot fill an unread subprocess pipe. Bypass environment proxies for the loopback readiness probe while retaining startup logs for failed fixtures.

Verification:
- Ruff 0.9.4 check, format check, and import check
- Python 3.10, 3.11, and 3.12 unit CI jobs
- Python 3.11 server CI job: 62 passed
- Python 3.12 MkDocs build
- pre-commit run --files tests/server/conftest.py
@lzx1413
lzx1413 requested review from ActivePeter and removed request for Kaimary July 28, 2026 11:22
@lzx1413
lzx1413 merged commit 23fd5ee into main Jul 28, 2026
5 checks passed
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.

1 participant