fix: ensure num_participants is accurate in webhook events (#4265)#4422
Open
MavenRain wants to merge 2 commits intolivekit:masterfrom
Open
fix: ensure num_participants is accurate in webhook events (#4265)#4422MavenRain wants to merge 2 commits intolivekit:masterfrom
MavenRain wants to merge 2 commits intolivekit:masterfrom
Conversation
…4265) Three fixes for stale/incorrect num_participants in webhook payloads: 1. Move participant map insertion before MarkDirty in join path so updateProto() counts the new participant. 2. Use fresh room.ToProto() for participant_joined webhook instead of a stale snapshot captured at session start. 3. Remove direct NumParticipants-- in leave path (inconsistent with updateProto's IsDependent check), force immediate proto update, and wait for completion before triggering onClose callbacks.
boks1971
reviewed
Apr 3, 2026
pkg/rtc/room.go
Outdated
| } | ||
| // Note: NumParticipants is NOT decremented directly here. | ||
| // Instead, updateProto() recalculates it from the participants map. | ||
| // This avoids stale counts in webhook events. |
pkg/rtc/room.go
Outdated
| } else { | ||
| r.protoProxy.MarkDirty(false) | ||
| // Mark dirty after adding participant so updateProto() counts them | ||
| r.protoProxy.MarkDirty(true) |
Contributor
There was a problem hiding this comment.
Setting it to false was by design. Room updates are batched. When set to true, for large rooms (live streaming kind of applications), the update rate could be quite high.
Maybe a separate method to get consistent view ican be invoked when sending webhook events.
Requesting @cnderrauber for more thoughts as he is thinking about this too.
pkg/rtc/room.go
Outdated
| // (e.g., in webhook callbacks triggered by p.Close()) reflect the | ||
| // correct participant count. | ||
| done := r.protoProxy.MarkDirty(true) | ||
| <-done |
Contributor
There was a problem hiding this comment.
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.
Three fixes for stale/incorrect num_participants in webhook payloads: