From bfff6bcbb28557fe359307840084b26bc199da0c Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 16 Nov 2026 08:05:19 -0800 Subject: [PATCH 1/2] chore(quest): claim quest/m0/flaky-media-restart.md Quest-Claim: 356a9723e2370765 From ffb757b9169c7b6cbc54b95df3cb6eeb131e2db2 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 16 Nov 2026 08:30:25 -0800 Subject: [PATCH 2/2] fix(scene): a media file stays ended when its last picture shows late A picture decoded past its moment waited in the show queue while the play reached its end and set the source Ended; showing it then set the status back to Live, until the next cue. The play now shows what is due before it reads as ended. The restart test also times both clips from the later one's start, which can trail the intro's by the write lead. Co-Authored-By: Claude Opus 5.5 --- quest/m0/flaky-media-restart.md | 23 ----------------------- rs/moq-scene/src/source.rs | 28 ++++++++++++++++++---------- 2 files changed, 18 insertions(+), 33 deletions(-) delete mode 100644 quest/m0/flaky-media-restart.md diff --git a/quest/m0/flaky-media-restart.md b/quest/m0/flaky-media-restart.md deleted file mode 100644 index 48ddfeb6..00000000 --- a/quest/m0/flaky-media-restart.md +++ /dev/null @@ -1,23 +0,0 @@ -# [S] The media restart test holds under load - -## Goal - -`source::media_tests::a_media_file_restarts_going_on_program` passes however -busy the host is. - -## Plan - -It hung once in 60 runs of `source::media_tests::` beside `stress-ng --cpu 96` -on a 32-CPU host, while the other eleven media tests passed every run -(found by moq-dev/studio#181, which fixed the looping test's flake under the -same load). A hang under a paused clock means the test holds the clock, with -`until`'s zero sleep, short of a moment the source sleeps until. - -Reproduce it first as #181 did: the test binary run 200 times, 16 at a time, -beside `stress-ng`, each under `timeout 120`. Then find which wait holds. One lead: the comment before the -first `until_time` says waiting for both clips "while the clock holds" starts -them together, but `shown` moves the clock to the intro's start with -`until_time`, so the still clip can begin later, and the fixed 1.1 s may not -cover both plays' ends, which include sound running past the last picture. -Read each play's end from `Feed::run().ended` instead of a fixed offset, as -#181 does for the loop. diff --git a/rs/moq-scene/src/source.rs b/rs/moq-scene/src/source.rs index e26c31e5..834a4006 100644 --- a/rs/moq-scene/src/source.rs +++ b/rs/moq-scene/src/source.rs @@ -1928,6 +1928,14 @@ impl Driver { }; let mut own = Own::new(listing, kio::clock::now()); let shows = Shows::default(); + // Show each picture handed over whose moment has come. + let show_due = || { + let now = kio::clock::now(); + while shows.queue.borrow().front().is_some_and(|(due, ..)| *due <= now) { + let (_, play, frame) = shows.queue.borrow_mut().pop_front().expect("peeked"); + self.show_play(play, Picture::Frame(frame)); + } + }; // The last channel on a strip to close drops what it has not played // yet, so a loop keeps its channel, sounding on, while a new cue drops // it, cutting off what the play before still had queued, pictures @@ -1993,6 +2001,10 @@ impl Driver { played.is_some() }; if rest { + // A picture handed over late, past its moment, may still + // wait to show when the play's end comes; shown after it, + // it would read the ended source as live again. + show_due(); set(&self.status, Status::Ended); self.ended(&mut cues, &mut own).await; } @@ -2006,13 +2018,9 @@ impl Driver { // has shown. let present = async { loop { - let now = kio::clock::now(); + show_due(); let due = shows.queue.borrow().front().map(|(due, ..)| *due); match due { - Some(due) if due <= now => { - let (_, play, frame) = shows.queue.borrow_mut().pop_front().expect("peeked"); - self.show_play(play, Picture::Frame(frame)); - } Some(due) => tokio::select! { () = kio::clock::sleep_until(due) => {} () = shows.handed.notified() => {} @@ -4235,11 +4243,11 @@ mod media_tests { let drivers = sources.sync(&collection); start(&sources, drivers).await; let (first, begin) = shown(sources.get("intro.mkv").unwrap()).await; - // Each clip starts once its first picture decodes, on a thread - // tokio cannot see. Waiting for both while the clock holds starts - // them together, so both end before the clock passes 1.1 s. - shown(sources.get("still.mkv").unwrap()).await; - until_time(begin.saturating_add(Duration::from_millis(1_100))).await; + // Each clip begins the write lead after its first picture decodes, + // on a thread tokio cannot see, so the still clip may begin after + // the intro has. + let (_, still) = shown(sources.get("still.mkv").unwrap()).await; + until_time(begin.max(still).saturating_add(Duration::from_millis(1_100))).await; until_status(&sources, "intro.mkv", Status::Ended).await; until_status(&sources, "still.mkv", Status::Ended).await; for name in ["intro.mkv", "still.mkv"] {