Skip to content

Add method to query rtcStats on room#663

Open
lukasIO wants to merge 1 commit into
mainfrom
lukas/getRtcStats
Open

Add method to query rtcStats on room#663
lukasIO wants to merge 1 commit into
mainfrom
lukas/getRtcStats

Conversation

@lukasIO
Copy link
Copy Markdown
Contributor

@lukasIO lukasIO commented May 19, 2026

No description provided.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 19, 2026

⚠️ No Changeset found

Latest commit: 79d88d4

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

View 2 additional findings in Devin Review.

Open in Devin Review

Comment on lines +202 to +212
const res = FfiClient.instance.request<GetSessionStatsRequest>({
message: {
case: 'getSessionStats',
value: {
roomHandle: this.ffiHandle.handle,
},
},
});
const cb = await FfiClient.instance.waitFor<GetSessionStatsCallback>(
(ev: FfiEvent) =>
ev.message.case === 'getSessionStats' && ev.message.value.asyncId === res.requestAsyncId,
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.

🔴 Wrong async ID field name causes getRtcStats to hang forever

The getRtcStats method accesses res.requestAsyncId to match the callback event, but every other async FFI method in the codebase (simulateScenario at room.ts:387, connect at room.ts:293, disconnect at room.ts:356, and all methods in participant.ts) uses res.asyncId. The response object returned by FfiClient.instance.request() will have an asyncId field (matching the FFI response protobuf), not requestAsyncId. At runtime, res.requestAsyncId evaluates to undefined, so the predicate in waitFor never matches any incoming event. This causes the method to hang indefinitely until the room disconnects and the AbortSignal fires, at which point it rejects with an abort error instead of returning stats.

Additionally, the type parameter is GetSessionStatsRequest instead of a Response type (every other call site uses the corresponding *Response type, e.g., SimulateScenarioResponse, ConnectResponse).

Prompt for agents
In packages/livekit-rtc/src/room.ts, the getRtcStats method has two issues on lines 202 and 212:

1. Line 202: The type parameter for FfiClient.instance.request should be the response type (likely GetSessionStatsResponse), not GetSessionStatsRequest. Every other call site in room.ts and participant.ts uses the *Response type (e.g. SimulateScenarioResponse, ConnectResponse, DisconnectResponse).

2. Line 212: res.requestAsyncId should be res.asyncId. Every other async Ffi method in the codebase uses res.asyncId to correlate the callback. Using requestAsyncId results in undefined at runtime, causing the waitFor predicate to never match.

You will need to check if GetSessionStatsResponse is exported from @livekit/rtc-ffi-bindings and import it, then change the type parameter on request<> and change requestAsyncId to asyncId.
Open in Devin Review

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

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