From 31579ac9376e904f7fe608c3bb2854348cf35466 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 15 Nov 2026 15:30:09 -0800 Subject: [PATCH 1/4] fix(moq-stats): a bucket run says nothing precedes its first group Since groups are keyed by their start (#8638), a bucket run's first group is no longer group 0, so a reader can't tell the run's first group from a later one. The run now skips every start below its first group, and `track::Ordered::is_skipped` exposes the check to ordered readers. Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/model/track.rs | 6 ++++++ rs/moq-stats/src/produce.rs | 24 ++++++++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/rs/moq-net/src/model/track.rs b/rs/moq-net/src/model/track.rs index 8e9e6dc0f67..505bf515ade 100644 --- a/rs/moq-net/src/model/track.rs +++ b/rs/moq-net/src/model/track.rs @@ -10793,6 +10793,12 @@ impl Ordered { self.inner.poll_largest(waiter) } + /// Whether the publisher declared every start in `groups` skipped; see + /// [`Subscriber::is_skipped`]. + pub fn is_skipped(&self, groups: ops::Range) -> bool { + self.inner.is_skipped(groups) + } + /// Whether `other` reads the same underlying track state. pub fn is_clone(&self, other: &Self) -> bool { self.inner.is_clone(&other.inner) diff --git a/rs/moq-stats/src/produce.rs b/rs/moq-stats/src/produce.rs index 5dfadba3838..35171806ad1 100644 --- a/rs/moq-stats/src/produce.rs +++ b/rs/moq-stats/src/produce.rs @@ -463,6 +463,8 @@ struct Snapshot { largest: Option, /// The interval the newest group opened in, which the next group has to pass. opened: Option, + /// The track's name is new, so nothing comes before its first group, and it says so. + fresh: bool, deltas: bool, /// The newest snapshot payload written, and what the last update wrote /// (zero when nothing). Bench builds only. @@ -481,6 +483,7 @@ impl Snapshot { group: None, largest: None, opened: None, + fresh: false, #[cfg(feature = "bench")] held: 0, #[cfg(feature = "bench")] @@ -488,6 +491,14 @@ impl Snapshot { } } + /// Declare every start below the first group skipped, for a track whose name no earlier + /// run used: a reader then knows the first group it reads opens the track + /// ([`moq_net::track::Subscriber::is_skipped`]). + fn fresh(mut self) -> Self { + self.fresh = true; + self + } + fn demand(&self) -> moq_net::track::Demand { self.track.demand() } @@ -543,6 +554,9 @@ impl Snapshot { if let Some(group) = self.group.take() { group.close()?; } + if self.fresh && self.largest.is_none() { + self.track.skip_groups(0..start); + } self.group = Some(self.track.append_group(start)?); self.largest = Some(start); self.opened = Some(stamp.group); @@ -622,7 +636,7 @@ impl Output { fn new(track: track::Producer) -> Self { Self { - snapshot: Snapshot::new(track, config()), + snapshot: Snapshot::new(track, config()).fresh(), frame: Frame::default(), } } @@ -908,7 +922,7 @@ impl BucketTrack { let track = broadcast.create_track(name.as_str(), info())?; Ok(Self { name, - snapshot: Snapshot::new(track, config()), + snapshot: Snapshot::new(track, config()).fresh(), body: BucketBody { epoch, tiers: Frame::default(), @@ -3168,7 +3182,7 @@ mod tests { let registry = producer.registry(); let (_, broadcast) = announced(&origin).await; let stats = crate::Consumer::new(broadcast.clone(), Default::default()); - // The listed run's name, and the start of its first group. + // The listed run's name, and the start of its first group, which nothing comes before. let run = async |broadcast: &moq_net::broadcast::Consumer| { let name = crate::listed_bucket_track(broadcast, &moq_net::Path::from_static("acme")).await; let mut track = subscribe(broadcast, &name).await; @@ -3177,7 +3191,9 @@ mod tests { let start = group.unwrap().unwrap().start; first = Some(first.map_or(start, |first: u64| first.min(start))); } - (name, first) + let first = first.expect("a run's first group is listed"); + assert!(track.is_skipped(0..first), "a run says nothing precedes its first group"); + (name, Some(first)) }; let session = From 93ee23fba6210a9f418ce87c641cfa48b08408d2 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 15 Nov 2026 15:31:52 -0800 Subject: [PATCH 2/4] style: fmt --- rs/moq-stats/src/produce.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rs/moq-stats/src/produce.rs b/rs/moq-stats/src/produce.rs index 35171806ad1..50727f8f44a 100644 --- a/rs/moq-stats/src/produce.rs +++ b/rs/moq-stats/src/produce.rs @@ -3192,7 +3192,10 @@ mod tests { first = Some(first.map_or(start, |first: u64| first.min(start))); } let first = first.expect("a run's first group is listed"); - assert!(track.is_skipped(0..first), "a run says nothing precedes its first group"); + assert!( + track.is_skipped(0..first), + "a run says nothing precedes its first group" + ); (name, Some(first)) }; From 1c9775a0325329be7902453d680a092b4f9e9b6b Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 15 Nov 2026 16:06:35 -0800 Subject: [PATCH 3/4] fix(moq-stats): only a bucket run is fresh; a totals track keeps its name Co-Authored-By: Claude Opus 5.5 --- rs/moq-stats/src/produce.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rs/moq-stats/src/produce.rs b/rs/moq-stats/src/produce.rs index 50727f8f44a..9701ced83cf 100644 --- a/rs/moq-stats/src/produce.rs +++ b/rs/moq-stats/src/produce.rs @@ -636,7 +636,7 @@ impl Output { fn new(track: track::Producer) -> Self { Self { - snapshot: Snapshot::new(track, config()).fresh(), + snapshot: Snapshot::new(track, config()), frame: Frame::default(), } } From 60645a2f2beecc888bc2afa04ec8ed16693cdc9c Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 15 Nov 2026 16:25:01 -0800 Subject: [PATCH 4/4] docs(moq-net): is_skipped knows only the skips recorded so far Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/model/track.rs | 3 +++ rs/moq-stats/src/produce.rs | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/rs/moq-net/src/model/track.rs b/rs/moq-net/src/model/track.rs index 505bf515ade..7c47c639982 100644 --- a/rs/moq-net/src/model/track.rs +++ b/rs/moq-net/src/model/track.rs @@ -10223,6 +10223,9 @@ impl Subscriber { /// subscriber's ranges. A copy knows only the skips its wire forwarded. /// /// What tells a reader that nothing lies between two groups, or before a track's first. + /// It knows only the skips recorded so far, so `false` means "not known skipped": a skip + /// still in flight reads `false`, as does one a local producer's cache expired below its + /// edge. A reader that asks once treats such a group as one with something before it. pub fn is_skipped(&self, groups: ops::Range) -> bool { let Some(last) = groups.end.checked_sub(1).filter(|last| *last >= groups.start) else { return true; diff --git a/rs/moq-stats/src/produce.rs b/rs/moq-stats/src/produce.rs index 9701ced83cf..54a597da756 100644 --- a/rs/moq-stats/src/produce.rs +++ b/rs/moq-stats/src/produce.rs @@ -493,7 +493,9 @@ impl Snapshot { /// Declare every start below the first group skipped, for a track whose name no earlier /// run used: a reader then knows the first group it reads opens the track - /// ([`moq_net::track::Subscriber::is_skipped`]). + /// ([`moq_net::track::Subscriber::is_skipped`]). A reader the skip hasn't reached, in + /// flight or forgotten by this relay's cache, reads the first group as a later one, so + /// a meter that bills a run from zero only on its first group never counts it twice. fn fresh(mut self) -> Self { self.fresh = true; self