From 928656da6400abca06fb1fdf35c5a13b0a3040fc Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 15 Nov 2026 23:43:42 -0800 Subject: [PATCH 1/3] fix(net): a redialed lite-07 session syncs once the doubt lets its routes in Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/lite/subscriber.rs | 10 ++++- rs/moq-net/src/lite/subscriber/routed.rs | 10 ++++- rs/moq-net/src/route/node.rs | 16 +++++++ rs/moq-net/src/route/path.rs | 25 ++++++++--- rs/moq-net/tests/integration/synced.rs | 53 ++++++++++++++++++++---- 5 files changed, 98 insertions(+), 16 deletions(-) diff --git a/rs/moq-net/src/lite/subscriber.rs b/rs/moq-net/src/lite/subscriber.rs index 035030d3a17..a08de26a373 100644 --- a/rs/moq-net/src/lite/subscriber.rs +++ b/rs/moq-net/src/lite/subscriber.rs @@ -2928,7 +2928,7 @@ impl AnnouncePrefix { // be let go in between. let retired = self.replacing.take().and_then(|old| old.retire()); // What the initial set put in the node is served before the - // snapshot lets readers see the origin synced. + // claims the old request served let go. if let Some(routed) = &mut run.routed { routed.outputs(&self.subscriber); } @@ -2936,7 +2936,7 @@ impl AnnouncePrefix { if std::mem::replace(&mut run.synced, true) { return Poll::Ready(Err(Error::ProtocolViolation)); } - self.snapshot = None; + // The snapshot lets go below, once the node shows every route. continue; } if run.initial > 0 { @@ -2975,6 +2975,12 @@ impl AnnouncePrefix { run.announced.poll_serve(&self.subscriber, waiter); if let Some(routed) = &mut run.routed { routed.poll(&self.subscriber, waiter)?; + // The initial set is in once the node shows every route the peer sent: one + // that only doubt keeps the node off, as on a session redialed to a node + // still in doubt, reaches the origin once the doubt lifts. + if run.synced && self.snapshot.is_some() && routed.poll_undoubted(&self.subscriber, waiter).is_ready() { + self.snapshot = None; + } } Poll::Pending })) diff --git a/rs/moq-net/src/lite/subscriber/routed.rs b/rs/moq-net/src/lite/subscriber/routed.rs index ed49f5785c9..081be08cdbd 100644 --- a/rs/moq-net/src/lite/subscriber/routed.rs +++ b/rs/moq-net/src/lite/subscriber/routed.rs @@ -9,7 +9,7 @@ use std::{ collections::{BTreeMap, BTreeSet, HashMap}, sync::Arc, - task::Poll, + task::{Poll, ready}, }; use crate::{ @@ -870,6 +870,14 @@ impl Routed { } } + /// Ready once nothing the peer offers on this stream waits on a doubt to reach the + /// origin, with what the node served meanwhile already in it. + pub(super) fn poll_undoubted(&mut self, subscriber: &Subscriber, waiter: &kio::Waiter) -> Poll<()> { + ready!(self.stream.poll_undoubted(waiter)); + self.outputs(subscriber); + Poll::Ready(()) + } + /// Serve requests on every claim whose queue woke. pub(super) fn poll(&mut self, subscriber: &Subscriber, waiter: &kio::Waiter) -> Result<(), Error> { while let Poll::Ready(output) = self.stream.poll_output(waiter) { diff --git a/rs/moq-net/src/route/node.rs b/rs/moq-net/src/route/node.rs index b939bccdad3..096c9a1ea28 100644 --- a/rs/moq-net/src/route/node.rs +++ b/rs/moq-net/src/route/node.rs @@ -1107,6 +1107,22 @@ impl Stream { self.queue.lock().pop() } + /// Ready once the peer offers no route on this stream that only doubt keeps the node + /// off ([`Router::doubted`]). Such a route waits on a doubt's timer, so this checks + /// again whenever the node's next deadline moves. + pub fn poll_undoubted(&self, waiter: &kio::Waiter) -> Poll<()> { + loop { + let armed = { + let state = self.node.lock(); + if !state.router.doubted(self.key) { + return Poll::Ready(()); + } + state.router.deadline() + }; + ready!(self.node.poll_deadline(armed, waiter)); + } + } + /// Date what the stream hands the node by its session's clock too. pub fn with_clock(mut self, clock: Deadlines) -> Self { self.clock = Some(clock); diff --git a/rs/moq-net/src/route/path.rs b/rs/moq-net/src/route/path.rs index 8febddc1dd0..2a77a482e65 100644 --- a/rs/moq-net/src/route/path.rs +++ b/rs/moq-net/src/route/path.rs @@ -2380,11 +2380,26 @@ impl Router { /// Whether a neighbour offers a route for `key` that only doubt keeps this node off. fn hopes(&self, key: &RouteId) -> bool { - (self.rx.get(key).into_iter().flatten()).any(|(peer, heard)| { - heard.state == State::Live - && !names(&heard.offer.path, self.hop) - && heard.offer.metric.checked_add(self.sessions[peer].link.cost).is_some() - && self.doubts_path(*peer, &heard.offer.path) + (self.rx.get(key).into_iter().flatten()).any(|(peer, heard)| self.kept_off(*peer, heard)) + } + + /// Whether only doubt keeps this node off the route `heard` from `peer`. + fn kept_off(&self, peer: N, heard: &Heard) -> bool { + heard.state == State::Live + && !names(&heard.offer.path, self.hop) + && heard.offer.metric.checked_add(self.sessions[&peer].link.cost).is_some() + && self.doubts_path(peer, &heard.offer.path) + } + + /// Whether `peer` offers a route that only doubt keeps this node off, where it has + /// no live one: it takes the route once the doubt lifts. + pub fn doubted(&self, peer: N) -> bool { + let Some(session) = self.sessions.get(&peer) else { + return false; + }; + session.heard.iter().any(|key| { + !self.routes.get(key).is_some_and(Route::live) + && (self.rx.get(key).and_then(|heard| heard.get(&peer))).is_some_and(|heard| self.kept_off(peer, heard)) }) } diff --git a/rs/moq-net/tests/integration/synced.rs b/rs/moq-net/tests/integration/synced.rs index ce0dece509f..b6dd671d364 100644 --- a/rs/moq-net/tests/integration/synced.rs +++ b/rs/moq-net/tests/integration/synced.rs @@ -5,6 +5,7 @@ //! on the answer, as a best effort, on the rest. use std::collections::BTreeSet; +use std::task::Poll; use std::time::Duration; use moq_net::{Version, origin}; @@ -12,8 +13,9 @@ use moq_net::{Version, origin}; use crate::support; use support::harness::{MockConnectOptions, connect_mock}; -/// Long enough, in virtual time, for anything in flight to reach the far side. -const SETTLE: Duration = Duration::from_secs(1); +/// Long enough, in virtual time, for anything in flight to reach the far side, +/// past the second a redialed session waits out the doubt on its peer. +const SETTLE: Duration = Duration::from_secs(2); fn produce_origin(hop: u64) -> origin::Producer { let (producer, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); @@ -22,13 +24,15 @@ fn produce_origin(hop: u64) -> origin::Producer { } /// Read events until the consumer syncs, returning the prefixes then announced. +/// Sync is checked whenever no event is ready, so a consumer that syncs early is +/// caught at that moment rather than at the next event. async fn read_until_synced(announced: &mut origin::Routes) -> BTreeSet { let mut seen = BTreeSet::new(); - while !announced.poll_synced(&kio::Waiter::noop()).is_ready() { - let event = kio::clock::timeout(SETTLE, announced.next()) - .await - .expect("synced in time") - .expect("the cursor stays open"); + let read = kio::wait(|waiter| loop { + let event = match announced.poll_next(waiter) { + Poll::Ready(event) => event.expect("the cursor stays open"), + Poll::Pending => return announced.poll_synced(waiter), + }; match event { origin::RouteEvent { kind: origin::RouteKind::Start | origin::RouteKind::Restart, @@ -47,7 +51,8 @@ async fn read_until_synced(announced: &mut origin::Routes) -> BTreeSet { .. } => {} } - } + }); + kio::clock::timeout(SETTLE, read).await.expect("synced in time"); seen } @@ -125,6 +130,38 @@ async fn a_second_session_catches_up() { drop(second); } +/// A session redialed after a cut waits out the doubt on the publisher before +/// its route reaches the origin, and the consumer stays unsynced until then: +/// synced still means every route the peer announced is shown. +#[kio::test] +async fn a_redial_syncs_once_the_doubt_lets_its_routes_in() { + let publisher = produce_origin(1); + let a = publisher.route("a", moq_net::origin::RouteOptions::hidden()).unwrap(); + a.announce().unwrap(); + + let subscriber = produce_origin(2); + let connect = || { + let mut options = MockConnectOptions::new("moq-lite-07-wip".parse::().unwrap()); + options.server_publish = Some(publisher.consume()); + options.client_subscribe = Some(subscriber.clone()); + connect_mock(options) + }; + let first = connect().await; + let mut announced = subscriber.consume().routes(); + assert_eq!(read_until_synced(&mut announced).await, BTreeSet::from(["a".to_string()])); + + first.client.abort(moq_net::Error::Cancel); + first.server.abort(moq_net::Error::Cancel); + let gone = kio::clock::timeout(SETTLE, announced.next()) + .await + .expect("withdrawn in time") + .expect("the cursor stays open"); + assert!(matches!(gone.kind, origin::RouteKind::End | origin::RouteKind::Offline)); + + let _second = connect().await; + assert_eq!(read_until_synced(&mut announced).await, BTreeSet::from(["a".to_string()])); +} + /// A cold relay's empty set is complete before an upstream joins it. #[kio::test] async fn a_cold_relay_syncs_then_forwards_upstream_routes_as_live() { From 080bde233b101c4e522548f636ecf0d624f22178 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 15 Nov 2026 23:48:34 -0800 Subject: [PATCH 2/3] style: rustfmt the redial sync test Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/tests/integration/synced.rs | 54 +++++++++++++++----------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/rs/moq-net/tests/integration/synced.rs b/rs/moq-net/tests/integration/synced.rs index b6dd671d364..c97923075c5 100644 --- a/rs/moq-net/tests/integration/synced.rs +++ b/rs/moq-net/tests/integration/synced.rs @@ -28,28 +28,30 @@ fn produce_origin(hop: u64) -> origin::Producer { /// caught at that moment rather than at the next event. async fn read_until_synced(announced: &mut origin::Routes) -> BTreeSet { let mut seen = BTreeSet::new(); - let read = kio::wait(|waiter| loop { - let event = match announced.poll_next(waiter) { - Poll::Ready(event) => event.expect("the cursor stays open"), - Poll::Pending => return announced.poll_synced(waiter), - }; - match event { - origin::RouteEvent { - kind: origin::RouteKind::Start | origin::RouteKind::Restart, - announce, - } => { - seen.insert(announce.prefix.to_string()); + let read = kio::wait(|waiter| { + loop { + let event = match announced.poll_next(waiter) { + Poll::Ready(event) => event.expect("the cursor stays open"), + Poll::Pending => return announced.poll_synced(waiter), + }; + match event { + origin::RouteEvent { + kind: origin::RouteKind::Start | origin::RouteKind::Restart, + announce, + } => { + seen.insert(announce.prefix.to_string()); + } + origin::RouteEvent { + kind: origin::RouteKind::End | origin::RouteKind::Offline, + announce, + } => { + seen.remove(announce.prefix.as_str()); + } + origin::RouteEvent { + kind: origin::RouteKind::Update, + .. + } => {} } - origin::RouteEvent { - kind: origin::RouteKind::End | origin::RouteKind::Offline, - announce, - } => { - seen.remove(announce.prefix.as_str()); - } - origin::RouteEvent { - kind: origin::RouteKind::Update, - .. - } => {} } }); kio::clock::timeout(SETTLE, read).await.expect("synced in time"); @@ -148,7 +150,10 @@ async fn a_redial_syncs_once_the_doubt_lets_its_routes_in() { }; let first = connect().await; let mut announced = subscriber.consume().routes(); - assert_eq!(read_until_synced(&mut announced).await, BTreeSet::from(["a".to_string()])); + assert_eq!( + read_until_synced(&mut announced).await, + BTreeSet::from(["a".to_string()]) + ); first.client.abort(moq_net::Error::Cancel); first.server.abort(moq_net::Error::Cancel); @@ -159,7 +164,10 @@ async fn a_redial_syncs_once_the_doubt_lets_its_routes_in() { assert!(matches!(gone.kind, origin::RouteKind::End | origin::RouteKind::Offline)); let _second = connect().await; - assert_eq!(read_until_synced(&mut announced).await, BTreeSet::from(["a".to_string()])); + assert_eq!( + read_until_synced(&mut announced).await, + BTreeSet::from(["a".to_string()]) + ); } /// A cold relay's empty set is complete before an upstream joins it. From 2997f6870ea24862309d1d0d4861bcbfa051a7a8 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 15 Nov 2026 23:56:33 -0800 Subject: [PATCH 3/3] docs(net): synced waits out a redial's doubt; verify-route names kept_off Co-Authored-By: Claude Opus 5.5 --- .claude/skills/verify-route/SKILL.md | 2 +- rs/moq-net/src/model/origin.rs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.claude/skills/verify-route/SKILL.md b/.claude/skills/verify-route/SKILL.md index 216d86ab2a6..2500c1baa5d 100644 --- a/.claude/skills/verify-route/SKILL.md +++ b/.claude/skills/verify-route/SKILL.md @@ -115,7 +115,7 @@ Sync commit: `cbb742cecae437ee94fbf25848521ac11b145fbc`, where [moq-dev/moq#8734 | --- | --- | | `rs/moq-net/src/route/path.rs` `Router::run`, `Router::select`, `Router::retain` | `Select` plans live routes and their reflected sources before `SelectKey` decides holds. | | `rs/moq-net/src/route/path.rs` `Offer::rank`, `Router::goaway`, `Router::drains`, `Router::report_draining`, `Router::dead` (`Dead::Draining`) | `Rank`, `Below`, `PathPrio`, `CostAt`, `GoAway`, `MarkDrain`, `Credited`, `ReportDrain`, `Recv` | -| `rs/moq-net/src/route/path.rs` `Router::pending`, `Router::hopes`, `Router::doubts_path` | `Pending`, `Hopes`, `Doubted`, `RelayDoubted` (a path's first node does not count), `Returned` | +| `rs/moq-net/src/route/path.rs` `Router::pending`, `Router::hopes`, `Router::kept_off`, `Router::doubts_path` | `Pending`, `Hopes`, `Doubted`, `RelayDoubted` (a path's first node does not count), `Returned` | | `rs/moq-net/src/route/path.rs` `Router::suspect`, `Router::doubt_until` | `Since`: a doubt on the publisher that begins notes the generation of the relay's own session to it. The router shares one generation across a session's streams (`Session::generation`), which the model's one stream per session leaves out. | | `rs/moq-net/src/route/path.rs` `Router::src` | `SrcKey` | | `rs/moq-net/src/route/path.rs` `Router::usable_offer`, `Offer` | `SelectKey`'s `Down`, `Want0`'s export check, and `DownOnly`: the down-only flag is set on a route learned over an upstream link or from a down-only one, and never sent over an upstream link. | diff --git a/rs/moq-net/src/model/origin.rs b/rs/moq-net/src/model/origin.rs index 909f893f76d..556dc1734ec 100644 --- a/rs/moq-net/src/model/origin.rs +++ b/rs/moq-net/src/model/origin.rs @@ -8617,7 +8617,9 @@ impl Routes { /// queued before then. A prefix not announced by then is not announced, rather /// than not heard yet. A session joining the scope later, such as a reconnect, /// takes this back until it syncs too; routes published on this origin - /// itself never wait. + /// itself never wait. On moq-lite-07 a session syncs only once this origin + /// shows every route its peer sent, so a redial waits out the doubt a closed + /// session left on that peer. /// /// Synced is relative to the session's peer, never global: a relay answers with /// what it holds without waiting on its own upstreams. Versions that cannot mark