Skip to content

Support for large RPC messages using data streams#1013

Open
1egoman wants to merge 18 commits intomainfrom
rpc-with-data-streams
Open

Support for large RPC messages using data streams#1013
1egoman wants to merge 18 commits intomainfrom
rpc-with-data-streams

Conversation

@1egoman
Copy link
Copy Markdown
Contributor

@1egoman 1egoman commented Apr 13, 2026

This is port of the identically named client-sdk-js pull request livekit/client-sdk-js#1832, adding support for RPC protocol version 2, via feeding the spec to a LLM.

Warning

This pull request was LLM generated and has only been lightly reviewed by a human. The author has tested this and confirms it works in the happy path, but no other validation has been done.

A more thorough review of this needs to occur before it could be merged. The plan is to hand this off to a rust sdk maintainer to get it fully across the line.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 13, 2026

Changeset

The following package versions will be affected by this PR:

Package Bump
livekit patch
livekit-api patch
livekit-ffi patch

Comment on lines +238 to +253
// =========================================================================
// v2 -> v2 tests (both sides support data streams)
// =========================================================================

/// Spec #1: Caller happy path (short payload) — v2 data stream used.
#[tokio::test]
async fn test_v2_v2_caller_happy_path_short() {
let client = Arc::new(RpcClientManager::new());
let transport = Arc::new(
MockTransport::new()
.with_remote_protocol("dest", CLIENT_PROTOCOL_DATA_STREAM_RPC),
);

let handle = spawn_perform_rpc(
client.clone(),
transport.clone(),
Copy link
Copy Markdown
Contributor Author

@1egoman 1egoman Apr 13, 2026

Choose a reason for hiding this comment

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

Note to any reviewers: The tests here don't use the larger e2e test infrastructure in this repository purposely, because some test need to fully emulate the behavior of an old client (ie, doing things like always sending RpcRequest / RpcResponse even with a newer client_protocol, etc).

I am not sure if this is a good idea or not. Halfway through the process, the LLM basically said it couldn't generate the tests with the e2e infrastructure and proposed this as an alternative so I let it go for it.

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.

There's also been some divergence for the single peer connection tests; in a follow-up, we should ensure all the E2EE tests are using common testing utilities (and make sure they can support any configuration needed by the test), but I would say for now it's better to include the tests even if they use different infrastructure.

Comment thread livekit-api/src/signal_client/mod.rs Outdated
/// Override the client_protocol advertised during join. If `None`, falls back
/// to `CLIENT_PROTOCOL_DEFAULT` (0). The SDK's default constructor sets this
/// to `CLIENT_PROTOCOL_DATA_STREAM_RPC` (1) to advertise data-stream RPC support.
pub client_protocol: Option<i32>,
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.

Nit
why not just make it a i32 and default to 0 , rather than optional

Copy link
Copy Markdown
Contributor Author

@1egoman 1egoman Apr 24, 2026

Choose a reason for hiding this comment

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

Looking at this again, I don't really understand why this even has to be a struct member. I think it should match the js implementation and just be a constant called something like ADVERTISED_CLIENT_PROTOCOL. Updated to use this constant approach instead in 4e63807.

Comment thread livekit/src/room/rpc/client.rs Outdated
&data.payload,
effective_timeout,
)
.await
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.

question

do we need .map_err(|e| { for v2 ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think this is needed - send_v2_request's returned error type is RpcError, and perform_rpc (the function this is in) returns Result<String, RpcError>.

Comment thread livekit/src/room/rpc/client.rs
Comment thread livekit/src/room/rpc/mod.rs Outdated

// RPC protocol version constants (distinct from client_protocol; this is the
// version field on RpcRequest / v2 stream attributes).
pub(crate) const RPC_VERSION_V1: u32 = 1;
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.

nit, use bool ?

Copy link
Copy Markdown
Contributor Author

@1egoman 1egoman Apr 22, 2026

Choose a reason for hiding this comment

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

This should be able to able to be incremented beyond two values, so I think keeping it some kind of uint makes sense.

Comment thread livekit/src/room/rpc/mod.rs Outdated
Comment thread livekit/src/room/rpc/server.rs Outdated
Comment thread livekit/src/room/rpc/server.rs
Self { handlers: Mutex::new(HashMap::new()) }
}

pub fn register_method(
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.

suggestion: I have a WIP PR (#858) to allow RPC method registration prior to room connection. I haven't merged this yet since the FFI portion is incomplete and requires some larger architectural changes, but the core change in the livekit crate is finished and could potentially be integrated here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nice! There's enough conflicts on that linked pull request where I think it probably makes more sense to integrate these as part of inevitably fixing the merge conflicts when that pull request is rebased.

Comment on lines +238 to +253
// =========================================================================
// v2 -> v2 tests (both sides support data streams)
// =========================================================================

/// Spec #1: Caller happy path (short payload) — v2 data stream used.
#[tokio::test]
async fn test_v2_v2_caller_happy_path_short() {
let client = Arc::new(RpcClientManager::new());
let transport = Arc::new(
MockTransport::new()
.with_remote_protocol("dest", CLIENT_PROTOCOL_DATA_STREAM_RPC),
);

let handle = spawn_perform_rpc(
client.clone(),
transport.clone(),
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.

There's also been some divergence for the single peer connection tests; in a follow-up, we should ensure all the E2EE tests are using common testing utilities (and make sure they can support any configuration needed by the test), but I would say for now it's better to include the tests even if they use different infrastructure.

@reenboog
Copy link
Copy Markdown
Contributor

Postponing my review until 1832.

@1egoman 1egoman force-pushed the rpc-with-data-streams branch from d37f3ae to 3980b10 Compare April 24, 2026 19:55
1egoman added 2 commits April 24, 2026 16:05
It doesn't need to be drilled through as an option, it's fundamentally
tied to the broader code context it is part of.
@xianshijing-lk
Copy link
Copy Markdown
Contributor

I think the code in general looks clean and easy to follow for me. what is the plan of landing it ?

@1egoman
Copy link
Copy Markdown
Contributor Author

1egoman commented Apr 24, 2026

@reenboog FWIW, the plan was to merge this and livekit/client-sdk-js#1832 at the same time - I don't want to get into the situation where the web version gets merged and this one gets blocked for a while and then it's a web only feature. Also, holding off on merging the web one means we can make protocol updates to v2 which are non backwards compatible during the review, if required. So, feel free to take a look at this now.

@1egoman 1egoman marked this pull request as ready for review April 24, 2026 20:46
@1egoman 1egoman changed the title (WIP) Support for large RPC messages using data streams Support for large RPC messages using data streams Apr 24, 2026
@1egoman
Copy link
Copy Markdown
Contributor Author

1egoman commented Apr 27, 2026

In regards to all the ci failures - this looks to be a github problem, NOT a problem with this branch. See here for another example of this arduino/setup-protoc@a8b67ba40b37d35169e222f3bb352603327985b6 action being unable to be downloaded: #1049

I'll rerun these in a few hours and hopefully this is transient / that will fix it.

@xianshijing-lk xianshijing-lk removed the request for review from reenboog April 30, 2026 17:50
Copy link
Copy Markdown
Contributor

@xianshijing-lk xianshijing-lk left a comment

Choose a reason for hiding this comment

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

lgtm

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.

4 participants