diff --git a/quest/m1/README.md b/quest/m1/README.md index 38b62fe1570..db14564f346 100644 --- a/quest/m1/README.md +++ b/quest/m1/README.md @@ -135,7 +135,6 @@ removed). - [A job's exact route continues its claim's readers](/quest/m1/announce-takeover.md) - a job's route inherits its claim's identity, replacing the ANNOUNCE_TAKEOVER predecessor design - [Subscribe ranges](/quest/m1/subscribe-ranges/README.md) - a lite-07 SUBSCRIBE asks for past and live ranges with absolute or relative ends, in either order, and replaces FETCH; merged ranges never starve a subscriber; relays fill misses by range, including over moq-transport - [Drop set](/quest/m1/drop-set.md) - each cursor judges missing groups against its own budget, so a narrow reader drops promptly and a widening re-offers groups already reported dropped on lite-07 -- [A tightened SUBSCRIBE keeps the start's budget honest](/quest/m1/start-budget-update.md) - a relay copy records the delay its start was resolved under, so a SUBSCRIBE_UPDATE tightening cannot make later readers skip fillable history - [Broadcast archives](/quest/m1/archive/README.md) - ANNOUNCE, TRACKS, and a SUBSCRIBE per track record every track under a prefix to any object_store, a host serves a stored broadcast back, and the catalog drops its archive pointer for a per-rendition `hls` field - [Finalize moq-lite-07](/quest/m1/lite07-finalize.md) - when the maintainer cuts it, lite-07 negotiates as `moq-lite-07` and the next release ships it - [Smoke token subject](/quest/m1/smoke-token-subject.md) - condition: grant subject ships; then the release smoke test signs with `--subject` diff --git a/quest/m1/start-budget-update.md b/quest/m1/start-budget-update.md deleted file mode 100644 index 04ecc8aafae..00000000000 --- a/quest/m1/start-budget-update.md +++ /dev/null @@ -1,54 +0,0 @@ -# [S] A tightened SUBSCRIBE keeps the start's budget honest - -## Goal - -A relay copy remembers the `max_delay` that was in effect when its -publisher resolved SUBSCRIBE_START, not only the one sent at SUBSCRIBE. If a -SUBSCRIBE_UPDATE tightens the delay before the start is picked, a later -reader whose delay is looser than the tightened one, but no looser than the -original, still fills the history between the two starts. Released wires are -unchanged. - -## Plan - -Decided 2026-10-29 (maintainer, `/quest-plan` of moq.pro's announce ramp -loss follow-ups): its own quest in m1, rather than waiting on -[Drop set](/quest/m1/drop-set.md) or -[Delete the old start bookkeeping](/quest/m1/subscribe-ranges/start-bookkeeping.md), -since it fixes released lite-06 behavior. - -Found by review of [#7168](https://github.com/moq-dev/moq/pull/7168): the -lite subscriber sets `requested_max_delay` once, at SUBSCRIBE -(`rs/moq-net/src/lite/subscriber.rs`). `Misses` then gives up every group -below the start for any reader whose budget is no looser than that value. -After a tightening update, the start was resolved under the tighter budget, -so the recorded looser one makes some readers skip history they could have -filled. It loses history only in that window; it does not bring back #7168's -over-fetch. - -Record the budget the start was actually resolved under. SUBSCRIBE_START -carries a group, not which update it was picked under, and updates can cross -it in flight, so the budget current when START arrives is not enough: an -update sent after the publisher picked the start would be recorded in its -place, too loose after a widening or too tight after a tightening. When the -subscriber cannot tell which of its sent budgets the publisher applied, -record the loosest of them. That keeps today's history loss in the -ambiguous window but never brings back the over-fetch. - -Add integration tests in `rs/moq-net/tests/integration`, direct and through -a relay: subscribe, tighten before the start, then a second reader widens -partly, which fails on `main` and passes with the fix; and a tightening and -a widening that each cross an already-picked START, where the recorded -budget must never be tighter than the one the start was picked under. - -Open question for whoever starts this: which lite-06 ordering, if any, tells -the subscriber the publisher applied a tightening before picking the start. -Without one, every tightening sent before START arrives stays ambiguous, the -loosest-budget rule records the SUBSCRIBE budget as today, and the Goal is -out of reach on the released wire. Then propose rewriting this quest to a -wire change for a later draft, or deleting it. - -## Related - -- [Drop set](/quest/m1/drop-set.md) - records the budget each drop was judged under, the same idea for drops -- [Delete the old start bookkeeping](/quest/m1/subscribe-ranges/start-bookkeeping.md) - moves where a subscription starts into the model, which should carry this field diff --git a/rs/moq-net/src/lite/subscriber.rs b/rs/moq-net/src/lite/subscriber.rs index 603abbc535b..cf9fcc32674 100644 --- a/rs/moq-net/src/lite/subscriber.rs +++ b/rs/moq-net/src/lite/subscriber.rs @@ -2140,7 +2140,6 @@ mod tests { .unwrap(), id: 0, max_delay: Duration::ZERO, - requested_max_delay: Duration::ZERO, start: None, priority: 0, requested: None, @@ -2316,7 +2315,6 @@ mod tests { .unwrap(), id: 0, max_delay: Duration::ZERO, - requested_max_delay: Duration::ZERO, start: Some(floor), priority: 0, requested: Some(floor), @@ -2773,7 +2771,6 @@ mod tests { stream, id: 0, max_delay: Duration::ZERO, - requested_max_delay: Duration::ZERO, start: Some(2), priority: 0, requested: Some(2), @@ -6741,9 +6738,6 @@ struct SubStream { /// start sits elsewhere the request-tracked floor stands instead, and demand /// returning here makes the declaration valid again. requested: Option, - /// The max delay the SUBSCRIBE itself carried, fixed for the stream's life: a lite-06+ - /// SUBSCRIBE_START resolves the start from it, skipping older groups as stale. - requested_max_delay: Duration, /// The groups received for this subscription, shared with its [`TrackEntry`]. tail: kio::Producer, /// The first group the publisher serves (SUBSCRIBE_START), once declared. @@ -7516,7 +7510,6 @@ impl Establish { stream, id: self.id, max_delay: wire_max_delay(self.subscription.max_delay), - requested_max_delay: wire_max_delay(self.subscription.max_delay), start: self.subscription.start(), ranges: self.ranges.clone(), priority: self.subscription.priority, @@ -8517,9 +8510,7 @@ impl ServeLoop { // request-tracked floor stands rather than a guess. if active.start == active.requested { let _ = match (serve.subscriber.version.resolves_start(), served) { - (true, Some(served)) => { - self.serving.start_resolved(served, active.requested_max_delay) - } + (true, Some(served)) => self.serving.start_resolved(served), _ => self.serving.start_at(served), }; } diff --git a/rs/moq-net/src/model/track.rs b/rs/moq-net/src/model/track.rs index 8ce096d3f6b..0cc48e09f1f 100644 --- a/rs/moq-net/src/model/track.rs +++ b/rs/moq-net/src/model/track.rs @@ -475,9 +475,9 @@ pub(crate) struct TrackState { // [`Subscriber::poll_start`]) wait on it; everything else treats the floor as usual. start_pending: bool, - // The budget the publisher resolved `start_sequence` from (a lite-06+ SUBSCRIBE_START), - // skipping every older group as stale under it. Cleared by any other declaration. - start_budget: Option, + // Whether the publisher resolved `start_sequence` (a lite-06+ SUBSCRIBE_START), which + // may sit above history a reader can still fill. Cleared by any other declaration. + start_resolved: bool, // A copy received from a remote publisher, whose declared end waits for groups still // in flight below it (see `tail`), and whose readers' relative and time anchors are @@ -2496,7 +2496,7 @@ impl TrackState { self.latch_settled(); self.start_sequence = start_sequence; self.start_pending = pending; - self.start_budget = None; + self.start_resolved = false; if let Some(start) = start_sequence { self.cache.wakes().arrived(..start); let now = self.cache.pool().now_wall(); @@ -3493,13 +3493,14 @@ impl Producer { Ok(()) } - /// [`Self::start_at`] a start the publisher resolved from `budget`: every older group - /// is stale under it, so a reader whose budget is no looser gives them up unasked. + /// [`Self::start_at`] a start the publisher resolved from its subscriber's budget. An + /// update can cross the response, so that budget is unknown: every older group stays + /// fillable, and a fill that finds none ends empty. #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] - pub(crate) fn start_resolved(&mut self, sequence: u64, budget: Duration) -> Result<()> { + pub(crate) fn start_resolved(&mut self, sequence: u64) -> Result<()> { let mut state = self.modify()?; state.set_start(Some(sequence), false); - state.start_budget = Some(budget); + state.start_resolved = true; Ok(()) } @@ -18807,29 +18808,26 @@ mod test { assert!(dynamic.poll_requested_fill(&waiter).is_pending()); } - /// Below a start its publisher resolved from a budget, a reader no looser than it gives - /// every group up unasked, while a looser one may still reach some, so it asks. + /// Below a start its publisher resolved, a reader asks for the history its budget + /// reaches: an update may have crossed the start, so the copy cannot tell which budget + /// skipped those groups, and a fill that finds none ends empty. #[test] #[cfg(feature = "async")] - fn below_a_start_resolved_from_a_budget_only_a_looser_reader_asks() { + fn below_a_resolved_start_a_reader_asks() { let mut producer = track_producer("test", Info::timed()); let dynamic = producer.requests(); - let mut narrow = producer.subscribe(replay()); - let mut wide = producer.subscribe(Subscription::default().with_max_delay(Duration::from_secs(60))); - producer.start_resolved(2, Duration::from_secs(30)).unwrap(); + let mut reader = producer.subscribe(replay()); + producer.start_resolved(2).unwrap(); write_group(&producer, 2); write_group(&producer, 3); let waiter = kio::Waiter::noop(); - assert_eq!(drain_groups(&mut narrow), [2, 3]); - assert_eq!(drained_drops(&mut narrow), [(0, 2)]); + assert_eq!(drain_groups(&mut reader), [2, 3]); assert!( - dynamic.poll_requested_fill(&waiter).is_pending(), - "the narrow reader asks nothing" + drained_drops(&mut reader).is_empty(), + "nothing below the start is given up unasked" ); - - assert_eq!(drain_groups(&mut wide), [2, 3]); let Poll::Ready(Ok(fill)) = dynamic.poll_requested_fill(&waiter) else { - panic!("the wide reader asks below the start"); + panic!("the reader asks below the start"); }; assert_eq!((fill.start().group, fill.end()), (0, 2)); } diff --git a/rs/moq-net/src/model/track/miss.rs b/rs/moq-net/src/model/track/miss.rs index 0359daeb224..feb76ffd73f 100644 --- a/rs/moq-net/src/model/track/miss.rs +++ b/rs/moq-net/src/model/track/miss.rs @@ -663,20 +663,12 @@ impl Misses { self.judged.insert(run.clone()); } let start = state.start_sequence.unwrap_or(0); - let (stale_below, unasked) = match state.start_budget { - // Its publisher skipped every older group as stale under a budget no tighter - // than this reader's, so they are stale for it too. - Some(budget) if drift.budget <= budget => (start, false), - // Such a copy cannot tell a group a looser reader's budget reaches, so it leaves - // them to the feed's re-offer. - Some(_) => (0, state.fills_from_start), - // The feed began at the live edge or the floor the copy asked for, so older - // groups are history only a reader naming them asked for. - None => ( - 0, - state.fills_from_start || state.received && named.is_none_or(|named| named >= start), - ), - }; + // Below a start its publisher resolved from a budget, which an update may have changed + // in flight, every older group is history a fill may still find. A feed that began at + // the live edge or the floor the copy asked for leaves older groups as history only a + // reader naming them asked for. + let unasked = state.fills_from_start + || !state.start_resolved && state.received && named.is_none_or(|named| named >= start); if unasked && start > 0 { candidates.remove(0..start); } @@ -740,10 +732,8 @@ impl Misses { // budget is stale throughout. let stale: Vec> = asks .iter() - .filter_map(|run| match state.drifted(run.end - 1, &drift.edge, drift.budget) { - true => Some(run.clone()), - false => Some(run.start..run.end.min(stale_below)).filter(|run| !run.is_empty()), - }) + .filter(|run| state.drifted(run.end - 1, &drift.edge, drift.budget)) + .cloned() .collect(); for run in stale { asks.remove(run.clone()); diff --git a/rs/moq-net/tests/integration/support/mock.rs b/rs/moq-net/tests/integration/support/mock.rs index 6de72cea5b9..d811138ab0d 100644 --- a/rs/moq-net/tests/integration/support/mock.rs +++ b/rs/moq-net/tests/integration/support/mock.rs @@ -204,7 +204,7 @@ impl MockSendStream { && size > 0 { if let Some(types) = self.first_byte.take() { - types.lock().unwrap().push(first.expect("non-empty write")); + types.lock().push(first.expect("non-empty write")); } self.line.arrivals.lock().unwrap().push_back(self.conn.arrival()); } @@ -427,7 +427,7 @@ impl Drop for MockChunks { type Resets = Arc>>; /// The first byte of each bidi stream one side has opened. -type StreamTypes = Arc>>; +type StreamTypes = Arc>>; /// One side's knobs. struct Side { @@ -832,7 +832,21 @@ impl MockSession { /// The first byte, the stream type, of every bidi stream this side has written to, /// in the order each was first written. pub fn bidi_types(&self) -> Vec { - self.side.bidi_types.lock().unwrap().clone() + self.side.bidi_types.read().clone() + } + + /// Wait for `count` streams of `kind` to reach the wire. + pub async fn bidi_count(&self, kind: u8, count: usize) { + kio::wait(|waiter| { + self.side.bidi_types.poll(waiter, |types| { + if types.iter().filter(|&&byte| byte == kind).count() >= count { + Poll::Ready(()) + } else { + Poll::Pending + } + }) + }) + .await; } /// Every code this side has reset a stream with, in order. diff --git a/rs/moq-net/tests/integration/widened_max_age.rs b/rs/moq-net/tests/integration/widened_max_age.rs index 477b4953646..eae49bf64e9 100644 --- a/rs/moq-net/tests/integration/widened_max_age.rs +++ b/rs/moq-net/tests/integration/widened_max_age.rs @@ -11,7 +11,7 @@ use std::collections::BTreeSet; use std::time::Duration; use moq_net::track::{Info, Range, Subscription}; -use moq_net::{Hop, Timescale, Timestamp, Version, origin, track}; +use moq_net::{Hop, Timescale, Timestamp, Version, kio, origin, track}; use crate::support::harness::{MockConnectOptions, MockPair, connect_mock, peer, spawn}; @@ -45,44 +45,57 @@ struct Chain { source: track::Producer, viewer: origin::Producer, links: Vec, + source_gate: kio::Producer, _hold: Vec>, } impl Chain { /// Without `relay`, the viewer reads the publisher directly. async fn new(version: &str, relay: bool) -> Self { + let chain = Self::empty(version, relay).await; + chain.populate(); + chain + } + + async fn empty(version: &str, relay: bool) -> Self { let version: Version = version.parse().unwrap(); let publisher = origin(1); let relay = relay.then(|| origin(2)); let viewer = origin(3); let mut links = Vec::new(); - match &relay { - Some(relay) => { - links.push(peer(version, &publisher, relay).await); - links.push(peer(version, relay, &viewer).await); - } - None => links.push(peer(version, &publisher, &viewer).await), + let source_gate = kio::Producer::new(true); + let mut options = MockConnectOptions::new(version); + options.server_publish = Some(publisher.consume()); + options.client_subscribe = Some(relay.as_ref().unwrap_or(&viewer).clone()); + options.server_gate = Some(source_gate.consume()); + links.push(connect_mock(options).await); + if let Some(relay) = &relay { + links.push(peer(version, relay, &viewer).await); } let broadcast = publisher.create_broadcast("live").unwrap(); let source = broadcast .create_track("video", Info::default().with_timescale(Timescale::MILLI)) .unwrap(); - for sequence in 0..GROUPS { - let mut group = source.create_group(moq_net::group::Info { sequence }).unwrap(); - group - .write_frame(Timestamp::from_millis(sequence * 1000).unwrap(), &b"x"[..]) - .unwrap(); - group.finish().unwrap(); - } broadcast.announce(Default::default()).unwrap(); Self { source, viewer, links, + source_gate, _hold: vec![Box::new(publisher), Box::new(relay), Box::new(broadcast)], } } + fn populate(&self) { + for sequence in 0..GROUPS { + let mut group = self.source.create_group(moq_net::group::Info { sequence }).unwrap(); + group + .write_frame(Timestamp::from_millis(sequence * 1000).unwrap(), &b"x"[..]) + .unwrap(); + group.finish().unwrap(); + } + } + /// The FETCH streams opened on any lite link, by their stream type 3. fn fetches(&self) -> usize { self.links @@ -116,7 +129,8 @@ async fn received(subscriber: &mut track::Subscriber) -> BTreeSet { /// A fresh reader asks no fill for the history below where its feed starts, through a relay /// or not: below a start resolved from a budget no tighter than its own, every group is -/// stale, and below a live edge start it names no floor under, none was asked for. +/// stale by its media time, and below a live edge start it names no floor under, none was +/// asked for. #[kio::test] async fn a_fresh_reader_fills_nothing_below_its_start() { for (version, want) in [ @@ -140,6 +154,48 @@ async fn a_fresh_reader_fills_nothing_below_its_start() { } } +/// Tighten while no start is selectable, then ask for a budget between the old and +/// selected ones. Hold the publisher's driver so only an actual fill request, rather +/// than its live re-offer, can prove the copy left the history below its start fillable. +#[kio::test] +async fn a_tightened_start_leaves_history_fillable_by_an_intermediate_reader() { + for relay in [false, true] { + let chain = Chain::empty(VERSION, relay).await; + let mut first = chain.subscribe(WIDE).await; + let mut source = chain.source.clone(); + while source.subscription_changed().await.unwrap().is_none() {} + first + .update( + Subscription::default() + .with_max_delay(NARROW) + .with_ranges([Range::oldest()]), + ) + .unwrap(); + while source.subscription_changed().await.unwrap().and_then(|s| s.max_delay) != Some(NARROW) {} + chain.populate(); + assert_eq!(received(&mut first).await, (6..GROUPS).collect()); + + *chain.source_gate.write().ok().unwrap() = false; + let before = chain.fetches(); + let mut intermediate = chain.subscribe(Duration::from_millis(4500)).await; + // Drive the reader's miss walk too, with the upstream deliberately parked. + let reading = kio::clock::sim::spawn(async move { + let mut got = BTreeSet::new(); + while got.len() < 6 { + got.insert(intermediate.recv_group().await.unwrap().unwrap().sequence); + } + got + }); + let upstream = &chain.links[0].client_transport; + kio::clock::timeout(TIMEOUT, upstream.bidi_count(3, before + 1)) + .await + .expect("the history below the start is fillable"); + *chain.source_gate.write().ok().unwrap() = true; + // This reader can also receive the feed's re-offer once the source resumes. + assert_eq!(reading.await.unwrap(), (4..GROUPS).collect(), "relay={relay}"); + } +} + /// What the subscriber reads after widening its own max age, through a relay or not. #[kio::test] async fn a_widened_reader_gets_what_was_skipped() {