Screen share: a late frame of an unpublished track stays off the bus (#908) #909

Closed
charles wants to merge 0 commits from fix-908-flaky-stream-end-test into textchat
Owner

Closes #908

Cause: a real race in the client's frame routing, not the test's timing and not the watch logic. Remote video frames and room events reach the runtime on two channels that two tasks read (apps/fluxer/src/voice_rt.rs). If the session passed a frame on just before its track was unpublished, the frame could be taken in after TrackUnpublished had already taken the track off the FrameBus. VideoRouting::frame then put it back under the old sid, and nothing removed it again. The store never unsubscribes a track that is no longer published, so the participant stayed "wanted". The stale frame stayed on the bus until the streamer left or the room was left. During the republish grace it also showed under the "Stream ended" overlay for that sid.

The store side was correct. In the failing run, the store had already dropped the watch after REPUBLISH_GRACE (the wait_for before it passed). The test then waited the full 30 s for the frame to leave the bus, and it never did. So a user is not left watching an ended stream. They get a leaked, frozen frame on the bus.

Fix

  • VideoRouting remembers the sids unpublished in the current room and drops their frames. A new TrackPublished for a sid clears it, and leaving the room clears the whole list.
  • When a participant leaves, it stops being "wanted", so its late frames are dropped too. If it comes back, the store asks for its screen share again.

Tests

  • New unit test voice_rt::tests::a_late_frame_of_a_gone_track_stays_off_the_bus sends the late frame on purpose. It fails on textchat and passes with the fix.
  • watched_stream_ending_stops_watching_by_itself no longer polls the bus against a wall-clock budget. It now asserts the bus state at the moment the store's state says the watch ended. It also checks that the first (republished) track left the bus. What it proves is unchanged: a quick republish keeps the watch, and a real end drops the watch after the grace (still >= REPUBLISH_GRACE) with the frames gone.

Verification (each run under dbus-run-session, FLUXER_NO_DESKTOP_NOTIFICATIONS=1, with 5 niced copies of the same test binary running the same test in a loop alongside; load average 11–23)

  • Before the fix: failed on run 31 with timed out waiting for: ada's frames are gone from the bus.
  • After the fix: 60 of 60 consecutive passes.
  • FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci: ==> xtask ci: all steps passed.

🤖 Generated with Claude Code

Closes #908 **Cause: a real race in the client's frame routing, not the test's timing and not the watch logic.** Remote video frames and room events reach the runtime on two channels that two tasks read (`apps/fluxer/src/voice_rt.rs`). If the session passed a frame on just before its track was unpublished, the frame could be taken in *after* `TrackUnpublished` had already taken the track off the `FrameBus`. `VideoRouting::frame` then put it back under the old sid, and nothing removed it again. The store never unsubscribes a track that is no longer published, so the participant stayed "wanted". The stale frame stayed on the bus until the streamer left or the room was left. During the republish grace it also showed under the "Stream ended" overlay for that sid. The store side was correct. In the failing run, the store had already dropped the watch after `REPUBLISH_GRACE` (the `wait_for` before it passed). The test then waited the full 30 s for the frame to leave the bus, and it never did. So a user is **not** left watching an ended stream. They get a leaked, frozen frame on the bus. **Fix** - `VideoRouting` remembers the sids unpublished in the current room and drops their frames. A new `TrackPublished` for a sid clears it, and leaving the room clears the whole list. - When a participant leaves, it stops being "wanted", so its late frames are dropped too. If it comes back, the store asks for its screen share again. **Tests** - New unit test `voice_rt::tests::a_late_frame_of_a_gone_track_stays_off_the_bus` sends the late frame on purpose. It fails on `textchat` and passes with the fix. - `watched_stream_ending_stops_watching_by_itself` no longer polls the bus against a wall-clock budget. It now asserts the bus state at the moment the store's state says the watch ended. It also checks that the first (republished) track left the bus. What it proves is unchanged: a quick republish keeps the watch, and a real end drops the watch after the grace (still `>= REPUBLISH_GRACE`) with the frames gone. **Verification** (each run under `dbus-run-session`, `FLUXER_NO_DESKTOP_NOTIFICATIONS=1`, with 5 niced copies of the same test binary running the same test in a loop alongside; load average 11–23) - Before the fix: failed on run 31 with `timed out waiting for: ada's frames are gone from the bus`. - After the fix: 60 of 60 consecutive passes. - `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci`: `==> xtask ci: all steps passed`. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Remote video frames and room events reach the runtime on two channels, read
by two tasks. A frame the session passed on just before its track was
unpublished could be taken in after `TrackUnpublished` had removed the track
from the `FrameBus`; `VideoRouting::frame` then put it back, keyed by the
gone sid, and nothing took it off again: the store never unsubscribes a
track that is no longer published, so the participant stayed "wanted". The
stale frame stayed on the bus until the streamer left or the room was left,
and showed under a "Stream ended" overlay of the same sid.

`VideoRouting` now remembers the sids unpublished in this room and refuses
their frames (a new `TrackPublished` of the sid lifts it; leaving the room
forgets them), and a participant that leaves is no longer wanted, so its
late frames stay off too.

The store side was right: the watch ended after REPUBLISH_GRACE every time.
`watched_stream_ending_stops_watching_by_itself` now checks the bus at the
moment the store has dropped the watch instead of polling it, and also
checks that the first, republished track left the bus.

Refs #908

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
Owner

Merged into textchat by hand (the merge API returns 405); the commits are in the branch.

Merged into `textchat` by hand (the merge API returns 405); the commits are in the branch.
charles closed this pull request 2026-11-18 17:33:22 +00:00
charles referenced this pull request from a commit 2026-11-18 22:34:35 +00:00

Pull request closed

Sign in to join this conversation.
No description provided.