From 5d8a489be7fc28b67a7251a03325c9fe4ce4c6d8 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 25 Oct 2026 15:18:50 -0700 Subject: [PATCH 1/4] fix(net): a lite-05/06 SUBSCRIBE_DROP ends its readers with Old Co-Authored-By: Claude Opus 5.5 --- doc/concept/moq-lite.md | 2 +- drafts/draft-lcurley-moq-lite.md | 2 +- js/json/src/snapshot/snapshot.test.ts | 16 ++++++++++++++++ js/net/MIGRATE.md | 2 +- js/net/src/lite/subscribe.ts | 8 ++++---- js/net/src/lite/tail.test.ts | 11 +++++++++-- rs/moq-net/MIGRATE.md | 2 +- rs/moq-net/src/lite/subscribe.rs | 5 +++-- rs/moq-net/src/lite/subscriber.rs | 12 ++++++++++-- 9 files changed, 46 insertions(+), 14 deletions(-) diff --git a/doc/concept/moq-lite.md b/doc/concept/moq-lite.md index 605c8eb9050..75ec4abcab4 100644 --- a/doc/concept/moq-lite.md +++ b/doc/concept/moq-lite.md @@ -271,7 +271,7 @@ Each subscription carries the knobs that decide behavior under congestion: On moq-lite 05 and later, a publisher explicitly reports groups that will not arrive. This lets a finished subscription settle without waiting for missing groups. A reader of a reported group, including one still arriving, ends with the publisher's error, such as `OLD` or `NOT_FOUND`. -On moq-lite 05 and 06 that code is application-specific, so every reported group ends with `NOT_FOUND` there. +On moq-lite 05 and 06 that code is application-specific, so every reported group ends with `OLD` there. Datagram delivery stays best effort. Ranges are both a request and a filter. A subscriber reads only the groups its diff --git a/drafts/draft-lcurley-moq-lite.md b/drafts/draft-lcurley-moq-lite.md index 03bd38eb7e6..0da72915c25 100644 --- a/drafts/draft-lcurley-moq-lite.md +++ b/drafts/draft-lcurley-moq-lite.md @@ -1857,7 +1857,7 @@ The `Message Length` describes the payload size on the wire. - Switched every variable-length integer, including SETUP parameter values, from QUIC's two-bit length prefix to moq-transport's leading-ones encoding, widening the range to 64 bits. - Hid routes with a `.`-prefixed segment below the requested prefix from announce discovery, and added the ANNOUNCE_REQUEST `Hidden` field to opt in. - Restored SUBSCRIBE_DROP (type 0x2), replacing Stream Count on SUBSCRIBE_END. Every sequence is accounted for by a Group Stream, a datagram, or a drop; a publisher SHOULD send a drop as soon as it gives a sequence up. -- SUBSCRIBE_DROP's Error Code is a stream error code, which ends the dropped groups' readers, including one still arriving. In lite-05 and lite-06 it is application-specific, so a subscriber there reads every drop as NOT_FOUND. +- SUBSCRIBE_DROP's Error Code is a stream error code, which ends the dropped groups' readers, including one still arriving. In lite-05 and lite-06 it is application-specific, so a subscriber there reads every drop as OLD. - SUBSCRIBE_END declares the final boundary while lower groups can still be in flight; the Subscribe Stream FIN follows once every Group Stream has finished or been reset. - Added the Spread Hash tie-break after the shortest path: a hash of the requested path and the route's Hop IDs, so equal-cost advertisers of one prefix share its paths. - Skipped the Spread Hash for a route a publisher announced directly at the requested path. diff --git a/js/json/src/snapshot/snapshot.test.ts b/js/json/src/snapshot/snapshot.test.ts index cbe6ba971e7..96610f52e52 100644 --- a/js/json/src/snapshot/snapshot.test.ts +++ b/js/json/src/snapshot/snapshot.test.ts @@ -627,6 +627,22 @@ test("a compressed delta is gated on its encoded size, not its plaintext", async expect(values[values.length - 1]).toEqual(patched); }); +// A publisher gives up a group a reader is still on once a newer one supersedes it, which every +// moq-lite version reports as OLD. The reader skips to the newer snapshot instead of failing. +test("snapshot consumer skips a group the publisher dropped mid-read", async () => { + const track = new Track.Producer("test"); + const consumer = new Consumer({ track: track.subscribe() }); + const first = track.appendGroup(); + first.writeFrame({ payload: new TextEncoder().encode('{"v":0}'), timestamp: Time.Timestamp.now() }); + expect((await consumer.latest())?.value).toEqual({ v: 0 }); + + const next = consumer.latest(); + track.dropGroups(0, 1, new NetError.Stream(StreamCode.Old)); + const second = track.appendGroup(); + second.writeFrame({ payload: new TextEncoder().encode('{"v":1}'), timestamp: Time.Timestamp.now() }); + expect((await next)?.value).toEqual({ v: 1 }); +}); + // A malformed or failed group must reach the caller; only an explicit retention gap is resumable. test("snapshot consumer propagates a non-gap frame failure", async () => { const track = new Track.Producer("test"); diff --git a/js/net/MIGRATE.md b/js/net/MIGRATE.md index 2bdc084a66e..3e12c757698 100644 --- a/js/net/MIGRATE.md +++ b/js/net/MIGRATE.md @@ -41,7 +41,7 @@ The wire messages (`Lite.Subscribe`, `Lite.TrackInfo`, `Ietf.Subscribe`, ...) ho A group the publisher cut, or named in `SUBSCRIBE_DROP`, after a `Track.Subscriber` saw it is now handed out, and its reads reject with the publisher's `StreamError`; before, it was skipped or ended cleanly. A group already held rejects the same way when the drop lands, even while its stream is still arriving. -On lite-05 and lite-06 the code is always `StreamCode.NotFound`. +On lite-05 and lite-06 the code is always `StreamCode.Old`. Treat a rejected group read as the loss of that group and keep reading the track, rather than ending the subscription. ### A claim answers by publishing (#5678) diff --git a/js/net/src/lite/subscribe.ts b/js/net/src/lite/subscribe.ts index c1fa30cd2ed..79599498a23 100644 --- a/js/net/src/lite/subscribe.ts +++ b/js/net/src/lite/subscribe.ts @@ -693,13 +693,13 @@ export class SubscribeDrop { /** * The error the dropped groups' readers end with, as `version` reads the code. * - * Before lite-07 the code is the application's, so every drop reads as NOT_FOUND: the - * groups are not there to deliver. + * Before lite-07 the code is the application's, so every drop reads as OLD: the publisher + * gave the groups up, and a reader moves on to a newer one as it would past a superseded group. */ cause(version: Version): Error { - if (!hasDropCode(version)) return new StreamError(StreamCode.NotFound, { message: "dropped" }); + if (!hasDropCode(version)) return new StreamError(StreamCode.Old); if (this.error > 0xffff_ffff) - return new StreamError(StreamCode.Internal, { message: `dropped: ${this.error}` }); + return new StreamError(StreamCode.Internal, { message: `invalid drop code: ${this.error}` }); return fromTransport({ source: "stream", streamErrorCode: this.error }); } diff --git a/js/net/src/lite/tail.test.ts b/js/net/src/lite/tail.test.ts index 88e2f7bed09..911a934a684 100644 --- a/js/net/src/lite/tail.test.ts +++ b/js/net/src/lite/tail.test.ts @@ -282,7 +282,7 @@ describe.each([Version.DRAFT_05, Version.DRAFT_06, Version.DRAFT_07])("%s", (ver }); // Lite-07 carries a stream error code; earlier versions an application one, so the same - // bytes read as NOT_FOUND there. + // bytes read as OLD there. test("a SUBSCRIBE_DROP ends a group still arriving, before the FIN", async () => { const { subscriber, reader, respond } = await subscribed(version, Milli(60_000)); await respond({ start: new SubscribeStart(0) }); @@ -297,8 +297,15 @@ describe.each([Version.DRAFT_05, Version.DRAFT_06, Version.DRAFT_07])("%s", (ver (err: unknown) => err, ); expect(err).toBeInstanceOf(StreamError); - expect((err as StreamError).code).toBe(version === Version.DRAFT_07 ? StreamCode(70) : StreamCode.NotFound); + expect((err as StreamError).code).toBe(version === Version.DRAFT_07 ? StreamCode(70) : StreamCode.Old); expect(reader.closed.peek()).toBeUndefined(); + + // The track goes on: the next group still reaches the reader. + const following = groupStream(subscriber, 1); + following.write("1.0"); + const next = await reader.recvGroup(); + expect(next?.sequence).toBe(1); + expect(await next?.readString()).toBe("1.0"); subscriber.close(); }); diff --git a/rs/moq-net/MIGRATE.md b/rs/moq-net/MIGRATE.md index f57d1574730..d1a1d486c5f 100644 --- a/rs/moq-net/MIGRATE.md +++ b/rs/moq-net/MIGRATE.md @@ -171,7 +171,7 @@ Clamp timestamps you build from unbounded input to `(1 << 61) - 1`. A group the publisher cut, or named in `SUBSCRIBE_DROP`, after a `track::Subscriber` saw it is now handed out, and reading it fails with the publisher's error; before, it was skipped or ended cleanly. A group already held fails the same way when the drop lands, even while its stream is still arriving. -On lite-05 and lite-06 the error is always `Error::Stream(StreamError::NotFound)`. +On lite-05 and lite-06 the error is always `Error::Stream(StreamError::Old)`. Treat a failed group read as the loss of that group and keep reading the track, rather than ending the subscription. ### A claim answers by publishing (#5678) diff --git a/rs/moq-net/src/lite/subscribe.rs b/rs/moq-net/src/lite/subscribe.rs index 7404fb6bed3..a7c401f7a18 100644 --- a/rs/moq-net/src/lite/subscribe.rs +++ b/rs/moq-net/src/lite/subscribe.rs @@ -659,11 +659,12 @@ impl SubscribeDrop { /// The error the dropped groups' readers end with, as `version` reads the code. /// /// Before lite-07 the code is the application's, so every drop reads as - /// [`StreamError::NotFound`]: the groups are not there to deliver. + /// [`StreamError::Old`]: the publisher gave the groups up, and a reader moves on to a + /// newer one as it would past a superseded group. pub fn error(&self, version: Version) -> StreamError { match version.has_drop_code() { true => u32::try_from(self.error).map_or(StreamError::Internal, |code| version.decode_stream_code(code)), - false => StreamError::NotFound, + false => StreamError::Old, } } } diff --git a/rs/moq-net/src/lite/subscriber.rs b/rs/moq-net/src/lite/subscriber.rs index 5593cb0ab9f..3ac61e0f854 100644 --- a/rs/moq-net/src/lite/subscriber.rs +++ b/rs/moq-net/src/lite/subscriber.rs @@ -3522,7 +3522,7 @@ mod tests { /// A SUBSCRIBE_DROP ends a group still arriving now, with its Error Code on lite-07. /// Earlier versions carry an application code there, so the same bytes read as - /// NOT_FOUND. + /// OLD. #[moq_clock::test] async fn a_subscribe_drop_ends_an_arriving_group_with_its_code() { for version in [Version::Lite05, Version::Lite06, Version::Lite07] { @@ -3570,6 +3570,7 @@ mod tests { let broadcast = crate::broadcast::Info::new().produce(); let request = broadcast.reserve_track("video").unwrap(); let serving = ServeLoop::new(&serve, request, crate::track::Info::timed()); + let producer = serving.serving.clone(); let mut arriving = serving.serving.create_group(group::Info { sequence: 2 }).unwrap(); arriving.write_frame(crate::Timestamp::ZERO, b"2".as_slice()).unwrap(); let mut reader = broadcast @@ -3592,13 +3593,20 @@ mod tests { let expected = match version { Version::Lite07 => crate::StreamError::App(5), - _ => crate::StreamError::NotFound, + _ => crate::StreamError::Old, }; let res = group.read_frame().now_or_never(); assert!( matches!(&res, Some(Err(Error::Stream(err))) if *err == expected), "{version:?}: {res:?}" ); + + // The track goes on: the next group still reaches the reader. + let mut following = producer.create_group(group::Info { sequence: 3 }).unwrap(); + following.write_frame(crate::Timestamp::ZERO, b"3".as_slice()).unwrap(); + let mut next = reader.recv_group().now_or_never().expect("the next group").unwrap().unwrap(); + assert_eq!(next.sequence, 3, "{version:?}"); + assert_eq!(next.read_frame().await.unwrap().unwrap().payload.as_ref(), b"3"); } } From 3caa228a98c1a41606ebaedbe3374581fc0635b0 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 25 Oct 2026 15:28:51 -0700 Subject: [PATCH 2/4] fix(net): an origin's released in-flight track ends as a cancel Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/lite/subscriber.rs | 7 ++++++- rs/moq-net/src/model/origin.rs | 17 ++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/rs/moq-net/src/lite/subscriber.rs b/rs/moq-net/src/lite/subscriber.rs index 3ac61e0f854..c934ccb0d5d 100644 --- a/rs/moq-net/src/lite/subscriber.rs +++ b/rs/moq-net/src/lite/subscriber.rs @@ -3604,7 +3604,12 @@ mod tests { // The track goes on: the next group still reaches the reader. let mut following = producer.create_group(group::Info { sequence: 3 }).unwrap(); following.write_frame(crate::Timestamp::ZERO, b"3".as_slice()).unwrap(); - let mut next = reader.recv_group().now_or_never().expect("the next group").unwrap().unwrap(); + let mut next = reader + .recv_group() + .now_or_never() + .expect("the next group") + .unwrap() + .unwrap(); assert_eq!(next.sequence, 3, "{version:?}"); assert_eq!(next.read_frame().await.unwrap().unwrap().payload.as_ref(), b"3"); } diff --git a/rs/moq-net/src/model/origin.rs b/rs/moq-net/src/model/origin.rs index cb205d915f2..b160d1aec8c 100644 --- a/rs/moq-net/src/model/origin.rs +++ b/rs/moq-net/src/model/origin.rs @@ -3147,11 +3147,22 @@ struct InFlight { routes: super::resume::Producer, // Kept for its readers: the logical track, the query holding its copy, and the copy's // subscription. - _accepted: Option, + accepted: Option, _copy: Option, _held: Option>, } +impl InFlight { + /// Let go once its last reader left. Nobody reads the logical track any more, so it ends + /// as a cancel rather than as a producer dropped unfinished. + fn release(self) { + self.routes.release(); + if let Some(accepted) = self.accepted { + let _ = accepted.abort(Error::Cancel); + } + } +} + /// Drives one front until it ends, then holds the tracks it left in flight until /// their last reader leaves, or until nothing owns the origin: a reader never keeps /// the driver from finishing. @@ -3170,7 +3181,7 @@ async fn run_front(task: FrontTask, origin: TasksWeak) { for io in std::mem::take(&mut in_flight) { match io.weak.poll_unused(waiter) { Poll::Pending => in_flight.push(io), - Poll::Ready(_) => io.routes.release(), + Poll::Ready(_) => io.release(), } } match in_flight.is_empty() { @@ -3685,7 +3696,7 @@ async fn serve_front(task: FrontTask) -> Vec { in_flight.push(InFlight { weak, routes, - _accepted: accepted, + accepted, _copy: copy.map(|(_, _, query)| query), _held: held, }); From 47da76fef385ca583b3edba9fe0c49df5ddc1b8f Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 25 Oct 2026 21:57:01 -0700 Subject: [PATCH 3/4] doc(lite): any pre-07 SUBSCRIBE_DROP ends its readers with OLD Co-Authored-By: Claude Opus 5.5 --- doc/concept/moq-lite.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/concept/moq-lite.md b/doc/concept/moq-lite.md index 75ec4abcab4..01448beab0b 100644 --- a/doc/concept/moq-lite.md +++ b/doc/concept/moq-lite.md @@ -271,7 +271,7 @@ Each subscription carries the knobs that decide behavior under congestion: On moq-lite 05 and later, a publisher explicitly reports groups that will not arrive. This lets a finished subscription settle without waiting for missing groups. A reader of a reported group, including one still arriving, ends with the publisher's error, such as `OLD` or `NOT_FOUND`. -On moq-lite 05 and 06 that code is application-specific, so every reported group ends with `OLD` there. +Before moq-lite 07 that code is application-specific, so every reported group ends with `OLD`. Datagram delivery stays best effort. Ranges are both a request and a filter. A subscriber reads only the groups its From 70aa17b5d65bfd91d105518ea44440ff934c5a52 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 26 Oct 2026 11:16:31 -0700 Subject: [PATCH 4/4] test(json): fail the read group with OLD through its public close dropGroups became package-internal in #6747, so the snapshot test ends the group a reader is on with an OLD close instead. Co-Authored-By: Claude Opus 5.5 --- js/json/src/snapshot/snapshot.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/json/src/snapshot/snapshot.test.ts b/js/json/src/snapshot/snapshot.test.ts index 96610f52e52..4f9344a60c3 100644 --- a/js/json/src/snapshot/snapshot.test.ts +++ b/js/json/src/snapshot/snapshot.test.ts @@ -637,7 +637,7 @@ test("snapshot consumer skips a group the publisher dropped mid-read", async () expect((await consumer.latest())?.value).toEqual({ v: 0 }); const next = consumer.latest(); - track.dropGroups(0, 1, new NetError.Stream(StreamCode.Old)); + first.close(new NetError.Stream(StreamCode.Old)); const second = track.appendGroup(); second.writeFrame({ payload: new TextEncoder().encode('{"v":1}'), timestamp: Time.Timestamp.now() }); expect((await next)?.value).toEqual({ v: 1 });