From 97f1e6232ac582e045a17634a2816011c8d7dedc Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 15 Nov 2026 04:26:24 -0800 Subject: [PATCH 1/3] chore(quest): claim quest/m1/flight-priority.md Quest-Claim: 3a2169ab830fd6c2 From 90735684f6d12ff5eb86f726435e587e6e474cd3 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 15 Nov 2026 04:39:47 -0800 Subject: [PATCH 2/3] fix(net): a flight asks upstream with its rider's priority and budget track::board hardcoded priority 0 and no budget for a flight's fill, so a late joiner's replay ranked below all live traffic upstream. The group's expiry, the subscriber's or fetch's per-reader policy, now reports what the reader asks fills with, and board asks with it (oldest first, since a flight holds one group). Co-Authored-By: Claude Opus 5.5 --- quest/m1/flight-priority.md | 16 ------- rs/moq-net/src/model/group.rs | 23 ++++++++++ rs/moq-net/src/model/track.rs | 71 ++++++++++++++++++++++++++++-- rs/moq-net/src/model/track/fill.rs | 2 +- 4 files changed, 92 insertions(+), 20 deletions(-) delete mode 100644 quest/m1/flight-priority.md diff --git a/quest/m1/flight-priority.md b/quest/m1/flight-priority.md deleted file mode 100644 index 4757f6feda5..00000000000 --- a/quest/m1/flight-priority.md +++ /dev/null @@ -1,16 +0,0 @@ -# [XS] A flight asks upstream with its riders' priority - -## Goal - -A flight's upstream fill (`track::board` in `rs/moq-net/src/model/track.rs`) -asks with the priority and delay of the reader that boarded it, as every other -fill does, so a late joiner's replay is not ranked below all live traffic on a -congested upstream link. - -## Plan - -Found 2026-11-14 by the [feature review](/quest/m3/release/feature-review.md): -`board` hardcodes `fill::Asking { priority: 0, max_delay: None }`. Pass the -rider's `Preferences` in, and add a test that the fill carries them. - -Public API: none. Wire: none. diff --git a/rs/moq-net/src/model/group.rs b/rs/moq-net/src/model/group.rs index 7331fdb0fda..b0b21060313 100644 --- a/rs/moq-net/src/model/group.rs +++ b/rs/moq-net/src/model/group.rs @@ -3866,6 +3866,9 @@ pub(super) trait Expiry: Send + Sync + std::panic::UnwindSafe + std::panic::RefU /// Keep the reader's budget and cap while following a replacement track's edge. fn for_track(&self, track: &track::Consumer) -> Arc; + + /// What the reader asks a fill with, such as the flight it boards. + fn asking(&self) -> super::track::Asking; } /// The read cursor over a [`Producer`]'s shared state. @@ -4069,6 +4072,18 @@ impl Consumer { self } + /// What this reader asks a fill with: its subscription's or fetch's, else the defaults. + pub(super) fn asking(&self) -> super::track::Asking { + self.expiry.as_ref().map_or( + super::track::Asking { + priority: 0, + max_delay: None, + order: super::subscription::Order::Ascending, + }, + |expiry| expiry.asking(), + ) + } + /// The hand-off of this copy's head, shared by every reader that could resume it /// elsewhere. pub(super) fn handoff(&self) -> Arc { @@ -7962,6 +7977,14 @@ mod test { fn for_track(&self, _: &track::Consumer) -> Arc { Arc::new(self.clone()) } + + fn asking(&self) -> crate::model::track::Asking { + crate::model::track::Asking { + priority: 0, + max_delay: None, + order: crate::model::subscription::Order::Ascending, + } + } } /// A reader that took every frame of an unfinished group still fails with `Old` when diff --git a/rs/moq-net/src/model/track.rs b/rs/moq-net/src/model/track.rs index fe00dfecd4f..e8525234ffc 100644 --- a/rs/moq-net/src/model/track.rs +++ b/rs/moq-net/src/model/track.rs @@ -34,6 +34,7 @@ use demand::Subscriptions; mod fill; mod hole; mod miss; +pub(super) use fill::Asking; pub use fill::Fill; use fill::FillState; pub(crate) use hole::Hole; @@ -3843,7 +3844,8 @@ pub(super) enum Board { } /// Board `reader`'s group at its frame, which the copy it read shed: ride a copy that -/// admits it, else ask the track's [`Requests`] handlers for a flight from that frame. +/// admits it, else ask the track's [`Requests`] handlers for a flight from that frame, +/// with the reader's priority and budget. /// `None` when no handler can serve one. /// /// A compressed group's flight starts at frame 0, since a later frame builds on the ones @@ -3858,10 +3860,10 @@ pub(super) fn board(track: &kio::Producer, reader: &group::Consumer) } let fills = state.fills.clone(); drop(state); + // One group either way, so it never turns a wider fill it joins newest first. let asking = fill::Asking { - priority: 0, - max_delay: None, order: Order::Ascending, + ..reader.asking() }; let (key, frame) = (reader.start, if compress { 0 } else { reader.index() }); let join = fills.lock().fly(&fills, key, frame, asking)?; @@ -6931,6 +6933,7 @@ impl Fetching { cache, reading: Reading::new(state.clone()), key, + priority: self.priority, max_delay: self.max_delay, superseded: Superseded::default(), }); @@ -7223,6 +7226,7 @@ struct FetchExpiry { cache: Arc, reading: Reading, key: u64, + priority: i8, max_delay: Option, superseded: Superseded, } @@ -7278,11 +7282,20 @@ impl group::Expiry for FetchExpiry { state, cache, key: self.key, + priority: self.priority, max_delay: self.max_delay, superseded: Superseded::default(), }) } + fn asking(&self) -> Asking { + Asking { + priority: self.priority, + max_delay: self.max_delay, + order: Order::Ascending, + } + } + fn ended(&self) { self.reading.release(); } @@ -7327,6 +7340,15 @@ impl group::Expiry for GroupExpiry { }) } + fn asking(&self) -> Asking { + let subscription = self.subscription.read(); + Asking { + priority: subscription.priority, + max_delay: subscription.delay.max, + order: subscription.order, + } + } + fn ended(&self) { self.reading.release(); } @@ -27550,6 +27572,49 @@ mod test { assert!(matches!(late.read_frame().now_or_never(), Some(Err(Error::Old)))); } + /// A flight asks upstream with its rider's priority and budget, a subscriber's or a + /// fetch's, as any other fill does, so a late joiner's replay is not ranked below live + /// traffic. It asks oldest first whatever the rider's order, since it holds one group. + #[test] + #[cfg(feature = "async")] + fn a_flight_asks_with_its_riders_priority() { + let budget = Duration::from_secs(10); + let producer = track_producer("test", Info::default()); + let requests = producer.requests(); + let mut sub = producer.subscribe( + Subscription::default() + .with_priority(5) + .with_delay(Delay::default().with_max(budget)) + .with_order(Order::Descending), + ); + let mut live = producer.append_next().unwrap(); + for index in 0..3_000u32 { + live.write_frame(crate::Timestamp::unscaled(live.start), numbered(index)) + .unwrap(); + } + let mut late = sub.recv_group().now_or_never().unwrap().unwrap().expect("group 0"); + assert_eq!(read_numbered(&mut late), None, "boarding"); + let fill = asked(&requests).expect("a flight"); + assert_eq!(fill.start(), Position { group: 0, frame: 0 }); + assert_eq!(fill.priority(), 5); + assert_eq!(fill.max_delay(), Some(budget)); + assert_eq!(fill.order(), Order::Ascending); + drop(late); + drop(fill); + + let fetch = group::Fetch::default().with_priority(-3).with_max_delay(budget); + let mut fetched = producer + .consume() + .fetch_group(0, fetch) + .now_or_never() + .expect("cached") + .expect("group 0"); + assert_eq!(read_numbered(&mut fetched), None, "boarding"); + let fill = asked(&requests).expect("a flight"); + assert_eq!(fill.priority(), -3); + assert_eq!(fill.max_delay(), Some(budget)); + } + /// Pool debt sheds a flight even once the cached copy of its group was evicted whole. #[test] #[cfg(feature = "async")] diff --git a/rs/moq-net/src/model/track/fill.rs b/rs/moq-net/src/model/track/fill.rs index 0272ec0ca1d..d96292f2b59 100644 --- a/rs/moq-net/src/model/track/fill.rs +++ b/rs/moq-net/src/model/track/fill.rs @@ -111,7 +111,7 @@ impl Pending { /// What a reader asks its fills with, which it may change while they are out. #[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub(super) struct Asking { +pub(in crate::model) struct Asking { pub priority: i8, pub max_delay: Option, pub order: Order, From af632654438bc057a679cce3efa7ccbc7dca4405 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 15 Nov 2026 04:55:22 -0800 Subject: [PATCH 3/3] fix(net): a looser rider asks again after a tighter budget's Old Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/model/track.rs | 85 +++++++++++++++++++++++++++++------ 1 file changed, 72 insertions(+), 13 deletions(-) diff --git a/rs/moq-net/src/model/track.rs b/rs/moq-net/src/model/track.rs index e8525234ffc..b88ac58883c 100644 --- a/rs/moq-net/src/model/track.rs +++ b/rs/moq-net/src/model/track.rs @@ -3869,6 +3869,8 @@ pub(super) fn board(track: &kio::Producer, reader: &group::Consumer) let join = fills.lock().fly(&fills, key, frame, asking)?; Some(Board::Wait(Boarding { join: Box::new(join), + fills, + asking, key, frame, })) @@ -3888,6 +3890,9 @@ pub(super) fn hand_over( pub(super) struct Boarding { // Boxed: a reader holds one only while boarding. join: Box, + // Where to ask again, with what, when a tighter budget than this reader's refused it. + fills: kio::Shared, + asking: fill::Asking, key: u64, frame: u64, } @@ -3908,15 +3913,36 @@ impl Boarding { }; let key = self.key; let answer = self.join.outcome().poll(waiter, |outcome| match outcome.refused(key) { - Some((err, _)) => Poll::Ready(Err(err.clone())), - None if outcome.is_accepted(key) => Poll::Ready(outcome.partial(key, frames).ok_or(Error::Cancel)), + Some((err, asked)) => Poll::Ready(Err((err.clone(), asked))), + None if outcome.is_accepted(key) => Poll::Ready(outcome.partial(key, frames).ok_or((Error::Cancel, None))), None => Poll::Pending, }); - Poll::Ready(match ready!(answer) { - Ok(Ok(copy)) => copy.try_consume().ok_or(Error::Cancel), - Ok(Err(err)) => Err(err), - Err(_closed) => Err(Error::NotFound), - }) + // The closed channel's guard borrows the join, which a retry replaces. + let (err, asked) = match ready!(answer.map(|answer| answer.map_err(drop))) { + Ok(Ok(copy)) => return Poll::Ready(copy.try_consume().ok_or(Error::Cancel)), + Ok(Err(refused)) => refused, + Err(_closed) => return Poll::Ready(Err(Error::NotFound)), + }; + // Boarded a flight already asked under a tighter budget, which judged the group too + // old for that budget, not ours: ask again with ours. Terminates, since the new + // flight asks at least our budget. + if !matches!(err, Error::Old) || !looser(asked, self.asking.max_delay) { + return Poll::Ready(Err(err)); + } + let Some(join) = self.fills.lock().fly(&self.fills, key, self.frame, self.asking) else { + return Poll::Ready(Err(err)); + }; + *self.join = join; + self.poll(waiter) + } +} + +/// Whether `ours` waits longer than the budget `asked` upstream, `None` being the longest. +fn looser(asked: Option, ours: Option) -> bool { + match (asked, ours) { + (Some(asked), Some(ours)) => ours > asked, + (Some(_), None) => true, + (None, _) => false, } } @@ -7004,12 +7030,7 @@ impl Fetching { // Joined after a tighter budget went on the wire, which judged the group too old // for that budget, not ours: ask again with ours. Terminates, since the new // fill asks at least our budget. - let looser = match (asked, self.max_delay) { - (Some(asked), Some(ours)) => ours > asked, - (Some(_), None) => true, - (None, _) => false, - }; - if matches!(err, Error::Old) && looser { + if matches!(err, Error::Old) && looser(asked, self.max_delay) { let options = group::Fetch { priority: self.priority, max_delay: self.max_delay, @@ -27615,6 +27636,44 @@ mod test { assert_eq!(fill.max_delay(), Some(budget)); } + /// A rider that boarded a flight already asked under a tighter budget is not failed by + /// that budget's `Old`: it asks a flight of its own with its budget. + #[test] + #[cfg(feature = "async")] + fn a_looser_rider_asks_again_after_old() { + let producer = track_producer("test", Info::default()); + let requests = producer.requests(); + let subscribe = |budget: u64| { + let delay = Delay::default().with_max(Duration::from_secs(budget)); + producer.subscribe(Subscription::default().with_delay(delay)) + }; + let (mut tight, mut loose) = (subscribe(1), subscribe(10)); + let mut live = producer.append_next().unwrap(); + for index in 0..3_000u32 { + live.write_frame(crate::Timestamp::unscaled(live.start), numbered(index)) + .unwrap(); + } + let recv = |sub: &mut Subscriber| sub.recv_group().now_or_never().unwrap().unwrap().expect("group 0"); + let (mut tight, mut loose) = (recv(&mut tight), recv(&mut loose)); + + assert_eq!(read_numbered(&mut tight), None, "boarding"); + let req = requests.requested_fill_group().now_or_never().unwrap().unwrap(); + assert_eq!(req.max_delay(), Some(Duration::from_secs(1))); + assert_eq!(read_numbered(&mut loose), None, "boards the same flight"); + assert!(requests.requested_fill_group().now_or_never().is_none(), "one flight"); + + req.reject(Error::Old); + assert!(matches!(tight.read_frame().now_or_never(), Some(Err(Error::Evicted)))); + assert_eq!(read_numbered(&mut loose), None, "asks again"); + let req = requests.requested_fill_group().now_or_never().unwrap().unwrap(); + assert_eq!(req.max_delay(), Some(Duration::from_secs(10))); + let mut flight = req.accept(None).unwrap(); + flight + .write_frame(crate::Timestamp::unscaled(flight.start), numbered(0)) + .unwrap(); + assert_eq!(read_numbered(&mut loose), Some(0)); + } + /// Pool debt sheds a flight even once the cached copy of its group was evicted whole. #[test] #[cfg(feature = "async")]