From 221cc5bc2a64cb87516083b79206231cf6eb068a Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 21 Oct 2026 12:54:07 -0700 Subject: [PATCH] fix(json): treat a publisher-reset group as a lost group A publisher resets a superseded group with stream code Old, which a reader sees as Error::Stream(StreamError::Old). #5677 narrowed the lost-group match in the moq-json snapshot and window consumers, and the moq-flate snapshot consumer, to the locally raised variants, so that reset became a fatal error and a catalog reader stopped for good. Classify by StreamError instead, so the local and wire spellings are the same loss. Co-Authored-By: Claude Opus 5.5 --- rs/moq-flate/src/snapshot/consumer.rs | 17 +++++--- rs/moq-flate/src/snapshot/mod.rs | 59 ++++++++++++++------------- rs/moq-json/src/snapshot/consumer.rs | 17 +++++--- rs/moq-json/src/snapshot/mod.rs | 57 ++++++++++++++------------ rs/moq-json/src/window/consumer.rs | 17 +++++--- rs/moq-json/src/window/mod.rs | 5 +++ 6 files changed, 99 insertions(+), 73 deletions(-) diff --git a/rs/moq-flate/src/snapshot/consumer.rs b/rs/moq-flate/src/snapshot/consumer.rs index 0fea756618d..b9f6bcb2a8e 100644 --- a/rs/moq-flate/src/snapshot/consumer.rs +++ b/rs/moq-flate/src/snapshot/consumer.rs @@ -95,12 +95,17 @@ impl Consumer { latest = Some(value); } Poll::Ready(Ok(None)) => self.group = None, - Poll::Ready(Err( - err @ (moq_net::Error::Old - | moq_net::Error::Evicted - | moq_net::Error::Lagged - | moq_net::Error::GroupTooLarge), - )) => { + // Judged by stream code, so a group the publisher reset as old is the same loss as + // one this side dropped. + Poll::Ready(Err(err)) + if matches!( + moq_net::StreamError::from(&err), + moq_net::StreamError::Old + | moq_net::StreamError::Evicted + | moq_net::StreamError::TooFarBehind + | moq_net::StreamError::GroupTooLarge + ) => + { // A later group starts a fresh snapshot and compression window. tracing::warn!(track = self.track.name(), group = group.sequence, error = ?err, "snapshot group lost; waiting for a newer one"); diff --git a/rs/moq-flate/src/snapshot/mod.rs b/rs/moq-flate/src/snapshot/mod.rs index 91887e02d3c..e498e6d1fe9 100644 --- a/rs/moq-flate/src/snapshot/mod.rs +++ b/rs/moq-flate/src/snapshot/mod.rs @@ -152,34 +152,37 @@ mod test { /// replacement rather than ending the reader. #[test] fn a_lost_group_waits_for_its_replacement() { - let track = moq_net::broadcast::Info::new() - .produce() - .create_track("test", timed()) - .unwrap(); - let mut consumer = consume(track.subscribe(None), false); - let waiter = kio::Waiter::noop(); - - // Group 0 delivers a value, then stays open with the reader parked on its next frame. - let mut group = track.create_group(moq_net::group::Info { sequence: 0 }).unwrap(); - group - .write_frame(moq_net::Timestamp::now(), Bytes::from_static(b"one")) - .unwrap(); - assert!(matches!(consumer.poll_latest(&waiter), Poll::Ready(Ok(Some(v))) if v.value == "one")); - assert!(consumer.poll_latest(&waiter).is_pending()); - - // The relay reclaims the group out from under the reader. - group.abort(moq_net::Error::Old).unwrap(); - assert!( - consumer.poll_latest(&waiter).is_pending(), - "a lost group must not end the reader" - ); - - // The replacement arrives and the reader picks up where the value now lives. - let mut group = track.create_group(moq_net::group::Info { sequence: 1 }).unwrap(); - group - .write_frame(moq_net::Timestamp::now(), Bytes::from_static(b"two")) - .unwrap(); - assert!(matches!(consumer.poll_latest(&waiter), Poll::Ready(Ok(Some(v))) if v.value == "two")); + // Lost on this side, then reset by the publisher: the reader sees the same loss either way. + for lost in [moq_net::Error::Old, moq_net::Error::Stream(moq_net::StreamError::Old)] { + let track = moq_net::broadcast::Info::new() + .produce() + .create_track("test", timed()) + .unwrap(); + let mut consumer = consume(track.subscribe(None), false); + let waiter = kio::Waiter::noop(); + + // Group 0 delivers a value, then stays open with the reader parked on its next frame. + let mut group = track.create_group(moq_net::group::Info { sequence: 0 }).unwrap(); + group + .write_frame(moq_net::Timestamp::now(), Bytes::from_static(b"one")) + .unwrap(); + assert!(matches!(consumer.poll_latest(&waiter), Poll::Ready(Ok(Some(v))) if v.value == "one")); + assert!(consumer.poll_latest(&waiter).is_pending()); + + // The group is lost out from under the reader. + group.abort(lost).unwrap(); + assert!( + consumer.poll_latest(&waiter).is_pending(), + "a lost group must not end the reader" + ); + + // The replacement arrives and the reader picks up where the value now lives. + let mut group = track.create_group(moq_net::group::Info { sequence: 1 }).unwrap(); + group + .write_frame(moq_net::Timestamp::now(), Bytes::from_static(b"two")) + .unwrap(); + assert!(matches!(consumer.poll_latest(&waiter), Poll::Ready(Ok(Some(v))) if v.value == "two")); + } } /// A stamped payload is written at its capture time, and the returned size is the encoded frame diff --git a/rs/moq-json/src/snapshot/consumer.rs b/rs/moq-json/src/snapshot/consumer.rs index e630536ce56..688d4d3ea96 100644 --- a/rs/moq-json/src/snapshot/consumer.rs +++ b/rs/moq-json/src/snapshot/consumer.rs @@ -124,12 +124,17 @@ impl Consumer { advanced = Some(frame.timestamp); } Poll::Ready(Ok(None)) => self.group = None, - Poll::Ready(Err( - err @ (moq_net::Error::Old - | moq_net::Error::Evicted - | moq_net::Error::Lagged - | moq_net::Error::GroupTooLarge), - )) => { + // Judged by stream code, so a group the publisher reset as old is the same loss as + // one this side dropped. + Poll::Ready(Err(err)) + if matches!( + moq_net::StreamError::from(&err), + moq_net::StreamError::Old + | moq_net::StreamError::Evicted + | moq_net::StreamError::TooFarBehind + | moq_net::StreamError::GroupTooLarge + ) => + { // A later group starts a fresh snapshot and compression window. tracing::warn!(track = self.track.name(), group = group.sequence, error = ?err, "snapshot group lost; waiting for a newer one"); diff --git a/rs/moq-json/src/snapshot/mod.rs b/rs/moq-json/src/snapshot/mod.rs index 6bc03283839..079800991bd 100644 --- a/rs/moq-json/src/snapshot/mod.rs +++ b/rs/moq-json/src/snapshot/mod.rs @@ -237,34 +237,37 @@ mod test { /// catalog group aged out of the relay cache underneath it. #[test] fn a_lost_group_waits_for_its_replacement() { - let track = moq_net::broadcast::Info::new() - .produce() - .create_track("test", timed()) - .unwrap(); - let mut consumer = Consumer::::new(track.subscribe(None), consumer::Config::default()); - let waiter = kio::Waiter::noop(); - - // Group 0 delivers a value, then stays open with the reader parked on its next frame. - let mut group = track.create_group(moq_net::group::Info { sequence: 0 }).unwrap(); - group - .write_frame(moq_net::Timestamp::now(), Bytes::from_static(br#"{"a":1}"#)) - .unwrap(); - assert!(matches!(consumer.poll_latest(&waiter), Poll::Ready(Ok(Some(v))) if v.value == json!({ "a": 1 }))); - assert!(consumer.poll_latest(&waiter).is_pending()); - - // The relay reclaims the group out from under the reader. - group.abort(moq_net::Error::Old).unwrap(); - assert!( - consumer.poll_latest(&waiter).is_pending(), - "a lost group must not end the reader" - ); + // Lost on this side, then reset by the publisher: the reader sees the same loss either way. + for lost in [moq_net::Error::Old, moq_net::Error::Stream(moq_net::StreamError::Old)] { + let track = moq_net::broadcast::Info::new() + .produce() + .create_track("test", timed()) + .unwrap(); + let mut consumer = Consumer::::new(track.subscribe(None), consumer::Config::default()); + let waiter = kio::Waiter::noop(); - // The replacement arrives and the reader picks up where the value now lives. - let mut group = track.create_group(moq_net::group::Info { sequence: 1 }).unwrap(); - group - .write_frame(moq_net::Timestamp::now(), Bytes::from_static(br#"{"a":2}"#)) - .unwrap(); - assert!(matches!(consumer.poll_latest(&waiter), Poll::Ready(Ok(Some(v))) if v.value == json!({ "a": 2 }))); + // Group 0 delivers a value, then stays open with the reader parked on its next frame. + let mut group = track.create_group(moq_net::group::Info { sequence: 0 }).unwrap(); + group + .write_frame(moq_net::Timestamp::now(), Bytes::from_static(br#"{"a":1}"#)) + .unwrap(); + assert!(matches!(consumer.poll_latest(&waiter), Poll::Ready(Ok(Some(v))) if v.value == json!({ "a": 1 }))); + assert!(consumer.poll_latest(&waiter).is_pending()); + + // The group is lost out from under the reader. + group.abort(lost).unwrap(); + assert!( + consumer.poll_latest(&waiter).is_pending(), + "a lost group must not end the reader" + ); + + // The replacement arrives and the reader picks up where the value now lives. + let mut group = track.create_group(moq_net::group::Info { sequence: 1 }).unwrap(); + group + .write_frame(moq_net::Timestamp::now(), Bytes::from_static(br#"{"a":2}"#)) + .unwrap(); + assert!(matches!(consumer.poll_latest(&waiter), Poll::Ready(Ok(Some(v))) if v.value == json!({ "a": 2 }))); + } } /// Nothing replaces a lost group once the track is finished, so the reader ends cleanly on the diff --git a/rs/moq-json/src/window/consumer.rs b/rs/moq-json/src/window/consumer.rs index 8d217777e96..75819be091f 100644 --- a/rs/moq-json/src/window/consumer.rs +++ b/rs/moq-json/src/window/consumer.rs @@ -69,12 +69,17 @@ impl Consumer { }; match group.poll_read_frame(waiter) { - Poll::Ready(Err( - moq_net::Error::Old - | moq_net::Error::Lagged - | moq_net::Error::Evicted - | moq_net::Error::GroupTooLarge, - )) => { + // Judged by stream code, so a group the publisher reset as old is the same loss as + // one this side dropped. + Poll::Ready(Err(err)) + if matches!( + moq_net::StreamError::from(&err), + moq_net::StreamError::Old + | moq_net::StreamError::TooFarBehind + | moq_net::StreamError::Evicted + | moq_net::StreamError::GroupTooLarge + ) => + { // This group is no longer complete, but the next one starts with a checkpoint // that can account for everything this reader missed. self.group = None; diff --git a/rs/moq-json/src/window/mod.rs b/rs/moq-json/src/window/mod.rs index 82c5fdc0eea..b0b5f1d012a 100644 --- a/rs/moq-json/src/window/mod.rs +++ b/rs/moq-json/src/window/mod.rs @@ -551,11 +551,16 @@ mod test { #[test] fn consumer_resumes_at_a_checkpoint_after_losing_a_group() { + // Each loss as this side raises it, then as a publisher's reset carries it. for err in [ moq_net::Error::Old, moq_net::Error::Lagged, moq_net::Error::Evicted, moq_net::Error::GroupTooLarge, + moq_net::Error::Stream(moq_net::StreamError::Old), + moq_net::Error::Stream(moq_net::StreamError::TooFarBehind), + moq_net::Error::Stream(moq_net::StreamError::Evicted), + moq_net::Error::Stream(moq_net::StreamError::GroupTooLarge), ] { let track = moq_net::broadcast::Info::new() .produce()