Repository navigation
CI proof: the subscriber does not enter an ice restart on a resume - #2
Merged
Merged
Conversation
avosa
force-pushed
the
fix/subscriber-ice-restart
branch
from
October 14, 2026 05:51
8e48cb8 to
e3e12b2
Compare
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
* Refresh subscribed codecs after publisher answer (Android) Android publishers keep dynacast-paused simulcast layers paused across publisher renegotiations (publish/unpublish, codec change, ICE restart), instead of silently uploading them until the next subscribed-quality change. * Update license header year on the two mock files * Serialize simulcast layer updates on the RTC thread setPublishingLayersForSender reads and writes RtpSender.parameters, and is now reached from two separate coroutine scopes over the same multi-threaded dispatcher, so the read-modify-write can interleave. Wrapping the shared call rather than either call site keeps the dynacast path and the publisher-answer refresh on one thread. * Note the server-side resend in the refresh KDoc livekit/livekit#4907 (server v1.13.8 and later) restates the subscribed qualities a few seconds after every publisher answer, so the old claim that the server only sends an update when the set changes no longer holds for newer servers. The client-side refresh still closes that window and covers older servers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Note the server-side resend in the changeset Servers from v1.13.8 restate the dynacast pause a few seconds after a publisher answer (livekit/livekit#4907), so the layers only stayed on indefinitely with older servers. Scope the release note accordingly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Max Heimbrock <43608204+MaxHeimbrock@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
150.7871.04 drops the AAA Certificate Services root from libwebrtc's compiled-in TURN/TLS trust anchors (rtc_base/ssl_roots.h), so certificates issued by the compromised eMudhra intermediates that are cross-signed by it are rejected. Claude-Session: https://claude.ai/code/session_01BsJ5Refi6x7GqXMqH4gJ4i Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
* update protocol to latest * Add changeset for protocol update
* feat: add temporary maven local
* chore(protocol): bump submodule to v1.50.4-4 for data streams v2 fields
Data streams v2 needs three things that landed upstream in protocol #1621
(first tagged v1.46.8); this SDK was pinned at v1.45.8-29:
- ClientInfo.Capability.CAP_COMPRESSION_DEFLATE_RAW = 2 (advertise)
- ParticipantInfo.capabilities = 21 (read remote caps)
- DataStream.Header.inline_content / compression (v2 wire fields)
Pinned to 28e604c, the same commit client-sdk-swift@data-streams-v2 and
rust-sdks use, so all three SDKs agree on the wire contract.
Two unrelated breaks from crossing five minor protocol versions, both fixed
here so the bump lands green:
- SignalClient's messageCase `when` gained STORE_DATA_BLOB_RESPONSE and
GET_DATA_BLOB_RESPONSE; stubbed as TODO like their neighbours.
- RoomAgentDispatch gained an `attributes` map, which ProtoConverterTest
requires the Kotlin DTO to mirror. Added as a nullable field with a
default, so it is source- and serialization-compatible.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* build: consume livekit-uniffi and make it loadable from unit tests
Adds the livekit-uniffi dependency to the SDK and everything needed to exercise
it from a host JVM test run. No SDK behavior changes yet.
The artifact is unreleased, so it resolves from mavenLocal() (already enabled on
this branch). Build it with `cargo make android-package-local` in rust-sdks, or
for a JVM-test-only workflow just generate the Kotlin bindings plus a host
cdylib -- no NDK required, and it avoids three Android target dirs' worth of
disk.
Three obstacles found and handled along the way:
- Nobody had ever generated Kotlin bindings for the data stream FFI
(`packages/kotlin/` did not exist in rust-sdks), and doing so surfaces two
uniffi codegen bugs that stop the generated file compiling at all:
a Rust method named `close` collides with the AutoCloseable `close()` uniffi
synthesizes, and an error variant field named `message` collides with
Throwable.message. scripts/patch-uniffi-kotlin.py patches the generated
output -- a build artifact, so rust-sdks source is untouched -- following the
precedent of the existing swift-workarounds task. Both still need a real
upstream fix.
- livekit-uniffi's AAR declares minSdk 24 against this SDK's 21. The native
library is built for platform 21, so the declaration is the only conflict;
overridden via tools:overrideLibrary in both manifests.
- The AAR depends on jna's *aar*, which carries only Android dispatch
libraries, so host JVM tests died in JNA before ever reaching our code. The
plain jna jar is added as a test dependency for its desktop libjnidispatch.
gradle/uniffi-native-lib.gradle points JNA at a host build of the library,
auto-discovering a sibling rust-sdks checkout and overridable via
LIVEKIT_UNIFFI_LIB_DIR. UniffiNativeLibraryTest asserts the library loads and
its checksums match the bindings, so a broken setup fails once with a clear
message instead of once per data stream test.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* feat(datastream): read peer client capabilities
Adds the types and read path for per-peer feature negotiation, which the data
streams v2 send path needs in order to decide whether a given recipient can
accept an inline or compressed stream.
- ClientCapability: public enum mirroring ClientInfo.Capability. fromProto
returns null for unrecognized values instead of throwing, unlike most
fromProto helpers here -- capabilities are an open set, so a peer on a newer
SDK must be tolerated, not fatal.
- ClientProtocolVersion.DATA_STREAM_V2 (2), documented as a baseline
commitment rather than an optional feature.
- Participant.capabilities, populated from ParticipantInfo.capabilities
alongside the existing clientProtocol.
Purely additive, and deliberately read-only for now: this SDK does not yet
advertise v2 or any capability. Advertising has to wait until the receive path
can actually handle inline and compressed streams, otherwise peers would
start sending framings the current Kotlin implementation cannot parse. That
flip lands with the cutover.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* feat(datastream): add the DataStreams FFI coordinator
Introduces the single place that touches livekit-uniffi. Not wired into anything
yet -- nothing injects it, so this commit changes no behavior.
DataStreams owns both FFI managers, the topic to handler registry, the FFI
delegates and the error mapping, so that everything above it keeps dealing only
in this SDK's own types.
Notable choices:
- The outgoing manager is built eagerly; the incoming one lazily on the first
inbound packet. Its payload cap comes from RoomOptions, which is not final
until connect() -- after this class is constructed -- so reading it eagerly
would silently ignore a maxPayloadSize passed to connect().
- Outbound packets go through an unbounded channel drained by one coroutine.
The FFI delegate is a synchronous callback on a Rust runtime thread and can
neither block nor suspend, but sending has to await publisher connection and
data channel backpressure. This keeps emission order and restores the
backpressure the previous implementation had.
- Stream handlers are dispatched onto our own scope rather than run inline on
the FFI thread, so an app handler that blocks cannot stall the core's runtime
and with it every other incoming stream.
- Delegates hold their owner strongly, unlike Swift. The JVM collects cycles,
so Swift's weak back-reference buys nothing here. What does matter is close()
running: the FFI's handle map holds the delegates from a static root, so
DataStreams registers with CloseableManager to release the native handles.
- Room state the send path needs (remote identities, protocols, capabilities,
the payload cap) arrives as assignable lambdas rather than by injecting Room,
which would be a Dagger cycle. Same pattern Room already uses for the RPC
managers.
Also adds the additive options this needs: `compress` on both stream option
classes and RoomOptions.dataStreamOptions.maxPayloadSize, all defaulted to
previous behavior.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* feat(datastream)!: back data streams with the Rust core
Cuts the data stream implementation over to livekit-uniffi. The hand-written
packet building and stream reassembly are gone; the managers are now thin
adapters over DataStreams.
The public API is unchanged. IncomingDataStreamManager and
OutgoingDataStreamManager keep their interfaces, so Room's and LocalParticipant's
delegation is untouched, and TextStreamSender / ByteStreamSender /
TextStreamReceiver / ByteStreamReceiver keep working by reusing their existing
seams: an FFI-backed StreamDestination, and a Channel pumped from an FFI reader.
The interface's handleStreamHeader/handleDataChunk/handleStreamTrailer remain as
shims that rebuild a packet, though Room now forwards whole packets instead --
v2 headers carry inline content and compression that only the core reads.
Behavior changes fall out of the implementation moving into a Rust actor, and
existing tests were updated to match rather than papered over:
- Sending and receiving are now asynchronous. A completed write means the core
accepted the payload, not that it reached the wire, and an incoming stream is
delivered after a round trip through the core. Tests that asserted
synchronously now await the outcome.
- Send failures no longer reach the caller: the core acknowledges a send when
it hands the packets over.
- StreamException.EncryptionTypeMismatch is unreachable; the core normalizes
encryption type at the boundary.
Three problems this shook out, all now handled:
- Everything on the FFI boundary runs on a real dispatcher, never the caller's.
The core resumes calls from its own runtime threads, which a virtual-time
test dispatcher can never deliver; worse, an unconfined dispatcher resumed
our coroutines *inline on a core runtime thread*, where waiting on data
channel backpressure deadlocked the runtime and stopped every stream.
- MockDataChannel's buffers became copy-on-write; sends now genuinely arrive
from several threads and assertions iterate the list concurrently.
- Test classes each get their own JVM. The core is process-global state loaded
via JNA, and Robolectric's per-class classloaders re-initializing the
bindings left callbacks pointing nowhere -- whole classes would time out
depending on execution order. Costs ~90s on this module; see the comment in
livekit-android-test/build.gradle.
All 326 tests pass, verified stable over repeated cold runs.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* feat(datastream): advertise data streams v2, and cover the FFI glue with tests
Completes the cutover by telling peers what we can now do, and adds the tests
for the parts of it that only fail in interop.
Advertisement, deferred until the receive path could handle what it invites:
- ConnectOptions.clientProtocol now defaults to DATA_STREAM_V2.
- The connect URL carries a `capabilities` param, and ClientInfo the matching
repeated field, both sourced from one ADVERTISED_CLIENT_CAPABILITIES list.
Compression is advertised unconditionally, since it is done by the core
rather than a platform codec.
Tests (54 new, 380 total, all passing):
- DataStreamsV2SendTest walks the framing matrix from the spec's "Minimum
required test cases" -- pre-v2 room, all-v2 room, v2-without-the-capability,
mixed room, targeted subsets, compress opt-out, incremental writers -- and
asserts on the packets that reach the engine. These are really tests of our
registry wiring: the core picks the framing from what we report about each
recipient, so getting that wrong produces packets a peer cannot read while
everything still looks fine locally.
- DataStreamsV2ReceiveTest covers the framings only v2 produces (inline,
inline compressed, a deflate stream spread across chunks), plus topic
routing, sender identity, abort-on-disconnect, the payload cap, and a
multi-byte text round trip through the byte channel the public reader uses.
- DataStreamsConversionTest pins the translation layer, in particular the
error mapping, which is lossy by design -- several core failures fold onto
one pre-existing public exception, and a wrong fold is invisible.
- ConnectionParamsTest asserts the advertisement on the actual connect URL.
The Swift SDK shipped this wiring broken on one of its two connect paths, so
it is asserted on the wire rather than on the values feeding it.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* style: apply spotless, and drain stragglers before RPC test tear-down
spotlessCheck is a CI gate; this is its output plus one flake fix.
awaitJob waited only for the RPC itself, but a completed call can still have
siblings finishing behind it -- closing the request stream, emitting a
disconnect event -- whose continuations are posted back to the test dispatcher
from the core's threads. Occasionally one landed after the test body returned
and surfaced as "unfinished coroutines found during the tear-down". Pump briefly
after the job completes so they run inside the test.
Verified over four consecutive cold runs of the full suite.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* feat(datastream): make the core's errors one to one with StreamException
Every failure the core can report is now distinguishable, rather than several
folding onto the nearest pre-existing case.
New exceptions:
- HeaderTooLargeException, PayloadTooLargeException. Both are subclasses of
LengthExceededException rather than siblings, so existing code catching that
keeps catching every size-limit failure while new code can tell them apart.
Neither failure mode existed before v2 (there was no header budget and no
payload cap), so nothing was relying on the old folding.
- InternalException, which previously arrived as a TerminatedException.
TerminatedException gains a `reason`, defaulted and @jvmoverloads'd so
single-argument construction is unchanged. It separates the five remaining cases
that share the type -- already closed, invalid header, missed chunk, send
failed, invalid file name -- plus IO.
Io no longer maps to AbnormalEndException. A local file read failing is not the
remote closing the stream on us, which is what that exception documents; it is
now TerminatedException with reason IO.
The one caveat: StreamException is sealed, so an exhaustive `when` over it in
consumer code will need a branch for InternalException. Catch-based handling,
which is how exceptions are used here, is unaffected.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* revert: drop the unrelated RoomAgentDispatch.attributes addition
Surfacing that field was fallout from the protocol bump, not part of data
streams, and it does not belong in this change.
ProtoConverterTest requires every proto field to be mirrored on the Kotlin DTO,
which is why it was added. Whitelisted instead, alongside the fields already
listed there, so the test states plainly that it is not surfaced yet.
Worth knowing: the SDK therefore cannot set agent dispatch attributes, which the
server now accepts. That is a real gap, just an unrelated one -- if it is wanted,
it should be its own change.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* test(datastream): verify on a real device, and fix a 16 KB page-size blocker
Adds instrumented tests and, in running them, found that the SDK could not have
worked on a 16 KB page-size device at all.
livekit-uniffi's AAR pins jna 5.16.0, whose libjnidispatch.so fails to load
there:
E linker: ".../libjnidispatch.so" program alignment (8192) cannot be smaller
than system page size (16384)
which surfaces as an inscrutable `NoClassDefFoundError: com.sun.jna.Native` --
JNA's classpath fallback masking the real dlopen failure. Our own
liblivekit_uniffi.so is fine (NDK r27 aligns to 16 KB by default), and so is
WebRTC's; JNA's prebuilt library is the only one that fails. Verified by loading
all three directly: only jnidispatch failed, and jna 5.19.1 loads.
The SDK now overrides the transitive pin. This matters beyond the emulator:
Android requires apps targeting API 35+ to support 16 KB page sizes, and such
devices ship today, so every data stream would have died on the first FFI call.
The real fix belongs in livekit-uniffi's own build.
DataStreamsOnDeviceTest (10 tests, passing on an API 37 arm64 emulator) covers
what the host JVM tests cannot:
- the AAR's .so loading on Android, through JNA, from packaged jniLibs;
- the bindings' Android cleaner path, chosen at API 34+, which uses
android.system.SystemCleaner. Under Robolectric that throws
IllegalAccessError and needs a JVM flag, so this is the only place it runs as
written;
- the v2 framings produced on-device matching the host build's, including a
send-to-receive loopback through the core that reconstructs a compressed
inline payload;
- this SDK's conversions and error mapping in an Android runtime.
No mocking framework: androidTest has no Mockito here, so these drive the FFI
directly with a capturing delegate, the same seam client-sdk-swift's tests use.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* build: fix the uniffi name collisions upstream, drop the patch script
Replaces scripts/patch-uniffi-kotlin.py, which rewrote the generated bindings
after the fact, with fixes in livekit-uniffi itself. The bindings now compile as
generated, so there is no post-processing step to remember or keep working.
The two collisions needed different mechanisms:
- `close` is fixed by [bindings.kotlin.rename] in livekit-uniffi's uniffi.toml,
which is per-language exactly as wanted: Kotlin sees `closeStream()` while
Swift, Python and Node keep `close()`. Only this SDK's two call sites change.
- `message` could not be. UniFFI keys its rename table by crate name but looks
up enum and record *members* by the item's full module path, so a rename for
anything declared in a submodule is accepted and silently ignored -- which is
also why the method rename works, since methods key off the crate name. That
looks like an upstream bug and is worth reporting. There is no field-level
`#[uniffi(name)]` attribute in 0.31 either (uniffi_macros takes field names
straight from the Rust identifier), so the field is renamed to `reason` in
Rust. That is global rather than Kotlin-only, but it is a better name for an
error detail anyway, and Swift binds these positionally so its mapping is
unaffected.
Renaming the field changes the FFI metadata, so the AAR and all three Android
libraries were rebuilt; the checksum check between bindings and .so would fail
otherwise.
Verified: 380 unit tests and 10 instrumented tests on an API 37 emulator, both
against bindings generated with no manual edits.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* fix(sample): stop LeakCanary crashing sample-app on launch
Every debug launch of sample-app dies in Activity.onCreate:
java.lang.AbstractMethodError: abstract method "androidx.lifecycle.ViewModel
androidx.lifecycle.ViewModelProvider$Factory.create(kotlin.reflect.KClass,
androidx.lifecycle.viewmodel.CreationExtras)"
on receiver leakcanary.internal.ViewModelClearedWatcher$...
LeakCanary watches ViewModels by registering a ViewModelProvider.Factory, and it
is binary-incompatible with the lifecycle 2.8.0 this project resolves: 2.8.0's
KMP refactor made `create(KClass, CreationExtras)` part of the interface, and
LeakCanary implements only the older overload. Checked 2.14 as well as the
pinned 2.8.1 -- both crash -- so this is not a stale-version problem and there
is no version to bump to.
Removing the auto-install provider is LeakCanary's own documented way to turn it
off, and it is the smallest change that gets the app running. It is scoped to
sample-app's debug manifest, so nothing else is affected.
Pre-existing and unrelated to data streams -- the same dependency is on main --
but it blocks running the sample app at all, which is where the data streams
panel in the next commit lives.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* feat(sample): add a data streams panel to sample-app
Adds a developer panel for exercising data streams by hand, reached from a new
icon beside the RPC tester in the in-call controls. Conceptually the Android
counterpart of livekit-examples/rust-dev-client#18, and structured the same way
that PR describes: a send section and a subscriptions section.
Until now the sample could only send a fixed `lk.chat` text stream from an
AlertDialog and surfaced receipts as a Toast -- no topic, no destination, no
byte streams, and nowhere to watch what arrived.
Send: text or bytes, a topic, a destination (a remote participant or everyone),
and a content box with `hello world` and `20k random` presets. Bytes are the
UTF-8 of the same box. The result line reports the new stream's id, or the
error. The 20k preset is deliberately random rather than a repeated character:
random data does not compress, so it exercises the compressed multi-packet path
instead of collapsing into a single inline packet.
Subscribe: register a topic as text or bytes and watch it fill up. Each
subscription is a card with its own scrolling list of arrivals, newest first,
showing sender, size, time and a preview -- truncated for text, hex plus utf8
for bytes, and capped at 100 per topic.
State lives on CallViewModel next to the RPC tester's, so subscriptions keep
collecting while the panel is closed and are unregistered with the room in
onCleared. Subscriptions are keyed on (topic, kind) because text and byte
handlers are separate registries and the same topic can carry one of each. A
topic something else already owns -- `lk.chat`, or the RPC topics the Room
registers -- comes back as a failed Result and is shown, not thrown. Read
failures are recorded as the preview, so a PayloadTooLarge or an aborted sender
is visible rather than silent.
Verified against a local livekit-server with two emulators in one room: text
round-tripped, 20k random arrived as 19.5KB with the preview truncated, bytes
and text coexisted on one topic with the hex/utf8 preview correct, the
destination dropdown listed the peer, and subscribing to `lk.chat` was refused
without a crash.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* fix(datastream): log every stream on an unhandled topic
The unhandled-topic warning was deduplicated through a `warnedTopics` set, so a
topic only ever logged once. The set is keyed on the topic string off the wire,
which is entirely the sending peer's to choose, and nothing ever removed an
entry -- not a disconnect, not `abortAllStreams`. A peer opening streams on
unique topic names grew that set for the life of the process.
Drop the set and log per stream, which is also what web and swift do: web's
IncomingDataStreamManager logs "ignoring incoming byte/text stream due to no
handler for topic" on every stream it discards.
Addresses the review comments "Unbounded set keyed on remote-supplied stream
topics allows memory growth" and "Memory grows without bound when a peer sends
streams on many unhandled topics" -- one set, so one fix.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* fix(datastream): hold an incoming stream to the encryption it opened with
Whether a data packet arrived encrypted is decided in RTCEngine, which decrypts
the whole packet before anything downstream sees it, and hands the answer to its
listener. Room dropped that answer on the floor for stream packets, and
DataStreams stamped StreamInfo.encryptionType from the *local* room's e2ee
configuration instead. Two things followed. A stream that arrived in plaintext
was reported to the app as GCM whenever this end had encryption enabled -- the
one field an app can check to find out, answering with what it wanted to hear.
And a peer could open a stream encrypted and then continue it in plaintext, with
nothing comparing the two.
The pre-port implementation compared every chunk and trailer against the
encryption recorded on the stream's header and closed the reader with
EncryptionTypeMismatch when they disagreed, and web's IncomingDataStreamManager
still does exactly that. The core cannot: encryption is applied and undone
either side of the FFI, so it only ever sees plaintext and reports NONE on every
stream. So the check comes back here, where the value still exists.
Room now forwards the engine's encryption type alongside the packet, and
DataStreams records what each header arrived under, checks each subsequent chunk
and trailer against it, and stamps StreamInfo from the recorded value rather
than from the room's configuration. A mismatching packet is dropped rather than
fed to the core, and the reader is failed with EncryptionTypeMismatch.
Failing the reader is more than closing a channel, because the core opens a
stream on its own loop: a contradicting chunk can arrive before the reader
exists. A failure recorded first is replayed onto the channel when the reader
turns up, so it raises instead of waiting for chunks that will never be
forwarded -- a test covers exactly that ordering.
The table is keyed on stream ids off the wire, so it is an LRU capped at 1024
streams rather than something a peer can grow forever. Entries deliberately are
not dropped when a stream ends: a single packet stream has no trailer, and a
stream failed above may still be waiting for its reader.
Addresses the review comments "End-to-end encryption of incoming data streams is
no longer verified" and "Unencrypted data streams are accepted and reported as
encrypted when end-to-end encryption is on" -- the same lost value, so one fix.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* feat(datastream): adopt the new livekit-uniffi binding surface
Tracks livekit-uniffi at rust-sdks#1286 head:
- handlePacketReceived now takes the encryption type the packet arrived
under, which the core needs because decryption destroys the encrypted_packet
oneof member: it cannot be recovered from the bytes. The core holds every
stream to its header's encryption and rejects mismatched chunks/trailers.
- onPacketsAvailable is a suspend function: the core awaits it, making the
delegate the back-pressure point (adopted properly in a follow-up commit).
- onStreamClosed is a new required delegate method, wired as a documented
no-op until ordered per-topic delivery lands.
- EncryptionTypeMismatch now carries the expected/received types.
* refactor(datastream): drop the SDK-side encryption bookkeeping, now done by the core
The incomingStreams table existed because the core could not see how a packet
arrived: it held each stream to its header's encryption, failed contradicted
streams (including before their reader existed), and remembered the value for
stamping StreamInfo. All three are the core's job now that handlePacketReceived
carries the encryption type: it rejects mismatched chunks AND trailers in
packet order on its own loop, and stamps the reader's info with the header's
arrival encryption.
What stays is currentEncryptionType() for outgoing streams: payload encryption
happens in RTCEngine after the core, so the core stamps outgoing streams NONE
and the room's real value is applied here.
The encryption test suite is unchanged in substance and passes through the
core; only the region comment moved with the responsibility.
* feat(datastream): fail sends whose packets never reach the transport
The outgoing delegate used to hand packets to an unbounded channel and
acknowledge immediately: engine failures were logged into the void ("there is
nobody left to return this to"), is_open could not go false on a send failure,
and a producer looping on write() could queue without bound.
The delegate is now the back-pressure point, as the core intends: it is a
suspend callback the core awaits, dedicating a single task so packet order is
preserved without a queue on this side. Deliveries run confined to the FFI
dispatcher, and a failed handoff throws PacketDeliveryException — failing the
originating send*/write with SEND_FAILED and closing the affected stream.
The channel, its drain coroutine, and sendPacket() are deleted.
* fix(datastream): build a fresh incoming manager per session
The incoming manager's payload cap is fixed at its construction, and the room
options it comes from can change between connects of the same Room. Lazily
memoizing one manager for the Room's lifetime silently pinned the first
session's cap — exactly the hazard the core's constructor docs call out.
abortAllStreams() becomes endSession(): abort every open stream, then discard
the manager so the next inbound packet builds a fresh one against the current
options. No await is needed in between — the abort and the destroy's shutdown
land on the manager's input queue in call order, so blocked readers observe
the abort's error. Handler registrations live on DataStreams and survive.
* test(datastream): expose the core's open-stream count for deterministic waits
The core answers openStreamCount() on its own loop, in order with the packets
and aborts fed before it — so a test can feed a header and await the count it
implies (or an abort and await zero) instead of inferring progress from
handler side effects or polling. Exposed as a test-only accessor on
DataStreams; inline single-packet streams complete during header handling and
are never counted.
Also sorts an import the previous commit left unordered.
* fix(datastream): stop rebuilding the incoming manager after close
close() destroyed the incoming manager but recorded nothing, so a packet
arriving afterwards -- entirely possible, since packets come off a data
channel callback -- lazily built a fresh native manager through
incomingManager(). That manager could never deliver anything (the scope its
delegate runs handlers on is already cancelled) and nothing would ever destroy
it: a silent native leak per late packet burst, and a dropped packet with no
error.
A closed flag under incomingLock makes incomingManager() and handleIncoming
no-ops after close. Ending a session is deliberately different: there,
leaving the manager null so the next packet rebuilds it is the point.
* fix(datastream): fail readers with a stream error when closed mid-read
close() cancels the coroutine scope with readers possibly still open, and the
pump's generic catch turned that internal CancellationException into the
reader channel's failure cause. receiveAsFlow rethrows the cause, and a
CancellationException silently cancels the collecting coroutine — so an app
awaiting readAll() never returned and never hit its catch(StreamException)
blocks. The rest of the SDK guards this hazard with
rethrowIfCancellationSignal(); the pump missed it.
The pump now fails the reader with TerminatedException before letting its own
cancellation proceed, so code blocked on a stream when the room shuts down
observes an error instead of stopping dead.
* fix: rename maxPayloadSize to maxPayloadByteLength to match other sdks
* chore(build): build against the published livekit-uniffi and drop the local-build workarounds
Moves livekit-uniffi from the unreleased 0.0.1 build resolved from
mavenLocal() to the published 0.1.12, in step with main, and removes the
struts the local build needed:
- the mavenLocal() repository;
- the jna @aar override in the SDK's dependencies (the jna version entry
stays, now only for the desktop JNA on the host unit-test classpath);
- the tools:overrideLibrary minSdk overrides in the SDK and test manifests.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* ci: run the FFI unit tests against a prebuilt host livekit-uniffi
Unit tests call the Rust core through JNA, which needs a host build of it;
the livekit-uniffi AAR carries only Android .so files.
- ci/get_uniffi_tag.sh prints the rust-sdks tag matching the catalog's
livekit-uniffi version, and ci/fetch_uniffi_cdylib.sh downloads and
checksums that release's host cdylib. The workflow passes its directory to
the tests with -PlivekitUniffiLibDir, fetching in a step of its own so a
failing script fails the step instead of being swallowed by the echo.
- The library files are registered as test task inputs, hashed by content,
so rebuilding the core in place re-runs the suite rather than serving the
previous results FROM-CACHE.
- A blank LIVEKIT_UNIFFI_LIB_DIR/livekitUniffiLibDir is unset for precedence,
so a valid lower-priority source still wins, but fails configuration when
nothing else is selected rather than falling through to auto-discovery and
testing against whatever core is lying around.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(datastream): degrade gracefully when liblivekit_uniffi fails to load
UniffiNativeLibrary remembers whether the native library could be loaded,
and UniffiModule shares one instance between data streams and both data
track managers, so one failed load is enough for all of them. It catches
LinkageError rather than UnsatisfiedLinkError: only the thread that ran the
failed class initializer sees the latter, and every later caller gets
NoClassDefFoundError.
DataStreams built its outgoing manager at construction, loading the library
while the room was still being built. It now builds it on first use, as it
already did the incoming one. A send fails with a StreamException when the
library is unavailable or data streams are closed, and an inbound packet is
dropped.
Tests: NativeLibraryUnavailableTest covers the unavailable paths, and a send
after close is checked to fail with a StreamException. RpcV2MockE2ETest now
waits for the outgoing stream header before collecting, since the first send
of a test class also loads the native library and can outlast the quiet
period; callers asserting no stream was sent keep the quiet wait alone. Also
puts simulateIncomingRequestStream's doc back on its own function and drops
one left behind for a helper that no longer exists.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(datastream): release FFI reader and writer handles explicitly
Readers for streams on unhandled topics:
Dropping an incoming stream's FFI reader on the floor does not close the
stream. Releasing the reader is the core's only per-stream close path --
manager.rs yield_chunk() closes a stream once chunk_tx.send() fails -- and
the Rust SDK gets that from ownership. Android does not: uniffi's handle map
owns the Rust Arc until destroy() runs, so dropping the Kotlin reference
drops nothing.
The stream therefore stayed open and its chunks piled up in the reader's
unbounded channel with nobody reading them, until the payload cap (5GB by
default) finally ended it. The JVM cleaner is no rescue -- the Kotlin object
is a bare long, so the GC sees no pressure from what is held on the Rust
side. Only chunked streams were affected; an inline single-packet stream is
complete on arrival and never registers as open.
Reader and writer handles in general:
destroy() was called only on the two managers. Readers were dropped once
pump() drained them and writers once closeStream() had ended the stream,
leaving both to uniffi's Cleaner -- a native object tied to a JVM object
that is a bare long, so nothing the GC feels any urgency about.
For readers this is only hygiene: the core-side stream has already ended by
the time pump() finishes. For writers it is not. RawStream's Drop sends the
closing trailer for a stream that was never closed, but only if it finds a
Tokio runtime in TLS -- and no JVM thread has one, neither the cleaner
thread nor whichever thread calls destroy(). So on Android that safety net
never fires, and callers must close their senders (useStreamSender) rather
than let them fall out of scope. Noted on WriterDestination; unchanged from
v1, which had the same contract.
Writers are released on every path that sets open = false, after which
nothing calls the FFI again: write() is gated on isOpen and close() returns
early. Both paths run only once the core has marked the stream closed, so no
trailer is ever owed at that point -- close() sets is_closed before sending
the trailer, and write_chunk() sets it on a failed send.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(datastream): contain destroyed-handle races and map every FFI failure onto StreamException
endSession() and close() destroy the incoming manager, and uniffi throws
IllegalStateException on a call that starts after its handle is destroyed.
Packet handling, aborts and the destroy now all run under ffiLock, so a
caller that read the manager cannot call it once it is gone. Aborting a
departed participant's streams no longer builds a manager just to abort
nothing, and a failed abort while ending the session no longer abandons the
rest of Room's disconnect cleanup.
The outgoing calls are the half of the destroyed-handle race that locking
cannot close: the manager is read under ffiLock, but each call suspends, so
the lock cannot span it, and a close() landing in that window makes uniffi
answer with IllegalStateException. Three places let it out:
- onFfi caught only FfiDataStreamException, so it escaped streamText and
streamBytes, both documented @throws StreamException.
- WriterDestination.write likewise, and that is declared
@checkresult ... : Result<Unit> -- it threw out of a function whose whole
contract is not to. Releasing the writer on close widened this one: the
same race used to produce AlreadyClosed, which mapped correctly.
- pump's catch-all closed the receiver's channel with the raw exception,
against BaseStreamReceiver's documented "the flow fails with a
StreamException".
toStreamExceptionOrInternal() passes a StreamException through, converts an
FFI error exactly, and wraps anything else with the original as its cause.
Each site rethrows cancellation first, so widening the catch does not swallow
it. A member rather than top-level: another top-level function here trips
detekt's per-file TooManyFunctions, which the class suppression does not
cover.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* docs(datastream): document the threading contract on the stream handler typealiases
Both are public and are what an app's lambda is checked against, through
Room's delegation of IncomingDataStreamManager. Their signatures are
unchanged from v1, but the contract behind them is not: handlers used to run
inline on the core's callback path, effectively serialized, and now each is
launched on its own coroutine. Nothing said so.
No annotation covers this. androidx's @workerthread cannot target a
typealias, and nothing in androidx expresses "may be invoked concurrently"
at all, so the KDoc carries it.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* chore(deps): update livekit-uniffi to 0.2.0
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* chore(detekt): clear the remaining findings and regenerate the release baseline
Suppresses the two findings the FFI boundary forces; neither is fixable by
restructuring:
- InjectDispatcher on ffiDispatcher: the core resumes continuations from its own
runtime threads, so this has to be a real thread-backed dispatcher. An injected
test dispatcher never resumes; an unconfined one runs our backpressure waits on
core runtime threads and deadlocks it.
- SwallowedException in OutgoingDelegate: the catch converts into a uniffi
generated error whose only field is a string, so no cause can cross the FFI
boundary. The original is logged with its stack trace first.
Regenerates the release baseline, which picks up the Room constructor's new
parameters and toStreamException, and drops five entries for findings that
no longer fire -- three from the old Kotlin data stream implementation this
branch removed, two from signatures that have since changed.
detektRelease: 5 findings -> 0.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* chore(detekt): regenerate baseline
* Bump to 0.3.0
* downgrade to livekit-uniffi 0.2.2 since 0.3.0 binaries aren't available
* chore(deps): switch to livekit-ffi-android 0.13.2
livekit-uniffi has been merged into livekit-ffi, so the bindings now
ship as io.livekit:livekit-ffi-android. The data stream and data track
FFI surface is unchanged; the Kotlin package moves from
io.livekit.uniffi to io.livekit.ffi, the native library from
liblivekit_uniffi to liblivekit_ffi, and the rust-sdks release tags
from livekit-uniffi/v* to livekit-ffi/v*.
This also picks up livekit-data-stream 0.1.9, which sends a targeted
stream's chunk and trailer packets only to its destination identities
instead of to the whole room.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: davidliu <davidliu@deviange.net>
Participant.updateFromInfo parsed lk.agent.inputs / lk.agent.outputs as JSON for every participant without catching errors. A value that wasn't a JSON array threw out of the signal handling coroutine and crashed the app. Catch and log the parse failure, leaving the previous agent attributes in place. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…#1054) * fix: drop encrypted data packets with an undecodable payload RTCEngine.onMessage parsed the decrypted bytes of an encrypted data packet with EncryptedPacketPayload.parseFrom without catching errors. Invalid bytes threw InvalidProtocolBufferException out of the WebRTC DataChannel.Observer callback. Catch the parse error, log it, and drop the packet, as is already done when decryption fails. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore: update license header year Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: drop undecodable data packets and signal responses Guard the remaining unguarded protobuf parses on peer and server input: the outer DataPacket parse in RTCEngine.onMessage, reached by every data channel message, and the SignalResponse parse in SignalClient. Both now log and drop the message instead of throwing out of the WebRTC observer or OkHttp listener callback. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: davidliu <davidliu@deviange.net>
* Validate region URLs before failing over to them `isLKCloud()` is checked against the server URL the application supplied, to decide whether region discovery applies at all. The URLs that came back were then used as they arrived: `RegionInfo` holds whatever string the response carried, and `getNextBestRegionUrl()` hands it straight to the connect path. Those URLs are not just connected to, they are authenticated to -- `fetchRegionSettings` sends the participant token as a bearer header, and `Room` calls `connectionWarmer.fetch(regionUrl)` on one before a connection attempt even starts. An entry should stand on its own merits rather than inherit trust from the configured server URL, and it should not be able to move that exchange onto cleartext. Add `isTrustedRegionUrl`: the URL must parse, name a `.livekit.cloud` or `.livekit.run` host, and use `wss` or `https`. Apply it in `applyRegionSettings`, which both ingestion paths now go through -- the `/settings/regions` fetch and `setServerReportedRegions`, which takes the regions the server reports over signaling. Both were unvalidated before. Rejected entries are logged rather than dropped silently. Unlike `isLKCloud()`, this check has no testing override. The existing `regionUrlProviderTesting` flag exists so a mock server URL passes the cloud check; it must not also make the SDK accept an untrusted region, and no release build can clear the new check. The host match is case-insensitive, since `URI.getHost()` preserves the case the response used. Six tests: the predicate against encrypted cloud URLs, cleartext schemes, foreign hosts, suffix near-misses and malformed input, plus one test per ingestion path. Both ingestion tests fail without the filter. * changesets --------- Co-authored-by: davidliu <davidliu@deviange.net>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
The publish jobs run livekit-android-test:testRelease, which now needs the host livekit-ffi cdylib. Fetch it the same way android.yml does. Also bring release.yml in line with changesets.yml by disabling the configuration cache for the publish step. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* Expose participantIdentity on RoomEvent.DataReceived DataReceived carries a nullable RemoteParticipant, which is null whenever the sender is not in the room - data sent through the Server API, or by a participant that has already left. In that case the receiver had no way to tell who sent the data. The identity was discarded before the event was built: the engine passed only the inner UserPacket to onUserPacket, while the authoritative participantIdentity lives on the enclosing DataPacket. Forward it through the listener and report it on every DataReceived event. Port of livekit/client-sdk-js#2092. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * Keep the old DataReceived constructor signature and document the new field Addresses review feedback: - A Kotlin default argument emits the full-arity constructor plus a synthetic one, so the previous five-argument JVM signature would have disappeared and modules compiled against an earlier SDK would fail to link. Add an explicit five-argument secondary constructor. - AGENTS.md asks for a short example with a new public API, so show attributing data when `participant` is null. - Update the copyright year range that spotless requires. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com> Co-authored-by: davidliu <davidliu@deviange.net>
DefaultReconnectPolicy returned a fixed delay per retry count, so every client disconnected by the same event waited exactly 100ms, then 300ms, then 300ms, in lockstep. They retried as one herd, and because the schedule is identical they could stay synchronised across attempts rather than drifting apart. Scale each delay by a random factor in [0.5, 1.5) so clients spread further apart with every retry. A first retry configured as zero draws from a fixed 0-500ms window instead, since there is no base delay to scale; a zero at any later index still means retry immediately. Port of livekit/client-sdk-js#2124. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
…vekit#1044) * Avoid splitting a surrogate pair when truncating to a byte budget truncateBytes binary searches for the longest prefix fitting a byte budget, counting in UTF-16 code units. When the budget fell between the two halves of a surrogate pair it cut the pair in half, returning a string ending in an unpaired high surrogate. That encodes to UTF-8 as a replacement character, so an RPC error message or data payload trimmed at such a boundary reached the remote peer corrupted. Step the cut point back one code unit when it lands on a high surrogate. Port of livekit/client-sdk-js#2126. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * Update the copyright year range for spotless Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * Truncate outgoing RpcError message and data Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com> Co-authored-by: davidliu <davidliu@deviange.net>
…livekit#1064) * Add Transport interface and move RTCEngine peer connections behind it RTCEngine now holds a Transport instead of separate publisher and subscriber fields. DualPeerConnectionTransport implements it for the existing two peer connection setup and owns the decisions that depend on that arrangement: ICE candidate routing, answering server offers, which peer connections a resume waits on, and the sync state descriptions. Whether to negotiate the publisher on join stays a transport decision, with hasPublished kept in the engine across full reconnects. The interface also covers what a single peer connection needs, with DualPeerConnectionTransport keeping today's behavior: - applyServerAnswer takes the answer's mid_to_track_id, now passed through SignalClient.Listener.onServerAnswer. - trackIdForReceiver resolves a remote track's ID from that mapping; Room.onAddTrack prefers it over the stream ID when present. - handleMediaSectionsRequirement handles the MediaSectionsRequirement signal message, which SignalClient now forwards. Either gains isLeft/isRight with smart-cast contracts. * Close the publisher when the subscriber peer connection cannot be created Both peer connections are locals until the DualPeerConnectionTransport is assigned, so a failure creating the subscriber left the publisher with no owner: its native PeerConnection has no finalizer and closeResources could not reach it. * Pass detekt for the Transport types Transport and DualPeerConnectionTransport suppress TooManyFunctions, as DataStreams does. The baseline entries for the test-only peer connection getters now match their transport!! form.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proves this branch on our own runners rather than waiting on an upstream approval. The change is proposed at livekit#1018; this pull request exists for its checks and is never merged.