Skip to content

Fix fast publication eligibility and response handling - #1300

Open
xianshijing-lk wants to merge 2 commits into
mainfrom
sxian/ordered-fast-publication
Open

xianshijing-lk wants to merge 2 commits into
mainfrom
sxian/ordered-fast-publication

Conversation

@xianshijing-lk

@xianshijing-lk xianshijing-lk commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Flutter already overlaps AddTrack registration and sender/SDP setup when server codecs are available, including in its default dual-PC mode. This follows up on livekit/rust-sdks#1704 by making the response lifecycle safe for that existing fast path: registration currently sends AddTrack before installing its per-call event listener, and rejection/disconnect can leave publication waiting for the full timeout.

Keep one CID-keyed response completer owned by the engine. Register it before sending AddTrack, resolve it on publication acceptance, fail it on request rejection or teardown, and remove it on every exit. Reject duplicate in-flight CIDs without replacing the original waiter. Clear cached publish codecs during cleanup so a later legacy connection cannot inherit the previous connection's fast-publication eligibility. Save advertised codecs regardless of fastPublish: that flag controls join-time publisher warm-up, while advertised codecs determine whether ordinary registration and SDP can overlap.

No public API or dependency changes. Codec-based eligibility is now independent of the publisher warm-up hint, matching JS and the revised Rust implementation. Fast and sequential publication retain their existing completion behavior. This main branch currently has no exposed single-PC connect option; this change works on its existing dual-PC transport and does not depend on adding SPC.

Validation with Flutter 3.44.9:

  • Nine focused tests passed: all four warm-up on/off × codecs present/absent combinations with withheld acknowledgment in audio publication, immediate response, rejection with same-CID retry, duplicate CID isolation, cleanup of pending registration/codecs, and disconnect/further-publication rejection.
  • Broader participant, room, leave, and disconnect/reconnect suites: 33 passed, one skipped.
  • Analysis of changed Dart files: no issues. Dart formatting, import sorting, and git diff --check passed.

Includes a patch changeset. Local initial-track/connect work is left untouched in its original checkout; this PR is based on current main and addresses ordinary track registration.

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

Note

Newer findings are available below. Devin Review posted a newer report on this PR, in addition to the findings presented here.

✅ Devin Review: No Issues Found

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

Devin Review

@xianshijing-lk xianshijing-lk changed the title Own response waiters throughout fast track publication Fix fast publication eligibility and response handling Nov 20, 2026

@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 found 1 new potential issue.

Devin Review

Comment thread lib/src/core/engine.dart
}

// Codec support permits overlap independently of the publisher warm-up hint.
_enabledPublishCodecs = event.response.enabledPublishCodecs;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Empty video codec during fallback

With subscriberPrimary=true and fastPublish=false, _enabledPublishCodecs activates broken video fallback for audio-first codec lists. Given Opus/VP8 and requested VP9, _publishVideoTrack converts Opus into an empty codec. AddTrackRequest then carries an empty primary video codec instead of VP8.

Learn more

Caching codecs for subscriber-primary connections without warm-up also enables the existing video codec fallback, not just overlapping negotiation. The fallback in _publishVideoTrack checks supported video codecs but selects the first entry from the unfiltered list. mimeTypeToVideoCodecString returns an empty string for audio/opus. That empty string becomes the primary SimulcastCodec and the track's codec rather than a supported video codec.

Example: Join with subscriberPrimary=true, fastPublish=false, and codecs [audio/opus, video/vp8]. Publish a camera track with VideoPublishOptions(videoCodec: 'vp9'). The fallback selects Opus and produces videoCodec: '', rather than selecting VP8.

Recommended fix: Filter the advertised codecs to supported video codecs before selecting a fallback in _publishVideoTrack. If no supported video codec remains, handle that case explicitly rather than converting an audio codec. Add a video publication regression test with warm-up disabled, an audio-first codec list, and an unavailable requested video codec.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

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.

2 participants