From c9bd66a5322343e7ed555894b7f677a8d4ad4397 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 7 Nov 2026 17:19:55 -0800 Subject: [PATCH 1/5] chore(quest): claim quest/m1/explicit-state/catalog-finish.md Quest-Claim: 4ac4b3dd05da51d1 From 875d9aa66eb8c54fe05d9e785957f4fb6347ac65 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 7 Nov 2026 17:21:31 -0800 Subject: [PATCH 2/5] fix(moq-mux): a failed catalog finish is final Co-Authored-By: Claude Opus 5.5 --- quest/m1/explicit-state/catalog-finish.md | 24 ---------- rs/moq-mux/src/catalog/producer.rs | 55 +++++++++++++++++++---- 2 files changed, 47 insertions(+), 32 deletions(-) delete mode 100644 quest/m1/explicit-state/catalog-finish.md diff --git a/quest/m1/explicit-state/catalog-finish.md b/quest/m1/explicit-state/catalog-finish.md deleted file mode 100644 index b13e67125e6..00000000000 --- a/quest/m1/explicit-state/catalog-finish.md +++ /dev/null @@ -1,24 +0,0 @@ -# [XS] A failed catalog finish is final - -## Goal - -`moq_mux::catalog::Producer::finish` is never half-finished: when finishing -either catalog track fails, the producer reports that failure for good and -both catalog tracks end. It is never left closed with a track still open. - -## Plan - -Planned 2026-11-07 (maintainer, /quest-complete), a follow-up of -[moq-dev/moq#8210](https://github.com/moq-dev/moq/pull/8210), which fixed -this shape in the importers and the container, audio, and JSON producers -but left the catalog producer outside its list. - -`finish` (`rs/moq-mux/src/catalog/producer.rs`) stores -`closed = Some(Error::Closed)` before `self.outputs.hang.finish()?` and -`self.outputs.msf_track.finish()?`. If the hang track's finish fails, the -MSF track is never finished, yet every later call reports a clean `Closed`. -Record the terminal outcome after the fallible work, as #8210 did: keep the -first error, abort or end the other track, and store the failure rather -than `Closed`. Test a failing track finish. - -Public API: none. Wire: none. diff --git a/rs/moq-mux/src/catalog/producer.rs b/rs/moq-mux/src/catalog/producer.rs index 37987e66cc5..7746c7feef4 100644 --- a/rs/moq-mux/src/catalog/producer.rs +++ b/rs/moq-mux/src/catalog/producer.rs @@ -1062,17 +1062,31 @@ impl Producer { /// Finish publishing to this catalog. /// /// An estimate rise still held by the once-a-second limit is not published: media has ended. + /// + /// A failure is final: both catalog tracks end (the other one aborted with that error), and every + /// later call reports it. pub fn finish(&mut self) -> crate::Result<()> { - { - let mut state = take(&self.current); - if let Some(err) = &state.closed { - return Err(err.clone()); + let mut state = take(&self.current); + if let Some(err) = &state.closed { + return Err(err.clone()); + } + let result = self + .outputs + .hang + .finish() + .map_err(crate::Error::from) + .and_then(|_| self.outputs.msf_track.finish().map_err(crate::Error::from)); + match result { + Ok(()) => { + state.closed = Some(moq_net::Error::Closed.into()); + Ok(()) + } + Err(err) => { + self.outputs.abort(&err); + state.closed = Some(err.clone()); + Err(err) } - state.closed = Some(moq_net::Error::Closed.into()); } - self.outputs.hang.finish()?; - self.outputs.msf_track.finish()?; - Ok(()) } } @@ -1545,6 +1559,31 @@ mod test { )); } + #[tokio::test(start_paused = true)] + async fn a_failed_finish_is_final_and_ends_both_tracks() { + let mut broadcast = moq_net::broadcast::Info::default().produce(); + let mut catalog = Producer::<()>::new(&mut broadcast, Config::default()).unwrap(); + let mut msf = broadcast + .consume() + .track(moq_msf::DEFAULT_NAME) + .unwrap() + .subscribe(None) + .await + .unwrap(); + catalog.outputs.hang.clone().abort(moq_net::Error::Unauthorized).unwrap(); + let err = catalog.finish().unwrap_err(); + assert!(!matches!(err, crate::Error::Moq(moq_net::Error::Closed))); + loop { + match msf.recv_group().await { + Ok(Some(_)) => continue, + Ok(None) => panic!("the MSF track ended cleanly after a failed finish"), + Err(_) => break, + } + } + assert_eq!(catalog.finish().unwrap_err().to_string(), err.to_string()); + assert_eq!(catalog.modify().err().unwrap().to_string(), err.to_string()); + } + /// The catalog and its MSF twin both rank above media. They're the index a player reads /// before any media is useful, and they're small enough that sitting above media can't starve /// it. Regression: the MSF track was minted with no `Info` at all, so one broadcast advertised From dd2311d4cc883de1ef78b5d9277d0dda004978ca Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 7 Nov 2026 17:21:35 -0800 Subject: [PATCH 3/5] fix(moq-mux): a failed catalog finish is final Co-Authored-By: Claude Opus 5.5 --- quest/m1/explicit-state/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/quest/m1/explicit-state/README.md b/quest/m1/explicit-state/README.md index cb1a3ff9a6e..ceb253badb6 100644 --- a/quest/m1/explicit-state/README.md +++ b/quest/m1/explicit-state/README.md @@ -77,7 +77,6 @@ which collapses that state and waits on [Drop set](/quest/m1/drop-set.md). - [Track and group end-of-life](/quest/m1/explicit-state/track-end.md) - moq-net's track and group outcomes are one enum each, in Rust and JS - [moq-net phase data](/quest/m1/explicit-state/net-phases.md) - moq-net's session and subscription state machines keep each phase's data in its variant - [moq-mux and moq-gst lifecycles](/quest/m1/explicit-state/mux-gst.md) - export sources, TS and fMP4 export tracks, and gst pads are explicit state -- [A failed catalog finish is final](/quest/m1/explicit-state/catalog-finish.md) - the catalog producer never reports closed with a catalog track left open - [Video's declared-end freeze is not a stall](/quest/m1/explicit-state/video-declared-end.md) - video holding its last picture through a declared end counts no stall, like audio's declared silence ## Related From 35b4bdb85e0aed69430add5fe48a687bf572be91 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 7 Nov 2026 17:35:37 -0800 Subject: [PATCH 4/5] style: fmt Co-Authored-By: Claude Opus 5.5 --- rs/moq-mux/src/catalog/producer.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/rs/moq-mux/src/catalog/producer.rs b/rs/moq-mux/src/catalog/producer.rs index 7746c7feef4..5ae55ae9de4 100644 --- a/rs/moq-mux/src/catalog/producer.rs +++ b/rs/moq-mux/src/catalog/producer.rs @@ -1570,7 +1570,12 @@ mod test { .subscribe(None) .await .unwrap(); - catalog.outputs.hang.clone().abort(moq_net::Error::Unauthorized).unwrap(); + catalog + .outputs + .hang + .clone() + .abort(moq_net::Error::Unauthorized) + .unwrap(); let err = catalog.finish().unwrap_err(); assert!(!matches!(err, crate::Error::Moq(moq_net::Error::Closed))); loop { From d31cc182981890c89f0209d593ebcded9767de32 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 7 Nov 2026 21:05:34 -0800 Subject: [PATCH 5/5] fix(moq-mux): report a failed catalog finish from handles made after it Pin the MSF track's abort cause in the test, per review. Co-Authored-By: Claude Opus 5.5 --- rs/moq-mux/src/catalog/producer.rs | 22 ++++++++++++++++++++-- rs/moq-mux/src/catalog/tracks.rs | 10 ++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/rs/moq-mux/src/catalog/producer.rs b/rs/moq-mux/src/catalog/producer.rs index 5ae55ae9de4..7a0fa308224 100644 --- a/rs/moq-mux/src/catalog/producer.rs +++ b/rs/moq-mux/src/catalog/producer.rs @@ -1059,6 +1059,11 @@ impl Producer { self.outputs.abort(&reason); } + /// The terminal outcome once the catalog tracks are closed. + pub(crate) fn closed(&self) -> Option { + take(&self.current).closed.clone() + } + /// Finish publishing to this catalog. /// /// An estimate rise still held by the once-a-second limit is not published: media has ended. @@ -1577,16 +1582,29 @@ mod test { .abort(moq_net::Error::Unauthorized) .unwrap(); let err = catalog.finish().unwrap_err(); - assert!(!matches!(err, crate::Error::Moq(moq_net::Error::Closed))); loop { match msf.recv_group().await { Ok(Some(_)) => continue, Ok(None) => panic!("the MSF track ended cleanly after a failed finish"), - Err(_) => break, + Err(moq_net::Error::Unauthorized) => break, + Err(other) => panic!("the MSF track ended with {other} instead of the finish cause"), } } assert_eq!(catalog.finish().unwrap_err().to_string(), err.to_string()); assert_eq!(catalog.modify().err().unwrap().to_string(), err.to_string()); + + // A handle made after the failure reports it too, not `NotPublished`. + let net = broadcast + .create_track("late", catalog.track_info(hang::catalog::PRIORITY.video)) + .unwrap(); + let mut late = catalog + .video( + net, + crate::catalog::hang::Container::Legacy(crate::container::Kind::Video), + None, + ) + .unwrap(); + assert_eq!(late.modify().err().unwrap().to_string(), err.to_string()); } /// The catalog and its MSF twin both rank above media. They're the index a player reads diff --git a/rs/moq-mux/src/catalog/tracks.rs b/rs/moq-mux/src/catalog/tracks.rs index 06c9d4d3341..08948b54c90 100644 --- a/rs/moq-mux/src/catalog/tracks.rs +++ b/rs/moq-mux/src/catalog/tracks.rs @@ -788,10 +788,16 @@ impl> Rendition { Ok(()) } + /// Why an unpublished rendition can't be edited: the catalog's terminal error once it is closed, + /// since a handle made after a failed finish must report that failure, else `NotPublished`. + fn unpublished(&self) -> crate::Error { + self.catalog.closed().unwrap_or(crate::Error::NotPublished) + } + /// Refine the rendition, refusing an unserializable edit before retaining it. pub(crate) fn config(&self) -> crate::Result { if !self.present { - return Err(crate::Error::NotPublished); + return Err(self.unpublished()); } self.catalog.config::(&self.name).ok_or(crate::Error::NotPublished) } @@ -822,7 +828,7 @@ impl> Rendition { /// Write `config` into the catalog, leaving the caller to choose how the guard publishes it. fn stage(&mut self, config: C) -> crate::Result> { if !self.present { - return Err(crate::Error::NotPublished); + return Err(self.unpublished()); } Self::check_decrease(&self.config()?.estimate(), &config.estimate())?; let mut guard = self.catalog.modify()?;