Repository navigation
Keep a bounded audio roster for the call worker's level meters - #107
Conversation
|
No actionable comments were generated in the recent review. WalkthroughThe call worker now maintains subscribed remote audio tracks in a bounded, ordered roster. Level measurement reads up to 64 tracks from that roster, which is updated when audio subscriptions or room connections change. ChangesRemote audio measurement
Estimated code review effort: 3 (Moderate) | ~25 minutes Change: Refactor Sequence Diagram(s)sequenceDiagram
participant RoomEvents
participant Call
participant AudioRoster
participant measure_sound
RoomEvents->>Call: Deliver subscription or removal event
Call->>AudioRoster: Add or remove track entries
measure_sound->>AudioRoster: Request measured tracks
AudioRoster-->>measure_sound: Return first MAX_MEASURED_TRACKS entries
Possibly related PRs
Suggested reviewers: Merge Risk:
|
|
✅ Review posted on
The review is posted here. |
The level meter tick copied the SDK's whole participant map of every connection (`Room::remote_participants`) every 100 ms. The size of that map is the SFU's choice. The worker now keeps `mapping::AudioRoster`: the subscribed remote audio tracks of every connection, at most 128, in subscription order. The room events keep it (audio `TrackSubscribed` and `TrackUnsubscribed`, `ParticipantDisconnected`, `Disconnected`, a lost connection). The meters measure its first 64 tracks, and a waiting track moves up when a measured one goes. The playout keeps listing every track from the SDK map, so deafen still reaches each one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
b819f8f to
8a0cc42
Compare
|
There was a problem hiding this comment.
🤖 Automated review of 8a0cc42
Bot review number 1 of 30.
The change replaces the per-tick copy of the SDK participant map with an event-maintained, bounded AudioRoster in mapping.rs, and the session integration, ADR text and AGENTS.md rule are consistent with it. I traced the add/remove paths (TrackSubscribed, TrackUnsubscribed, ParticipantDisconnected, Disconnected, other_lost), the bounds (MAX_KEPT_AUDIO_TRACKS 128 kept, MAX_MEASURED_TRACKS 64 measured), the removal of remote_audio_by_participant/Slots::open_indexed (no remaining callers in the parts of the tree I could search), and that remote_audio() still serves the playout from the full map. I found no defect in the changed code: the roster stays bounded, removals are keyed by connection and identity so another SFU's tracks are not cleared, a refused track is documented as unmetered and still plays, and measure_sound no longer touches Room::remote_participants().
No issues found.
✅ Approved: no unresolved findings at [P3] MINOR (Defect) or above.
Model beam → deepseek-v4.1-flash · skill code-change-review · 5 files reviewed. Reply to an inline comment to discuss it.
#103 took call protocol tag 17 and version 13 for SetStats, so ScreenFrames moves to tag 18 and the wire version rises to 14. The unknown-tag test moves to 19, and the old-version test refuses 6 to 13. The ADR index lists ADR-0065, ADR-0066 and ADR-0067 in order. The protocol guidance keeps both entries and names tag 19 as the next one. ADR-0067 gives the new reason for the version. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#107 removed `Slots::open_indexed` with its last caller then, the level meters' track list. #103 added a new caller, the statistics probe in `session.rs`. Each compiled alone; together on `main` (5277241) the call worker does not compile. The method comes back as it was, and the mixed connections test also checks the indexed list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#107 removed `Slots::open_indexed` with its last caller then, the level meters' track list. #103 added a new caller, the statistics probe in `session.rs`. Each compiled alone; together on `main` (5277241) the call worker does not compile. The method comes back as it was, and the mixed connections test also checks the indexed list. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…R-0067, needs owner approval) (#105) * Add the Windows screen frame pipe format and the ScreenFrames message The call protocol gains screen_frame.rs: the bounded format of the pipe from the capture helper to the call worker (ADR-0067), built on the media-protocol frame headers, and ToWorker::ScreenFrames (tag 17) that names the pipe's read end inside the worker. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Add the Windows screen helper crate and its launch in the media broker persephone-screen-helper captures the one approved monitor with Windows.Graphics.Capture and writes bounded BGRA frames to a pipe. The broker starts it outside any AppContainer, in a Job with one process and a memory limit, with the call worker's mitigations (no Win32k lockdown), child processes blocked and only its two pipe handles inherited, and duplicates the frame pipe into the call worker. wgc.rs moves to the helper, gdi.rs to the containment gate; the worker reads the pipe and no longer captures. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Start the screen helper from the core and keep it with the share After the user's Yes and the layout re-read, the core starts the helper for the share through the broker, hands the frame pipe to the call worker (ScreenFrames, then SetScreen) and keeps the helper in the call task. The helper ends with the share, the worker's end of it, the call and the session; the core closes its control pipe, waits 2 s, terminates the Job and joins the waiter. A helper exit maps to the share state. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Ship the screen helper next to the Windows core and cap its memory The Windows release builds, signs, bundles and checks persephone-screen-helper.exe with the call worker, tools/dev.py builds it with the core, and the helper's Job caps memory at 512 MiB (85 MiB measured). The gate's screen probe compiles the helper's wgc.rs and monitor.rs and its own gdi.rs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Propose ADR-0067 and update the guidance for the screen helper ADR-0067 (proposed, needs owner approval) records the helper outside the call worker, what it gains and what it costs, including that the worker still has no Win32k lockdown. The share question no longer says that Windows draws no border. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Record the screen helper run and fix a Clippy finding in the worker tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Word ADR-0067's outcome as proposed and match its memory peak The record is proposed, so its outcome says "Proposed option", as ADR-0062 does. The peak memory is the 87 MiB that the evidence records. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Address the independent review of the Windows screen helper - A share start reserves both command slots (ScreenFrames and SetScreen) before the pipe goes into the worker, so a queue with one free slot fails only the share, and no pipe is left in the worker. - Pipe ends are never inheritable outside the media broker's process-start lock. A launch makes its child's ends inheritable under the lock and closes them before it releases it; the UI host start and a profile switch take the same lock. This also covers the call worker's own pipes. - The end of a call cancels and awaits a running pick (at most 2 s), stops and joins a helper that it started, and waits until no reaped helper is active (at most 5 s). The pick checks the cancel again before the launch, and its idle wait looks at the cancel. - A helper counts as active until its exit is seen, and a failed wait no longer spins the waiter thread. - A frame pipe that the worker closed (exit 13) is Unavailable, not Off. - The worker takes a frame pipe value only when GetNamedPipeInfo accepts it (not a socket) and it is none of its standard handles. - No helper starts when the core does not know its own path. - ADR-0067, the guidance files and the broker's comments say the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Keep the newest screen frame, stop helpers at once, and count launches The helper keeps the newest frame that its rate gate refuses and copies it when the gate opens. The worker's Windows backend paces pictures a little slower than the feed limiter and keeps the newest early picture, reading into two kept buffers without a new allocation. A pick holds a LaunchGuard from its last cancel check until its helper counts as active, so the end of the call waits for a launch under way. The handle's stop closes the helper control pipe at once through a HelperStop, also when the worker queue is full, and that exit is not reported as the helper's own end. The fake helper's control close is idempotent, the real-helper test compares the picture with the approved mode, the broker reads the peak memory from the Job only, and the ADR links and doc comments are fixed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Count launches and helpers in one counter, repeat a still screen, and check the stop before each write A launch and its helper now count in one counter, so a single read of it can never miss a launch that is handing its count to the helper. The worker's Windows backend counts its picture gap from the end of the callback, so the feed's limiter never sees a shorter gap, and hands the newest picture on again every second while the screen stays still, so a picture dropped before the track was published still goes. The helper looks at its control pipe again just before it writes each picture, so no new picture goes after it saw the stop. ADR-0067 states that pictures written before that can still reach the call. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Bound each frame item by one deadline, poll slower between items, and close every pool frame A helper that trickled an item a byte at a time could hold the worker's capture thread forever, because the stall time started again on each read. `PipeReader::begin_item` now gives the whole item one deadline, and the Windows backend calls it before each item. The wait between items looks at the pipe every 25 ms instead of 5 ms, and never past its own limit, so a still screen wakes the thread 40 times a second, not 200. Reads inside an item keep 5 ms. Every frame from the WGC pool is a `PoolFrame` that closes it on drop, so each buffer goes back on every path. The burst test checks properties, not one timing-dependent sequence, and ADR-0067 says that the burst path is designed and unit tested, not measured. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Record the remaining stop and launch windows in ADR-0067 - The stop text says that the helper's look at the control pipe and its write are not one step, and that the worker can still hand on a waiting, kept or repeated picture from before the stop until it handles its own stop or reads the end item. The worker's stop closes its frame admission first. - The negative consequences list both windows for the owner: pictures from before a stop, and a helper that a launch starts after both end waits. - "Not verified" names the live still-screen and burst cases. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * End an item's deadline at the next wait, and report only copied frames - `PipeReader::wait_for_data` clears the last item's deadline, so the next item never reads under an older one, and a read without `begin_item` has its own `STALL_TIMEOUT` as documented. New test. - `wgc::Capture::poll` returns true only when a picture was copied or the pool was made again, so the helper waits after a refused frame and polls again at once after a late copy of the kept one. - The worker's docs say why the still-screen repeat runs for the whole share, and that its cost and the encoder's own resend were not measured. - ADR-0067: the worker's stop is queued at once only with room in the queue; the border and cursor are intended, not looked at; and the frame admission sentence names how the feed drops late pictures. - crates/core/AGENTS.md: only Windows awaits a running pick at the end. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Raise the call protocol to version 13 for the screen frames main has version 12 (ADR-0064) without `ScreenFrames`, so this branch no longer keeps that number. With version 13, a core and a call worker built from different branches refuse each other at the first message, not when a share starts. The old-version test now refuses 6 to 12. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Fit the first screen item in the open timeout, lock test starts, and correct the helper records The Windows backend waits at most 6 s for the first item, so that wait and the item's 3 s deadline end 1 s before the 10 s open timeout; a const assertion keeps it so. Every Windows test start in the core takes the media broker's process-start lock through spawn_for_test, because the test binary also launches a real helper. The screen evidence names the review commits that its first helper run does not cover and records a second run after them. The helper guidance, the documentation index and the package lists now match the code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Lock the last Windows test start in the core, and correct four notes The pick.rs junction test starts mklink through spawn_for_test too, so every Windows test start of the core's library takes the process-start lock, and the broker guidance lists each place. The core guidance says the `s` byte is the Linux portal path only, and states the helper stop's two waits and its conditional join. ADR-0067 names the worker's whole pipe check, and the second helper run names its core files by repository path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * End the call worker before the screen helpers, bound the WGC pool size, and fix four test races The end of a call stopped and joined the screen helpers before it ended the call worker, so a helper that ignored its control pipe kept the microphone, the camera and the room open for seconds after the user left. finish now ends the worker first (Leave, or a kill after the session's end), then joins the helpers beside the membership end. The helper checks the capture limits before it makes or remakes a WGC frame pool, whose buffers have that size. Three worker tests wait for the picture they depend on, and the non-pipe test passes a handle it owns. The real-helper test keeps the frame pipe open until the helper stopped. The ADR and the evidence no longer claim more than was checked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Give the whole wait of a call's end for its screen helpers Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Hold picture 2 by its bytes, and give each test handle one owner The slow-callback test counted callbacks, so a repeat of picture 1 after a paused test thread could take picture 2's place as the slow one. The callback for picture 2 is now found by its bytes: it says when it starts, waits until the test has written picture 3, and then waits 80 ms more. The checks allow repeats of picture 1 before picture 2 and of picture 3 after it, and need picture 3 right after picture 2, at least the screen limit later. With the gap counted from the start of the callback, the test fails. The frame pipe tests gave one handle two owners. The handles now move into the reader or into `adopt`, and a refused handle comes back to the test, which checks that it is still open. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Wait for picture 2 by its bytes, and drain the real helper's pipe The good-items test waited for two pictures, so a repeat of picture 1 after a paused test thread could let the end item go before picture 2. It now waits for picture 2 itself, and its checks allow repeats. The real-helper test kept the read end open but stopped reading after the first item. A second picture (about 14 MiB) would hold the helper in its write, and the stop would end in a terminate. The reader now reads on until the helper's end of the pipe closes, and the test waits at most 10 s for it to end after the stop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Restore Slots::open_indexed for the statistics probe #107 removed `Slots::open_indexed` with its last caller then, the level meters' track list. #103 added a new caller, the statistics probe in `session.rs`. Each compiled alone; together on `main` (5277241) the call worker does not compile. The method comes back as it was, and the mixed connections test also checks the indexed list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Cancel a waiting pick on stop and call end, and own frame pipe values - The handle's accepted stop sets the waiting pick's cancel at once, and a pick that begins after an unread stop begins cancelled. - The call's end cancels a waiting pick before it waits for the worker. - The worker lists each frame pipe value it owns (FramePipe) and refuses a value it already owns, so a repeated ScreenFrames cannot alias it. - The real-helper test requires the Stopped end item and a clean close; the finish test requires Leave; the burst test allows repeats. - ADR-0067 states tag 18 and why the version rises to 14. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Clear the pick's cancel slot when the pick ends, and bound the helper test - screen_picked and stopped_pick_ended clear ScreenControl::pick_cancel under the lock they already take, so the slot names only a pick that waits and a later stop finds none. - The real-helper test names a leaked write end when the frame pipe does not close after the helper's exit. - Its memory bound grows with the picture (64 MiB and four pictures) instead of the Job's cap, which the kernel enforces anyway. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Run the helper tests one at a time The tests that start fake helpers or launches share the process's one helper count. A hanging helper of one test held it for seconds while another waited for no helper to be active, so given_a_helper_that_obeys_when_stopped_then_it_is_joined_without_a_terminate failed once on Linux. Each such test now holds HELPER_TESTS (a tokio mutex, so the async tests hold it across their awaits). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * End a call without capture without waiting for the helper count A call's end waited until no helper was active in the process, also when the call never began a pick or held a helper. Such a call has no helper of its own that could still be active, and an earlier call's end waited for its own, so it now skips that wait (screen_capture_used). Tests that end a call without capture no longer wait behind another test's hanging helper; the two pick tests that end their call take HELPER_TESTS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Cancel a waiting pick at the session end, and keep its helper wait - stop_for_session_end sets the waiting pick's cancel under the screen control lock before Ended shows, so a Yes given after the session ended starts no helper while the call task finishes its current step. - The end of the session always waits for the process's helper count; only a call that the user leaves without a pick or a helper skips it. - The ADR, the guidance and the HELPER_TESTS comment say which ends read the count; the other-SFU session-end test takes HELPER_TESTS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Count the session end as a screen stop, and say when it waits The end of the session cancelled a waiting pick but did not count a stop. A cancelled pick that ended before the call task read the end saw no stop, and stopped_pick_ended could begin a new pick after the session had ended. stop_for_session_end now calls stop_accepted, as the handle's stop does: the stop counts, the pick is cancelled, and the share's session closes, all before Ended shows. The record and the docs said the end of the session always waits for the helper count. Only a call that the session end stops waits (finish(true)); a session that ends with no call running does not, and must not block. The ADR, the core guidance and the code docs now say so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Test the end wait with a held guard, not an elapsed time The call-end test released a launch guard on a thread after 300 ms and asserted that the end took at least 250 ms. A descheduled test task could see a correct end finish sooner and fail. The test now holds the guard itself, checks that the end is still pending, then drops the guard and awaits the end. The end's wait runs on a blocking thread, so its future stays pending while the guard is held. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Say which helpers the end joins, and that a left helper stays active The call's end joins the share's helper and a helper that the pick returns within PICK_END_WAIT. A pick that outlives that wait is not joined: it drops its helper to a reaper, which only the count wait covers. ADR-0067, the core guidance and the end_screen_helpers doc said every helper was stopped and joined. A session that ends with no call running does not wait. A helper that an earlier call left stays active until its reaper's stop ends it, or until the core exits and the Job's kill-on-close ends it. The text said it was handled. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Say that an earlier helper may outlive a skipped wait, and bound the next share The text justified a call's skipped helper wait by saying the earlier call's end had waited for its helper. That wait is bounded and can run out, so an earlier helper can still be active. ADR-0067 and the end_screen_helpers doc now say so, and that the next share waits at most 5 s (HELPER_IDLE_WAIT) until no helper is active and is otherwise unavailable, so no second helper starts. The core guidance now states the flag's sense: screen_capture_used is false for a call that began no pick and held no helper, and the call task sets it to true and never clears it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>



Summary
The call worker's level meter tick copied the SDK's whole participant map of every connection every 100 ms. Now the worker keeps a bounded roster of the subscribed remote audio tracks from the room events, and the tick reads only that roster. There is no call protocol change.
What changed
mapping::AudioRoster<T>is pure, with no LiveKit types. It keeps the subscribed remote audio tracks by connection, identity and track SID, in subscription order. It keeps at mostMAX_KEPT_AUDIO_TRACKS(128).measured()gives the firstMAX_MEASURED_TRACKS(64). This constant moved here fromsession.rs.session.rsaddsCall::audio_roster.on_eventadds a track on each audioTrackSubscribed, of every source.on_eventremoves tracks on audioTrackUnsubscribed(every source),ParticipantDisconnectedandDisconnected.other_lostremoves the lost connection's tracks.measure_soundreadsaudio_roster.measured().remote_audio_by_participantis removed.Slots::open_indexedis removed because nothing uses it now.remote_audioserves the playout (deafen and volume). It runs only on a change and still lists every track from the SDK map, so deafen reaches every track. The join listings still callremote_participants()once each.crates/call-worker/AGENTS.md, ADR-0055 and ADR-0059 state the rule. Both ADRs stay proposed.Why it changed
Room::remote_participants()clones the whole map under a read lock. The SFU sets the size of that map, so a copy on each 100 ms tick had no bound.I read the LiveKit 0.11 source to confirm that the events keep the roster correct:
Call, so it sees each subscription made during the connect. This is also true for other SFUs.handle_restarting), unpublishes each track. This sendsTrackUnsubscribed, and thenParticipantDisconnectedfollows. The dispatcher's channels are unbounded, so no event is lost.release_remote_participants, after aDisconnected) removes participants without events. For this reason the roster also removes a connection onDisconnectedand on a lost connection.Changes in behaviour:
HashMaporder, which can change on each tick. Now they are the first 64 subscribed.PR #103's
measure_statsalso callsremote_participants()on its stats tick (only while the details are open), and it usesSlots::open_indexed. Whichever of the two PRs merges second must change:measure_statsshould then read an index like this one. It needs each participant's microphone and video tracks, and the audio roster does not keep video tracks or the source. Extend the index in PR #103 after this PR merges.Checks run on commit b819f8f:
cargo fmt --all -- --check, andcargo clippy --locked -p persephone-call-worker --all-targets -- -D warnings(crt-static,LK_CUSTOM_WEBRTC). Both pass.cargo test --locked -p persephone-call-worker. 190 passed, 2 ignored, and 1 skipped (given_worker_runtime_when_tcp_connects_then_it_does_not_panic, which this host's loopback refuses).cargo test --locked -p persephone-call-worker --all-targets(243 passed, 2 ignored) and Clippy with-D warningspass. The format check did not run there, because rustfmt is not installed for that toolchain.mainat 590fd4a (Share the screen on Windows in the call worker's container and on macOS (ADR-0064, needs owner approval) #102), at 8a0cc42 on Windows:cargo fmt --all -- --check, Clippy with-D warnings(crt-static) andcargo test --locked -p persephone-call-worker(200 passed, 3 ignored, the TCP test skipped) exit 0. The Linux VM run above is from b819f8f, before the rebase.Not run: a live call, and a call with more than 64 remote audio tracks.
Tests
Updated
None
New
In
crates/call-worker/src/mapping.rs:given_subscribed_audio_tracks_when_measured_then_they_come_in_subscription_ordergiven_a_kept_track_when_it_is_subscribed_again_then_it_is_replaced_in_its_placegiven_kept_tracks_when_one_is_unsubscribed_then_only_that_track_goesgiven_a_participant_with_tracks_when_it_leaves_then_its_tracks_on_that_connection_gogiven_tracks_on_two_connections_when_one_goes_down_then_only_its_tracks_gogiven_an_invalid_identity_or_connection_when_a_track_comes_then_nothing_is_keptgiven_more_tracks_than_are_measured_when_measured_ones_go_then_waiting_ones_move_up🤖 Generated with Claude Code
Code Rabbit
AudioRosterof subscribed remote audio tracks. It holds up to 128 tracks in subscription order. It replaces the per-tick copy of the SDK participant map.Slots::open_indexedis removed.MAX_MEASURED_TRACKSmoves fromsession.rstomapping.rs, andMAX_KEPT_AUDIO_TRACKSis added.crates/call-worker/AGENTS.md, ADR-0055, and ADR-0059 document the new metering policy.#103,measure_statsmust index microphone and video tracks. The audio roster does not track them.