From 0b49ab4ceffb79e6070991a58b72cc34d41aca61 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 2 Nov 2026 04:01:26 -0800 Subject: [PATCH 1/5] chore(quest): claim quest/m1/relay-fetched-copy-subscribe.md Quest-Claim: 1eca63ae47203bdd From 18459764e3579a89db3fd72bc798e1b4d5a25bc6 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 2 Nov 2026 04:03:17 -0800 Subject: [PATCH 2/5] chore(quest): checkpoint retained-copy validation blocker Co-Authored-By: GPT-6.1 Sol --- quest/m1/relay-fetched-copy-subscribe.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/quest/m1/relay-fetched-copy-subscribe.md b/quest/m1/relay-fetched-copy-subscribe.md index 6bdfdb07d52..c536caef97e 100644 --- a/quest/m1/relay-fetched-copy-subscribe.md +++ b/quest/m1/relay-fetched-copy-subscribe.md @@ -26,4 +26,25 @@ gets no SUBSCRIBE_OK within 5 s. It hangs the same way on main - Test it in `rs/moq-net/tests/integration/fetch_only.rs` on drafts 18 and 22, direct and through a relay. +Checkpoint 2026-11-02: claimed in +[moq-dev/moq#7631](https://github.com/moq-dev/moq/pull/7631), but validation +stops before compilation. `quest gate nix develop --command just rs test +-p moq-net -E 'test(a_subscribe_after_track_status_keeps_timestamps)'` +fails when mbx launches Cargo: `Argument list too long (os error 7)`. +The existing repo-side launcher fix is +[moq-dev/moq#7594](https://github.com/moq-dev/moq/pull/7594). No validation +bypass or source change was made; reproduction, implementation, and the +four-case matrix remain undone. Resume this claim once standard validation +works. + +Source inspection finds two waits to investigate: the linger handler's +`wants_feed` excludes wholly historical demand, while `subscribe_track` +waits for `poll_live`; and resuming a copy waits for its fill head before +`set_live`. Distinguish a fresh upstream answer from cache readiness without +answering from an earlier report. These are unverified hypotheses, not an +executed reproduction. Inspected the open range/origin work, including +[moq-dev/moq#7625](https://github.com/moq-dev/moq/pull/7625) and +[moq-dev/moq#7624](https://github.com/moq-dev/moq/pull/7624); their scopes and +ownership remain unchanged. + Public API: none. Wire: none. From 42d579f90330278c68169641fff3432883a994e0 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 2 Nov 2026 10:38:26 -0800 Subject: [PATCH 3/5] fix(net): a relay answers a SUBSCRIBE on a copy it kept after a fetch A wire SUBSCRIBE reaching a relay's fetch-only copy hung with no SUBSCRIBE_OK, for two reasons: - The IETF publisher waits for the live edge before answering, but the lingering copy read a bounded history range as fetch-only and never subscribed upstream. A wire subscription now asks for the live feed (`Subscription::feed`, crate-private), so the relay subscribes again and answers from the upstream's SUBSCRIBE_OK. - A resumed subscription bounded below the answer's Largest Object waited forever for the cache to show that group. Such a feed now makes the copy current from the answer alone (`set_live_ahead`). Removes the finished quest. Co-Authored-By: Claude Opus 5.5 --- quest/m1/README.md | 1 - quest/m1/relay-fetched-copy-subscribe.md | 50 ------ rs/moq-net/src/ietf/publisher.rs | 3 + rs/moq-net/src/ietf/subscriber.rs | 17 +- rs/moq-net/src/model/subscription.rs | 7 + rs/moq-net/src/model/track.rs | 27 +++- rs/moq-net/src/model/track/demand.rs | 11 +- rs/moq-net/tests/integration/fetch_only.rs | 171 +++++++++++++++++++++ 8 files changed, 228 insertions(+), 59 deletions(-) delete mode 100644 quest/m1/relay-fetched-copy-subscribe.md diff --git a/quest/m1/README.md b/quest/m1/README.md index aca58df2b8b..c581d04f2b5 100644 --- a/quest/m1/README.md +++ b/quest/m1/README.md @@ -146,7 +146,6 @@ per-frame CPU growth since #5926. - [Bindings see a moq-transport run end as an end](/quest/m1/ffi-ietf-run-end.md) - an IETF publisher ending its run reaches moq-ffi consumers as an end, not `Internal` - [Byte-stream renditions form a ladder](/quest/m1/stream-ladder.md) - moq-ffi stream producers link as `lower` and disable unfundable rungs like frame producers - [moq export ends when the broadcast ends](/quest/m1/export-broadcast-end.md) - the export finishes on its own, proven without a give-up timeout -- [A relay answers a SUBSCRIBE on a copy it kept after a fetch](/quest/m1/relay-fetched-copy-subscribe.md) - the downstream SUBSCRIBE_OK waits for the upstream edge instead of hanging - [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 diff --git a/quest/m1/relay-fetched-copy-subscribe.md b/quest/m1/relay-fetched-copy-subscribe.md deleted file mode 100644 index c536caef97e..00000000000 --- a/quest/m1/relay-fetched-copy-subscribe.md +++ /dev/null @@ -1,50 +0,0 @@ -# [S] A relay answers a SUBSCRIBE on a copy it kept after a fetch - -## Goal - -A moq-transport subscriber gets SUBSCRIBE_OK for a history SUBSCRIBE sent -through a relay that holds a copy kept after a FETCH. The OK names the live -edge from the upstream's SUBSCRIBE_OK, never from the relay's cache or an -edge the upstream reported earlier. An integration test covers it. - -## Plan - -Planned 2026-11-01 (maintainer, follow-up of -[moq-dev/moq#7545](https://github.com/moq-dev/moq/pull/7545)). - -Repro, from #7545's review: the relay fetches group 2 of an unfinished track. -A fresh draft-22 session then subscribes `with_range(1..2)` through it, and -gets no SUBSCRIBE_OK within 5 s. It hangs the same way on main -(`3ae67897`), where the relay does subscribe upstream, so this bug predates -#7545. - -- The maintainer decided on 2026-11-01, on #7545, that the OK waits until the - live edge is known, and is never taken from the cache. So the fix is not to - answer from the stale reported edge. -- Find why the upstream's SUBSCRIBE_OK doesn't reach the downstream OK on a - fetched copy, and fix that. -- Test it in `rs/moq-net/tests/integration/fetch_only.rs` on drafts 18 and 22, - direct and through a relay. - -Checkpoint 2026-11-02: claimed in -[moq-dev/moq#7631](https://github.com/moq-dev/moq/pull/7631), but validation -stops before compilation. `quest gate nix develop --command just rs test --p moq-net -E 'test(a_subscribe_after_track_status_keeps_timestamps)'` -fails when mbx launches Cargo: `Argument list too long (os error 7)`. -The existing repo-side launcher fix is -[moq-dev/moq#7594](https://github.com/moq-dev/moq/pull/7594). No validation -bypass or source change was made; reproduction, implementation, and the -four-case matrix remain undone. Resume this claim once standard validation -works. - -Source inspection finds two waits to investigate: the linger handler's -`wants_feed` excludes wholly historical demand, while `subscribe_track` -waits for `poll_live`; and resuming a copy waits for its fill head before -`set_live`. Distinguish a fresh upstream answer from cache readiness without -answering from an earlier report. These are unverified hypotheses, not an -executed reproduction. Inspected the open range/origin work, including -[moq-dev/moq#7625](https://github.com/moq-dev/moq/pull/7625) and -[moq-dev/moq#7624](https://github.com/moq-dev/moq/pull/7624); their scopes and -ownership remain unchanged. - -Public API: none. Wire: none. diff --git a/rs/moq-net/src/ietf/publisher.rs b/rs/moq-net/src/ietf/publisher.rs index 5723cf9cd27..d35ed9945d6 100644 --- a/rs/moq-net/src/ietf/publisher.rs +++ b/rs/moq-net/src/ietf/publisher.rs @@ -33,6 +33,9 @@ fn serving_subscription(subscriber_priority: u8) -> Subscription { priority: super::priority::from_wire(subscriber_priority), // No Max Age is the publisher's retention alone, whatever it turns out to be. max_delay: None, + // SUBSCRIBE_OK names the live edge, which a relay learns only from its upstream's + // answer: never from its cache, nor from an edge reported before. + feed: true, ..Default::default() } } diff --git a/rs/moq-net/src/ietf/subscriber.rs b/rs/moq-net/src/ietf/subscriber.rs index 826897ba137..88d4cf30da7 100644 --- a/rs/moq-net/src/ietf/subscriber.rs +++ b/rs/moq-net/src/ietf/subscriber.rs @@ -756,15 +756,15 @@ fn largest_group(track: &track::Producer, answer: Option) -> Opt } /// Whether `subscription` needs a live feed for a copy whose publisher reported its Largest -/// Object in group `edge`: one of its ranges is open, counts back from the live edge, or -/// reaches the group the publisher may still be writing. Ranges wholly below it read only -/// history, which fills serve. +/// Object in group `edge`: a reader asked for it ([`track::Subscription::feed`]), or one of +/// its ranges is open, counts back from the live edge, or reaches the group the publisher +/// may still be writing. Ranges wholly below it read only history, which fills serve. fn wants_feed(subscription: &track::Subscription, edge: Option) -> bool { if subscription.ranges.is_empty() { return false; } let history = subscription.start().is_some() && subscription.end().zip(edge).is_some_and(|(end, edge)| end <= edge); - !history + subscription.feed || !history } /// A copy with no subscription upstream, kept for fetches and a returning subscriber. @@ -3585,7 +3585,14 @@ impl Subscriber { && (poll_headed(&fill, waiter).is_ready() || largest.is_some_and(|largest| track.poll_past(largest.group, waiter).is_ready())) { - track.set_live(largest, None); + match largest { + // A feed ending before the answer's Largest never shows it, so the + // answer alone makes the copy current. + Some(largest) if sent_bounds.1.is_some_and(|end| end <= largest.group) => { + track.set_live_ahead(largest) + } + largest => track.set_live(largest, None), + } resuming = None; } // The last subscriber left: the upstream subscription goes with it, as on diff --git a/rs/moq-net/src/model/subscription.rs b/rs/moq-net/src/model/subscription.rs index 08bf5ae5d66..2528465a33d 100644 --- a/rs/moq-net/src/model/subscription.rs +++ b/rs/moq-net/src/model/subscription.rs @@ -94,6 +94,11 @@ pub struct Subscription { /// subscribers fresh. Each subscriber's own publisher (a relay's downstream session) /// still serves it in its own order. pub order: Order, + /// Whether this reader needs the source's live feed, not only its history: a wire + /// publisher owes its peer an answer naming the live edge, which only the upstream's own + /// answer gives. A session holding no upstream subscription for its copy subscribes again + /// for such a reader, whatever its ranges. Aggregated as any: one such reader is enough. + pub(crate) feed: bool, } /// Which of a subscription's pending groups the publisher sends first. @@ -294,6 +299,7 @@ impl Default for Subscription { max_delay: Some(Duration::ZERO), ranges: vec![Range::oldest()], order: Order::Descending, + feed: false, } } } @@ -475,6 +481,7 @@ impl Combined { if let Order::Descending = sub.order { combined.order = Order::Descending; } + combined.feed |= sub.feed; } /// The aggregate, or `None` without a subscriber. diff --git a/rs/moq-net/src/model/track.rs b/rs/moq-net/src/model/track.rs index 214e500bdfb..ae228999fdc 100644 --- a/rs/moq-net/src/model/track.rs +++ b/rs/moq-net/src/model/track.rs @@ -2846,6 +2846,21 @@ impl TrackState { /// read as the live edge, though the route already holds a newer one. #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] fn set_live(&mut self, largest: Option, start: Option) { + self.answered(largest, start, true); + } + + /// [`Self::set_live`] for a feed that serves no group from `largest`'s on, such as a + /// bounded subscription of history: the cache can never show that group, so the answer + /// alone makes it current, and relative starts count back from that group. + #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] + fn set_live_ahead(&mut self, largest: Position) { + self.answered(Some(largest), None, false); + } + + /// The route answered with `largest`. With `reaches`, its feed reaches that group, so + /// readers wait until the cache shows it. + #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] + fn answered(&mut self, largest: Option, start: Option, reaches: bool) { let Feed::Idle { newest } = self.feed else { return; }; @@ -2868,7 +2883,7 @@ impl TrackState { _ => self.live_floor, }; match largest.map(|largest| largest.group) { - Some(from) if !self.shows(from) => self.feed = Feed::Answered { from }, + Some(from) if reaches && !self.shows(from) => self.feed = Feed::Answered { from }, edge => self.go_live(edge), } } @@ -3686,6 +3701,16 @@ impl Producer { } } + /// [`Self::set_live`] for a feed that serves no group from `largest`'s on, such as a + /// bounded subscription of history: readers resume at once, counting relative starts + /// back from `largest`'s group. A no-op unless idle. + #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] + pub(crate) fn set_live_ahead(&mut self, largest: Position) { + if let Ok(mut state) = self.modify() { + state.set_live_ahead(largest); + } + } + /// Whether a subscription feeds this copy: its session holds one upstream for it, or /// none, so nothing reaches it but what fills answer. Only the session knows, from its /// own state; the cache never tells. While unfed, a bounded read's holes are misses up diff --git a/rs/moq-net/src/model/track/demand.rs b/rs/moq-net/src/model/track/demand.rs index 53caec2e017..63df3990e0e 100644 --- a/rs/moq-net/src/model/track/demand.rs +++ b/rs/moq-net/src/model/track/demand.rs @@ -22,6 +22,8 @@ pub(super) struct Subscriptions { max_delay: BTreeMap, ranges: Ranges, descending: usize, + /// Subscribers that need the live feed; see [`Subscription::feed`]. + feed: usize, /// The lowest group consumers want while no refresh is pending, never lowered. See /// [`super::Demand::wanted`]. wanted: u64, @@ -35,16 +37,17 @@ pub(super) struct Subscriptions { } /// Everything the aggregate holds besides its ranges. -type Scalars = (i8, Option, Order); +type Scalars = (i8, Option, Order, bool); impl Subscriptions { pub(super) fn combined(&self) -> Option { - let (priority, max_delay, order) = self.scalars()?; + let (priority, max_delay, order, feed) = self.scalars()?; Some(Subscription { priority, max_delay, ranges: self.ranges.union(), order, + feed, }) } @@ -65,6 +68,7 @@ impl Subscriptions { } else { Order::Descending }, + self.feed != 0, ) }) } @@ -140,6 +144,7 @@ impl Subscriptions { } } self.descending += usize::from(new.order == Order::Descending); + self.feed += usize::from(new.feed); self.count += 1; } if let Some(old) = old { @@ -151,6 +156,7 @@ impl Subscriptions { } } self.descending -= usize::from(old.order == Order::Descending); + self.feed -= usize::from(old.feed); self.count -= 1; } if reshaped || self.scalars() != prev { @@ -315,6 +321,7 @@ mod tests { } else { Order::Descending }, + feed: rng.random_bool(0.25), }; match (&mut slots[index], rng.random_range(0..3)) { (slot @ None, _) => *slot = Some((producer.subscribe(next.clone()), next)), diff --git a/rs/moq-net/tests/integration/fetch_only.rs b/rs/moq-net/tests/integration/fetch_only.rs index 89a735d04e3..51a0db75474 100644 --- a/rs/moq-net/tests/integration/fetch_only.rs +++ b/rs/moq-net/tests/integration/fetch_only.rs @@ -320,3 +320,174 @@ async fn a_relay_serves_a_bounded_read_of_history_without_subscribing_upstream() } assert!(failures.is_empty(), "failed: {failures:?}"); } + +/// Write group `sequence` of [`frames`] to a live track. +fn write_group(track: &moq_net::track::Producer, sequence: u64) { + let mut group = track.create_group(moq_net::group::Info { sequence }).unwrap(); + for frame in frames(sequence) { + group.write_frame(Timestamp::ZERO, frame).unwrap(); + } + group.finish().unwrap(); +} + +/// Publish a live track of groups `0..groups`, which the publisher keeps writing. +fn publish_live( + origin: &moq_net::origin::Producer, + groups: u64, +) -> (moq_net::origin::Publication, moq_net::track::Producer) { + let broadcast = origin.create_broadcast("bcast").unwrap(); + let track = broadcast.create_track("video", timed()).unwrap(); + broadcast.announce(Default::default()).unwrap(); + for sequence in 0..groups { + write_group(&track, sequence); + } + (broadcast, track) +} + +/// A relay of a live track holding a copy a fetch left unfed, and a fresh session to it. +struct FetchedCopy { + /// The publisher's track, which has since moved past the edge the fetch learned. + track: moq_net::track::Producer, + /// The track through the fresh session, which knows no edge, so its reads SUBSCRIBE. + fresh: moq_net::track::Consumer, + _held: Vec>, +} + +async fn fetched_copy(version: Version) -> FetchedCopy { + let publisher = produce_origin(1); + let (broadcast, track) = publish_live(&publisher, 3); + + let relay = produce_origin(2); + let mut options = MockConnectOptions::new(version); + options.server_publish = Some(publisher.consume()); + options.client_subscribe = Some(relay.clone()); + let upstream = connect_mock(options).await; + + // The fetch learns Largest Object (2, 1) from TRACK_STATUS, and subscribes nowhere. + let fetcher = produce_origin(3); + let mut options = MockConnectOptions::new(version); + options.server_publish = Some(relay.consume()); + options.client_subscribe = Some(fetcher.clone()); + let fetching = connect_mock(options).await; + let fetched = resolve(&fetcher).await; + assert_eq!(fetch(&fetched, 2).await.expect("fetch"), frames(2), "{version}"); + assert!(track.subscription().is_none(), "{version}: the fetch subscribed"); + + // The edge moves on, so an answer from the earlier report would be stale. + write_group(&track, 3); + + let client = produce_origin(3); + let mut options = MockConnectOptions::new(version); + options.server_publish = Some(relay.consume()); + options.client_subscribe = Some(client.clone()); + let downstream = connect_mock(options).await; + let fresh = resolve(&client).await.track("video").unwrap(); + + FetchedCopy { + track, + fresh, + _held: vec![ + Box::new(downstream), + Box::new(client), + Box::new(fetched), + Box::new(fetching), + Box::new(fetcher), + Box::new(upstream), + Box::new(relay), + Box::new(broadcast), + Box::new(publisher), + ], + } +} + +async fn history_through_fetched_copy(version: Version) { + let copy = fetched_copy(version).await; + // A front's bounded read parks past its end, so this reads the group and stops there. + let mut sub = subscribe_history(©.fresh).await; + assert!( + copy.track.subscription().is_some(), + "{version}: answered without subscribing upstream" + ); + assert_eq!(next_frames(&mut sub).await, Some(frames(1)), "{version}"); +} + +/// A history SUBSCRIBE reaching a relay's copy kept after a fetch is answered from the +/// upstream's SUBSCRIBE_OK, never the edge the fetch learned, and reads its history. +/// Draft 18 joins only at the live edge, so a bounded read with no edge known is refused +/// before it is sent. +#[kio::test] +async fn a_relay_answers_a_history_subscribe_on_a_fetched_copy() { + let version: Version = "moq-transport-22".parse().unwrap(); + kio::clock::timeout(TIMEOUT, history_through_fetched_copy(version)) + .await + .expect("timed out"); +} + +async fn live_through_fetched_copy(version: Version) { + let copy = fetched_copy(version).await; + let mut sub = kio::clock::timeout(TIMEOUT, copy.fresh.subscribe(None)) + .await + .expect("subscribe timed out") + .expect("subscribe"); + // The live join starts at the upstream's current group, not the one the fetch reported. + assert_eq!(next_frames(&mut sub).await, Some(frames(3)), "{version}"); + write_group(©.track, 4); + assert_eq!(next_frames(&mut sub).await, Some(frames(4)), "{version}"); +} + +/// A live SUBSCRIBE reaching a relay's copy kept after a fetch joins at the upstream's +/// current edge. +#[kio::test] +async fn a_relay_answers_a_live_subscribe_on_a_fetched_copy() { + for version in VERSIONS { + let version: Version = version.parse().unwrap(); + kio::clock::timeout(TIMEOUT, live_through_fetched_copy(version)) + .await + .unwrap_or_else(|_| panic!("{version}: timed out")); + } +} + +/// A copy kept after a fetch resumes a bounded subscription that ends at or below the +/// upstream's new Largest Object, and reads it, though no group past its end arrives. +#[kio::test] +async fn a_resumed_bounded_subscription_reads_below_the_answered_edge() { + kio::clock::timeout(TIMEOUT, async { + let version: Version = "moq-transport-22".parse().unwrap(); + let publisher = produce_origin(1); + let (broadcast, track) = publish_live(&publisher, 2); + + let client = produce_origin(2); + let mut options = MockConnectOptions::new(version); + options.server_publish = Some(publisher.consume()); + options.client_subscribe = Some(client.clone()); + let pair = connect_mock(options).await; + + // The fetch learns Largest Object (1, 1), and leaves the copy unfed. + let remote = resolve(&client).await; + assert_eq!(fetch(&remote, 0).await.expect("fetch"), frames(0)); + for sequence in 2..4 { + write_group(&track, sequence); + } + + // Past the reported edge, so it subscribes; the answer names group 3, which the + // bounded feed never delivers. + let copy = remote.track("video").unwrap(); + let subscription = moq_net::track::Subscription::default() + .with_order(moq_net::track::Order::Ascending) + .with_max_delay(None) + .with_range(1..3); + let mut sub = kio::clock::timeout(TIMEOUT, copy.subscribe(subscription)) + .await + .expect("subscribe timed out") + .expect("subscribe"); + // Read in arrival order, whichever group lands first. + let mut read = vec![next_frames(&mut sub).await, next_frames(&mut sub).await]; + read.sort(); + assert_eq!(read, [Some(frames(1)), Some(frames(2))]); + assert!(track.subscription().is_some(), "the read never subscribed"); + + drop((sub, copy, remote, pair, track, broadcast, client, publisher)); + }) + .await + .expect("timed out"); +} From ba9f79ddb633f85277fcdce1493fe84d48ada0d7 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 2 Nov 2026 10:46:06 -0800 Subject: [PATCH 4/5] fix(net): a resumed feed starts where it asked The answer's Largest stood in for where a resumed absolute feed starts, so a copy that went idle holding a group raised its floor past that group and a bounded resume of it could never read it. Pass the subscription's own start, or none for a live join. Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/ietf/subscriber.rs | 7 ++- rs/moq-net/src/model/track.rs | 8 ++-- rs/moq-net/tests/integration/fetch_only.rs | 52 ++++++++++++++++++++++ 3 files changed, 61 insertions(+), 6 deletions(-) diff --git a/rs/moq-net/src/ietf/subscriber.rs b/rs/moq-net/src/ietf/subscriber.rs index 88d4cf30da7..eb3bc9e6041 100644 --- a/rs/moq-net/src/ietf/subscriber.rs +++ b/rs/moq-net/src/ietf/subscriber.rs @@ -3585,13 +3585,16 @@ impl Subscriber { && (poll_headed(&fill, waiter).is_ready() || largest.is_some_and(|largest| track.poll_past(largest.group, waiter).is_ready())) { + // An absolute feed starts where it asked, whatever the answer's Largest; a + // live join's starts there. + let from = sent_bounds.0.filter(|_| !live); match largest { // A feed ending before the answer's Largest never shows it, so the // answer alone makes the copy current. Some(largest) if sent_bounds.1.is_some_and(|end| end <= largest.group) => { - track.set_live_ahead(largest) + track.set_live_ahead(largest, from) } - largest => track.set_live(largest, None), + largest => track.set_live(largest, from), } resuming = None; } diff --git a/rs/moq-net/src/model/track.rs b/rs/moq-net/src/model/track.rs index ae228999fdc..19273342d93 100644 --- a/rs/moq-net/src/model/track.rs +++ b/rs/moq-net/src/model/track.rs @@ -2853,8 +2853,8 @@ impl TrackState { /// bounded subscription of history: the cache can never show that group, so the answer /// alone makes it current, and relative starts count back from that group. #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] - fn set_live_ahead(&mut self, largest: Position) { - self.answered(Some(largest), None, false); + fn set_live_ahead(&mut self, largest: Position, start: Option) { + self.answered(Some(largest), start, false); } /// The route answered with `largest`. With `reaches`, its feed reaches that group, so @@ -3705,9 +3705,9 @@ impl Producer { /// bounded subscription of history: readers resume at once, counting relative starts /// back from `largest`'s group. A no-op unless idle. #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] - pub(crate) fn set_live_ahead(&mut self, largest: Position) { + pub(crate) fn set_live_ahead(&mut self, largest: Position, start: Option) { if let Ok(mut state) = self.modify() { - state.set_live_ahead(largest); + state.set_live_ahead(largest, start); } } diff --git a/rs/moq-net/tests/integration/fetch_only.rs b/rs/moq-net/tests/integration/fetch_only.rs index 51a0db75474..2f1c9683bd6 100644 --- a/rs/moq-net/tests/integration/fetch_only.rs +++ b/rs/moq-net/tests/integration/fetch_only.rs @@ -491,3 +491,55 @@ async fn a_resumed_bounded_subscription_reads_below_the_answered_edge() { .await .expect("timed out"); } + +/// A copy that went idle holding a group resumes a bounded subscription of that group after +/// the upstream moved on, and still reads it: the feed starts where it asked, not at the +/// answer's Largest, so the cached group stays below no floor. +#[kio::test] +async fn a_resumed_bounded_subscription_keeps_its_cached_start() { + kio::clock::timeout(TIMEOUT, async { + let version: Version = "moq-transport-22".parse().unwrap(); + let publisher = produce_origin(1); + let (broadcast, track) = publish_live(&publisher, 1); + + let client = produce_origin(2); + let mut options = MockConnectOptions::new(version); + options.server_publish = Some(publisher.consume()); + options.client_subscribe = Some(client.clone()); + let pair = connect_mock(options).await; + + // A live read caches group 0, then leaves, so the copy goes idle holding it. + let remote = resolve(&client).await; + let copy = remote.track("video").unwrap(); + let mut live = kio::clock::timeout(TIMEOUT, copy.subscribe(None)) + .await + .expect("subscribe timed out") + .expect("subscribe"); + assert_eq!(next_frames(&mut live).await, Some(frames(0))); + drop(live); + let mut watch = track.clone(); + while watch.subscription().is_some() { + kio::clock::timeout(TIMEOUT, watch.subscription_changed()) + .await + .expect("unsubscribe timed out") + .unwrap(); + } + for sequence in 1..4 { + write_group(&track, sequence); + } + + // Past the edge the live read learned, so it subscribes; the answer names group 3. + let subscription = moq_net::track::Subscription::default() + .with_max_delay(None) + .with_range(0..1); + let mut sub = kio::clock::timeout(TIMEOUT, copy.subscribe(subscription)) + .await + .expect("subscribe timed out") + .expect("subscribe"); + assert_eq!(next_frames(&mut sub).await, Some(frames(0))); + + drop((sub, copy, remote, pair, track, broadcast, client, publisher)); + }) + .await + .expect("timed out"); +} From 58a8b4f8379f2f66a33cb1663ea4e07cd19cbdd5 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 2 Nov 2026 12:04:55 -0800 Subject: [PATCH 5/5] fix(net): a draft-18 join leaves a bounded end open instead of refusing it A wire SUBSCRIBE now resumes a lingering copy whatever its range, so a relay speaking draft 18 upstream refused a downstream history SUBSCRIBE's end in subscribe_join and aborted the shared copy for every reader. A draft-18 join is live anyway: earlier groups come from fills and readers stop at their own end, so the end stays local, as a later start already does. subscribe_join is now infallible. The resume gate also answers a live join's feed with set_live, since its feed has no end on the wire and so reaches the answer's Largest. Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/ietf/subscriber.rs | 62 +++++++--------------- rs/moq-net/tests/integration/fetch_only.rs | 50 +++++++++++------ 2 files changed, 54 insertions(+), 58 deletions(-) diff --git a/rs/moq-net/src/ietf/subscriber.rs b/rs/moq-net/src/ietf/subscriber.rs index eb3bc9e6041..e276e216075 100644 --- a/rs/moq-net/src/ietf/subscriber.rs +++ b/rs/moq-net/src/ietf/subscriber.rs @@ -2961,13 +2961,7 @@ impl Subscriber { } }; let start = subscription.as_ref().and_then(|s| s.start()); - let join = match subscribe_join(start, subscription.as_ref().and_then(|s| s.end()), self.version) { - Ok(join) => join, - Err(err) => { - target.fail(err); - return None; - } - }; + let join = subscribe_join(start, subscription.as_ref().and_then(|s| s.end()), self.version); // A live join delivers nothing below the group SUBSCRIBE_OK names as Largest. Every // draft-18 join is one, since its joining FETCH carries that group alone. let live = start.is_none() || join.fetch; @@ -3590,8 +3584,8 @@ impl Subscriber { let from = sent_bounds.0.filter(|_| !live); match largest { // A feed ending before the answer's Largest never shows it, so the - // answer alone makes the copy current. - Some(largest) if sent_bounds.1.is_some_and(|end| end <= largest.group) => { + // answer alone makes the copy current. A live join's feed is open. + Some(largest) if !live && sent_bounds.1.is_some_and(|end| end <= largest.group) => { track.set_live_ahead(largest, from) } largest => track.set_live(largest, from), @@ -3670,10 +3664,7 @@ impl Subscriber { }; let ranges = if bounds != sent_bounds { let mut join = if Filter::is_draft20(self.version) { - match subscribe_join(bounds.0, bounds.1, self.version) { - Ok(join) => join, - Err(err) => return Poll::Ready(End::Invalid(err)), - } + subscribe_join(bounds.0, bounds.1, self.version) } else { Join { filter: match bounds { @@ -12129,24 +12120,22 @@ struct Join { /// Earlier drafts have no fill parameter. Every subscription is a live join: Largest /// Object, followed by a joining FETCH relative at offset 0 for that group's head. An /// earlier start's groups are left to the copy's fills, one FETCH per run of them, and a -/// later start skips the head locally. A bounded end has no -/// joining-FETCH spelling, so it is refused rather than left open. +/// later start skips the head locally. A bounded end has no joining-FETCH spelling +/// either, so the join stays open and readers stop at their own end: refusing it would +/// abort a resumed copy for every reader it serves. /// /// A start group we already know is absolute on draft-22 and needs no fill: the /// subscription's own range covers it, which is what our publisher serves from its cache. -fn subscribe_join(start: Option, end: Option, version: Version) -> Result { +fn subscribe_join(start: Option, end: Option, version: Version) -> Join { if !Filter::is_draft20(version) { - if end.is_some() { - return Err(Error::Unsupported); - } - return Ok(Join { + return Join { filter: Filter::NextObject, fill: None, fetch: true, - }); + }; } - Ok(match start { + match start { // The live join: everything after the live edge, plus the current group's head. None => Join { filter: Filter::NextObject, @@ -12180,7 +12169,7 @@ fn subscribe_join(start: Option, end: Option, version: Version) -> Res fill: None, fetch: false, }, - }) + } } /// Resolve the first absolute ID or a later ID delta without overflowing. Subgroup relay @@ -12228,7 +12217,7 @@ mod filter_tests { #[test] fn live_joins_the_current_group_with_a_fill() { assert_eq!( - subscribe_join(None, None, Version::Draft22).unwrap(), + subscribe_join(None, None, Version::Draft22), Join { filter: Filter::NextObject, fill: Some(ietf::Fill { @@ -12246,7 +12235,7 @@ mod filter_tests { #[test] fn a_past_start_is_absolute() { assert_eq!( - subscribe_join(Some(7), Some(10), Version::Draft22).unwrap(), + subscribe_join(Some(7), Some(10), Version::Draft22), Join { filter: Filter::Absolute { start: ietf::Location { group: 7, object: 0 }, @@ -12262,7 +12251,7 @@ mod filter_tests { #[test] fn the_whole_track_is_unfiltered() { assert_eq!( - subscribe_join(Some(0), None, Version::Draft22).unwrap(), + subscribe_join(Some(0), None, Version::Draft22), Join { filter: Filter::Unfiltered, fill: None, @@ -12273,36 +12262,25 @@ mod filter_tests { const JOINING_DRAFTS: [Version; 1] = [Version::Draft18]; - /// Every draft-18 join is Largest Object plus a joining FETCH, whatever its start, - /// so the current group's head arrives on the fetch stream and the live tail on the + /// Every draft-18 join is Largest Object plus a joining FETCH, whatever its start or + /// end, so the current group's head arrives on the fetch stream and the live tail on the /// subscription. #[test] fn older_drafts_always_join_live() { for version in JOINING_DRAFTS { - for start in [None, Some(7)] { + for (start, end) in [(None, None), (Some(7), None), (Some(7), Some(10))] { assert_eq!( - subscribe_join(start, None, version).unwrap(), + subscribe_join(start, end, version), Join { filter: Filter::NextObject, fill: None, fetch: true, }, - "{version} from {start:?}" + "{version} from {start:?} to {end:?}" ); } } } - - /// A bounded end has no joining-FETCH spelling, so it is refused rather than left open. - #[test] - fn older_drafts_refuse_a_bounded_end() { - for version in JOINING_DRAFTS { - assert!( - matches!(subscribe_join(Some(7), Some(10), version), Err(Error::Unsupported)), - "{version}" - ); - } - } } /// Draft-22's current-group join, where one group arrives on two streams: the fill fetch diff --git a/rs/moq-net/tests/integration/fetch_only.rs b/rs/moq-net/tests/integration/fetch_only.rs index 2f1c9683bd6..253515daa44 100644 --- a/rs/moq-net/tests/integration/fetch_only.rs +++ b/rs/moq-net/tests/integration/fetch_only.rs @@ -350,15 +350,18 @@ struct FetchedCopy { track: moq_net::track::Producer, /// The track through the fresh session, which knows no edge, so its reads SUBSCRIBE. fresh: moq_net::track::Consumer, + /// The broadcast through the session that fetched, another reader of the relay's copy. + fetched: moq_net::broadcast::Consumer, _held: Vec>, } -async fn fetched_copy(version: Version) -> FetchedCopy { +/// The relay speaks `upstream_version` to the publisher and `version` downstream. +async fn fetched_copy(upstream_version: Version, version: Version) -> FetchedCopy { let publisher = produce_origin(1); let (broadcast, track) = publish_live(&publisher, 3); let relay = produce_origin(2); - let mut options = MockConnectOptions::new(version); + let mut options = MockConnectOptions::new(upstream_version); options.server_publish = Some(publisher.consume()); options.client_subscribe = Some(relay.clone()); let upstream = connect_mock(options).await; @@ -386,10 +389,10 @@ async fn fetched_copy(version: Version) -> FetchedCopy { FetchedCopy { track, fresh, + fetched, _held: vec![ Box::new(downstream), Box::new(client), - Box::new(fetched), Box::new(fetching), Box::new(fetcher), Box::new(upstream), @@ -400,31 +403,43 @@ async fn fetched_copy(version: Version) -> FetchedCopy { } } -async fn history_through_fetched_copy(version: Version) { - let copy = fetched_copy(version).await; +async fn history_through_fetched_copy(upstream: Version, version: Version) { + let copy = fetched_copy(upstream, version).await; // A front's bounded read parks past its end, so this reads the group and stops there. let mut sub = subscribe_history(©.fresh).await; assert!( copy.track.subscription().is_some(), - "{version}: answered without subscribing upstream" + "{upstream} to {version}: answered without subscribing upstream" + ); + assert_eq!(next_frames(&mut sub).await, Some(frames(1)), "{upstream} to {version}"); + // The copy still serves its other reader. + assert_eq!( + fetch(©.fetched, 0).await.expect("fetch after the SUBSCRIBE"), + frames(0), + "{upstream} to {version}" ); - assert_eq!(next_frames(&mut sub).await, Some(frames(1)), "{version}"); } /// A history SUBSCRIBE reaching a relay's copy kept after a fetch is answered from the -/// upstream's SUBSCRIBE_OK, never the edge the fetch learned, and reads its history. -/// Draft 18 joins only at the live edge, so a bounded read with no edge known is refused -/// before it is sent. +/// upstream's SUBSCRIBE_OK, never the edge the fetch learned, and reads its history. A +/// draft-18 upstream has no bounded join, so the relay joins it live and serves the history +/// from fills, keeping the copy for its other readers. #[kio::test] async fn a_relay_answers_a_history_subscribe_on_a_fetched_copy() { - let version: Version = "moq-transport-22".parse().unwrap(); - kio::clock::timeout(TIMEOUT, history_through_fetched_copy(version)) - .await - .expect("timed out"); + for (upstream, version) in [ + ("moq-transport-22", "moq-transport-22"), + ("moq-transport-18", "moq-transport-22"), + ("moq-transport-18", "moq-transport-18"), + ] { + let (upstream, version): (Version, Version) = (upstream.parse().unwrap(), version.parse().unwrap()); + kio::clock::timeout(TIMEOUT, history_through_fetched_copy(upstream, version)) + .await + .unwrap_or_else(|_| panic!("{upstream} to {version}: timed out")); + } } async fn live_through_fetched_copy(version: Version) { - let copy = fetched_copy(version).await; + let copy = fetched_copy(version, version).await; let mut sub = kio::clock::timeout(TIMEOUT, copy.fresh.subscribe(None)) .await .expect("subscribe timed out") @@ -449,6 +464,8 @@ async fn a_relay_answers_a_live_subscribe_on_a_fetched_copy() { /// A copy kept after a fetch resumes a bounded subscription that ends at or below the /// upstream's new Largest Object, and reads it, though no group past its end arrives. +/// Draft 22 only: a draft-18 join is live, so these groups come from one fill of the run, +/// and our publisher answers only a one-group FETCH. #[kio::test] async fn a_resumed_bounded_subscription_reads_below_the_answered_edge() { kio::clock::timeout(TIMEOUT, async { @@ -494,7 +511,8 @@ async fn a_resumed_bounded_subscription_reads_below_the_answered_edge() { /// A copy that went idle holding a group resumes a bounded subscription of that group after /// the upstream moved on, and still reads it: the feed starts where it asked, not at the -/// answer's Largest, so the cached group stays below no floor. +/// answer's Largest, so the cached group stays below no floor. Draft 22 only: a draft-18 +/// join is live, so it starts at the answer's Largest whatever it asked. #[kio::test] async fn a_resumed_bounded_subscription_keeps_its_cached_start() { kio::clock::timeout(TIMEOUT, async {