From a4f29d8e3feb21a1f3887436a8bbadaa7091ccbe Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 28 Sep 2026 22:05:24 -0700 Subject: [PATCH 1/2] chore: claim relay late joiner history quest Co-Authored-By: Codex From fe8ecc7ebf6a03106369f630bd0aa95f827bf564 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 28 Sep 2026 22:23:17 -0700 Subject: [PATCH 2/2] fix(net): preserve history when parking relay tracks Co-Authored-By: Codex --- quest/m1/README.md | 1 - quest/m1/relay-late-joiner-history.md | 44 ------------- quest/m1/track-tail-interop.md | 1 - rs/moq-net/src/model/origin.rs | 10 +++ rs/moq-net/tests/history_groups.rs | 91 +++++++++++++++++++++++++++ 5 files changed, 101 insertions(+), 46 deletions(-) delete mode 100644 quest/m1/relay-late-joiner-history.md diff --git a/quest/m1/README.md b/quest/m1/README.md index 82f33591744..b0916c73c4e 100644 --- a/quest/m1/README.md +++ b/quest/m1/README.md @@ -17,7 +17,6 @@ transport, benchmark tooling); worktrees isolate commits, not semantics. ## Required -- [Late joiner history](/quest/m1/relay-late-joiner-history.md) - a subscriber joining a relay's track from group 0 later still receives the cached finished group below the live one - [Cluster routing](/quest/m1/cluster-routing.md) - an announcement says where a broadcast originates, not how to reach it, and a relay hears only the prefixes its clients asked for - [Exact scope](/quest/m1/exact-scope.md) - a reader never sees an exact broadcast outside its scope, in Rust or JS; prefix routes above it still present as the empty path - [Track tail interop](/quest/m1/track-tail-interop.md) - a Rust publisher ending a track with a group in flight is read to its end by the JS subscriber, and the reverse, in `just test interop` diff --git a/quest/m1/relay-late-joiner-history.md b/quest/m1/relay-late-joiner-history.md deleted file mode 100644 index bd041dc43ce..00000000000 --- a/quest/m1/relay-late-joiner-history.md +++ /dev/null @@ -1,44 +0,0 @@ -# [M] Late joiner history - -## Goal - -A second subscriber that joins a relay's track from group 0 while a first -subscriber still holds it receives every group the relay has cached, -including a finished group older than the open live one. A regression test -that joins late through a relay fails before the fix. - -## Plan - -Found downstream on moq.pro: its billing rollup tracks replay a finished -history group followed by an open live group, and a second browser opening -the Cost page on the same edge intermittently loses the older group, so -prior-period usage rows are missing. Production dashboards are affected, -not just tests. #4387 fixed the first viewer's version of this; what it -leaves is the viewer that joins later. - -What we saw: - -- With #4387 applied, moq.pro's `e2e/tests/rollup-history.spec.ts - --repeat-each 12` still fails about a quarter of runs, always on the - second viewer. The edge logs `serving group` only for the newer group on - that viewer's subscription, while the first viewer got both. -- A late-joiner variant of `rs/moq-net/tests/history_groups.rs` showed the - relay's late cursor spliced across two segments with its floor at the - newer group, so the cached older group sat below it. The segment churn - comes through `Action::Query`, `Splice`, `Park`, and `Release` in - `rs/moq-net/src/model/origin.rs`, triggered by the TRACK_INFO request that - precedes each subscription and then goes idle. -- That variant is not a faithful reproduction yet: under paused time the - origin's linger timers fire during the test's idle waits, so it also failed - for lite-03 and the IETF drafts, which the real stack does not. A - reproduction needs to keep the relay's track warm without auto-advancing - past the linger, or drive the timers explicitly. - -Start from how a newly spliced or parked segment derives its floor for a -subscriber that asked for group 0, and whether a warm copy's cached groups -below the new segment's first group stay reachable. The -[splice edge cases](/quest/m1/splice-edges.md) touch the same code. - -## Related - -- [Splice edge cases](/quest/m1/splice-edges.md) - other spliced-track cases that lose or mis-judge groups diff --git a/quest/m1/track-tail-interop.md b/quest/m1/track-tail-interop.md index 01b0a683388..f33cff39350 100644 --- a/quest/m1/track-tail-interop.md +++ b/quest/m1/track-tail-interop.md @@ -41,7 +41,6 @@ delivered and clean. The ordering race itself stays in the unit tests. ## Required - [SUBSCRIBE_DROP](/quest/m1/subscribe-drop.md) - publishers name every group they won't deliver, which the lite-07 case checks -- #4387 merges: a relayed subscription resolves its start from its source, so earlier in-flight groups are not lost (it adds quest/m1/relay-late-joiner-history.md) ## Related diff --git a/rs/moq-net/src/model/origin.rs b/rs/moq-net/src/model/origin.rs index d39e9c206f1..8fa6facb730 100644 --- a/rs/moq-net/src/model/origin.rs +++ b/rs/moq-net/src/model/origin.rs @@ -2095,6 +2095,7 @@ fn warm_copy(source: &track::Consumer, head: Option<&WarmGroup>) -> Option) -> Option= latest); if head.is_finished() { let _ = track.adopt_group(head.clone(), true); + first = Some(head.sequence); if is_latest { edge = Some(WarmGroup(head.clone())); } } else if is_latest { edge = warm_rebuild(&track, head, None); + first = edge.as_ref().map(|_| head.sequence); } } @@ -2131,10 +2134,17 @@ fn warm_copy(source: &track::Consumer, head: Option<&WarmGroup>) -> Option 3, + 6 => 2, + sequence => panic!("unexpected group {sequence}"), + }; + for _ in 0..frames { + assert!(group.read_frame().await.unwrap().is_some()); + } + sequences.push(group.sequence); + } + sequences.sort(); + assert_eq!(sequences, [5, 6]); +} + +#[tokio::test] +async fn a_late_subscriber_receives_the_relays_cached_history() { + tokio::time::pause(); + // Older drafts canonicalize group 0 to the live edge instead of replay. + let version: Version = "moq-lite-07-wip".parse().unwrap(); + let publisher = produce_origin(1); + let broadcast = publisher.create_broadcast("bcast").unwrap(); + let track = broadcast + .create_track("history", Info::default().with_max_age(FOREVER)) + .unwrap(); + broadcast.announce(Default::default()).unwrap(); + 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; + let first = produce_origin(3); + let mut options = MockConnectOptions::new(version); + options.server_publish = Some(relay.consume()); + options.client_subscribe = Some(first.clone()); + let first_pair = connect_mock(options).await; + let consumer = first.consume(); + consumer.routed("bcast").await.unwrap(); + let remote = consumer.request_broadcast("bcast").await.unwrap(); + let subscription = Subscription::default() + .with_max_age(FOREVER) + .with_start(Position::group(0)); + let first_subscription = subscription.clone(); + let first_reader = tokio::spawn(async move { + let mut sub = remote + .track("history") + .unwrap() + .subscribe(first_subscription) + .await + .unwrap(); + read_history(&mut sub).await; + sub + }); + track.used().await.unwrap(); + upstream.server_transport.hold_unis(); + let mut old = track.create_group(moq_net::group::Info { sequence: 5 }).unwrap(); + for _ in 0..3 { + old.write_frame(Timestamp::now(), &b"old"[..]).unwrap(); + } + old.finish().unwrap(); + let mut live = track.create_group(moq_net::group::Info { sequence: 6 }).unwrap(); + for _ in 0..2 { + live.write_frame(Timestamp::now(), &b"live"[..]).unwrap(); + } + // Both streams open before paused time advances; 10ms stays below linger. + tokio::time::sleep(Duration::from_millis(10)).await; + upstream.server_transport.release_unis_reversed(); + let first_sub = tokio::time::timeout(TIMEOUT, first_reader) + .await + .expect("first subscriber history") + .unwrap(); + let late = produce_origin(4); + let mut options = MockConnectOptions::new(version); + options.server_publish = Some(relay.consume()); + options.client_subscribe = Some(late.clone()); + let late_pair = connect_mock(options).await; + let consumer = late.consume(); + consumer.routed("bcast").await.unwrap(); + let remote = consumer.request_broadcast("bcast").await.unwrap(); + let mut late_sub = remote.track("history").unwrap().subscribe(subscription).await.unwrap(); + tokio::time::timeout(TIMEOUT, read_history(&mut late_sub)) + .await + .unwrap_or_else(|_| panic!("{version}: late subscriber history")); + drop((first_sub, late_sub, first_pair, late_pair, upstream, live)); +}