From 0cd17fc25c5049cdfd2c2047ca1fadc8bf4e3879 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 21 Nov 2026 02:00:29 -0800 Subject: [PATCH 1/2] chore(quest): claim quest/m0/cue-test-flake.md Quest-Claim: 8d6fbcbbe1175ac2 From 5b1a73c9f5e8d8864ec44796007b6c03fee19a36 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 21 Nov 2026 02:10:44 -0800 Subject: [PATCH 2/2] fix(studio): start the sources with the engine, not on the program's first frame The engine synced its sources only on the program thread's first tick, so a caller of Engine::start could find none running when that thread was slow to be scheduled, as a_cue_waits_for_take did on a loaded runner. Co-Authored-By: Claude Opus 5.5 --- quest/m0/cue-test-flake.md | 22 ---------------- rs/moq-studio/src/engine.rs | 52 ++++++++++++++++++++----------------- 2 files changed, 28 insertions(+), 46 deletions(-) delete mode 100644 quest/m0/cue-test-flake.md diff --git a/quest/m0/cue-test-flake.md b/quest/m0/cue-test-flake.md deleted file mode 100644 index 0d59c0ce..00000000 --- a/quest/m0/cue-test-flake.md +++ /dev/null @@ -1,22 +0,0 @@ -# [S] The cue test passes every time on CI - -## Goal - -`engine::tests::a_cue_waits_for_take` passes on every run of nightly's -Software render job, with its root cause fixed rather than its assertion -loosened or retried. - -## Plan - -It failed twice in a row on that job, then passed on the same commit -([run 44848291984](https://github.com/moq-dev/studio/actions/runs/44848291984), -jobs 136673346473 and 136697397976 failed, 136713241257 passed), and it passes -locally (`just render-sw`'s filter on lavapipe). It fails at -`rs/moq-studio/src/engine.rs:4449`: `refused(Action::Mute("host"))` says -"`host` has no sound", so `controls::sounds` found no strip for the `host` -broadcast source, which every opened broadcast source has -(`Source::has_audio`). So `state.sources` did not hold `host` at that moment -on a slow runner: find what opens and closes a source no scene shows, and when, -and make the test wait on that event, or the engine hold it, whichever is the -intended behavior. The assertion landed with -[moq-dev/studio#219](https://github.com/moq-dev/studio/pull/219). diff --git a/rs/moq-studio/src/engine.rs b/rs/moq-studio/src/engine.rs index ef07ab1c..7e2b8630 100644 --- a/rs/moq-studio/src/engine.rs +++ b/rs/moq-studio/src/engine.rs @@ -1197,10 +1197,10 @@ impl Drop for Joined { impl Engine { /// Open the `loaded` collection and history on `launch.gpu`, start the - /// program clock, and save both to `autosave`'s files as they change, - /// starting at once. Recordings go into `launch.recordings`. Guests join - /// once the engine [joins](Self::join) a room. Nothing is published until - /// the studio [goes live](Self::go_live). + /// program clock and the collection's sources, and save both to + /// `autosave`'s files as they change, starting at once. Recordings go into + /// `launch.recordings`. Guests join once the engine [joins](Self::join) a + /// room. Nothing is published until the studio [goes live](Self::go_live). /// /// Call inside the tokio runtime that serves the relay connections. pub async fn start(launch: Launch, autosave: Autosave, loaded: autosave::Loaded) -> anyhow::Result> { @@ -1275,7 +1275,7 @@ impl Engine { sources, compositor, cameras: BTreeMap::new(), - stale: true, + stale: false, edits: autosave.edits(), renamed: Vec::new(), #[cfg(test)] @@ -1323,13 +1323,15 @@ impl Engine { // publication alive beside a retry's. let starting = Starting(Some(engine.clone())); // The audio clock first, so the bus keeps up with the program clock by - // the time the program starts the sources, whose sound otherwise waits - // for it. + // the time the sources start, whose sound otherwise waits for it. let mix = engine.clone(); let config = bus.config().clone(); let rate = config.sample_rate; let thread = clocked("audio".into(), async move || mix.run_audio(start, config, mixer).await)?; engine.threads.lock().unwrap().push(thread); + // Before the program thread, so whoever holds the engine finds every + // source running, however late that thread first runs. + engine.sync(&mut engine.state.lock().unwrap()); let program = engine.clone(); let thread = clocked("program".into(), async move || { program.run_program(start, epoch, recording).await @@ -1586,6 +1588,20 @@ impl Engine { .map(|monitor| (monitor.name().to_string(), monitor.failed())) } + /// Run exactly the sources `state`'s collection has, each on a thread of + /// its own, and point the audio at its audio scenes. + fn sync(&self, state: &mut State) { + let drivers = state.sources.sync(&state.collection); + self.recorder.set_sources(&state.collection); + if !drivers.is_empty() { + let mut running = self.running.lock().unwrap(); + // Forgets the threads that have ended. + running.retain_mut(|ended| ended.try_recv() == Err(TryRecvError::Empty)); + running.extend(drivers.into_iter().map(spawn)); + } + self.pick_audio(state); + } + /// Point the program audio, the recorded audio, the monitor, and each /// guest's return feed at the audio scenes `state` now has. fn pick_audio(&self, state: &State) { @@ -1873,15 +1889,7 @@ impl Engine { let state = &mut *guard; let synced = std::mem::take(&mut state.stale); if synced { - let drivers = state.sources.sync(&state.collection); - self.recorder.set_sources(&state.collection); - if !drivers.is_empty() { - let mut running = self.running.lock().unwrap(); - // Forgets the threads that have ended. - running.retain_mut(|ended| ended.try_recv() == Err(TryRecvError::Empty)); - running.extend(drivers.into_iter().map(spawn)); - } - self.pick_audio(state); + self.sync(state); } // On air, each published scene's line starts once it is @@ -3985,14 +3993,10 @@ mod tests { let engine = start(gpu, Vec::new(), dir.path(), autosave, red_canvas()) .await .expect("the studio starts"); - // The program thread starts the sources on its first sync. - kio::clock::timeout(Duration::from_secs(10), async { - while engine.state.lock().unwrap().sources.get("red").is_none() { - kio::clock::sleep(Duration::from_millis(20)).await; - } - }) - .await - .expect("the source starts"); + assert!( + engine.state.lock().unwrap().sources.get("red").is_some(), + "the source starts" + ); let secs = Duration::from_secs; engine.state.lock().unwrap().dark.insert("red".into(), secs(12)); let local = engine.local(kio::clock::now());