From 044ab7d7b0c1e3c236431024b369f4427fb0fc8b Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 19 Nov 2026 05:00:13 -0800 Subject: [PATCH 01/15] chore(quest): claim quest/m2/multicast/roll-echo-stall.md Quest-Claim: a31a1e0969a7366d From 6e35acdb4809eafe20c4b9d5d201fee6c9cf734f Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 19 Nov 2026 04:09:23 -0800 Subject: [PATCH 02/15] fix(moq-net): a time start a shared lite-07 copy already covers is placed A relay's copy asked from the oldest group for one reader adds no range for a later reader's earlier time start, so the publisher never reports where one starts, and the copy waited for it forever: a lite-06 subscriber resuming onto the relay mid-roll read nothing until the track ended. A range asked from the oldest group now counts as asked from time 0, and any range asked from at or before a time that the publisher started past it places that time. Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/lite/subscriber.rs | 5 +- rs/moq-net/src/model/track.rs | 60 +++++++++- rs/moq-net/tests/integration/main.rs | 1 + .../tests/integration/shared_copy_start.rs | 105 ++++++++++++++++++ 4 files changed, 164 insertions(+), 7 deletions(-) create mode 100644 rs/moq-net/tests/integration/shared_copy_start.rs diff --git a/rs/moq-net/src/lite/subscriber.rs b/rs/moq-net/src/lite/subscriber.rs index 4abb3ca4f1..02babe6a33 100644 --- a/rs/moq-net/src/lite/subscriber.rs +++ b/rs/moq-net/src/lite/subscriber.rs @@ -10144,7 +10144,9 @@ impl SubStream { /// Tell the copy where the publisher started each live range: one asked from a group's /// start, which a reader's time start there resolves to when the copy holds no group at /// it, and one counting back, which the copy, holding only part of the track, can't count. - /// Lite-07 only, where each range's start is reported. + /// One asked from the oldest group counts as asked from time 0, so its start places any + /// earlier time start a reader joining it asks. Lite-07 only, where each range's start is + /// reported. fn report_starts(&self, serving: &track::Producer) { if !self.live.reports_starts() { return; @@ -10157,6 +10159,7 @@ impl SubStream { }; match range.start { Some(lite::Anchor::Absolute(time)) if time.frame == 0 => times.push((time.group, *start)), + None => times.push((0, *start)), Some(lite::Anchor::Relative(back)) => { if let Some(Some(latest)) = self.edges.get(&id) { relative.push((back, *start, *latest)); diff --git a/rs/moq-net/src/model/track.rs b/rs/moq-net/src/model/track.rs index 416e8fb28a..17fe944481 100644 --- a/rs/moq-net/src/model/track.rs +++ b/rs/moq-net/src/model/track.rs @@ -1227,16 +1227,24 @@ impl TrackState { /// or where the publisher reports starting the range it asked from `time`. A group past /// it says the feed went by: one between still in flight, a stream overtaken, would /// only add that group to the reader's range. + /// + /// A range asked from an earlier time, or from the oldest group (reported as time 0), + /// that the publisher started past `time` says the same: no group starts at or before + /// it. A reader joining a copy that another reader already asks from further back adds + /// no range of its own, so that is the only report its time start gets. fn containing_received(&self, time: u64) -> Containing { if self.lookup.contains_key(&time) { return Containing::Group(time); } - match self.time_starts.get(&time) { - Some(&start) if start <= time => return Containing::Group(start), - // The publisher serves nothing at or before it, as it does for a time older than - // every group it holds. - Some(_) => return Containing::Before, - None => {} + if let Some(&start) = self.time_starts.get(&time) + && start <= time + { + return Containing::Group(start); + } + // The publisher serves nothing at or before it, as it does for a time older than + // every group it holds. Bounded by the copy's live wire ranges. + if self.time_starts.range(..=time).any(|(_, &start)| start > time) { + return Containing::Before; } match self.lookup.range(..=time).next_back() { Some((&key, _)) @@ -15447,6 +15455,46 @@ mod test { assert_eq!(drain(&mut past), vec![1000, 3000]); } + /// A reader joining a lite-07 copy that another reader already asks from further back adds + /// no range of its own, so its publisher reports no start for the reader's time. The start + /// of a range asked from earlier, or from the oldest group, places it: past the time, no + /// group starts at or before it, and a publisher serving the reader learns where delivery + /// starts. At or before the time, a group between may still arrive. + #[test] + #[cfg(feature = "async")] + fn a_received_copy_places_a_time_start_by_an_earlier_range() { + let from = |time| { + Subscription::default() + .with_ranges([Range { + start: Anchor::Time(time), + end: None, + }]) + .with_delay(Delay::default().with_max(None)) + }; + let placed = + |subscriber: &mut Subscriber| subscriber.resolved()[0].map(|resolved| (resolved.start, resolved.floored)); + let producer = track_producer("test", Info::timed()); + producer.received(); + producer.anchored(); + write_group(&producer, 1000); + + let mut before = producer.subscribe(from(500)); + let mut after = producer.subscribe(from(1500)); + assert_eq!(placed(&mut before), None); + assert!(before.poll_start(&kio::Waiter::noop()).is_pending()); + + // Only a range asked from a later time: says nothing of 500. + producer.time_starts([(700, 1000)]); + assert_eq!(placed(&mut before), None); + + // The range asked from the oldest group started at 1000. + producer.time_starts([(0, 1000)]); + assert_eq!(placed(&mut before), Some((0, false))); + assert!(before.poll_start(&kio::Waiter::noop()).is_ready()); + assert_eq!(drain(&mut before), vec![1000]); + assert_eq!(placed(&mut after), None, "a group past 1000 may still arrive"); + } + /// A lite-07 copy holds only part of the track, so a relative start counts back as its /// publisher reported, not over the groups the copy holds, until a group past the latest /// the publisher counted from moves the live edge. diff --git a/rs/moq-net/tests/integration/main.rs b/rs/moq-net/tests/integration/main.rs index 48b3485359..67fccffef8 100644 --- a/rs/moq-net/tests/integration/main.rs +++ b/rs/moq-net/tests/integration/main.rs @@ -83,6 +83,7 @@ mod session_close; mod session_panic; mod settled_end_survives_abort; mod setup_negotiation; +mod shared_copy_start; mod slow_joiner; mod source_errors; mod stream_credit; diff --git a/rs/moq-net/tests/integration/shared_copy_start.rs b/rs/moq-net/tests/integration/shared_copy_start.rs new file mode 100644 index 0000000000..7ea56ee754 --- /dev/null +++ b/rs/moq-net/tests/integration/shared_copy_start.rs @@ -0,0 +1,105 @@ +#![cfg(feature = "async")] + +//! A relay's subscriber asking from a time before the copy it joins is fed. +//! +//! The relay pulls the track over lite-07 for a reader of its own, from the oldest group +//! its budget keeps, so its copy starts at the live edge. A downstream peer then subscribes +//! from an earlier group, as an older relay resuming onto this one does, after the publisher +//! expired everything there. Its range adds nothing to what the copy already asks, so the +//! publisher never reports where a range from that time starts, and the group containing +//! it never arrives: the subscription must still start, at the oldest group the copy holds. + +use std::time::Duration; + +use moq_net::track::{Anchor, Delay, Info, Range, Subscription}; +use moq_net::{Timescale, Timestamp, Version, origin}; + +use crate::route_change::{link, produce_origin, settle}; + +const TIMEOUT: Duration = Duration::from_secs(10); + +/// One group every 100ms, keyed by its start in milliseconds. +const STEP: u64 = 100; + +fn write(track: &moq_net::track::Producer, key: u64) { + let mut group = track.create_group(moq_net::group::Info { start: key }).unwrap(); + group + .write_frame(Timestamp::from_millis(key).unwrap(), &b"x"[..]) + .unwrap(); + group.finish().unwrap(); +} + +/// Write the groups `keys` in real time. +async fn play(track: &moq_net::track::Producer, keys: std::ops::Range) { + for key in keys.step_by(STEP as usize) { + write(track, key); + kio::clock::sleep(Duration::from_millis(STEP)).await; + } +} + +/// The groups a downstream subscriber over `version` reads when it asks from 500, long +/// expired at the publisher, while the relay's own reader already holds the copy. +async fn read_from_expired(version: &str) -> Vec { + let publisher = produce_origin(1); + let relay = produce_origin(2); + let downstream = produce_origin(3); + + let broadcast = publisher.route("live", origin::RouteOptions::hidden()).unwrap(); + let track = broadcast + .broadcast() + .create_track( + "video", + Info::default() + .with_timescale(Timescale::MILLI) + .with_max_age(Some(Duration::from_millis(500))), + ) + .unwrap(); + broadcast.announce().unwrap(); + play(&track, 0..1000).await; + + // The relay's own reader pulls the copy from the live edge. + let _up = link("moq-lite-07-wip".parse().unwrap(), &publisher, &relay).await; + let local = kio::clock::timeout(TIMEOUT, relay.consume().follow("live", None).unwrap().available()) + .await + .unwrap() + .unwrap() + .unwrap(); + let _local = local.track("video").unwrap().subscribe(Subscription::default()).await.unwrap(); + play(&track, 1000..2000).await; + + let _down = link(version.parse::().unwrap(), &relay, &downstream).await; + let remote = kio::clock::timeout(TIMEOUT, downstream.consume().follow("live", None).unwrap().available()) + .await + .unwrap() + .unwrap() + .unwrap(); + let subscription = Subscription::default() + .with_delay(Delay::default().with_max(Duration::from_secs(60))) + .with_ranges([Range { + start: Anchor::Time(500), + end: None, + }]); + let mut sub = remote.track("video").unwrap().subscribe(subscription).await.unwrap(); + play(&track, 2000..3000).await; + settle().await; + + let mut read = Vec::new(); + while let Ok(Ok(Some(group))) = kio::clock::timeout(Duration::from_millis(1), sub.recv_group()).await { + read.push(group.start); + } + read.sort_unstable(); + read +} + +#[kio::test] +async fn an_older_start_on_a_shared_copy_is_fed() { + for version in ["moq-lite-06", "moq-lite-07-wip"] { + let read = read_from_expired(version).await; + // Everything from the oldest group the relay still holds, through the live edge. + assert_eq!(read.last(), Some(&2900), "{version}: fed to the live edge, read {read:?}"); + assert!( + read.windows(2).all(|pair| pair[1] - pair[0] == STEP), + "{version}: no gap once started, read {read:?}" + ); + } +} From 56e15bfb9ec9b596001daa8b6d5ce31979d5912b Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 19 Nov 2026 04:51:22 -0800 Subject: [PATCH 03/15] fix(moq-net): a floor at a time start waits on no placing A pre-lite-07 wire's absolute start serves the first group at or after it, so its floor keeps out the group containing the time below it. The publisher still waited for a lite-07 copy to place that group before answering where delivery starts, which a copy whose fills for it were refused as stale never does. Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/model/subscription/window.rs | 11 +++++-- rs/moq-net/src/model/track.rs | 35 +++++++++++++++++++-- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/rs/moq-net/src/model/subscription/window.rs b/rs/moq-net/src/model/subscription/window.rs index 8a48191412..b74db136ce 100644 --- a/rs/moq-net/src/model/subscription/window.rs +++ b/rs/moq-net/src/model/subscription/window.rs @@ -307,9 +307,14 @@ impl Window { !self.reaching.is_empty() } - /// Whether a time start still waits on the groups held to place it. - pub fn is_waiting(&self) -> bool { - !self.waiting.is_empty() + /// Whether a time start still waits on the groups held to place it, where the group + /// containing it may start above `floor`. One at or below the floor needs no placing: the + /// floor already keeps out every group but one starting there, and serves the first group + /// from it either way. + pub fn is_waiting_above(&self, floor: u64) -> bool { + self.waiting + .iter() + .any(|&position| matches!(self.spans[position].anchor, Anchor::Time(time) if time > floor)) } /// Resolve what the groups now held settle: relative anchors once `latest` exists, and diff --git a/rs/moq-net/src/model/track.rs b/rs/moq-net/src/model/track.rs index 17fe944481..ee17e95420 100644 --- a/rs/moq-net/src/model/track.rs +++ b/rs/moq-net/src/model/track.rs @@ -10641,7 +10641,8 @@ impl Subscriber { /// none: groups arrive newest first, so the first to arrive is not the oldest served. /// /// Pending too while a time start waits on the groups held to place it, since where its - /// range starts is unknown until then. + /// range starts is unknown until then, unless the floor sits at or past that time, as a + /// pre-lite-07 wire's start does: the group containing it is out of range then. #[cfg_attr(feature = "async", kio::wrapper)] pub fn poll_start(&mut self, waiter: &kio::Waiter) -> Poll> { let cursor = match &mut self.inner { @@ -10650,12 +10651,12 @@ impl Subscriber { }; let start = ready!(Consumer::poll_state_start(&cursor.state, waiter)); cursor.sync(); - if cursor.filter.window.is_waiting() { + if cursor.filter.window.is_waiting_above(cursor.min_key) { // Registered before syncing again, so a change placing it after this wakes it. A // closed track places it at once, since nothing more can arrive. let closed = cursor.state.poll(waiter, |_| Poll::<()>::Pending).is_ready(); cursor.sync(); - if !closed && cursor.filter.window.is_waiting() { + if !closed && cursor.filter.window.is_waiting_above(cursor.min_key) { return Poll::Pending; } } @@ -15495,6 +15496,34 @@ mod test { assert_eq!(placed(&mut after), None, "a group past 1000 may still arrive"); } + /// A floor at or past a time start, as a pre-lite-07 wire's start sets, keeps out the group + /// containing that time unless it starts there, so where the range starts waits on nothing + /// a lite-07 copy has yet to place. Without the floor, it waits. + #[test] + #[cfg(feature = "async")] + fn a_floor_at_a_time_start_waits_on_no_placing() { + let from = |time| { + Subscription::default() + .with_ranges([Range { + start: Anchor::Time(time), + end: None, + }]) + .with_delay(Delay::default().with_max(None)) + }; + let producer = track_producer("test", Info::timed()); + producer.received(); + producer.anchored(); + write_group(&producer, 1000); + + let mut open = producer.subscribe(from(500)); + assert!(open.poll_start(&kio::Waiter::noop()).is_pending()); + let mut floored = producer.subscribe(from(500)).with_range(500..); + assert!(floored.poll_start(&kio::Waiter::noop()).is_ready()); + let mut below = producer.subscribe(from(500)).with_range(499..); + assert!(below.poll_start(&kio::Waiter::noop()).is_pending()); + assert_eq!(drain(&mut floored), vec![1000]); + } + /// A lite-07 copy holds only part of the track, so a relative start counts back as its /// publisher reported, not over the groups the copy holds, until a group past the latest /// the publisher counted from moves the live edge. From 62dfe66f95e26c7fcc97a6a346b63d3b682e5563 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 19 Nov 2026 05:38:14 -0800 Subject: [PATCH 04/15] fix(moq-net): carry the time start fixes onto main's span map and range API Co-Authored-By: Claude Opus 5.5 --- quest/m2/multicast/roll-echo-stall.md | 59 ------------------- rs/moq-net/src/model/subscription/window.rs | 2 +- rs/moq-net/src/model/track.rs | 5 +- .../tests/integration/shared_copy_start.rs | 13 +++- 4 files changed, 15 insertions(+), 64 deletions(-) delete mode 100644 quest/m2/multicast/roll-echo-stall.md diff --git a/quest/m2/multicast/roll-echo-stall.md b/quest/m2/multicast/roll-echo-stall.md deleted file mode 100644 index 7200a79c1d..0000000000 --- a/quest/m2/multicast/roll-echo-stall.md +++ /dev/null @@ -1,59 +0,0 @@ -# [M] A subscription from an old relay mid-roll is fed - -## Goal - -Mid-roll, a new relay feeds every SUBSCRIBE an old (lite-06) neighbour sends -it, including one that arrives as that neighbour withdraws its own echo of the -broadcast. Today the new relay accepts the subscription and forwards no group -until the broadcast ends, so the old relay's viewers stay subscribed, see the -broadcast live, and read nothing. - -No reader starves in -`just test mesh-replay --mesh test/mesh-replay/ring6.toml --script test/mesh-replay/half-roll.toml --broadcasts 32` -or in the nightly ring meshes' rolls, once `[[known]]` no longer names this -quest in `test/mesh-replay/script.toml`. - -## Plan - -Found by [the mesh replay](/test/mesh-replay/README.md). In the ring of six, -rolling `b` onto the new build starved old relay `c`'s readers of `a`'s -broadcasts in 3 of 4 nightly cells: 9 of 24 paths at 4 broadcasts per relay, -40 and 41 of 192 at 32. Rolls further on starved others the same way. The half -roll alone (`a` and `b`) starved them in 1 of 3 runs at 4 broadcasts. - -What the logs of a chain of three show (`a` dials `b` dials `c`, roll `a` then -`b`), with `b` the new relay and `c` the old one: - -1. `b` restarts on the new build and dials `c`. Its predecessor's session to `c` - is still draining, so the old relay `c` announces `a`'s broadcasts to the new - `b` over lite-06 with three hops, learned through that predecessor: `b` - hears its own stale state echoed back before its link to `a` is up. -2. `b`'s link to `a` comes up a second later. `b` pulls some of `a`'s broadcasts - from `a` for its own reader and for `c`'s first subscribes, and those flow. -3. The predecessor's session to `c` times out (the 10s idle timeout). In one - millisecond, `c` unannounces the echoed broadcasts to `b` and resubscribes - the ones it read through the predecessor, now on the new `b`. -4. `b` logs `subscribed started` for those subscribes and serves nothing until - the publisher stops 50s later, when it serves one group from step 3 and - then the final group. Its own upstream subscription to `a` for the same - broadcasts is live the whole time, feeding `b`'s reader. - -So a lite-06 subscription that resolves while its broadcast's echoed route is -being withdrawn attaches to something that never delivers, and nothing moves -it to the live route. Likely in how the publisher resolves a request against -the origin while a route is withdrawn: the wait for a claim's route -([moq-dev/moq#9052](https://github.com/moq-dev/moq/pull/9052)), or the lite-06 -path's announce handling (hop counts are not checked against loops), in -`rs/moq-net/src/lite/publisher.rs` and `rs/moq-net/src/model/`. Rerun after -[moq-dev/moq#9112](https://github.com/moq-dev/moq/pull/9112), which changes how -a let-go claim's copies end but keeps lite-06 routes as they are. Run with -`HARNESS_KEEP=1 MESH_REPLAY_LOG=debug` to keep every relay's debug log. - -Decided 2026-11-19 (coordinator, to which the maintainer delegated the call -while away): ✅ the lite-07 cut waits on it (rejected: cutting without it). -It needs an old relay, so it lasts only as long as a roll does, but every roll -passes through it, once per relay, and a starved viewer sees a live broadcast -that never plays; letting a deployment roll lite-07 out safely is the reason -for the cut. - -Not a wire change. diff --git a/rs/moq-net/src/model/subscription/window.rs b/rs/moq-net/src/model/subscription/window.rs index b74db136ce..de8219d504 100644 --- a/rs/moq-net/src/model/subscription/window.rs +++ b/rs/moq-net/src/model/subscription/window.rs @@ -314,7 +314,7 @@ impl Window { pub fn is_waiting_above(&self, floor: u64) -> bool { self.waiting .iter() - .any(|&position| matches!(self.spans[position].anchor, Anchor::Time(time) if time > floor)) + .any(|&position| matches!(self.spans[&position].anchor, Anchor::Time(time) if time > floor)) } /// Resolve what the groups now held settle: relative anchors once `latest` exists, and diff --git a/rs/moq-net/src/model/track.rs b/rs/moq-net/src/model/track.rs index ee17e95420..258f8f71bf 100644 --- a/rs/moq-net/src/model/track.rs +++ b/rs/moq-net/src/model/track.rs @@ -15472,8 +15472,9 @@ mod test { }]) .with_delay(Delay::default().with_max(None)) }; - let placed = - |subscriber: &mut Subscriber| subscriber.resolved()[0].map(|resolved| (resolved.start, resolved.floored)); + let placed = |subscriber: &mut Subscriber| { + subscriber.resolved_ranges()[0].map(|resolved| (resolved.start, resolved.floored)) + }; let producer = track_producer("test", Info::timed()); producer.received(); producer.anchored(); diff --git a/rs/moq-net/tests/integration/shared_copy_start.rs b/rs/moq-net/tests/integration/shared_copy_start.rs index 7ea56ee754..40443ffc56 100644 --- a/rs/moq-net/tests/integration/shared_copy_start.rs +++ b/rs/moq-net/tests/integration/shared_copy_start.rs @@ -64,7 +64,12 @@ async fn read_from_expired(version: &str) -> Vec { .unwrap() .unwrap() .unwrap(); - let _local = local.track("video").unwrap().subscribe(Subscription::default()).await.unwrap(); + let _local = local + .track("video") + .unwrap() + .subscribe(Subscription::default()) + .await + .unwrap(); play(&track, 1000..2000).await; let _down = link(version.parse::().unwrap(), &relay, &downstream).await; @@ -96,7 +101,11 @@ async fn an_older_start_on_a_shared_copy_is_fed() { for version in ["moq-lite-06", "moq-lite-07-wip"] { let read = read_from_expired(version).await; // Everything from the oldest group the relay still holds, through the live edge. - assert_eq!(read.last(), Some(&2900), "{version}: fed to the live edge, read {read:?}"); + assert_eq!( + read.last(), + Some(&2900), + "{version}: fed to the live edge, read {read:?}" + ); assert!( read.windows(2).all(|pair| pair[1] - pair[0] == STEP), "{version}: no gap once started, read {read:?}" From 3b1e9224e7a439a432b20d3d04af4173e08edc26 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 19 Nov 2026 05:38:16 -0800 Subject: [PATCH 05/15] chore(quest): finish roll-echo-stall; a roll's starved reader fails the replay again Co-Authored-By: Claude Opus 5.5 --- quest/m2/multicast/README.md | 5 ++--- quest/m2/multicast/reopen-starve.md | 1 - test/mesh-replay/script.toml | 20 ++++++++++++-------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/quest/m2/multicast/README.md b/quest/m2/multicast/README.md index e773589c9b..0b1e7694d4 100644 --- a/quest/m2/multicast/README.md +++ b/quest/m2/multicast/README.md @@ -38,9 +38,8 @@ children, the two flaws it found, [a reader resuming on a detour learned after its session closed](/quest/m2/multicast/detour-resume.md) and [a route moving behind one next hop resending a group](/quest/m2/multicast/resend.md), whose fix changes the wire, -and two flaws the mesh replay found, -[feeding an old relay's subscription mid-roll](/quest/m2/multicast/roll-echo-stall.md) -and [a reader starving after a lite-07 link reopens](/quest/m2/multicast/reopen-starve.md); +and a flaw the mesh replay found, +[a reader starving after a lite-07 link reopens](/quest/m2/multicast/reopen-starve.md); and on [route layer acceptance](/quest/m2/cluster-routes/acceptance.md) retiring the lite-06 mitigations. It does not wait on diff --git a/quest/m2/multicast/reopen-starve.md b/quest/m2/multicast/reopen-starve.md index f080e0ec12..13cd5f2a55 100644 --- a/quest/m2/multicast/reopen-starve.md +++ b/quest/m2/multicast/reopen-starve.md @@ -57,5 +57,4 @@ Not a wire change. ## Related -- [roll-echo-stall](/quest/m2/multicast/roll-echo-stall.md) - the mid-roll starvation, through a lite-06 neighbour - [detour-resume](/quest/m2/multicast/detour-resume.md) - a front that ends, rather than waits, when its session closes before the detour arrives diff --git a/test/mesh-replay/script.toml b/test/mesh-replay/script.toml index 00132c8947..fbce94df71 100644 --- a/test/mesh-replay/script.toml +++ b/test/mesh-replay/script.toml @@ -43,19 +43,23 @@ check = "unfed" kind = "stuck" quest = "/quest/m2/multicast/detour-resume.md" -# Mid-roll, a new relay accepts an old neighbour's subscribe that arrives as the neighbour -# withdraws its echo of the broadcast, then forwards nothing. `half-roll.toml` reproduces it -# and lists nothing known. +# On lite-07 alone, a reader behind a reopened link or a crashed relay starves when its relay +# asked a neighbour whose own route had not returned yet. Not on a roll, so a roll's starved +# reader still fails. `reopen.toml` reproduces it and lists nothing known. [[known]] check = "unfed" kind = "starved" -event = "roll" -quest = "/quest/m2/multicast/roll-echo-stall.md" +event = "reopen-link" +quest = "/quest/m2/multicast/reopen-starve.md" + +[[known]] +check = "unfed" +kind = "starved" +event = "reopen-relay" +quest = "/quest/m2/multicast/reopen-starve.md" -# On lite-07 alone, a reader behind a reopened link or a crashed relay starves when its relay -# asked a neighbour whose own route had not returned yet. After the roll entry, so a roll's -# starved reader stays with roll-echo-stall. `reopen.toml` reproduces it and lists nothing known. [[known]] check = "unfed" kind = "starved" +event = "kill" quest = "/quest/m2/multicast/reopen-starve.md" From 879d3b1176e6c06d096ae932497d7f925600be6c Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 19 Nov 2026 07:02:40 -0800 Subject: [PATCH 06/15] fix(moq-net): a held group outranks an earlier range's start; port to js/net A start reported for an earlier range places a time only while the copy holds no group at or before it. The JS copy reports an oldest range as asked from 0 and places a time start by it the same way. Co-Authored-By: Claude Opus 5.5 --- js/net/src/lite/publisher.test.ts | 23 ++++++++++++ js/net/src/lite/subscriber.ts | 5 ++- js/net/src/track.ts | 9 ++++- rs/moq-net/src/model/track.rs | 62 ++++++++++++++++++++++++------- 4 files changed, 82 insertions(+), 17 deletions(-) diff --git a/js/net/src/lite/publisher.test.ts b/js/net/src/lite/publisher.test.ts index 86f5cd3c6d..ff71f163a9 100644 --- a/js/net/src/lite/publisher.test.ts +++ b/js/net/src/lite/publisher.test.ts @@ -1676,6 +1676,29 @@ for (const version of [Version.DRAFT_05, Version.DRAFT_06, Version.DRAFT_07]) { } } +// A relay's copy already asks from the oldest group, so a downstream asking from time 2 adds no +// range upstream and gets no start of its own. The oldest range starting at 6 still places it: +// the source holds nothing at or before 2. +test("lite draft-07: a time start a copy's oldest range covers starts where that range did", async () => { + const sub = await servedSubscription({ version: Version.DRAFT_07, startGroup: 2n }); + // The relay's own reader, asking from the oldest group, which the copy's demand then starts at. + const local = sub.track.subscribe({ delay: { max: Duration.millis(60_000) } }); + try { + hooks.receiveTrack(sub.track); + await flush(); + hooks.timeStarts(sub.track, [[0n, 6n]]); + hooks.startTrack(sub.track, { start: 6n }); + sub.serve(6n); + expect(await sub.servedSequence()).toBe(6n); + const response = await decodeSubscribeResponse(sub.client.reader, Version.DRAFT_07); + if (!("start" in response)) throw new Error("expected SUBSCRIBE_START"); + expect(response.start.starts[0]).toBe(6n); + } finally { + local.close(); + await sub.close(); + } +}); + // A relay's group stream can beat the upstream START on its own stream. Resolving from that // group would give up the backlog the START still promises, so the first group waits for it. for (const version of [Version.DRAFT_06, Version.DRAFT_07]) { diff --git a/js/net/src/lite/subscriber.ts b/js/net/src/lite/subscriber.ts index dddc9e1133..ef34998558 100644 --- a/js/net/src/lite/subscriber.ts +++ b/js/net/src/lite/subscriber.ts @@ -2872,8 +2872,8 @@ export class Subscriber { // say where one starts. Mirrors the Rust `SubStream::declare`. #declare(entry: SubscribeEntry): void { // Where the publisher started each live range asked from a group's start, which a reader's - // time start there resolves to when the copy holds no group at it. Mirrors the Rust - // `report_time_starts`. + // time start there resolves to when the copy holds no group at it, and one asked from the + // oldest group as asked from 0. Mirrors the Rust `SubStream::report_starts`. const times: [bigint, bigint][] = []; // And each one counting back, which the copy, holding only part of the track, can't count, // with the latest group it counted back from. @@ -2886,6 +2886,7 @@ export class Subscriber { if (at === undefined) continue; if (time !== undefined) times.push([time, at]); else if (back !== undefined) relative.push([back, at, entry.edges.get(id)]); + else if (range !== undefined && range.start === undefined) times.push([0n, at]); } hooks.timeStarts(entry.track, times); hooks.relativeStarts(entry.track, relative); diff --git a/js/net/src/track.ts b/js/net/src/track.ts index 93c029ad15..d208bc055e 100644 --- a/js/net/src/track.ts +++ b/js/net/src/track.ts @@ -3620,7 +3620,14 @@ export class Subscriber { if (below !== undefined && (covered(below + 1n, time + 1n, () => true) || index < keys.length)) { return { group: below }; } - if (below === undefined && covered(0n, time + 1n, () => true)) return "before"; + if (below === undefined) { + if (covered(0n, time + 1n, () => true)) return "before"; + // A range asked from an earlier time, or from the oldest group (as 0), that the + // publisher started past it says the same, while the copy holds no group there. + for (const [asked, start] of anchors.starts) { + if (asked < time && start > time) return "before"; + } + } return "unknown"; } if (below !== undefined) return { group: below }; diff --git a/rs/moq-net/src/model/track.rs b/rs/moq-net/src/model/track.rs index 258f8f71bf..b7b5fb17cb 100644 --- a/rs/moq-net/src/model/track.rs +++ b/rs/moq-net/src/model/track.rs @@ -1228,23 +1228,23 @@ impl TrackState { /// it says the feed went by: one between still in flight, a stream overtaken, would /// only add that group to the reader's range. /// - /// A range asked from an earlier time, or from the oldest group (reported as time 0), - /// that the publisher started past `time` says the same: no group starts at or before - /// it. A reader joining a copy that another reader already asks from further back adds - /// no range of its own, so that is the only report its time start gets. + /// With no group held at or before `time`, a range asked from an earlier time, or from + /// the oldest group (reported as time 0), that the publisher started past `time` says + /// the same: no group starts at or before it. A reader joining a copy that another + /// reader already asks from further back adds no range of its own, so that is the only + /// report its time start gets. A group the copy still holds there is a group the + /// publisher has since expired, so it wins: the time still waits to learn whether it + /// contains it. fn containing_received(&self, time: u64) -> Containing { if self.lookup.contains_key(&time) { return Containing::Group(time); } - if let Some(&start) = self.time_starts.get(&time) - && start <= time - { - return Containing::Group(start); - } - // The publisher serves nothing at or before it, as it does for a time older than - // every group it holds. Bounded by the copy's live wire ranges. - if self.time_starts.range(..=time).any(|(_, &start)| start > time) { - return Containing::Before; + match self.time_starts.get(&time) { + Some(&start) if start <= time => return Containing::Group(start), + // The publisher serves nothing at or before it, as it does for a time older than + // every group it holds. + Some(_) => return Containing::Before, + None => {} } match self.lookup.range(..=time).next_back() { Some((&key, _)) @@ -1253,7 +1253,11 @@ impl TrackState { { Containing::Group(key) } - None if self.dropped_cover(0..time.saturating_add(1)) => Containing::Before, + None if self.dropped_cover(0..time.saturating_add(1)) + || self.time_starts.range(..time).any(|(_, &start)| start > time) => + { + Containing::Before + } _ => Containing::Unknown, } } @@ -15497,6 +15501,36 @@ mod test { assert_eq!(placed(&mut after), None, "a group past 1000 may still arrive"); } + /// A group the copy still holds at or before a time start outranks a start reported for an + /// earlier range: the publisher expiring it says nothing of whether it contains the time. + #[test] + #[cfg(feature = "async")] + fn a_received_copy_keeps_a_held_group_over_an_earlier_range() { + let from = |time| { + Subscription::default() + .with_ranges([Range { + start: Anchor::Time(time), + end: None, + }]) + .with_delay(Delay::default().with_max(None)) + }; + let placed = |subscriber: &mut Subscriber| { + subscriber.resolved_ranges()[0].map(|resolved| (resolved.start, resolved.floored)) + }; + let producer = track_producer("test", Info::timed()); + producer.received(); + producer.anchored(); + write_group(&producer, 2000); + + let mut reader = producer.subscribe(from(2500)); + producer.time_starts([(0, 3000)]); + assert_eq!(placed(&mut reader), None, "the held 2000 may contain 2500"); + + write_group(&producer, 3000); + assert_eq!(placed(&mut reader), Some((2000, true))); + assert_eq!(drain(&mut reader), vec![2000, 3000]); + } + /// A floor at or past a time start, as a pre-lite-07 wire's start sets, keeps out the group /// containing that time unless it starts there, so where the range starts waits on nothing /// a lite-07 copy has yet to place. Without the floor, it waits. From f681b815c6852005f8d3cd8995bdcdbc36ab7d27 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 19 Nov 2026 08:27:35 -0800 Subject: [PATCH 07/15] chore: format, and drop reopen-starve's empty Related heading Co-Authored-By: Claude Opus 5.5 --- quest/m2/multicast/reopen-starve.md | 3 --- rs/moq-net/src/model/subscription/window.rs | 7 ++++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/quest/m2/multicast/reopen-starve.md b/quest/m2/multicast/reopen-starve.md index b025269e45..fe5c392d15 100644 --- a/quest/m2/multicast/reopen-starve.md +++ b/quest/m2/multicast/reopen-starve.md @@ -54,6 +54,3 @@ so it is a lite-07 regression on a link flap or a crash, which a deployment sees daily. Not a wire change. - -## Related - diff --git a/rs/moq-net/src/model/subscription/window.rs b/rs/moq-net/src/model/subscription/window.rs index 04f8a98dcf..967e61bfde 100644 --- a/rs/moq-net/src/model/subscription/window.rs +++ b/rs/moq-net/src/model/subscription/window.rs @@ -1022,7 +1022,12 @@ mod tests { window.runs(0).collect::>(), window.missable(0).collect::>(), (window.floor(), window.start(), window.named(), window.end()), - (window.resolved(), lookups, window.is_settled(), !window.waiting.is_empty()), + ( + window.resolved(), + lookups, + window.is_settled(), + !window.waiting.is_empty(), + ), ) } From 7023f2ef3d7755453dcbfcef5221f3f741fdc693 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 19 Nov 2026 09:03:04 -0800 Subject: [PATCH 08/15] fix(moq-net): a floored waiting time start reports where delivery starts On lite-07, an update before SUBSCRIBE_START floors the cursor at a waiting range's time, and `poll_start` no longer waits on it, so `starts` reported no start for a live range. Such a range starts where delivery does, the answer placing it would give. The newest start reported past its range's time is now kept as `time_starts` is replaced, in Rust and JS, rather than rescanned on every reader's settle. Co-Authored-By: Claude Opus 5.5 --- js/net/src/track.ts | 23 ++++++---- rs/moq-net/src/lite/publisher.rs | 75 ++++++++++++++++++++++++++++++-- rs/moq-net/src/model/track.rs | 21 ++++----- 3 files changed, 97 insertions(+), 22 deletions(-) diff --git a/js/net/src/track.ts b/js/net/src/track.ts index 7c6cd09585..4e67ce38ef 100644 --- a/js/net/src/track.ts +++ b/js/net/src/track.ts @@ -1053,6 +1053,8 @@ let keysOf: (producer: Producer) => readonly bigint[]; let timeAnchors: (producer: Producer) => { atKeys: boolean; starts: ReadonlyMap; + /** The newest of `starts` past the time its range asked from, 0 when none is. */ + past: bigint; relative: ReadonlyMap; /** Bumped whenever the others, or whether the producer is a received copy, change. */ placing: number; @@ -1318,6 +1320,9 @@ export class Producer { // Where the upstream publisher started each of a lite-07 copy's live wire ranges, by the time // it asked from. Mirrors the Rust `TrackState::time_starts`. #timeStarts = new Map(); + // The newest start in `#timeStarts` past the time its range asked from, kept as it is + // replaced: a reader's `unplaced` reads it on every settle. Mirrors the Rust `starts_past`. + #startsPast = 0n; // On a lite-07 copy, where the publisher started each live range counting back, by its count. #relativeStarts = new Map(); // Counts changes to how a time start is placed other than by groups arriving or drops: the wire, @@ -1554,6 +1559,7 @@ export class Producer { timeAnchors = (producer) => ({ atKeys: producer.#startsAtKeys, starts: producer.#timeStarts, + past: producer.#startsPast, relative: producer.#relativeStarts, placing: producer.#placing, }); @@ -1563,6 +1569,10 @@ export class Producer { }; hooks.timeStarts = (producer, starts) => { producer.#timeStarts = new Map(starts); + producer.#startsPast = 0n; + for (const [asked, start] of producer.#timeStarts) { + if (asked < start && start > producer.#startsPast) producer.#startsPast = start; + } producer.#placing++; }; hooks.relativeStarts = (producer, starts) => { @@ -3633,8 +3643,10 @@ export class Subscriber { if (drops.covers(0n, time + 1n)) return "before"; // A range asked from an earlier time, or from the oldest group (as 0), that the // publisher started past it says the same, while the copy holds no group there. - for (const [asked, start] of anchors.starts) { - if (asked < time && start > time) return "before"; + if (anchors.past > time) { + for (const [asked, start] of anchors.starts) { + if (asked < time && start > time) return "before"; + } } } return "unknown"; @@ -3654,12 +3666,7 @@ export class Subscriber { // `containing` places a time below every held group from a start reported past an // earlier range's time, which an eviction brings about without moving the mark, so a // run there starts past the newest such start. Mirrors the Rust `TrackState::unplaced`. - let past = 0n; - if (wire) { - for (const [asked, start] of anchors.starts) { - if (asked < start && start > past) past = start; - } - } + const past = wire ? anchors.past : 0n; const unheld = (run: Run | undefined): Run | undefined => run && run.start < past ? { start: past, end: run.end } : run; if (anchors.atKeys || state.fetch) { diff --git a/rs/moq-net/src/lite/publisher.rs b/rs/moq-net/src/lite/publisher.rs index 42e6567250..fb8278467a 100644 --- a/rs/moq-net/src/lite/publisher.rs +++ b/rs/moq-net/src/lite/publisher.rs @@ -5892,15 +5892,32 @@ impl TrackRun { if !self.ctx.version.has_ranges() { return vec![Some(start)]; } + use crate::track::Anchor; // SUBSCRIBE_START answers the SUBSCRIBE's ranges, by Range ID: none for one an update // retired already, and SUBSCRIBE_STARTED answers each one an update added. self.track .resolved_keys(0..self.initial) .into_iter() - .map(|resolved| { - let resolved = resolved?; - let from = resolved.start.max(start); - resolved.end.is_none_or(|end| end > from).then_some(from) + .zip(0..) + .map(|(resolved, id)| { + let (from, end) = match resolved { + Some(resolved) => (resolved.start.max(start), resolved.end), + // A time start still waiting at or below the floor, as an update before the + // start leaves one: whichever group contains it is out of range, so the range + // starts where delivery does, the answer placing it would give. + None => match self.requested.ranges.get(&id)? { + crate::track::Range { + start: Anchor::Time(time), + end, + } if *time <= self.floor => match end { + None => (start, None), + Some(Anchor::Time(last)) => (start, Some(last.saturating_add(1))), + Some(_) => return None, + }, + _ => return None, + }, + }; + end.is_none_or(|end| end > from).then_some(from) }) .collect() } @@ -8067,6 +8084,23 @@ mod serve_group_test { (TrackRun::new(ctx, track, bounds, 0, steer), writer, log) } + /// [`lite07_run`] with the SUBSCRIBE asking for `ranges` on `track`. + fn lite07_run_ranges( + track: &track::Producer, + ranges: &[lite::Range], + ) -> (TrackRun, Writer, Log) { + let bounds = Bounds::new(ranges, false); + let subscriber = track.subscribe( + track::Subscription::default() + .with_delay(track::Delay::default().with_max(Duration::from_secs(3600))) + .with_ranges(bounds.ranges.iter().copied()), + ); + let (mut run, writer, log) = lite07_run(SinkSession::new(Log::default()), subscriber); + run.initial = bounds.ranges.len() as u64; + run.requested = Requested::new((0..).zip(bounds.ranges.iter().copied())); + (run, writer, log) + } + /// [`lite_run`] with the SUBSCRIBE naming group `start`. fn lite_run_from( version: Version, @@ -8730,6 +8764,39 @@ mod serve_group_test { ); } + /// An update before SUBSCRIBE_START that leaves only a time start a lite-07 copy can't + /// place yet floors the cursor at that time, so the group containing it is out of range + /// whichever it is: the range starts where delivery does, reported rather than left + /// without a start. + #[kio::test] + async fn lite07_a_floored_time_start_reports_where_delivery_starts() { + let mut track = track::Producer::new( + Arc::new(broadcast::Info::default()), + "test", + crate::track::Info::timed(), + ); + track.received(); + track.anchored(); + write_group(&mut track, 1000, 1000); + let kept = lite::Range::span(Some(500), 0, None, None); + let (mut run, mut writer, log) = + lite07_run_ranges(&track, &[lite::Range::span(Some(100), 0, None, None), kept]); + assert!(run.poll_step(&mut writer, &kio::Waiter::noop()).is_ready()); + assert!(run.start.resolved().is_none(), "time 100 waits on the copy to place it"); + + run.update(lite07_add(&run, &[(1, kept)], 2, &[])); + while run.poll_step(&mut writer, &kio::Waiter::noop()).is_ready() {} + let starts: Vec<_> = responses(&mut writer, &log) + .await + .into_iter() + .filter_map(|msg| match msg { + lite::SubscribeResponse::Start(start) => Some(start.starts), + _ => None, + }) + .collect(); + assert_eq!(starts, [vec![None, Some(1000)]]); + } + /// A gap the publisher never declared might have existed, so the end names it with a /// DROP rather than a SKIP: here the reader passed it, so it is stale. #[kio::test] diff --git a/rs/moq-net/src/model/track.rs b/rs/moq-net/src/model/track.rs index 1cf0aa9e71..57fb096749 100644 --- a/rs/moq-net/src/model/track.rs +++ b/rs/moq-net/src/model/track.rs @@ -754,6 +754,9 @@ pub(crate) struct TrackState { // a time it holds no group at, but its publisher reports where it resolved one. Replaced // whole as the ranges change, so it holds at most one entry per live range. time_starts: BTreeMap, + // The newest start in `time_starts` past the time its range asked from, kept as it is + // replaced: [`Holdings::unplaced`] reads it on every settle of every reader. + starts_past: Option, // Where the upstream publisher started each of a lite-07 copy's live wire ranges counting // back, by how many groups each counted, with the latest group it counted from: the copy // holds only part of the track, so it can't count back over its own groups. Replaced whole @@ -1138,15 +1141,7 @@ impl Holdings for TrackState { /// unknown times do. fn unplaced(&self) -> Option { let none = Unplaced::NONE; - let past = match self.anchors { - Anchors::Wire => self - .time_starts - .iter() - .filter(|&(asked, start)| asked < start) - .map(|(_, &start)| start) - .max(), - _ => None, - }; + let past = self.starts_past.filter(|_| self.anchors == Anchors::Wire); // The times below every held group that no inference from an earlier range places. let unheld = |run: ops::RangeInclusive| match past { Some(past) => (*run.start()).max(past)..=*run.end(), @@ -1318,7 +1313,8 @@ impl TrackState { Containing::Group(key) } None if self.dropped_cover(0..time.saturating_add(1)) - || self.time_starts.range(..time).any(|(_, &start)| start > time) => + || (self.starts_past.is_some_and(|past| past > time) + && self.time_starts.range(..time).any(|(_, &start)| start > time)) => { Containing::Before } @@ -4819,6 +4815,11 @@ impl Producer { if let Ok(mut state) = self.modify() && state.time_starts != starts { + state.starts_past = starts + .iter() + .filter(|&(asked, start)| asked < start) + .map(|(_, &start)| start) + .max(); state.time_starts = starts; state.placing += 1; } From 3b76d6a95c1f76f8800354e7b265cdfa8b895004 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 19 Nov 2026 09:33:41 -0800 Subject: [PATCH 09/15] fix(moq-net): a floored waiting start keeps the end its window resolved `TrackRun::starts` read a floored waiting range's end from the request, so a relative end reported no start. It now asks the model for the waiting range's time and resolved end (`Subscriber::waiting_key`). Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/lite/publisher.rs | 75 ++++++++++----------- rs/moq-net/src/model/subscription/window.rs | 7 ++ rs/moq-net/src/model/track.rs | 13 ++++ 3 files changed, 56 insertions(+), 39 deletions(-) diff --git a/rs/moq-net/src/lite/publisher.rs b/rs/moq-net/src/lite/publisher.rs index fb8278467a..b1409c1bd6 100644 --- a/rs/moq-net/src/lite/publisher.rs +++ b/rs/moq-net/src/lite/publisher.rs @@ -5892,28 +5892,19 @@ impl TrackRun { if !self.ctx.version.has_ranges() { return vec![Some(start)]; } - use crate::track::Anchor; // SUBSCRIBE_START answers the SUBSCRIBE's ranges, by Range ID: none for one an update // retired already, and SUBSCRIBE_STARTED answers each one an update added. - self.track - .resolved_keys(0..self.initial) - .into_iter() - .zip(0..) - .map(|(resolved, id)| { + let resolved = self.track.resolved_keys(0..self.initial); + (0..) + .zip(resolved) + .map(|(id, resolved)| { let (from, end) = match resolved { Some(resolved) => (resolved.start.max(start), resolved.end), // A time start still waiting at or below the floor, as an update before the // start leaves one: whichever group contains it is out of range, so the range // starts where delivery does, the answer placing it would give. - None => match self.requested.ranges.get(&id)? { - crate::track::Range { - start: Anchor::Time(time), - end, - } if *time <= self.floor => match end { - None => (start, None), - Some(Anchor::Time(last)) => (start, Some(last.saturating_add(1))), - Some(_) => return None, - }, + None => match self.track.waiting_key(id)? { + (time, end) if time <= self.floor => (start, end), _ => return None, }, }; @@ -8770,31 +8761,37 @@ mod serve_group_test { /// without a start. #[kio::test] async fn lite07_a_floored_time_start_reports_where_delivery_starts() { - let mut track = track::Producer::new( - Arc::new(broadcast::Info::default()), - "test", - crate::track::Info::timed(), - ); - track.received(); - track.anchored(); - write_group(&mut track, 1000, 1000); - let kept = lite::Range::span(Some(500), 0, None, None); - let (mut run, mut writer, log) = - lite07_run_ranges(&track, &[lite::Range::span(Some(100), 0, None, None), kept]); - assert!(run.poll_step(&mut writer, &kio::Waiter::noop()).is_ready()); - assert!(run.start.resolved().is_none(), "time 100 waits on the copy to place it"); + // Open, and through the latest group, which already holds group 1000. + for end in [None, Some(lite::Anchor::Relative(0))] { + let mut track = track::Producer::new( + Arc::new(broadcast::Info::default()), + "test", + crate::track::Info::timed(), + ); + track.received(); + track.anchored(); + write_group(&mut track, 1000, 1000); + let kept = lite::Range { + end, + ..lite::Range::span(Some(500), 0, None, None) + }; + let (mut run, mut writer, log) = + lite07_run_ranges(&track, &[lite::Range::span(Some(100), 0, None, None), kept]); + assert!(run.poll_step(&mut writer, &kio::Waiter::noop()).is_ready()); + assert!(run.start.resolved().is_none(), "time 100 waits on the copy to place it"); - run.update(lite07_add(&run, &[(1, kept)], 2, &[])); - while run.poll_step(&mut writer, &kio::Waiter::noop()).is_ready() {} - let starts: Vec<_> = responses(&mut writer, &log) - .await - .into_iter() - .filter_map(|msg| match msg { - lite::SubscribeResponse::Start(start) => Some(start.starts), - _ => None, - }) - .collect(); - assert_eq!(starts, [vec![None, Some(1000)]]); + run.update(lite07_add(&run, &[(1, kept)], 2, &[])); + while run.poll_step(&mut writer, &kio::Waiter::noop()).is_ready() {} + let starts: Vec<_> = responses(&mut writer, &log) + .await + .into_iter() + .filter_map(|msg| match msg { + lite::SubscribeResponse::Start(start) => Some(start.starts), + _ => None, + }) + .collect(); + assert_eq!(starts, [vec![None, Some(1000)]], "ending at {end:?}"); + } } /// A gap the publisher never declared might have existed, so the end names it with a diff --git a/rs/moq-net/src/model/subscription/window.rs b/rs/moq-net/src/model/subscription/window.rs index 967e61bfde..4d810783d5 100644 --- a/rs/moq-net/src/model/subscription/window.rs +++ b/rs/moq-net/src/model/subscription/window.rs @@ -474,6 +474,13 @@ impl Window { }) } + /// The range keyed `key` while its time start waits on the groups held to place it: that + /// time, and the exclusive end it resolved to, `None` while it stays open. + pub fn waiting_key(&self, key: u64) -> Option<(u64, Option)> { + let span = self.spans.get(&key)?; + span.waits_on().map(|time| (time, span.end)) + } + /// Each range resolved, in key order, as [`Self::resolved_key`] reads it. pub fn resolved(&self) -> Vec> { self.ranges.keys().map(|key| self.resolved_key(*key)).collect() diff --git a/rs/moq-net/src/model/track.rs b/rs/moq-net/src/model/track.rs index 57fb096749..41549417a4 100644 --- a/rs/moq-net/src/model/track.rs +++ b/rs/moq-net/src/model/track.rs @@ -10861,6 +10861,19 @@ impl Subscriber { } } + /// This subscriber's range keyed `key` while its time start waits on the groups held to + /// place it: that time, and the exclusive end it resolved to. `None` once it resolved, or + /// for a reader following route copies, which resolve its ranges for it. + pub(crate) fn waiting_key(&mut self, key: u64) -> Option<(u64, Option)> { + match &mut self.inner { + Inner::Plain(cursor) => { + cursor.sync(); + cursor.filter.window.waiting_key(key) + } + Inner::Resume(..) => None, + } + } + /// This subscriber's range keyed `key` as resolved here; see [`Self::resolved_keys`]. #[cfg(test)] #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] From f3dcc0e7cd964971df2e5a7bc2af3ff444aa7071 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 19 Nov 2026 10:01:09 -0800 Subject: [PATCH 10/15] chore(moq-net): waiting_key is async-only Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/model/subscription/window.rs | 1 + rs/moq-net/src/model/track.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/rs/moq-net/src/model/subscription/window.rs b/rs/moq-net/src/model/subscription/window.rs index 4d810783d5..ee0a68e2ae 100644 --- a/rs/moq-net/src/model/subscription/window.rs +++ b/rs/moq-net/src/model/subscription/window.rs @@ -476,6 +476,7 @@ impl Window { /// The range keyed `key` while its time start waits on the groups held to place it: that /// time, and the exclusive end it resolved to, `None` while it stays open. + #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] pub fn waiting_key(&self, key: u64) -> Option<(u64, Option)> { let span = self.spans.get(&key)?; span.waits_on().map(|time| (time, span.end)) diff --git a/rs/moq-net/src/model/track.rs b/rs/moq-net/src/model/track.rs index 41549417a4..39298c8689 100644 --- a/rs/moq-net/src/model/track.rs +++ b/rs/moq-net/src/model/track.rs @@ -10864,6 +10864,7 @@ impl Subscriber { /// This subscriber's range keyed `key` while its time start waits on the groups held to /// place it: that time, and the exclusive end it resolved to. `None` once it resolved, or /// for a reader following route copies, which resolve its ranges for it. + #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] pub(crate) fn waiting_key(&mut self, key: u64) -> Option<(u64, Option)> { match &mut self.inner { Inner::Plain(cursor) => { From f38cf96cbb89d37721252af5c786380477fe9b03 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 19 Nov 2026 10:27:19 -0800 Subject: [PATCH 11/15] fix(moq-net): a routed reader tells its serving copy's waiting time start A reader following route copies answered no waiting range, so `TrackRun::starts` reported no start for a floored waiting range on a routed subscription. It now asks the serving copy, whose subscription mirrors the reader's ranges in key order. Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/model/resume.rs | 57 ++++++++++++++++++++++++++++++++++ rs/moq-net/src/model/track.rs | 6 ++-- 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/rs/moq-net/src/model/resume.rs b/rs/moq-net/src/model/resume.rs index 013b8bb34d..a2742ced23 100644 --- a/rs/moq-net/src/model/resume.rs +++ b/rs/moq-net/src/model/resume.rs @@ -1025,6 +1025,23 @@ impl Subscriber { keys.into_iter().map(|key| window.resolved_key(key)).collect() } + /// The reader's range keyed `key` while its time start waits; see + /// [`track::Subscriber::waiting_key`]. + #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] + pub(super) fn waiting_key(&self, key: u64) -> Option<(u64, Option)> { + let mut reader = self.reader(); + if reader.window().resolved_key(key).is_some() { + return None; + } + // Only the serving copy places it: the reader's own window holds no groups. Its + // subscription mirrors the reader's ranges in key order. + let index = reader.keys.iter().position(|&mirrored| mirrored == key)?; + match &mut reader.copies.last_mut()?.sub { + Sub::Ready(sub) => sub.waiting_key(index as u64), + Sub::Pending(_) => None, + } + } + /// The lowest group at or above `from` the reader's ranges cover; see /// [`track::Subscriber::next_in_range`]. pub(super) fn next_in_range(&self, from: u64) -> Option { @@ -3590,6 +3607,46 @@ mod test { drop(held); } + /// A routed reader's time start that its serving copy can't place yet says what it waits + /// on and where it ends, as a plain reader's does, so a publisher whose floor already keeps + /// out the group containing it can say where the range starts. + #[kio::test] + async fn a_routed_reader_tells_a_waiting_time_start() { + let routes = Producer::new(); + let logical = logical(&routes); + let serving = received_copy(); + serving.anchored(); + routes.serve(serving.consume()); + write(&serving, 1000); + let ranges = Subscription::default() + .with_delay(Delay::default().with_max(None)) + .with_ranges([track::Range { + start: Anchor::Time(500), + end: None, + }]); + let mut open = logical + .consume() + .subscribe(ranges.clone()) + .now_or_never() + .unwrap() + .unwrap(); + assert!(open.poll_start(&kio::Waiter::noop()).is_pending()); + assert_eq!(open.resolved_range(0), None); + assert_eq!(open.waiting_key(0), Some((500, None))); + + // A floor at the time keeps out whichever group contains it: the start waits on nothing. + let mut floored = logical + .consume() + .subscribe(ranges) + .now_or_never() + .unwrap() + .unwrap() + .with_range(500..); + assert!(floored.poll_start(&kio::Waiter::noop()).is_ready()); + assert_eq!(floored.resolved_range(0), None); + assert_eq!(floored.waiting_key(0), Some((500, None))); + } + /// As [`an_ended_copy_leaves_a_time_start_to_the_serving_copy`], for a reader that replaces /// its ranges while its copy has failed: the replacement places them. #[kio::test] diff --git a/rs/moq-net/src/model/track.rs b/rs/moq-net/src/model/track.rs index 39298c8689..a0f377c90a 100644 --- a/rs/moq-net/src/model/track.rs +++ b/rs/moq-net/src/model/track.rs @@ -10862,8 +10862,8 @@ impl Subscriber { } /// This subscriber's range keyed `key` while its time start waits on the groups held to - /// place it: that time, and the exclusive end it resolved to. `None` once it resolved, or - /// for a reader following route copies, which resolve its ranges for it. + /// place it, or on its route copies for a reader following them: that time, and the + /// exclusive end it resolved to. `None` once it resolved. #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] pub(crate) fn waiting_key(&mut self, key: u64) -> Option<(u64, Option)> { match &mut self.inner { @@ -10871,7 +10871,7 @@ impl Subscriber { cursor.sync(); cursor.filter.window.waiting_key(key) } - Inner::Resume(..) => None, + Inner::Resume(resume, _) => resume.waiting_key(key), } } From 21b0324b7ec0e961abb931a1e176c7fc24964e2e Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 19 Nov 2026 10:58:05 -0800 Subject: [PATCH 12/15] perf(moq-net): look up waiting ranges in one batch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `TrackRun::starts` asked each unresolved range separately, and a routed reader re-synced its window and searched its keys linearly per range, so one SUBSCRIBE_START cost O(R²) with R ranges waiting. `waiting_keys` answers them together, as `resolved_keys` does, and finds each key by binary search. Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/lite/publisher.rs | 13 +++++++---- rs/moq-net/src/model/resume.rs | 37 ++++++++++++++++++++------------ rs/moq-net/src/model/track.rs | 14 ++++++------ 3 files changed, 40 insertions(+), 24 deletions(-) diff --git a/rs/moq-net/src/lite/publisher.rs b/rs/moq-net/src/lite/publisher.rs index b1409c1bd6..eef0f16dfe 100644 --- a/rs/moq-net/src/lite/publisher.rs +++ b/rs/moq-net/src/lite/publisher.rs @@ -5895,15 +5895,20 @@ impl TrackRun { // SUBSCRIBE_START answers the SUBSCRIBE's ranges, by Range ID: none for one an update // retired already, and SUBSCRIBE_STARTED answers each one an update added. let resolved = self.track.resolved_keys(0..self.initial); - (0..) - .zip(resolved) - .map(|(id, resolved)| { + let unresolved = (0..) + .zip(&resolved) + .filter(|(_, resolved)| resolved.is_none()) + .map(|(id, _)| id); + let mut waiting = self.track.waiting_keys(unresolved).into_iter(); + resolved + .into_iter() + .map(|resolved| { let (from, end) = match resolved { Some(resolved) => (resolved.start.max(start), resolved.end), // A time start still waiting at or below the floor, as an update before the // start leaves one: whichever group contains it is out of range, so the range // starts where delivery does, the answer placing it would give. - None => match self.track.waiting_key(id)? { + None => match waiting.next().flatten()? { (time, end) if time <= self.floor => (start, end), _ => return None, }, diff --git a/rs/moq-net/src/model/resume.rs b/rs/moq-net/src/model/resume.rs index a2742ced23..9dcc481687 100644 --- a/rs/moq-net/src/model/resume.rs +++ b/rs/moq-net/src/model/resume.rs @@ -1025,21 +1025,30 @@ impl Subscriber { keys.into_iter().map(|key| window.resolved_key(key)).collect() } - /// The reader's range keyed `key` while its time start waits; see - /// [`track::Subscriber::waiting_key`]. + /// The reader's ranges keyed in `keys` while their time starts wait; see + /// [`track::Subscriber::waiting_keys`]. #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] - pub(super) fn waiting_key(&self, key: u64) -> Option<(u64, Option)> { + pub(super) fn waiting_keys(&self, keys: impl IntoIterator) -> Vec)>> { let mut reader = self.reader(); - if reader.window().resolved_key(key).is_some() { - return None; - } - // Only the serving copy places it: the reader's own window holds no groups. Its + reader.window(); + let reader = &mut *reader; + // Only the serving copy places one: the reader's own window holds no groups. Its // subscription mirrors the reader's ranges in key order. - let index = reader.keys.iter().position(|&mirrored| mirrored == key)?; - match &mut reader.copies.last_mut()?.sub { - Sub::Ready(sub) => sub.waiting_key(index as u64), - Sub::Pending(_) => None, - } + let indices: Vec> = keys + .into_iter() + .map(|key| match reader.window.resolved_key(key) { + Some(_) => None, + None => reader.keys.binary_search(&key).ok().map(|index| index as u64), + }) + .collect(); + let mut found = match reader.copies.last_mut().map(|copy| &mut copy.sub) { + Some(Sub::Ready(sub)) => sub.waiting_keys(indices.iter().flatten().copied()).into_iter(), + _ => Vec::new().into_iter(), + }; + indices + .into_iter() + .map(|index| index.and_then(|_| found.next().flatten())) + .collect() } /// The lowest group at or above `from` the reader's ranges cover; see @@ -3632,7 +3641,7 @@ mod test { .unwrap(); assert!(open.poll_start(&kio::Waiter::noop()).is_pending()); assert_eq!(open.resolved_range(0), None); - assert_eq!(open.waiting_key(0), Some((500, None))); + assert_eq!(open.waiting_keys([0]), [Some((500, None))]); // A floor at the time keeps out whichever group contains it: the start waits on nothing. let mut floored = logical @@ -3644,7 +3653,7 @@ mod test { .with_range(500..); assert!(floored.poll_start(&kio::Waiter::noop()).is_ready()); assert_eq!(floored.resolved_range(0), None); - assert_eq!(floored.waiting_key(0), Some((500, None))); + assert_eq!(floored.waiting_keys([0]), [Some((500, None))]); } /// As [`an_ended_copy_leaves_a_time_start_to_the_serving_copy`], for a reader that replaces diff --git a/rs/moq-net/src/model/track.rs b/rs/moq-net/src/model/track.rs index a0f377c90a..09c2dec936 100644 --- a/rs/moq-net/src/model/track.rs +++ b/rs/moq-net/src/model/track.rs @@ -10861,17 +10861,19 @@ impl Subscriber { } } - /// This subscriber's range keyed `key` while its time start waits on the groups held to - /// place it, or on its route copies for a reader following them: that time, and the - /// exclusive end it resolved to. `None` once it resolved. + /// This subscriber's ranges keyed in `keys` while their time starts wait on the groups + /// held to place them, or on its route copies for a reader following them: each one's + /// time, and the exclusive end it resolved to. `None` for one that resolved. #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] - pub(crate) fn waiting_key(&mut self, key: u64) -> Option<(u64, Option)> { + pub(crate) fn waiting_keys(&mut self, keys: impl IntoIterator) -> Vec)>> { match &mut self.inner { Inner::Plain(cursor) => { cursor.sync(); - cursor.filter.window.waiting_key(key) + keys.into_iter() + .map(|key| cursor.filter.window.waiting_key(key)) + .collect() } - Inner::Resume(resume, _) => resume.waiting_key(key), + Inner::Resume(resume, _) => resume.waiting_keys(keys), } } From 7860341e44e45900273249413f0daac07023e160 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 19 Nov 2026 11:56:07 -0800 Subject: [PATCH 13/15] fix(moq-net): port roll-echo-stall to #9183's reader-keyed copy subscriptions #9183 keys a copy's own subscription by the reader's keys rather than by position, and resolved_ranges now takes the keys to resolve. waiting_keys passes the reader's key straight through, and the new tests ask for key 0. Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/model/resume.rs | 4 ++-- rs/moq-net/src/model/track.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/rs/moq-net/src/model/resume.rs b/rs/moq-net/src/model/resume.rs index 67c1d8f210..bd0c573ba1 100644 --- a/rs/moq-net/src/model/resume.rs +++ b/rs/moq-net/src/model/resume.rs @@ -1179,12 +1179,12 @@ impl Subscriber { reader.window(); let reader = &mut *reader; // Only the serving copy places one: the reader's own window holds no groups. Its - // subscription mirrors the reader's ranges in key order. + // subscription keys each range as the reader does. let indices: Vec> = keys .into_iter() .map(|key| match reader.window.resolved_key(key) { Some(_) => None, - None => reader.keys.binary_search(&key).ok().map(|index| index as u64), + None => reader.mirrored.ranges.contains_key(&key).then_some(key), }) .collect(); let mut found = match reader.copies.last_mut().map(|copy| &mut copy.sub) { diff --git a/rs/moq-net/src/model/track.rs b/rs/moq-net/src/model/track.rs index 949a00c9e9..f705d99915 100644 --- a/rs/moq-net/src/model/track.rs +++ b/rs/moq-net/src/model/track.rs @@ -15849,7 +15849,7 @@ mod test { .with_delay(Delay::default().with_max(None)) }; let placed = |subscriber: &mut Subscriber| { - subscriber.resolved_ranges()[0].map(|resolved| (resolved.start, resolved.floored)) + subscriber.resolved_ranges([0])[0].map(|resolved| (resolved.start, resolved.floored)) }; let producer = track_producer("test", Info::timed()); producer.received(); @@ -15887,7 +15887,7 @@ mod test { .with_delay(Delay::default().with_max(None)) }; let placed = |subscriber: &mut Subscriber| { - subscriber.resolved_ranges()[0].map(|resolved| (resolved.start, resolved.floored)) + subscriber.resolved_ranges([0])[0].map(|resolved| (resolved.start, resolved.floored)) }; let producer = track_producer("test", Info::timed()); producer.received(); @@ -15918,7 +15918,7 @@ mod test { .with_delay(Delay::default().with_max(None)) }; let placed = |subscriber: &mut Subscriber| { - subscriber.resolved_ranges()[0].map(|resolved| (resolved.start, resolved.floored)) + subscriber.resolved_ranges([0])[0].map(|resolved| (resolved.start, resolved.floored)) }; let producer = track_producer("test", Info::timed()); producer.received(); From de7abe7c558152624c2500c7db9863288fc6849a Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 19 Nov 2026 12:38:03 -0800 Subject: [PATCH 14/15] fix(moq-net): a range placed between SUBSCRIBE_START's two reads still names its start resolved_keys and waiting_keys each sync the cursor, so an upstream answer on another thread can place a waiting range between them, leaving it neither resolved nor waiting, and SUBSCRIBE_START named no start for it. Placing is one-way, so those ranges are read again: resolved now, unless an update retired them. Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/lite/publisher.rs | 39 +++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/rs/moq-net/src/lite/publisher.rs b/rs/moq-net/src/lite/publisher.rs index 5d53b237cb..d348b9d6fd 100644 --- a/rs/moq-net/src/lite/publisher.rs +++ b/rs/moq-net/src/lite/publisher.rs @@ -5894,24 +5894,37 @@ impl TrackRun { } // SUBSCRIBE_START answers the SUBSCRIBE's ranges, by Range ID: none for one an update // retired already, and SUBSCRIBE_STARTED answers each one an update added. - let resolved = self.track.resolved_keys(0..self.initial); - let unresolved = (0..) + let mut resolved = self.track.resolved_keys(0..self.initial); + let unresolved: Vec = (0..) .zip(&resolved) .filter(|(_, resolved)| resolved.is_none()) - .map(|(id, _)| id); - let mut waiting = self.track.waiting_keys(unresolved).into_iter(); - resolved - .into_iter() - .map(|resolved| { - let (from, end) = match resolved { - Some(resolved) => (resolved.start.max(start), resolved.end), + .map(|(id, _)| id) + .collect(); + let waiting = self.track.waiting_keys(unresolved.iter().copied()); + // Each read syncs the cursor on its own, so an upstream answer on another thread can + // place a range between them. Placing is one-way: a range no longer waiting is resolved + // now, unless an update retired it, so read those again rather than name no start. + let placed: Vec = (unresolved.iter().zip(&waiting)) + .filter(|(_, waiting)| waiting.is_none()) + .map(|(&id, _)| id) + .collect(); + if !placed.is_empty() { + for (id, late) in placed.iter().zip(self.track.resolved_keys(placed.iter().copied())) { + resolved[*id as usize] = late; + } + } + let mut waiting = unresolved.iter().copied().zip(waiting).peekable(); + (0..) + .zip(resolved) + .map(|(id, resolved)| { + let waits = waiting.next_if(|(key, _)| *key == id).and_then(|(_, waits)| waits); + let (from, end) = match (resolved, waits) { + (Some(resolved), _) => (resolved.start.max(start), resolved.end), // A time start still waiting at or below the floor, as an update before the // start leaves one: whichever group contains it is out of range, so the range // starts where delivery does, the answer placing it would give. - None => match waiting.next().flatten()? { - (time, end) if time <= self.floor => (start, end), - _ => return None, - }, + (None, Some((time, end))) if time <= self.floor => (start, end), + (None, _) => return None, }; end.is_none_or(|end| end > from).then_some(from) }) From 2ea51acbf7e7e746701850ad220bdcafe1d4390a Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 19 Nov 2026 13:48:41 -0800 Subject: [PATCH 15/15] fix(moq-net): a routed reader places each range its copy resolved on its own `Reader::resolve` placed a routed reader's ranges all or none, so an earlier range still waiting on a time start left a later range the serving copy had resolved unplaced. With the floor shortcut letting SUBSCRIBE_START out meanwhile, that live range went out with no start, and a range an update added got no SUBSCRIBE_STARTED until the end. Each range now places where its copy resolved it, independently. `js/net` mirrors it. Co-Authored-By: Claude Opus 5.5 --- js/net/src/resume.test.ts | 25 ++++++++++++ js/net/src/resume.ts | 45 +++++++++++----------- js/net/src/window.ts | 11 ++++++ rs/moq-net/src/lite/publisher.rs | 53 ++++++++++++++++++++++++++ rs/moq-net/src/model/resume.rs | 65 +++++++++++++++++++++++++++----- 5 files changed, 167 insertions(+), 32 deletions(-) diff --git a/js/net/src/resume.test.ts b/js/net/src/resume.test.ts index 31d937c8e3..85c11e2537 100644 --- a/js/net/src/resume.test.ts +++ b/js/net/src/resume.test.ts @@ -4665,6 +4665,31 @@ test("a group an inner front hands out already failed still continues on the out b.close(); }); +// Mirrors `a_routed_reader_places_a_range_past_one_still_waiting` in rs/moq-net/src/model/resume.rs: +// a range the copy placed is placed on the reader too while an earlier one still waits on a time +// start, so a publisher names its start. +test("a routed reader places a range past one still waiting", async () => { + const a = new BroadcastProducer(); + const ta = copy(a); + hooks.receiveTrack(ta.producer); + const front = new Front(); + front.serve(a.consume()); + ta.write(64n); + const sub = front.consumer + .track("seq") + .subscribe({ delay: { max: null }, ranges: [{ start: { time: 66n } }, { start: { time: 64n } }] }); + try { + await settle(); + const resolved = hooks.servingResolved(sub); + expect(resolved[0]).toBeUndefined(); + expect(resolved[1]?.start).toBe(64n); + } finally { + sub.close(); + front.consumer.close(); + a.close(); + } +}); + // Mirrors `an_ended_copy_leaves_a_time_start_to_the_serving_copy` in rs/moq-net/src/model/resume.rs: // a copy that failed holds nothing past its last group, so it reaches a time start past that group // back to its oldest. The copy continuing the track places it where the track holds it. diff --git a/js/net/src/resume.ts b/js/net/src/resume.ts index 5d145e2f68..d2310a9c78 100644 --- a/js/net/src/resume.ts +++ b/js/net/src/resume.ts @@ -666,10 +666,10 @@ class Reader implements ResumeSource { } /** - * The reader's ranges resolved, a relative or time anchor where the first copy to place them - * all placed it, whatever its failover cap: that bounds what the copy delivers, not where the - * ranges resolve. Kept once placed, past that copy being let go. Pending, naming every group, - * while an anchor waits on a copy to place it. A copy resolves a time start against the groups + * The reader's ranges resolved, a relative or time anchor where the first copy to place it + * placed it, whatever its failover cap: that bounds what the copy delivers, not where the ranges + * resolve. Kept once placed, past that copy being let go. A range stays as first held, unplaced, + * while an anchor of its waits on a copy to place it. A copy resolves a time start against the groups * it holds, which may place it below where the reader's window did: the window decides what is * handed out. Mirrors the Rust `Reader::window`. */ @@ -704,42 +704,41 @@ class Reader implements ResumeSource { } /** - * Resolve unsettled {@link #window} anchors with a copy's resolution of the reader's ranges, - * unless an anchor still waits there too. Mirrors the Rust `Reader::resolve`. + * Place each unsettled {@link #window} range where a copy resolved it, on its own: one whose + * anchors still wait leaves the rest placed, so a publisher names their starts. Mirrors the Rust + * `Reader::resolve`. */ #resolve(resolved: readonly (Resolved | undefined)[]): void { const resolution = this.#resolution; if (!resolution) return; - // Once placed, relative and time starts stay pinned even while a time end settles. - const placed = resolution.window.pending ? undefined : resolution.window.resolved(); - const anchored: track.Range[] = []; - for (const [index, range] of resolution.from.entries()) { - const at = resolved[index]; + const placed: [bigint, track.Range][] = []; + for (const key of resolution.window.unsettled()) { + const range = resolution.from[Number(key)]; + if (range === undefined) continue; + const at = resolved[Number(key)]; if (!at) { // A range the copy left unresolved keeps its anchors, which only a copy can place. const unplaced = range.start?.relative !== undefined || (range.start?.time ?? 0n) > 0n || range.end?.relative !== undefined; - if (unplaced && !isEmpty(range)) return; - anchored.push(range); + // Placed as it is: nothing of it waits on a copy. + if (!unplaced || isEmpty(range)) placed.push([key, range]); continue; } - const previous = placed?.[index]; - const start = previous ?? at; - const end = previous?.end ?? at.end; - if (range.end !== undefined && end === 0n) { - anchored.push(EMPTY); + if (range.end !== undefined && at.end === 0n) { + placed.push([key, EMPTY]); continue; } const out: track.Range = {}; // One that reached back to the oldest group still does, as on a plain reader. - if (range.start !== undefined && start.floored) out.start = { time: start.start }; - if (range.end !== undefined) out.end = end === undefined ? range.end : { time: end - 1n }; - anchored.push(out); + if (range.start !== undefined && at.floored) out.start = { time: at.start }; + if (range.end !== undefined) out.end = at.end === undefined ? range.end : { time: at.end - 1n }; + // A relative end still open would leave it waiting on a first group it never gets. + if (out.end?.relative !== undefined && !isEmpty(out)) continue; + placed.push([key, out]); } - const window = new Window(anchored, undefined, AT_KEYS); - if (!window.pending) resolution.window = window; + if (placed.length > 0) resolution.window.edit([], placed, undefined, AT_KEYS); } /** The reader's ranges, as its preferences name them. */ diff --git a/js/net/src/window.ts b/js/net/src/window.ts index a8b90bb0fe..f99e24ac20 100644 --- a/js/net/src/window.ts +++ b/js/net/src/window.ts @@ -560,6 +560,17 @@ export class Window { return this.#pending.size > 0; } + /** + * The keys of the ranges still waiting on a relative anchor, a live join's reach back, or a + * time start. Mirrors the Rust `Window::unsettled`. + */ + unsettled(): Set { + const keys = new Set([...this.#pending, ...this.#reaching]); + for (const entry of this.#waiting.all()) for (const key of entry.keys) keys.add(key); + for (const entry of this.#looking.all()) for (const key of entry.keys) keys.add(key); + return keys; + } + /** Whether nothing is left to resolve as groups arrive. */ get settled(): boolean { return this.#pending.size === 0 && !this.#unplaced() && this.#looking.size === 0; diff --git a/rs/moq-net/src/lite/publisher.rs b/rs/moq-net/src/lite/publisher.rs index d348b9d6fd..48d39a2c8e 100644 --- a/rs/moq-net/src/lite/publisher.rs +++ b/rs/moq-net/src/lite/publisher.rs @@ -8838,6 +8838,59 @@ mod serve_group_test { } } + /// As [`lite07_a_floored_time_start_reports_where_delivery_starts`], on a relay's front + /// whose copy already resolved a later range: that range names the group it resolved to, + /// whatever the floored one still waits on. + #[kio::test] + async fn lite07_a_routed_range_past_a_floored_time_start_reports_its_start() { + let mut routed = track::Routed::new("test", crate::track::Info::timed()); + routed.copy.received(); + routed.copy.anchored(); + write_group(&mut routed.copy, 1000, 1000); + let initial = [ + lite::Range::span(Some(100), 0, None, None), + lite::Range::span(Some(500), 0, None, None), + lite::Range::span(Some(1000), 0, None, None), + ]; + let bounds = Bounds::new(&initial, false); + let subscriber = routed + .logical + .consume() + .subscribe( + track::Subscription::default() + .with_delay(track::Delay::default().with_max(Duration::from_secs(3600))) + .with_ranges(bounds.ranges.iter().copied()), + ) + .now_or_never() + .expect("an accepted logical track answers at once") + .unwrap(); + let (mut run, mut writer, log) = lite07_run(SinkSession::new(Log::default()), subscriber); + run.initial = bounds.ranges.len() as u64; + run.requested = Requested::new((0..).zip(bounds.ranges.iter().copied())); + assert!(run.poll_step(&mut writer, &kio::Waiter::noop()).is_ready()); + assert!(run.start.resolved().is_none(), "time 100 waits on the copy to place it"); + + let live = [(1, initial[1]), (2, initial[2])]; + run.update(lite07_add(&run, &live, 3, &[])); + while run.poll_step(&mut writer, &kio::Waiter::noop()).is_ready() {} + // A range an update adds afterwards is told where it starts too. + run.update(lite07_add(&run, &live, 3, &[initial[2]])); + while run.poll_step(&mut writer, &kio::Waiter::noop()).is_ready() {} + let answers: Vec<_> = responses(&mut writer, &log) + .await + .into_iter() + .filter_map(|msg| match msg { + lite::SubscribeResponse::Start(start) => Some((None, start.starts)), + lite::SubscribeResponse::Started(started) => Some((Some(started.id), vec![started.start])), + _ => None, + }) + .collect(); + assert_eq!( + answers, + [(None, vec![None, Some(1000), Some(1000)]), (Some(3), vec![Some(1000)])] + ); + } + /// A gap the publisher never declared might have existed, so the end names it with a /// DROP rather than a SKIP: here the reader passed it, so it is stale. #[kio::test] diff --git a/rs/moq-net/src/model/resume.rs b/rs/moq-net/src/model/resume.rs index bd0c573ba1..6b4c5260ae 100644 --- a/rs/moq-net/src/model/resume.rs +++ b/rs/moq-net/src/model/resume.rs @@ -1747,8 +1747,8 @@ impl Reader { &self.window } - /// Place the unsettled [`Self::window`] ranges where a copy resolved them, unless one it - /// leaves unresolved, or a relative anchor, still waits there too. + /// Place each unsettled [`Self::window`] range where a copy resolved it, on its own: one + /// whose anchors still wait leaves the rest placed, so a publisher names their starts. fn resolve(&mut self, resolved: &BTreeMap) { let mut placed = Vec::new(); for key in self.window.unsettled() { @@ -1761,7 +1761,7 @@ impl Reader { && (matches!(range.start, Anchor::Relative(_) | Anchor::Time(1..)) || matches!(range.end, Some(Anchor::Relative(_)))) { - return; + continue; } // Placed as it is: nothing of it waits on a copy. placed.push((key, range)); @@ -1783,13 +1783,15 @@ impl Reader { Anchor::Relative(_) | Anchor::Time(_) => Anchor::Oldest, start => start, }; - placed.push((key, track::Range { start, end })); + let range = track::Range { start, end }; + // A relative end still open would leave it waiting on a first group it never gets. + if !range.is_empty() && matches!(range.end, Some(Anchor::Relative(_))) { + continue; + } + placed.push((key, range)); } - // A relative end still open leaves the window waiting on a first group it never gets. - if placed.iter().any(|(_, range)| { - !range.is_empty() - && (matches!(range.start, Anchor::Relative(_)) || matches!(range.end, Some(Anchor::Relative(_)))) - }) { + // An edit restarts the window's coverage check, so one that places nothing is skipped. + if placed.is_empty() { return; } self.window @@ -4152,6 +4154,51 @@ mod test { assert_eq!(floored.waiting_keys([0]), [Some((500, None))]); } + /// A routed reader places each range its copy resolved, even while an earlier one waits on + /// a time start: a floor at that time lets the start go out, and the later range names its + /// group rather than none. + #[kio::test] + async fn a_routed_reader_places_a_range_past_one_still_waiting() { + let routes = Producer::new(); + let logical = logical(&routes); + let serving = received_copy(); + serving.anchored(); + routes.serve(serving.consume()); + write(&serving, 1000); + let ranges = Subscription::default() + .with_delay(Delay::default().with_max(None)) + .with_ranges([ + track::Range { + start: Anchor::Time(500), + end: None, + }, + track::Range { + start: Anchor::Time(1000), + end: None, + }, + ]); + let mut floored = logical + .consume() + .subscribe(ranges) + .now_or_never() + .unwrap() + .unwrap() + .with_range(500..); + assert!(floored.poll_start(&kio::Waiter::noop()).is_ready()); + assert_eq!(floored.waiting_keys([0, 1]), [Some((500, None)), None]); + assert_eq!( + floored.resolved_keys([0, 1]), + [ + None, + Some(Resolved { + start: 1000, + end: None, + floored: true, + }) + ] + ); + } + /// As [`an_ended_copy_leaves_a_time_start_to_the_serving_copy`], for a reader that replaces /// its ranges while its copy has failed: the replacement places them. #[kio::test]