From dcac617ee11b673c5a8d9135c1aefb41142a98b7 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 14 Nov 2026 14:48:14 -0800 Subject: [PATCH 1/4] chore(quest): claim quest/m2/group-drops-wire.md Quest-Claim: 2c6b7f1bd930d27f From 48ad4755059e70051ff8d3e5b8154b2d0bd3c43c Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 14 Nov 2026 15:58:19 -0800 Subject: [PATCH 2/4] fix(moq-net): read a group header before a full window stops its stream A GROUP stream ranked parked from the moment it arrived, so when the receive window filled, one whose header was still arriving went first: a stop that freed a few bytes and left the subscriber knowing the group only through the publisher's SUBSCRIBE_DROP. It now keeps the unidentified rank until its header is read, and ranks parked only while it waits unread on SETUP, TRACK_INFO or a duplicate. GROUP's size is capped at its three varints. The lite-07 draft now states that a Group Stream the subscriber stopped is named in SUBSCRIBE_DROP with the stop's code, even after a reliable reset, as both publishers already do; Rust and JS tests pin it. Closes quest/m2/group-drops-wire.md. Co-Authored-By: Claude Opus 5.5 --- drafts/draft-lcurley-moq-lite.md | 5 +- js/net/src/lite/publisher.test.ts | 31 +++++++++ quest/m2/README.md | 5 +- quest/m2/group-drops-wire.md | 64 ------------------- quest/m2/group-drops.md | 16 +++-- quest/m2/lite07-finalize.md | 11 ++-- rs/moq-net/src/lite/group.rs | 4 ++ rs/moq-net/src/lite/publisher.rs | 38 +++++++++++ rs/moq-net/src/lite/subscriber.rs | 23 ++++--- rs/moq-net/src/lite/test_transport.rs | 20 ++++++ rs/moq-net/src/priority.rs | 12 ++-- .../tests/integration/receive_credit.rs | 43 +++++++++++++ 12 files changed, 181 insertions(+), 91 deletions(-) delete mode 100644 quest/m2/group-drops-wire.md diff --git a/drafts/draft-lcurley-moq-lite.md b/drafts/draft-lcurley-moq-lite.md index 86276e9a114..af2e8d7ddec 100644 --- a/drafts/draft-lcurley-moq-lite.md +++ b/drafts/draft-lcurley-moq-lite.md @@ -2096,8 +2096,8 @@ A Group Stream also wins over a stale drop of its sequence that arrives after it Either way the Group Stream accounts for the sequence, and the next SUBSCRIBE_UPDATE does not reopen it: the publisher, having served it, neither serves it again nor names it in another drop. For every sequence in the subscription's range, the publisher MUST send a Group Stream or name it in SUBSCRIBE_SKIP or SUBSCRIBE_DROP. -This includes streams reset before their headers were delivered. -A reliably delivered reset retaining the Group Stream header accounts for that group instead, unless it is YIELDED. +This includes streams reset before their headers were delivered, and streams the subscriber stopped (STOP_SENDING), which it may have discarded unread; such a drop carries the STOP_SENDING's Error Code. +A reliably delivered reset retaining the Group Stream header accounts for that group instead, unless it is YIELDED or answers a STOP_SENDING. A [paused](#yield) Group is accounted for only once a continuation completes it, a reset of one other than YIELDED ends it, or a SUBSCRIBE_DROP names it. The publisher SHOULD name a sequence as soon as it gives it up, without waiting for SUBSCRIBE_FINISH. @@ -2488,6 +2488,7 @@ An application-specific payload. - Added `Error Code` to SUBSCRIBE_FINISH: a track can end with an error while keeping the groups below its end. - Restored SUBSCRIBE_DROP (type 0x2), replacing Stream Count on SUBSCRIBE_FINISH. Every sequence is accounted for by a Group Stream 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. +- A Group Stream the subscriber stopped (STOP_SENDING) is named in SUBSCRIBE_DROP with the STOP_SENDING's Error Code, even after a reliable reset. - Refuse a SUBSCRIBE_DROP whose Group Start is greater than Group End plus one on every earlier version that carries it. - SUBSCRIBE_DROP and SUBSCRIBE_SKIP carry `Group Start` and `Group Count` in place of an inclusive `Group End`. A range past 2^64-1 is a PROTOCOL_VIOLATION. - Added SUBSCRIBE_SKIP (type 0x3) for sequences the publisher declared it will never produce, which ends no reader and is final: a Group is never created at a skipped sequence. A skip overrides an earlier drop of the same sequences, whatever its Error Code, without re-delivering to readers the drop already ended, and never overrides a Group that arrived. A gap in the sequence numbers is not a skip, since Groups may be created out of order; a sequence never had and never declared skipped is named in SUBSCRIBE_DROP. SUBSCRIBE_DROP no longer names declared skips. diff --git a/js/net/src/lite/publisher.test.ts b/js/net/src/lite/publisher.test.ts index 5eecdf35e0b..c129c3a723c 100644 --- a/js/net/src/lite/publisher.test.ts +++ b/js/net/src/lite/publisher.test.ts @@ -894,6 +894,13 @@ async function servedSubscription( } return { sequence: header.sequence, frameStart: header.frameStart, payloads }; }, + // Stop the next group stream the publisher opened with `code`, before reading any of it, + // as a subscriber that discards a stream unread does. + async stopServed(code: number): Promise { + const next = await opened.read(); + if (next.done) throw new Error("the publisher opened no group stream"); + await next.value.cancel({ source: "stream", streamErrorCode: code }); + }, // The sequence alone, for tests that only care which groups reached the wire. async servedSequence(): Promise { return (await this.servedGroup())?.sequence; @@ -1249,6 +1256,30 @@ for (const version of [Version.DRAFT_06, Version.DRAFT_07]) { } }); + // A subscriber may stop a group stream before reading which group it carried, so the drop + // is its only account of it. Mirrors the Rust `a_stopped_group_stream_is_dropped_with_its_stop_code`. + test(`lite ${version}: a stopped group stream is dropped with ${version === Version.DRAFT_07 ? "its stop code" : "no code"}`, async () => { + const sub = await servedSubscription({ version, startGroup: 0n }); + try { + // Left open, so only the stop ends its stream. + const group = sub.track.createGroup(0n); + group.writeFrame(textFrame("hello", Timestamp.fromMillis(0))); + await sub.stopServed(StreamCode.Evicted); + for (;;) { + const resp = await decodeSubscribeResponse(sub.client.reader, version); + if (!("drop" in resp)) continue; + expect([resp.drop.start, resp.drop.end, resp.drop.error]).toEqual([ + 0n, + 1n, + version === Version.DRAFT_07 ? StreamCode.Evicted : 0, + ]); + break; + } + } finally { + await sub.close(); + } + }); + test(`lite ${version}: a routed track forwards its serving route's drop`, async () => { const sub = await servedSubscription({ version, startGroup: 0n, routed: true }); try { diff --git a/quest/m2/README.md b/quest/m2/README.md index 695937d8738..09867cac6ec 100644 --- a/quest/m2/README.md +++ b/quest/m2/README.md @@ -247,8 +247,9 @@ what would need a breaking release had it landed right after the cut: tier and partition tests run before it (maintainer; rejected: moving it to m3 and fixing late routing flaws in lite-08). - ✅ [Group drops](/quest/m2/group-drops.md) split: its lite-07 wire question - is [its own quest](/quest/m2/group-drops-wire.md), which starts now and - gates the freeze; the public `Ordered` API waits for the model. + was its own quest, settled without a wire-format change in + [moq-dev/moq#8774](https://github.com/moq-dev/moq/pull/8774); the public + `Ordered` API waits for the model. [Catalog at timestamp](/quest/m2/catalog-at-timestamp.md) no longer waits for `@moq/net` by start, and [the bindings](/quest/m2/time-addressing/bindings.md) shrink to a rename, since the model already fills each field with the start. diff --git a/quest/m2/group-drops-wire.md b/quest/m2/group-drops-wire.md deleted file mode 100644 index d20faf15772..00000000000 --- a/quest/m2/group-drops-wire.md +++ /dev/null @@ -1,64 +0,0 @@ -# [M] A moq-lite subscriber always learns which group it abandoned - -## Goal - -No group a moq-lite subscriber gives up on vanishes because its stream was -stopped or evicted before its header was read: the subscriber always learns -the ID of a group it abandoned. moq-transport reports what its wire allows, -and the PR records any gap there. Whether this needs a lite-07 wire change is -settled before lite-07 freezes. - -## Plan - -Split 2026-11-14 from [the public drop signal](/quest/m2/group-drops.md) (the -m2 triage before the cut, under /quest-afk, for the maintainer's review): -✅ the wire half reads no group key, so it starts now, and -[lite-07's freeze](/quest/m2/lite07-finalize.md) waits on it instead of on -the public API (rejected: keeping one quest, which holds this wire question -until the Rust model lands). - -Planned 2026-11-04 with the maintainer, from -[moq-dev/moq#7838](https://github.com/moq-dev/moq/pull/7838). Under that -benchmark's overload policy, overcommitted cells hang. Sometimes the subscriber -drops a group without `recv_group` ever returning it: either the group's stream -was evicted before its header was read, or the group was evicted and so was the -FETCH that refetched it. The 4 MiB-frame cell hits this on every run; the -256-stream cell sometimes does. - -✅ **The wire mechanism is this quest's call, with numbers** (maintainer, -2026-11-04). Compare: - -- **The publisher answers STOP_SENDING with SUBSCRIBE_DROP.** Lite already - sends SUBSCRIBE_DROP on the control stream when a group fails at the - publisher (`GroupServe::settle_failed`, `rs/moq-net/src/lite/publisher.rs`, - versions with a track stream), but a subscriber's STOP_SENDING doesn't - produce one. -- **The subscriber reads a group's header before it stops or evicts that - stream.** - -Doing both is fine if each is needed. Start with the maintainer's question: -why does the subscriber stop or evict a stream before reading its header at -all? If receive-window eviction can wait for the header, take the no-wire -path and remove this quest from -[lite07-finalize](/quest/m2/lite07-finalize.md)'s Required. - -Take the numbers from the receive-windows benchmark's overcommitted cells (256 -streams, 4 MiB frames, follow; `rs/moq-tokio/tests/integration/receive_credit.rs`): -each must account for every group sent as delivered or abandoned, counted -inside moq-net until [the public drop signal](/quest/m2/group-drops.md) lets -the benchmark count them itself. Compare their throughput and the -control-stream bytes each mechanism adds. Cover moq-transport too, or say why -it differs. A wire rule applies to `js/net`'s publisher and subscriber in the -same PR. - -The drop set owns the per-cursor drop runs and their reasons -([moq-dev/moq#8476](https://github.com/moq-dev/moq/pull/8476)); this changes -only whether an abandoned group is known, not how a cursor judges a missing -one. - -Public API: none. Wire: possibly lite-07-wip (SUBSCRIBE_DROP for a stopped -group), decided here. - -## Related - -- [The public drop signal](/quest/m2/group-drops.md) - surfaces what this makes known to the application diff --git a/quest/m2/group-drops.md b/quest/m2/group-drops.md index 45d11313061..d0cb3bc7783 100644 --- a/quest/m2/group-drops.md +++ b/quest/m2/group-drops.md @@ -16,9 +16,16 @@ Planned 2026-11-04 with the maintainer, from reports a group the subscriber dropped without `recv_group` returning it, so a reader that paces on delivered-or-evicted groups stalls. Split 2026-11-14 (the m2 triage before the cut, under /quest-afk, for the maintainer's review): -[the wire half](/quest/m2/group-drops-wire.md) makes every abandoned group -known and decides lite-07's part; this publishes it. It stays in m2 because -the `Ordered` change below is breaking. +the wire half made every abandoned group known and decided lite-07's part; +this publishes it. It stays in m2 because the `Ordered` change below is +breaking. + +The wire half ([moq-dev/moq#8774](https://github.com/moq-dev/moq/pull/8774)) +found every group the overcommitted cells lose already in the drop set: a +scratch reader polling `poll_drop` beside `recv_group` finished every cell of +the receive-windows benchmark with delivered, evicted-after-header and dropped +groups summing to those sent, on lite-06 and lite-07. So surfacing +`poll_drop` alone unskips those cells. - ✅ **Milestone** (maintainer, 2026-11-04): it changes public API, so it lands before the cut. @@ -56,12 +63,11 @@ Callers match the new item, and a caller that ignores drops takes the group arm; the PR's MIGRATE notes say so. `recv_group` and the unordered cursor are unchanged, so a reader that needs drop accounting reads through `Ordered`. `@moq/net` and the bindings mirror it only with a named consumer. -Wire: none; [the wire half](/quest/m2/group-drops-wire.md) owns it. +Wire: none. ## Required - [Address groups by timestamp](/quest/m2/time-addressing/model.md) - the drop range is keyed by start -- [A moq-lite subscriber always learns which group it abandoned](/quest/m2/group-drops-wire.md) - the benchmark's cells finish only once no abandoned group is lost ## Related diff --git a/quest/m2/lite07-finalize.md b/quest/m2/lite07-finalize.md index f10cc5eb5ef..cac268c0291 100644 --- a/quest/m2/lite07-finalize.md +++ b/quest/m2/lite07-finalize.md @@ -147,17 +147,18 @@ would need a breaking release had it landed right after the cut: the signed transcript. Rejected: keeping the pin in m2, where the freeze waits on nixpkgs as well as the cut; dropping the check, which would find a transcript flaw only after the freeze. -- ✅ The wire half of group drops split out as - [its own quest](/quest/m2/group-drops-wire.md), which this waits on in - place of [the public drop signal](/quest/m2/group-drops.md), an API change - that doesn't touch the wire. +- ✅ The wire half of group drops split out as its own quest, which this + waited on in place of [the public drop signal](/quest/m2/group-drops.md), + an API change that doesn't touch the wire. It settled without a + wire-format change ([moq-dev/moq#8774](https://github.com/moq-dev/moq/pull/8774)): + both publishers already name a Group Stream the subscriber stopped in + SUBSCRIBE_DROP, which the draft now states, even after a reliable reset. ## Required - [Routes and announces](/quest/m2/cluster-routes/README.md) - lite-07 carries the route layer: ROUTE per origin node and path-less ANNOUNCE, with the native hop list gone (only the temporary lite-06 compatibility chain remains) - [Lite-07 by start](/quest/m2/time-addressing/lite07.md) - lite-07 carries group starts, previous-start links, GROUP_END, and time bounds instead of sequence numbers - [@moq/net by start](/quest/m2/time-addressing/js.md) - JS speaks the same lite-07 wire -- [A moq-lite subscriber always learns which group it abandoned](/quest/m2/group-drops-wire.md) - may add SUBSCRIBE_DROP for a stopped group; leaves this list if it takes the no-wire path ## Related diff --git a/rs/moq-net/src/lite/group.rs b/rs/moq-net/src/lite/group.rs index 1da6ab4320b..b9bfb3e5f67 100644 --- a/rs/moq-net/src/lite/group.rs +++ b/rs/moq-net/src/lite/group.rs @@ -18,6 +18,10 @@ pub struct Group { } impl<'a> Message<'a> for Group { + /// Three varints of at most 9 bytes each, so a header still arriving holds few bytes at + /// its [unidentified](crate::priority::RECV_UNIDENTIFIED) receive rank. + const MAX_SIZE: usize = 3 * 9; + fn decode_msg(r: &mut Decoder<'a>, version: Version) -> Result { let subscribe = r.varint()?; let sequence = r.varint()?; diff --git a/rs/moq-net/src/lite/publisher.rs b/rs/moq-net/src/lite/publisher.rs index 482e88c8f48..ffe29fba18c 100644 --- a/rs/moq-net/src/lite/publisher.rs +++ b/rs/moq-net/src/lite/publisher.rs @@ -9344,6 +9344,44 @@ mod serve_group_test { assert_eq!(drops(&mut writer, &log, version).await, [(1, 1)]); } + /// A group stream the subscriber stopped is named in SUBSCRIBE_DROP, with the stop's code + /// where the wire carries one: a stream stopped before its header was read leaves the + /// subscriber no other way to learn which group it carried. + #[kio::test] + async fn a_stopped_group_stream_is_dropped_with_its_stop_code() { + for version in [Version::Lite05, Version::Lite06, Version::Lite07] { + let mut track = track::Producer::new( + Arc::new(broadcast::Info::default()), + "test", + crate::track::Info::timed(), + ); + let subscriber = track.subscribe(None); + let evicted = version.encode_stream_code(&crate::StreamError::Evicted); + let session = SinkSession::new(Log::default()).with_stopped_unis(evicted); + let (mut run, mut writer, log) = lite_run(version, session, subscriber); + write_group(&mut track, 0, 0); + while run.poll_step(&mut writer, &kio::Waiter::noop()).is_ready() {} + + kio::wait(|waiter| writer.poll_flush(waiter)).await.unwrap(); + let writes = log.writes.lock().unwrap().clone(); + let mut buf = writes.as_slice(); + let mut dropped = Vec::new(); + while !buf.is_empty() { + let (msg, size) = lite::SubscribeResponse::decode_slice(buf, version).unwrap(); + buf = &buf[size..]; + if let lite::SubscribeResponse::Drop(drop) = msg { + dropped.push((drop.groups.clone(), drop.error(version))); + } + } + let error = match version.has_drop_code() { + true => crate::StreamError::Evicted, + // An application code, which this side reads as stale. + false => crate::StreamError::Old, + }; + assert_eq!(dropped, [(0..1, error)], "{version:?}"); + } + } + /// A wide upstream DROP is held and forwarded as a range, never one entry per sequence, /// and a wider one later forwards only what is new. #[kio::test] diff --git a/rs/moq-net/src/lite/subscriber.rs b/rs/moq-net/src/lite/subscriber.rs index faf9436b70d..9f20e7fc960 100644 --- a/rs/moq-net/src/lite/subscriber.rs +++ b/rs/moq-net/src/lite/subscriber.rs @@ -1675,11 +1675,10 @@ impl Drop for SetupWait { #[kio::machine(self.state: GroupRecvState)] impl GroupRecv { - fn new(subscriber: Subscriber, mut reader: Reader) -> Self { - // Until its group opens, the stream may wait unread on the peer's SETUP or its - // subscription's TRACK_INFO, so a full window stops it before the stream either - // arrives on. - reader.set_priority(crate::priority::RECV_PARKED); + /// The stream keeps its [unidentified](crate::priority::RECV_UNIDENTIFIED) rank until its + /// header is read, and ranks [parked](crate::priority::RECV_PARKED) only while it waits + /// unread, so a full window stops what holds the most first. + fn new(subscriber: Subscriber, reader: Reader) -> Self { Self { subscriber, reader, @@ -1693,12 +1692,16 @@ impl GroupRecv { let header: (bool, lite::Group) = wait!(Header => { // Before the header, which a wait after it would lose. let Poll::Ready(ietf) = self.subscriber.peer_setup.poll_ietf(waiter) else { - let waits = &self.subscriber.setup_waits; - self.setup_wait.get_or_insert_with(|| SetupWait::new(waits)); + if self.setup_wait.is_none() { + self.setup_wait = Some(SetupWait::new(&self.subscriber.setup_waits)); + self.reader.set_priority(crate::priority::RECV_PARKED); + } // Unread meanwhile, so a reset or an eviction would otherwise go unseen. return self.reader.poll_reset(waiter).map(Err); }; - self.setup_wait = None; + if self.setup_wait.take().is_some() { + self.reader.set_priority(crate::priority::RECV_UNIDENTIFIED); + } self.reader.poll_decode::(waiter).map_ok(|hdr| (ietf, hdr)) })?; @@ -1709,6 +1712,7 @@ impl GroupRecv { match subs.get_mut(&header.1.subscribe) { Some(entry) if entry.copy.is_none() => { self.park_wait = Some(ParkWait::new(&self.subscriber.park_waits)); + self.reader.set_priority(crate::priority::RECV_PARKED); Some(entry.park(&header.1)) } _ => None, @@ -1748,6 +1752,9 @@ impl GroupRecv { } }; let mut open: Option = Some(open?); + if matches!(open, Some(Open::Duplicate(_))) { + self.reader.set_priority(crate::priority::RECV_PARKED); + } // A duplicate of a copy still arriving waits, unread, for that copy to settle. let opened: Opened = wait!(Hold => loop { let mut duplicate = match open.take() { diff --git a/rs/moq-net/src/lite/test_transport.rs b/rs/moq-net/src/lite/test_transport.rs index d0b6ab5a8a7..fd62c787c03 100644 --- a/rs/moq-net/src/lite/test_transport.rs +++ b/rs/moq-net/src/lite/test_transport.rs @@ -238,6 +238,8 @@ pub struct SinkSend { finished: bool, /// A finished stream still parks, like a peer that has not acknowledged the FIN. unacked_fin: bool, + /// The peer stopped the stream (STOP_SENDING) with this code before reading it. + stopped: Option, /// The send group the stream joined. group: Option, } @@ -288,6 +290,7 @@ impl SinkSend { written: 0, finished: false, unacked_fin: false, + stopped: None, group: None, } } @@ -312,6 +315,7 @@ impl SinkSend { written: 0, finished: false, unacked_fin: false, + stopped: None, group: None, } } @@ -395,6 +399,12 @@ impl poll::SendStream for SinkSend { } fn poll_closed(&self, _waiter: &kio::Waiter) -> Poll> { + if let Some(code) = self.stopped { + return Poll::Ready(Err(SinkError { + code, + stream: Some(code), + })); + } match self.finished && !self.unacked_fin { true => Poll::Ready(Ok(())), // Nothing to acknowledge yet, so park like a peer that never answers. @@ -635,6 +645,8 @@ pub struct SinkSession { uni_open_gate: Option>, /// Set by [`Self::with_unacked_fin`]. unacked_fin: bool, + /// Set by [`Self::with_stopped_unis`]. + stopped_unis: Option, /// Set by [`Self::with_groups`]. groups: bool, /// Set by [`Self::with_datagrams`]; zero disables datagrams. @@ -667,6 +679,13 @@ impl SinkSession { self } + /// Have the peer stop every unidirectional stream with `code` (STOP_SENDING), as a + /// subscriber that discarded it before reading its header does. + pub fn with_stopped_unis(mut self, code: u32) -> Self { + self.stopped_unis = Some(code); + self + } + /// Open send groups, as native QUIC does, recording them in the log. pub fn with_groups(mut self) -> Self { self.groups = true; @@ -822,6 +841,7 @@ impl poll::Session for SinkSession { (None, None) => SinkSend::new(self.log.clone()), }; send.unacked_fin = self.unacked_fin; + send.stopped = self.stopped_unis; Poll::Ready(Ok(send.opened(options))) } diff --git a/rs/moq-net/src/priority.rs b/rs/moq-net/src/priority.rs index c8e7e903970..efc68f1c843 100644 --- a/rs/moq-net/src/priority.rs +++ b/rs/moq-net/src/priority.rs @@ -521,11 +521,13 @@ impl PriorityHandle { /// The receive priority of a control stream, kept over every other stream when the /// receive window fills: nothing downstream proceeds without it, and it is small. -/// -/// A stream not yet identified keeps the transport's default of 0, which every group -/// stream sits below. pub const RECV_CONTROL: i64 = i64::MAX; +/// The receive priority of a stream not yet identified, the transport's default, kept until +/// a group stream's header is read: above every group stream, since it holds at most a +/// header's bytes, and stopping it before then hides which group it carried. +pub const RECV_UNIDENTIFIED: i64 = 0; + /// The receive priority of a group stream held unread until a control message says how to /// read it, such as its subscription's TRACK_INFO: below every other stream, so a full /// receive window stops it first and the control message it waits on still gets credit. @@ -622,8 +624,8 @@ mod tests { assert!(recv_group(0, u64::MAX, order) < recv_group(1, 0, order)); assert!(recv_group(0, 0, order) < recv_group(1, u64::MAX, order)); assert!(recv_group(i8::MIN, u64::MAX, order) < recv_group(-1, 0, order)); - assert!(recv_group(i8::MAX, 0, order) < 0); - assert!(recv_group(i8::MAX, u64::MAX, order) < 0); + assert!(recv_group(i8::MAX, 0, order) < RECV_UNIDENTIFIED); + assert!(recv_group(i8::MAX, u64::MAX, order) < RECV_UNIDENTIFIED); assert!(recv_group(i8::MIN, 0, order) > RECV_PARKED); assert!(recv_group(i8::MIN, u64::MAX, order) > RECV_PARKED); } diff --git a/rs/moq-tokio/tests/integration/receive_credit.rs b/rs/moq-tokio/tests/integration/receive_credit.rs index cf6f2c133d1..31eab8ec1ca 100644 --- a/rs/moq-tokio/tests/integration/receive_credit.rs +++ b/rs/moq-tokio/tests/integration/receive_credit.rs @@ -684,6 +684,49 @@ async fn groups_waiting_for_track_info_give_way_first() { } } +/// A GROUP header still arriving when group streams overcommit the window outlasts them: +/// it holds only the header's bytes, and stopping it would hide which group it carried. +/// Once a group stream gives way, the header completes and its group is delivered. +#[tokio::test] +async fn a_header_still_arriving_outlasts_group_streams() { + let setup = reversed("moq-lite-07-wip").await; + let (_track, mut sub) = setup.subscribe("video", 0).await; + + // Subscription 0's group 100, cut after the first byte of its header. + let whole = group_stream(0, 100, 16); + let (head, rest) = whole.split_at(3); + let mut header = setup.conn.open_uni(Default::default()).await.expect("open"); + header.write_all(head).await.expect("header start"); + header.flush().await.expect("flush"); + + // Partial frames, together more than the window: one group stream gives way. + let groups = (1..=3) + .map(|sequence| { + let mut bytes = group_stream(0, sequence, WINDOW / 2); + bytes.truncate(bytes.len() - WINDOW / 2 + WINDOW * 2 / 5); + bytes + }) + .collect(); + setup.raw(false, groups, 1).await; + + header.write_all(rest).await.expect("the header stream was stopped"); + // Held until the group is read: dropping it would reset the stream. + let _finished = header.finish(); + loop { + let mut group = next_group(&mut sub).await; + if group.sequence != 100 { + continue; + } + let frame = kio::clock::timeout(TIMEOUT, group.read_frame()) + .await + .expect("frame timed out") + .expect("the header's group failed") + .expect("group ended"); + assert_eq!(frame.payload.len(), 16); + break; + } +} + /// Control requests that never complete fill the window: one is stopped with its stream, /// and the session carries on. #[tokio::test] From fa575b3c48a2964ea85076935c34e4364b07740f Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 14 Nov 2026 17:10:53 -0800 Subject: [PATCH 3/4] test(moq-net): derive GROUP's size cap from its fields and pin the longest header The cap is now its three fields times the longest varint either form decodes, named varint::MAX_LEN, rather than a bare 27. A test encodes the longest header on every lite version, each field at its form's largest value, reads it back under the cap, and checks lite-07 fills it exactly. Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/coding/varint.rs | 4 ++ rs/moq-net/src/lite/group.rs | 66 +++++++++++++++++++++++++++++++-- 2 files changed, 67 insertions(+), 3 deletions(-) diff --git a/rs/moq-net/src/coding/varint.rs b/rs/moq-net/src/coding/varint.rs index 8a1e1f6fcbc..a89e397db3e 100644 --- a/rs/moq-net/src/coding/varint.rs +++ b/rs/moq-net/src/coding/varint.rs @@ -17,6 +17,10 @@ pub struct BoundsExceeded; /// The largest value the QUIC form can carry: `2^62 - 1`. pub(crate) const MAX_QUIC: u64 = (1 << 62) - 1; +/// The longest varint either form decodes, minimal or not: the leading-ones form's 9 bytes, +/// past QUIC's 8. +pub(crate) const MAX_LEN: usize = 9; + /// How a protocol version lays out a varint on the wire. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub(crate) enum Form { diff --git a/rs/moq-net/src/lite/group.rs b/rs/moq-net/src/lite/group.rs index b9bfb3e5f67..abb78e3a368 100644 --- a/rs/moq-net/src/lite/group.rs +++ b/rs/moq-net/src/lite/group.rs @@ -17,10 +17,16 @@ pub struct Group { pub frame_start: u64, } +impl Group { + /// The varints the newest layout carries: Subscribe ID, Group Sequence and Frame Start. + const FIELDS: usize = 3; +} + impl<'a> Message<'a> for Group { - /// Three varints of at most 9 bytes each, so a header still arriving holds few bytes at - /// its [unidentified](crate::priority::RECV_UNIDENTIFIED) receive rank. - const MAX_SIZE: usize = 3 * 9; + /// Every field at its longest varint, so a header still arriving holds few bytes at its + /// [unidentified](crate::priority::RECV_UNIDENTIFIED) receive rank. Versions before + /// lite-07 carry no more fields, in a shorter varint form. + const MAX_SIZE: usize = Self::FIELDS * crate::coding::varint::MAX_LEN; fn decode_msg(r: &mut Decoder<'a>, version: Version) -> Result { let subscribe = r.varint()?; @@ -95,4 +101,58 @@ mod test { crate::coding::decode_buf(&mut buf.as_slice(), Version::Lite05, |r, v| Group::decode_msg(r, v)).unwrap(); assert_eq!(got.frame_start, 0); } + + /// The size cap admits the longest header every version can carry: each field at its + /// form's largest value, whose minimal encoding is already that form's longest. Lite-07 + /// fills the cap exactly, and one byte more is refused at the length prefix. + #[test] + fn the_longest_header_reads_back_under_the_cap() { + let versions = [ + Version::Lite01, + Version::Lite02, + Version::Lite03, + Version::Lite04, + Version::Lite05, + Version::Lite06, + Version::Lite07, + ]; + for version in versions { + let (max, longest) = match Form::from(version) { + Form::Quic => (crate::coding::varint::MAX_QUIC, 8), + Form::LeadingOnes => (u64::MAX, crate::coding::varint::MAX_LEN), + }; + let fields = if version.has_frame_bounds() { 3 } else { 2 }; + let msg = Group { + subscribe: max, + sequence: max, + frame_start: if version.has_frame_bounds() { max } else { 0 }, + }; + + let mut body = Vec::new(); + msg.encode_msg(&mut Encoder::new(&mut body, version.into()), version) + .unwrap(); + assert_eq!(body.len(), fields * longest, "{version:?}"); + assert!(body.len() <= ::MAX_SIZE, "{version:?}"); + + let mut wire = Vec::new(); + msg.encode(&mut Encoder::new(&mut wire, version.into()), version) + .unwrap(); + let (got, used) = Group::decode_slice(&wire, version).unwrap(); + assert_eq!(used, wire.len(), "{version:?}"); + assert_eq!( + (got.subscribe, got.sequence, got.frame_start), + (msg.subscribe, msg.sequence, msg.frame_start), + "{version:?}" + ); + } + + assert_eq!(::MAX_SIZE, 27); + let over = ::MAX_SIZE + 1; + let mut wire = vec![over as u8]; + wire.resize(1 + over, 0); + assert!(matches!( + Group::decode_slice(&wire, Version::Lite07), + Err(DecodeError::MessageTooLarge { size: 28, max: 27 }) + )); + } } From 3329c3c839b7bba942af006a64eb824eb51e1f5b Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 14 Nov 2026 17:19:49 -0800 Subject: [PATCH 4/4] docs(draft): a drop for a stopped duplicate leaves a completed group whole Co-Authored-By: Claude Opus 5.5 --- drafts/draft-lcurley-moq-lite.md | 1 + 1 file changed, 1 insertion(+) diff --git a/drafts/draft-lcurley-moq-lite.md b/drafts/draft-lcurley-moq-lite.md index af2e8d7ddec..72ffb076a57 100644 --- a/drafts/draft-lcurley-moq-lite.md +++ b/drafts/draft-lcurley-moq-lite.md @@ -2097,6 +2097,7 @@ Either way the Group Stream accounts for the sequence, and the next SUBSCRIBE_UP For every sequence in the subscription's range, the publisher MUST send a Group Stream or name it in SUBSCRIBE_SKIP or SUBSCRIBE_DROP. This includes streams reset before their headers were delivered, and streams the subscriber stopped (STOP_SENDING), which it may have discarded unread; such a drop carries the STOP_SENDING's Error Code. +A drop naming a stopped duplicate of a Group that another Group Stream already completed changes nothing for that Group: its readers keep it whole. A reliably delivered reset retaining the Group Stream header accounts for that group instead, unless it is YIELDED or answers a STOP_SENDING. A [paused](#yield) Group is accounted for only once a continuation completes it, a reset of one other than YIELDED ends it, or a SUBSCRIBE_DROP names it. The publisher SHOULD name a sequence as soon as it gives it up, without waiting for SUBSCRIBE_FINISH.