From 51c5b7f96be87e96b33ae65eee30daa9d5370351 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Wed, 21 Oct 2026 22:35:24 -0700 Subject: [PATCH 01/12] quest: claim quest/m1/track-live Co-Authored-By: Claude Opus 5.5 From 9d1da78ccb51a5c977fa854680ab9dfb153b79b1 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Wed, 21 Oct 2026 22:46:31 -0700 Subject: [PATCH 02/12] fix(net): a relative start on an idle copy counts from the live feed Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/model/subscription.rs | 4 +- rs/moq-net/src/model/track.rs | 130 +++++++++++++++++++++++---- 2 files changed, 114 insertions(+), 20 deletions(-) diff --git a/rs/moq-net/src/model/subscription.rs b/rs/moq-net/src/model/subscription.rs index ca15f330985..5dfa6811b89 100644 --- a/rs/moq-net/src/model/subscription.rs +++ b/rs/moq-net/src/model/subscription.rs @@ -108,7 +108,9 @@ pub enum Order { /// /// A relative or time anchor resolves at the hop that serves it, when it starts serving /// and again whenever the subscriber replaces its ranges. Before any group exists a -/// relative anchor resolves at the first one, so [`Range::live`] starts there. +/// relative anchor resolves at the first one, so [`Range::live`] starts there. A relay's +/// copy waiting on a fresh upstream answer counts from the live feed's latest group once +/// it answers, never from the groups an ended feed left in its cache. /// /// No published wire carries either yet: upstream, a relative or time start is no floor, /// the same request as [`Range::oldest`], and a relative or time end is no end. Behind a diff --git a/rs/moq-net/src/model/track.rs b/rs/moq-net/src/model/track.rs index 84fb2f216a7..968b4739c5e 100644 --- a/rs/moq-net/src/model/track.rs +++ b/rs/moq-net/src/model/track.rs @@ -377,11 +377,13 @@ pub(crate) struct TrackState { // datagrams, so it can run ahead of any cached group. max_sequence: Option, - // The first and newest groups the publisher produced, which fetched backfill never - // moves: where relative starts count back from. The first is kept after it is evicted, - // for a relative start taken before any group was produced. - first_produced: Option, + // The newest group the publisher produced, which fetched backfill never moves: where + // relative starts count back from (see `latest_live`). newest_produced: Option, + // Where a relative start taken before the live feed produced anything counts back + // from: the newest group when the feed went live, or else the first it produced + // since. Kept after the group is evicted. + first_live: Option, // The name's sequence namespace within the broadcast, which can run past this track's // `max_sequence` when an earlier producer of the name wrote further. @@ -981,6 +983,26 @@ impl TrackState { self.feed == Feed::Live || self.sealed || self.end.is_some() || self.abort.is_some() } + /// Where relative starts count back from: the newest group the live feed produced. + /// `None` while the cache does not reflect the feed, since an idle copy's newest group + /// is only what an ended feed left: a start taken then waits, as on an empty track. + fn latest_live(&self) -> Option { + let floor = self.live_floor.unwrap_or(0); + self.newest_produced.filter(|&newest| self.readable() && newest >= floor) + } + + /// Where a relative start that waited on [`Self::latest_live`] counts back from. + fn first_live(&self) -> Option { + self.first_live.filter(|_| self.readable()) + } + + /// The cache reflects the live feed again: a relative start that waited counts back + /// from its newest group now. + fn go_live(&mut self) { + self.feed = Feed::Live; + self.first_live = self.latest_live(); + } + fn poll_recv_group(&self, index: usize, min_sequence: u64) -> Poll>> { let start = index.saturating_sub(self.offset); let readable = self.readable(); @@ -1794,7 +1816,7 @@ impl TrackState { self.latest_group = Some(sequence); } if visible { - self.first_produced.get_or_insert(sequence); + self.first_live.get_or_insert(sequence); self.newest_produced = self.newest_produced.max(Some(sequence)); } if !self.protects(sequence) { @@ -1897,7 +1919,7 @@ impl TrackState { if let Feed::Answered { from } = self.feed && sequence >= from { - self.feed = Feed::Live; + self.go_live(); } } @@ -2323,10 +2345,10 @@ impl TrackState { (None, Some(cached)) => Some(cached.saturating_add(1)), _ => self.live_floor, }; - self.feed = match largest { - Some(largest) if !self.shows(largest.group) => Feed::Answered { from: largest.group }, - _ => Feed::Live, - }; + match largest { + Some(largest) if !self.shows(largest.group) => self.feed = Feed::Answered { from: largest.group }, + _ => self.go_live(), + } } /// Whether readers can already see content at or past `sequence`. @@ -5549,7 +5571,7 @@ impl Cursor { let preferences = subscription.read(); let ranges_revision = subscription.ranges_revision(); let state = state.read(); - let (window, refused) = match Window::new(&preferences.ranges, state.newest_produced, &*state) { + let (window, refused) = match Window::new(&preferences.ranges, state.latest_live(), &*state) { Ok(window) => (window, None), Err(err) => (Window::new(&[], None, &*state).expect("nothing to refuse"), Some(err)), }; @@ -5665,7 +5687,7 @@ impl Cursor { let moved = match replaced { Some((revision, ranges)) => { self.filter.resolved = revision; - match Window::new(&ranges, state.newest_produced, &*state) { + match Window::new(&ranges, state.latest_live(), &*state) { Ok(window) => { self.filter.window = window; self.filter.refused = None; @@ -5675,10 +5697,11 @@ impl Cursor { true } None if self.filter.window.is_settled() => false, - // The track had no produced group when the ranges resolved, so the newest one - // then was the first to arrive, however many have arrived or left since. - None if self.filter.window.is_pending() => self.filter.window.settle(state.first_produced, &*state), - None => self.filter.window.settle(state.newest_produced, &*state), + // The live feed had no group when the ranges resolved, so the newest one then was + // the first to arrive, or the newest once it went live, however many have arrived + // or left since. + None if self.filter.window.is_pending() => self.filter.window.settle(state.first_live(), &*state), + None => self.filter.window.settle(state.latest_live(), &*state), }; drop(state); if moved { @@ -6228,7 +6251,7 @@ impl Republish { } let state = self.state.read(); // The update was refused before it got here if the track can't resolve it. - let Ok(window) = Window::new(&ranges, state.newest_produced, &*state) else { + let Ok(window) = Window::new(&ranges, state.latest_live(), &*state) else { return; }; drop(state); @@ -6626,7 +6649,7 @@ impl Subscriber { /// The lowest group this subscriber's ranges name, as resolved here when it last read: /// `None` while one reaches back to the oldest group still around, or a relative - /// start still waits on the first group to arrive. + /// start still waits on the first group from the live feed. /// /// Where a reader that waits on each group in sequence starts, rather than at whatever /// arrives first, which newest-first delivery makes the latest. @@ -6665,7 +6688,7 @@ impl Subscriber { match &self.inner { Inner::Plain(cursor) => { let state = cursor.state.read(); - Window::new(ranges, state.newest_produced, &*state) + Window::new(ranges, state.latest_live(), &*state) .map(|window| window.resolved()) .unwrap_or_default() } @@ -8001,6 +8024,75 @@ mod test { assert_eq!(reader.poll_largest(&noop), Poll::Ready(Some(Position::group(5)))); } + /// A relay copy holding groups 0 to 3 from an ended feed, idle until its route answers. + fn idle_copy() -> Producer { + let mut producer = track_producer("test", Info::default()); + for sequence in 0..4 { + framed(&producer, sequence, 1).finish().unwrap(); + } + producer.set_idle(); + producer + } + + /// Every group `reader` can take right now, in delivery order. + fn ready_groups(reader: &mut Subscriber) -> Vec { + let noop = kio::Waiter::noop(); + let mut sequences = Vec::new(); + while let Poll::Ready(Ok(Some(group))) = reader.poll_recv_group(&noop) { + sequences.push(group.sequence); + } + sequences + } + + /// A relative start taken while the copy is idle counts back from the live feed's + /// latest group once the route answers, not from the newest one an ended feed left. + #[test] + fn a_relative_start_on_an_idle_copy_counts_from_the_live_feed() { + let behind = Range { + start: Anchor::Relative(1), + end: None, + }; + for (ranges, expected) in [(Range::live(), vec![4]), (behind, vec![3, 4])] { + let mut producer = idle_copy(); + let mut reader = producer.subscribe(replay().with_ranges([ranges])); + assert_eq!(ready_groups(&mut reader), Vec::::new(), "the copy is idle"); + assert_eq!(reader.floor(), None, "the start waits for the live feed"); + + producer.set_live(Some(Position::group(4)), None); + framed(&producer, 4, 1).finish().unwrap(); + assert_eq!(ready_groups(&mut reader), expected, "{ranges:?}"); + } + } + + /// A relative start waits past groups the route resends below its answer: the feed + /// goes live, and the start resolves, only once the answer shows. + #[test] + fn a_relative_start_on_an_idle_copy_waits_for_the_answer_to_show() { + let mut producer = idle_copy(); + let mut reader = producer.subscribe(replay().with_ranges([Range::live()])); + producer.set_live(Some(Position::group(5)), None); + framed(&producer, 4, 1).finish().unwrap(); + assert_eq!(ready_groups(&mut reader), Vec::::new(), "the answer has not shown"); + + framed(&producer, 5, 1).finish().unwrap(); + assert_eq!(ready_groups(&mut reader), vec![5]); + } + + /// A route that answers with nothing leaves the cache unrelated to its feed, so a + /// relative start resolves at the first group the feed then produces. + #[test] + fn a_relative_start_on_an_idle_copy_skips_a_cache_the_route_disowns() { + let mut producer = idle_copy(); + let mut reader = producer.subscribe(replay().with_ranges([Range::live()])); + producer.set_live(None, None); + assert_eq!(ready_groups(&mut reader), Vec::::new()); + assert_eq!(reader.floor(), None, "no cached group anchors the start"); + + framed(&producer, 7, 1).finish().unwrap(); + assert_eq!(ready_groups(&mut reader), vec![7]); + assert_eq!(reader.floor(), Some(7)); + } + #[test] #[cfg(feature = "async")] fn append_datagram_roundtrip() { From 0c9406f677cfc83f6203fc99a320cac4e12ff56c Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Wed, 21 Oct 2026 22:47:32 -0700 Subject: [PATCH 03/12] style: rustfmt Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/model/track.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rs/moq-net/src/model/track.rs b/rs/moq-net/src/model/track.rs index 968b4739c5e..92b529d415c 100644 --- a/rs/moq-net/src/model/track.rs +++ b/rs/moq-net/src/model/track.rs @@ -988,7 +988,8 @@ impl TrackState { /// is only what an ended feed left: a start taken then waits, as on an empty track. fn latest_live(&self) -> Option { let floor = self.live_floor.unwrap_or(0); - self.newest_produced.filter(|&newest| self.readable() && newest >= floor) + self.newest_produced + .filter(|&newest| self.readable() && newest >= floor) } /// Where a relative start that waited on [`Self::latest_live`] counts back from. From 2a408200d5cddbb90a234c86053e448d5d711753 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 22 Oct 2026 08:21:14 -0700 Subject: [PATCH 04/12] quest(m1): settle track-live into the passthrough markers Co-Authored-By: Claude Opus 5.5 --- quest/m1/README.md | 2 +- quest/m1/track-live.md | 50 +++++++++++++++++++++--------------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/quest/m1/README.md b/quest/m1/README.md index c46e8eec290..0c5ecc15136 100644 --- a/quest/m1/README.md +++ b/quest/m1/README.md @@ -104,7 +104,7 @@ lite-07 stream type here. - [WebGPU on Safari](/quest/m1/webgpu-safari.md) - the WebGPU renderer is verified on Safari 26 for macOS and iOS - [Interop finish](/quest/m1/interop-finish.md) - the interop matrix proves a clean broadcast finish across implementations - [Exporters follow a rendition to a new track](/quest/m1/export-rendition-rebind.md) - the fMP4, TS, MKV and FLV exporters rebuild a rendition whose resolved `track` or `broadcast` changes under the same ID -- [Track live signal](/quest/m1/track-live.md) - a reader can wait for its track's feed to be live, so a player skips old cached groups while a fresh upstream subscription starts +- [Live edge passthrough](/quest/m1/track-live.md) - the publishers' live-edge reads carry `private: passthrough` markers once public serving lands - [moq-net compiles once](/quest/m1/net-erase-transport.md) - the session drivers stop monomorphizing per transport and per crate, saving several MiB of the relay, FFI library, `libmoq` and CLI - [Audio devices on ARM](/quest/m1/audio-devices-arm.md) - `just rs audio-devices` passes on the hosted ARM runner - [CI housekeeping](/quest/m1/ci-housekeeping.md) - validate queue nextest at 24 threads and remove the actionlint queue ignore after its release diff --git a/quest/m1/track-live.md b/quest/m1/track-live.md index f5c5532e5d9..9e0dd948279 100644 --- a/quest/m1/track-live.md +++ b/quest/m1/track-live.md @@ -1,31 +1,31 @@ -# [M] A reader can tell when its track is live +# [XS] Mark the publishers' live edge as passthrough ## Goal -A track reader in moq-net and `@moq/net` can wait for, and check, whether its -track's feed is live: a local producer from the start, a relay's copy once its -upstream subscription answers. A player uses it to skip the old cached groups -a warm copy serves while it waits for a fresh upstream subscription, instead -of rendering them. +The built-in publishers' live-edge reads stay private and carry +`// private: passthrough` instead of a `pending` marker naming this quest: +`track::Subscriber::poll_live` and `latest_sequence` on +`track::{Producer,Consumer,Subscriber}` in Rust, and `wire.ts` +`Broadcast.largest`, `hooks.latestSequence`, and `hooks.bufferedLargest` in JS. +`sh/rs/model-markers.py` passes with no marker naming this quest. ## Plan -`largest()` already waits for live internally (#5924), so it never reports -what an ended feed left; this quest makes the signal itself public. - -- Rust has the state: `TrackState::feed` (`Live`, `Idle`, `Answered`) and - `readable()` in `rs/moq-net/src/model/track.rs`, the crate-private - `resume` `poll_live`, and the crate-private `Producer::is_live`. Expose one - reader-side `poll_live`/`live()` (or `is_live`) on `track::Subscriber` and - `track::Ordered`, and decide whether the publishers' crate-private - `poll_live` folds into it (see - [Public serving](/quest/m1/public-model/serve.md)). -- JS has no equivalent: a track never goes idle, so its reader is live from - the start. Mirror the name, and the idle state if JS gains warm copies. -- Decide what a reader does with groups served before live: keep serving - them (today) and let the caller skip by the signal, or offer a mode that - starts at the live edge. - -## Related - -- [Public serving](/quest/m1/public-model/serve.md) - the publishers' `poll_live` and the `largest()` decision +Settled by the maintainer on 2026-10-22 (moq-dev/moq#6278): + +- ✅ No public live signal. A reader gets nothing from an idle copy's cache + until the route's answer shows, `Range::live()` and other relative starts + resolve against the live feed rather than what an ended feed left (#6278), + and `largest()` waits out an idle copy (#5924). +- ✅ The publishers' buffered edge stays private as passthrough: it is a + wire-answer detail (SUBSCRIBE_OK, TRACK_STATUS Largest), and a custom + publisher answers with `largest()`. +- ✅ Groups cached before live are never served while idle; once live, a + reader gets what its ranges and max delay hold, as on a cold relay. + +Public serving re-marks these items as pending on this quest, so apply the +markers once it lands. + +## Required + +- [Public serving](/quest/m1/public-model/serve.md) - moves the publishers' live-edge markers onto this quest From ab0344c1f0ae82e7e0581cc081ccb30827e107aa Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 22 Oct 2026 08:22:57 -0700 Subject: [PATCH 05/12] fix(net): an idle copy's unreached end does not make its cache readable Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/model/track.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/rs/moq-net/src/model/track.rs b/rs/moq-net/src/model/track.rs index 92b529d415c..75f99d4dfbd 100644 --- a/rs/moq-net/src/model/track.rs +++ b/rs/moq-net/src/model/track.rs @@ -978,9 +978,10 @@ impl TrackState { /// The cached producer rather than a consumer: `consume` reads the clock and can /// take the group's own lock, which the caller does once the track guard is gone. /// Whether readers may take from the cache: it reflects the live feed, or the track - /// ended, which makes the cache the whole of it. + /// reached its end, which makes the cache the whole of it. An end declared but not + /// reached does not: the groups before it are still to come from the feed. fn readable(&self) -> bool { - self.feed == Feed::Live || self.sealed || self.end.is_some() || self.abort.is_some() + self.feed == Feed::Live || self.sealed || self.abort.is_some() || self.is_complete() } /// Where relative starts count back from: the newest group the live feed produced. @@ -8094,6 +8095,24 @@ mod test { assert_eq!(reader.floor(), Some(7)); } + /// An end the idle copy has not reached does not make its cache the whole track: until + /// the route answers, it serves nothing and anchors no relative start. + #[test] + fn an_idle_copy_with_a_future_end_waits_for_the_live_feed() { + let mut producer = idle_copy(); + producer.finish_at(Position::group(10)).unwrap(); + let mut live = producer.subscribe(replay().with_ranges([Range::live()])); + let mut oldest = producer.subscribe(replay()); + assert_eq!(ready_groups(&mut live), Vec::::new(), "the copy is idle"); + assert_eq!(live.floor(), None, "the start waits for the live feed"); + assert_eq!(ready_groups(&mut oldest), Vec::::new(), "the copy is idle"); + + producer.set_live(Some(Position::group(4)), None); + framed(&producer, 4, 1).finish().unwrap(); + assert_eq!(ready_groups(&mut live), vec![4]); + assert_eq!(ready_groups(&mut oldest), vec![0, 1, 2, 3, 4]); + } + #[test] #[cfg(feature = "async")] fn append_datagram_roundtrip() { From 10b5e8ed0b62d1bdd9da48d72c75f99f9b6aff17 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 22 Oct 2026 09:02:05 -0700 Subject: [PATCH 06/12] fix(net): a relative start counts from a datagram that shows the route's answer Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/model/track.rs | 37 +++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/rs/moq-net/src/model/track.rs b/rs/moq-net/src/model/track.rs index 75f99d4dfbd..3e4c8b2658d 100644 --- a/rs/moq-net/src/model/track.rs +++ b/rs/moq-net/src/model/track.rs @@ -470,6 +470,9 @@ pub(crate) struct TrackState { // Readers start at this group: the route's live feed starts past a gap after // everything cached, so nothing bounds how old the cache below it is. live_floor: Option, + // The group the route last answered with, which its datagrams can show before any + // group reaches it: relative starts count back from it until a newer group arrives. + live_edge: Option, // The newest group cached when the track went idle: what the route's answer is // judged against, whatever lands before it. #[cfg_attr(not(feature = "async"), allow(dead_code))] @@ -984,13 +987,15 @@ impl TrackState { self.feed == Feed::Live || self.sealed || self.abort.is_some() || self.is_complete() } - /// Where relative starts count back from: the newest group the live feed produced. - /// `None` while the cache does not reflect the feed, since an idle copy's newest group - /// is only what an ended feed left: a start taken then waits, as on an empty track. + /// Where relative starts count back from: the live feed's newest group, produced or + /// answered. `None` while the cache does not reflect the feed, since an idle copy's + /// newest group is only what an ended feed left: a start taken then waits, as on an + /// empty track. fn latest_live(&self) -> Option { let floor = self.live_floor.unwrap_or(0); self.newest_produced - .filter(|&newest| self.readable() && newest >= floor) + .max(self.live_edge) + .filter(|&latest| self.readable() && latest >= floor) } /// Where a relative start that waited on [`Self::latest_live`] counts back from. @@ -2347,6 +2352,7 @@ impl TrackState { (None, Some(cached)) => Some(cached.saturating_add(1)), _ => self.live_floor, }; + self.live_edge = largest.map(|largest| largest.group); match largest { Some(largest) if !self.shows(largest.group) => self.feed = Feed::Answered { from: largest.group }, _ => self.go_live(), @@ -8113,6 +8119,29 @@ mod test { assert_eq!(ready_groups(&mut oldest), vec![0, 1, 2, 3, 4]); } + /// A datagram can show the route's answer before any group does, as it does when a + /// datagram is the first thing the resumed feed sends. A relative start counts back + /// from that answer, not from the older groups cached below it. + #[test] + #[cfg(feature = "async")] + fn a_relative_start_on_an_idle_copy_counts_from_a_datagram_edge() { + let mut producer = idle_copy(); + let mut reader = producer.subscribe(replay().with_ranges([Range::live()])); + producer + .insert_datagram(4, None, bytes::Bytes::from_static(b"x")) + .unwrap(); + producer.set_live(Some(Position::group(4)), None); + assert_eq!( + ready_groups(&mut reader), + Vec::::new(), + "no group reached the edge" + ); + assert_eq!(reader.floor(), Some(4), "the answer anchors the start"); + + framed(&producer, 5, 1).finish().unwrap(); + assert_eq!(ready_groups(&mut reader), vec![5]); + } + #[test] #[cfg(feature = "async")] fn append_datagram_roundtrip() { From 1dcb6c23a3afcbcc3b92a58d46292be1c5f210b4 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 22 Oct 2026 09:16:42 -0700 Subject: [PATCH 07/12] fix(net): an idle copy that ends anchors a waiting relative start at its newest group Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/model/track.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/rs/moq-net/src/model/track.rs b/rs/moq-net/src/model/track.rs index 3e4c8b2658d..d4590ab875d 100644 --- a/rs/moq-net/src/model/track.rs +++ b/rs/moq-net/src/model/track.rs @@ -998,9 +998,14 @@ impl TrackState { .filter(|&latest| self.readable() && latest >= floor) } - /// Where a relative start that waited on [`Self::latest_live`] counts back from. + /// Where a relative start that waited on [`Self::latest_live`] counts back from. An idle + /// copy that ended without going live counts from its newest group, which its cache now + /// holds the whole of, and not from where an earlier feed began. fn first_live(&self) -> Option { - self.first_live.filter(|_| self.readable()) + match self.feed { + Feed::Live => self.first_live, + _ => self.latest_live(), + } } /// The cache reflects the live feed again: a relative start that waited counts back @@ -8119,6 +8124,19 @@ mod test { assert_eq!(ready_groups(&mut oldest), vec![0, 1, 2, 3, 4]); } + /// An idle copy that ends without going live makes its cache the whole track, so a + /// relative start that waited counts back from its newest group, not from where the + /// earlier feed began. + #[test] + fn a_relative_start_on_an_idle_copy_that_ends_counts_from_its_newest_group() { + let producer = idle_copy(); + let mut reader = producer.subscribe(replay().with_ranges([Range::live()])); + assert_eq!(ready_groups(&mut reader), Vec::::new(), "the copy is idle"); + + producer.finish().unwrap(); + assert_eq!(ready_groups(&mut reader), vec![3]); + } + /// A datagram can show the route's answer before any group does, as it does when a /// datagram is the first thing the resumed feed sends. A relative start counts back /// from that answer, not from the older groups cached below it. From 61dbf91aaceb1a85a5def46a1199505666bb56b9 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 22 Oct 2026 10:04:41 -0700 Subject: [PATCH 08/12] quest(m1): track-live is ready once #6138 merged Co-Authored-By: Claude Opus 5.5 --- quest/m1/track-live.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/quest/m1/track-live.md b/quest/m1/track-live.md index 9e0dd948279..47627c0efeb 100644 --- a/quest/m1/track-live.md +++ b/quest/m1/track-live.md @@ -11,6 +11,8 @@ The built-in publishers' live-edge reads stay private and carry ## Plan +Decided 2026-10-22 (maintainer): ready now. [moq-dev/moq#6138](https://github.com/moq-dev/moq/pull/6138) merged; Public serving lives on only for its own leftover, which this quest does not wait for. + Settled by the maintainer on 2026-10-22 (moq-dev/moq#6278): - ✅ No public live signal. A reader gets nothing from an idle copy's cache From 1b518194a0bbad02a1596d427f72242f3f2295ed Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 22 Oct 2026 10:04:57 -0700 Subject: [PATCH 09/12] quest(m1): drop track-live's Required on Public serving Co-Authored-By: Claude Opus 5.5 --- quest/m1/track-live.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/quest/m1/track-live.md b/quest/m1/track-live.md index 47627c0efeb..56e555d51b8 100644 --- a/quest/m1/track-live.md +++ b/quest/m1/track-live.md @@ -25,9 +25,8 @@ Settled by the maintainer on 2026-10-22 (moq-dev/moq#6278): - ✅ Groups cached before live are never served while idle; once live, a reader gets what its ranges and max delay hold, as on a cold relay. -Public serving re-marks these items as pending on this quest, so apply the -markers once it lands. +Public serving ([moq-dev/moq#6138](https://github.com/moq-dev/moq/pull/6138), merged) re-marked these items as pending on this quest, so apply the markers now. -## Required +## Related -- [Public serving](/quest/m1/public-model/serve.md) - moves the publishers' live-edge markers onto this quest +- [Public serving](/quest/m1/public-model/serve.md) - moved the publishers' live-edge markers onto this quest From 839aff779e09ecc2be51babe2b0f08f82170e2ee Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 22 Oct 2026 13:39:21 -0700 Subject: [PATCH 10/12] quest(m1): track-live waits for #6138 to merge Co-Authored-By: Claude Opus 5.5 --- quest/m1/track-live.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/quest/m1/track-live.md b/quest/m1/track-live.md index 56e555d51b8..582b8b08b05 100644 --- a/quest/m1/track-live.md +++ b/quest/m1/track-live.md @@ -11,7 +11,7 @@ The built-in publishers' live-edge reads stay private and carry ## Plan -Decided 2026-10-22 (maintainer): ready now. [moq-dev/moq#6138](https://github.com/moq-dev/moq/pull/6138) merged; Public serving lives on only for its own leftover, which this quest does not wait for. +Waits for [moq-dev/moq#6138](https://github.com/moq-dev/moq/pull/6138) (public serving cursor) to merge, then applies the markers. Public serving lives on after that only for its own leftover, which this quest does not wait for. Settled by the maintainer on 2026-10-22 (moq-dev/moq#6278): @@ -25,8 +25,8 @@ Settled by the maintainer on 2026-10-22 (moq-dev/moq#6278): - ✅ Groups cached before live are never served while idle; once live, a reader gets what its ranges and max delay hold, as on a cold relay. -Public serving ([moq-dev/moq#6138](https://github.com/moq-dev/moq/pull/6138), merged) re-marked these items as pending on this quest, so apply the markers now. +Public serving ([moq-dev/moq#6138](https://github.com/moq-dev/moq/pull/6138), still open) re-marks these items as pending on this quest; once it merges, apply the markers. ## Related -- [Public serving](/quest/m1/public-model/serve.md) - moved the publishers' live-edge markers onto this quest +- [Public serving](/quest/m1/public-model/serve.md) - moves the publishers' live-edge markers onto this quest From 1691f620cd931dda9d5d4535e371543796105db4 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 23 Oct 2026 11:34:22 -0700 Subject: [PATCH 11/12] fix(net): an idle copy forgets its ended feed's datagram edge Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/model/track.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/rs/moq-net/src/model/track.rs b/rs/moq-net/src/model/track.rs index 3df5bbe4591..9716b78a1cc 100644 --- a/rs/moq-net/src/model/track.rs +++ b/rs/moq-net/src/model/track.rs @@ -2344,6 +2344,8 @@ impl TrackState { #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] fn set_idle(&mut self) { self.feed = Feed::Idle; + // The ended feed's answer: an idle copy that ends counts from what it cached. + self.live_edge = None; self.idle_newest = self .lookup .iter() @@ -8390,6 +8392,24 @@ mod test { assert_eq!(ready_groups(&mut reader), vec![5]); } + /// An idle copy forgets the edge its previous feed answered with, which only a datagram + /// it dropped showed: when it ends without going live, a relative start counts back + /// from its newest cached group. + #[test] + #[cfg(feature = "async")] + fn an_idle_copy_that_ends_forgets_an_earlier_datagram_edge() { + let mut producer = idle_copy(); + producer + .insert_datagram(4, None, bytes::Bytes::from_static(b"x")) + .unwrap(); + producer.set_live(Some(Position::group(4)), None); + producer.set_idle(); + let mut reader = producer.subscribe(replay().with_ranges([Range::live()])); + assert_eq!(ready_groups(&mut reader), Vec::::new(), "the copy is idle"); + producer.finish().unwrap(); + assert_eq!(ready_groups(&mut reader), vec![3]); + } + #[test] #[cfg(feature = "async")] fn append_datagram_roundtrip() { From df61b64643db8d90664071689fdde15b27a4d47a Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 23 Oct 2026 11:50:04 -0700 Subject: [PATCH 12/12] refactor(net): keep each feed's anchors inside its Feed state The live feed's first group and answered edge, and the idle copy's newest group, now live in the Feed variant that set them, so a later feed state cannot read an ended feed's answer. Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/model/track.rs | 110 +++++++++++++++++++++------------- 1 file changed, 68 insertions(+), 42 deletions(-) diff --git a/rs/moq-net/src/model/track.rs b/rs/moq-net/src/model/track.rs index 9716b78a1cc..441ac387503 100644 --- a/rs/moq-net/src/model/track.rs +++ b/rs/moq-net/src/model/track.rs @@ -287,22 +287,50 @@ impl Sequence { } } -/// Whether a track's cache reflects its live feed; see [`TrackState::set_idle`]. -#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +/// Whether a track's cache reflects its live feed; see [`TrackState::set_idle`]. Each +/// state holds what only that feed knows, so nothing an ended feed set outlives it. +#[derive(Clone, Copy, Debug)] enum Feed { /// Readers take from the cache. - #[default] - Live, + Live { + /// Where a relative start taken before the feed produced anything counts back + /// from: the newest group when it went live, or else the first it produced since. + /// Kept after the group is evicted. + first: Option, + /// The group the route answered with, which its datagrams can show before any + /// group reaches it: relative starts count back from it until a newer group + /// arrives. + edge: Option, + }, /// The upstream subscription ended with the copy still held, so how stale the cache /// is cannot be told until the route answers again. #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] - Idle, + Idle { + /// The newest group cached when the track went idle: what the route's answer is + /// judged against, whatever lands before it. + newest: Option, + }, /// The route answered that its feed reaches group `from`, which the cache cannot show /// yet: until it can, the newest group cached would read as the live edge. #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] Answered { from: u64 }, } +impl Default for Feed { + fn default() -> Self { + Self::Live { + first: None, + edge: None, + } + } +} + +impl Feed { + fn is_live(&self) -> bool { + matches!(self, Self::Live { .. }) + } +} + #[derive(Default)] // pending: /quest/m1/public-model/deferred.md pub(crate) struct TrackState { @@ -376,10 +404,6 @@ pub(crate) struct TrackState { // The newest group the publisher produced, which fetched backfill never moves: where // relative starts count back from (see `latest_live`). newest_produced: Option, - // Where a relative start taken before the live feed produced anything counts back - // from: the newest group when the feed went live, or else the first it produced - // since. Kept after the group is evicted. - first_live: Option, // The name's sequence namespace within the broadcast, which can run past this track's // `max_sequence` when an earlier producer of the name wrote further. @@ -466,13 +490,6 @@ pub(crate) struct TrackState { // Readers start at this group: the route's live feed starts past a gap after // everything cached, so nothing bounds how old the cache below it is. live_floor: Option, - // The group the route last answered with, which its datagrams can show before any - // group reaches it: relative starts count back from it until a newer group arrives. - live_edge: Option, - // The newest group cached when the track went idle: what the route's answer is - // judged against, whatever lands before it. - #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] - idle_newest: Option, // Where production stopped, snapshotted when the open groups are released (an // abort, or the last producer dropping). Computed live from the cache otherwise; @@ -973,17 +990,21 @@ impl TrackState { /// reached its end, which makes the cache the whole of it. An end declared but not /// reached does not: the groups before it are still to come from the feed. fn readable(&self) -> bool { - self.feed == Feed::Live || self.sealed || self.abort.is_some() || self.is_complete() + self.feed.is_live() || self.sealed || self.abort.is_some() || self.is_complete() } /// Where relative starts count back from: the live feed's newest group, produced or /// answered. `None` while the cache does not reflect the feed, since an idle copy's /// newest group is only what an ended feed left: a start taken then waits, as on an - /// empty track. + /// empty track. An idle copy that ends counts from its newest cached group. fn latest_live(&self) -> Option { + let edge = match self.feed { + Feed::Live { edge, .. } => edge, + _ => None, + }; let floor = self.live_floor.unwrap_or(0); self.newest_produced - .max(self.live_edge) + .max(edge) .filter(|&latest| self.readable() && latest >= floor) } @@ -992,16 +1013,19 @@ impl TrackState { /// holds the whole of, and not from where an earlier feed began. fn first_live(&self) -> Option { match self.feed { - Feed::Live => self.first_live, + Feed::Live { first, .. } => first, _ => self.latest_live(), } } - /// The cache reflects the live feed again: a relative start that waited counts back - /// from its newest group now. - fn go_live(&mut self) { - self.feed = Feed::Live; - self.first_live = self.latest_live(); + /// The cache reflects the live feed again, which reaches `edge` if the route named it: + /// a relative start that waited counts back from its newest group now. + fn go_live(&mut self, edge: Option) { + self.feed = Feed::Live { first: None, edge }; + self.feed = Feed::Live { + first: self.latest_live(), + edge, + }; } /// Find the next live group at or after `index` in arrival order. @@ -1845,7 +1869,9 @@ impl TrackState { self.latest_group = Some(sequence); } if visible { - self.first_live.get_or_insert(sequence); + if let Feed::Live { first, .. } = &mut self.feed { + first.get_or_insert(sequence); + } self.newest_produced = self.newest_produced.max(Some(sequence)); } if !self.protects(sequence) { @@ -1927,7 +1953,7 @@ impl TrackState { if let Feed::Answered { from } = self.feed && sequence >= from { - self.go_live(); + self.go_live(Some(from)); } } @@ -2343,15 +2369,13 @@ impl TrackState { /// datagrams go too, since a reader returning later must not be handed them. #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] fn set_idle(&mut self) { - self.feed = Feed::Idle; - // The ended feed's answer: an idle copy that ends counts from what it cached. - self.live_edge = None; - self.idle_newest = self + let newest = self .lookup .iter() .rev() .find(|(_, slot)| slot.is_shown()) .map(|(sequence, _)| *sequence); + self.feed = Feed::Idle { newest }; self.datagram_offset += self.datagrams.len(); self.datagrams.clear(); // An open group stops because this copy dropped its feed, not because the publisher @@ -2378,12 +2402,12 @@ impl TrackState { /// read as the live edge, though the route already holds a newer one. #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] fn set_live(&mut self, largest: Option, start: Option) { - if self.feed != Feed::Idle { + let Feed::Idle { newest } = self.feed else { return; - } + }; // Judged by what survived: the cancel that idled the copy resets the group in flight, // and an answer past it leaves a gap after the newest group still cached. - let cached = self.idle_newest.take().and_then(|newest| { + let cached = newest.and_then(|newest| { self.lookup .range(..=newest) .rev() @@ -2399,10 +2423,9 @@ impl TrackState { (None, Some(cached)) => Some(cached.saturating_add(1)), _ => self.live_floor, }; - self.live_edge = largest.map(|largest| largest.group); - match largest { - Some(largest) if !self.shows(largest.group) => self.feed = Feed::Answered { from: largest.group }, - _ => self.go_live(), + match largest.map(|largest| largest.group) { + Some(from) if !self.shows(from) => self.feed = Feed::Answered { from }, + edge => self.go_live(edge), } } @@ -2613,7 +2636,7 @@ fn poll_largest( /// end that is not reached yet does not count: an idle copy's largest is still only what /// its ended feed left. fn largest_live(state: &TrackState, waiter: &kio::Waiter) -> Poll<()> { - match state.feed == Feed::Live || state.sealed || state.abort.is_some() || state.largest_settled() { + match state.feed.is_live() || state.sealed || state.abort.is_some() || state.largest_settled() { true => Poll::Ready(()), false => { state.watch_tail(waiter); @@ -3108,7 +3131,7 @@ impl Producer { #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] // private: capability gap pub(crate) fn is_live(&self) -> bool { - self.state.read().feed == Feed::Live + self.state.read().feed.is_live() } /// While idle, the newest group cached when the track went idle: a route asked from @@ -3117,7 +3140,10 @@ impl Producer { // private: capability gap pub(crate) fn idle_newest(&self) -> Option { let state = self.state.read(); - state.idle_newest.filter(|_| state.feed == Feed::Idle) + match state.feed { + Feed::Idle { newest } => newest, + _ => None, + } } /// [`Request::request_start`] for a copy already accepted, which a held copy's next @@ -4533,7 +4559,7 @@ impl Consumer { self.with_state(|state| { state.is_some_and(|state| { let state = state.read(); - state.routes.is_none() && state.published && !state.closed && state.feed == Feed::Live + state.routes.is_none() && state.published && !state.closed && state.feed.is_live() }) }) }