From fe3301813c3af515f32e93fdab9e6e3bb6d43562 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 7 Nov 2026 16:06:20 -0800 Subject: [PATCH 1/2] chore(quest): claim quest/m2/unbounded-groups/fetch-run-unpaced.md Quest-Claim: 268ff44e8cad95e0 From b1f3b352561bf1393a393704448702e45c9a7303 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 7 Nov 2026 16:35:13 -0800 Subject: [PATCH 2/2] fix(net): a moq-transport FETCH run reads at its stream's speed Remove the group-boundary pacing #8117 added: once a reader lost a group to eviction, the FETCH stream was held unread until a reader took the group before. Pacing between groups is head-of-line blocking, so a slow reader now falls back on Evicted and refill-once or a refresh, as on lite-07. Co-Authored-By: Claude Opus 5.5 --- quest/m2/unbounded-groups/README.md | 1 - .../m2/unbounded-groups/fetch-run-unpaced.md | 36 ---- rs/moq-net/src/coding/reader.rs | 7 +- rs/moq-net/src/ietf/subscriber.rs | 170 ++---------------- rs/moq-net/src/lite/test_transport.rs | 14 -- rs/moq-net/src/model/track/fill.rs | 11 -- 6 files changed, 19 insertions(+), 220 deletions(-) delete mode 100644 quest/m2/unbounded-groups/fetch-run-unpaced.md diff --git a/quest/m2/unbounded-groups/README.md b/quest/m2/unbounded-groups/README.md index aaf669e83fb..1157a11f5b9 100644 --- a/quest/m2/unbounded-groups/README.md +++ b/quest/m2/unbounded-groups/README.md @@ -183,4 +183,3 @@ the model layer (maintainer, 2026-10-30). - [Byte holes](/quest/m2/unbounded-groups/byte-holes.md) - segments inside a frame shed like front frames and flights start at `(frame, byte)` on the current lite wip; the frame cap goes - [JS byte holes](/quest/m2/unbounded-groups/js-byte-holes.md) - `@moq/net` mirrors the byte-offset wire and continues a frame cut off mid-way - [Compressed frames have no size cap and inflate as a bounded stream](/quest/m2/unbounded-groups/compressed-stream.md) - A compressed frame of any size publishes and is received in Rust and `@moq/net`, like a plain one -- [Remove FETCH-run pacing](/quest/m2/unbounded-groups/fetch-run-unpaced.md) - a moq-transport FETCH run is no longer held at group boundaries for a slow reader, matching lite-07 diff --git a/quest/m2/unbounded-groups/fetch-run-unpaced.md b/quest/m2/unbounded-groups/fetch-run-unpaced.md deleted file mode 100644 index 76effd60446..00000000000 --- a/quest/m2/unbounded-groups/fetch-run-unpaced.md +++ /dev/null @@ -1,36 +0,0 @@ -# [S] Remove FETCH-run pacing - -## Goal - -A moq-transport FETCH run reads its stream at the speed it arrives, as a -lite-07 history run does: no wire request is held at group boundaries for a -slow reader. A reader that falls off the cache tail gets `Evicted`, then -refill-once or a refresh, on both wires. - -## Plan - -Decided 2026-11-07 (maintainer, /quest-unblock): ✅ no flow control between -groups on either wire (rejected: (a) holding lite-07 group streams unread and -admitting them in the fill's order; (b) narrowing the subscription's ranges -to the next owed group; (c) fetching paced runs a group at a time). Pacing -between groups is head-of-line blocking: under backpressure the head is -evicted and cancels everything queued behind it. SUBSCRIBE is best-effort; per-subscription flow control was considered and not judged worth it. -This deletes the planned lite-07 pacing quest and undoes what -[moq-dev/moq#8117](https://github.com/moq-dev/moq/pull/8117) added for -moq-transport FETCH. - -- Remove `track::Fill::poll_run_paced` (`rs/moq-net/src/model/track/fill.rs`) - and the FETCH stream's `poll_pace` hold that calls it - (`rs/moq-net/src/ietf/subscriber.rs`), with #8117's tests and any reader or - test-transport hooks only they use. -- Keep `TrackState::evictions`: `track/miss.rs` reads it too. -- Out of scope: [moq-dev/moq#8017](https://github.com/moq-dev/moq/pull/8017)'s - pacing of a batch fill's local handler by its fastest reader, which holds - no wire stream. -- Update the epic README's prose that describes FETCH-run pacing, if any. - -Public API: none. Wire: none. - -## Related - -- [Unbounded groups](/quest/m2/unbounded-groups/README.md) - the epic whose eviction and refill rules a slow reader now falls back on diff --git a/rs/moq-net/src/coding/reader.rs b/rs/moq-net/src/coding/reader.rs index 6c3485637ff..c4e343f17df 100644 --- a/rs/moq-net/src/coding/reader.rs +++ b/rs/moq-net/src/coding/reader.rs @@ -474,13 +474,12 @@ impl Reader { self.poll_pace(waiter, group.poll_admit(waiter, header, self.stream.window())) } - /// Wait out `paced`, a pace gate on what this stream writes next, if the session has room - /// for the credit this stream holds while paused (see [`Pause`]); otherwise read on, - /// unpaced. + /// Wait out `paced`, the group's pace gate, if the session has room for the credit this + /// stream holds while paused (see [`Pause`]); otherwise read on, and the group sheds. /// /// A paused stream is not read, so it is watched for a reset instead, which fails the /// wait rather than leaving it to the group's reader to notice. - pub(crate) fn poll_pace(&mut self, waiter: &kio::Waiter, paced: Poll<()>) -> Poll> + fn poll_pace(&mut self, waiter: &kio::Waiter, paced: Poll<()>) -> Poll> where S: Pause, { diff --git a/rs/moq-net/src/ietf/subscriber.rs b/rs/moq-net/src/ietf/subscriber.rs index 3b8eb9ccf88..f652df74a23 100644 --- a/rs/moq-net/src/ietf/subscriber.rs +++ b/rs/moq-net/src/ietf/subscriber.rs @@ -7573,12 +7573,6 @@ impl RecvGroupFetch { /// properties, never past FETCH_OK's End Location. A group's objects end where the next /// group's begin, since a FETCH carries every object of its range in order. Before /// draft-22 the stream must also reach an object bound inside the last group. -/// -/// Once a reader of the track lost a group to eviction, each group after the first waits, -/// its stream unread, until a reader picked up the one before, so a run wider than the -/// cache never evicts its own groups ahead of its readers (see [`track::Fill::poll_run_paced`]). -/// The pause holds receive credit, so it is taken only while the session's paused streams -/// leave room for it, as within a group. struct GroupFetchObjects { version: Version, /// The next Object ID expected in the current group. @@ -7587,9 +7581,6 @@ struct GroupFetchObjects { first: bool, /// The object whose payload is being read: its group, its Object ID, and where it goes. payload: Option<(u64, u64, FetchPayloadRead)>, - /// The first object of the next group and its sequence, read while the run waits for its - /// readers to pick up the group before. - paced: Option<(FetchedObject, u64)>, } /// Where a fetch object's payload goes. @@ -7611,7 +7602,6 @@ impl GroupFetchObjects { prior_group: None, first: true, payload: None, - paced: None, } } @@ -7640,38 +7630,22 @@ impl GroupFetchObjects { } } - let (object, sequence) = match self.paced.take() { - Some(paced) => paced, - None => { - let Some(object) = ready!(poll_fetch_object(stream, self.first, waiter))? else { - break; - }; - self.first = false; - if !object.subgroup_ok && !object.datagram { - tracing::warn!("subgroup ID is not supported, dropping group fetch"); - return Poll::Ready(Err(Error::Unsupported)); - } - - let group = resolve_fetch_group(self.prior_group, object.group)?; - if let Some(group) = group { - self.prior_group = Some(group); - } - // The first object always names its group, so a later one leaving it out stays in it. - let sequence = group.or(writer.sequence()).ok_or(Error::ProtocolViolation)?; - (object, sequence) - } + let Some(object) = ready!(poll_fetch_object(stream, self.first, waiter))? else { + break; }; + self.first = false; + if !object.subgroup_ok && !object.datagram { + tracing::warn!("subgroup ID is not supported, dropping group fetch"); + return Poll::Ready(Err(Error::Unsupported)); + } + + let group = resolve_fetch_group(self.prior_group, object.group)?; + if let Some(group) = group { + self.prior_group = Some(group); + } + // The first object always names its group, so a later one leaving it out stays in it. + let sequence = group.or(writer.sequence()).ok_or(Error::ProtocolViolation)?; if writer.sequence() != Some(sequence) { - // The group before is whole, so its readers see it end while the stream waits, - // unread, for them to pick it up: flow control then holds the publisher back. - writer.finish()?; - match stream.poll_pace(waiter, writer.fetch.fill.poll_run_paced(waiter)) { - Poll::Ready(res) => res?, - Poll::Pending => { - self.paced = Some((object, sequence)); - return Poll::Pending; - } - } self.next = writer.open(sequence, object.datagram)?; } else if object.datagram { // A datagram group has one object, so it never shares one with a stream. @@ -17186,116 +17160,6 @@ mod stitch_tests { assert!(matches!(receive.await, Err(Error::Evicted))); } - /// What a slow reader of a FETCH run ten times wider than the cache gets, taking a group - /// each time the run's stream is polled, once a reader of the track lost a group to - /// eviction or not. An ascending reader reads in sequence, a descending one as groups - /// arrive. - async fn read_a_fetch_run_slowly(outran: bool, order: track::Order) -> Vec { - const GROUPS: u64 = 40; - const SIZE: usize = 10_000; - let payload = vec![0u8; SIZE]; - let mut objects = Vec::new(); - // The first Group ID is 0, and each later one, a delta, 0 again: the next group. - for _ in 0..GROUPS { - objects.extend(group_fetch_objects(0, 0, &[&payload[..]])); - } - // The session grants a stream credit of one group, so a paused stream holds one. - let window = crate::transport::ReceiveWindow::new(GROUPS * SIZE as u64, SIZE as u64); - let session = ScriptedSession::per_stream_eof(vec![objects]).with_receive_window(window); - let mut run = GroupFetchRun::with_session(VERSION, session).await; - let pool = crate::cache::Pool::new(crate::cache::Config::default().with_capacity(4 * SIZE as u64)); - run.track = track::Producer::new( - std::sync::Arc::new(crate::broadcast::Info { - pool, - ..Default::default() - }), - "video", - track::Info::default().with_timescale(None).with_max_age(None), - ); - let dynamic = run.track.requests(); - run.track.start_at(GROUPS).unwrap(); - let mut live = run.track.create_group(group::Info { sequence: GROUPS }).unwrap(); - live.write_frame(None, &payload[..]).unwrap(); - let waiter = kio::Waiter::noop(); - if outran { - // A reader judges the live edge cached and loses it before taking it. - let mut lost = run - .track - .subscribe( - track::Subscription::default() - .with_ranges([track::Range::groups(0..GROUPS + 1)]) - .with_delay(track::Delay::default().with_max(None)), - ) - .ordered(); - assert!(lost.poll_next_group(&waiter).is_pending()); - run.track.evict(GROUPS); - } - - let subscriber = run.track.subscribe( - track::Subscription::default() - .with_ranges([track::Range::groups(0..GROUPS)]) - .with_order(order) - .with_delay(track::Delay::default().with_max(None)), - ); - type Read = Box Poll>>>; - let mut reader: Read = match order { - track::Order::Ascending => { - let mut ordered = subscriber.ordered(); - Box::new(move |waiter| ordered.poll_next_group(waiter)) - } - track::Order::Descending => { - let mut subscriber = subscriber; - Box::new(move |waiter| subscriber.poll_recv_group(waiter)) - } - }; - assert!(reader(&waiter).is_pending(), "group 0 is a miss"); - let fill = dynamic.requested_fill().await.expect("the reader asked for the run"); - assert_eq!((fill.start().group, fill.end()), (0, GROUPS)); - let slot = kio::Producer::new(GroupFetch::Ready(RangeFetch { - fill: std::sync::Arc::new(fill), - timescale: None, - first: 0, - last: GROUPS - 1, - start: 0, - end: None, - })); - let mut receiving = run.subscriber.clone(); - let mut receive = std::pin::pin!(receiving.recv_group_fetch(&mut run.stream, slot)); - let (mut read, mut received) = (Vec::new(), false); - for _ in 0..4 * GROUPS { - if !received && let Poll::Ready(res) = futures::poll!(&mut receive) { - res.expect("the run is received"); - received = true; - } - match reader(&waiter) { - Poll::Ready(Ok(Some(group))) => read.push(group.sequence), - // What it lost is given up, which ends its range. - Poll::Ready(Ok(None)) => break, - Poll::Ready(Err(err)) => panic!("the reader failed: {err}"), - Poll::Pending if received => break, - Poll::Pending => {} - } - } - read - } - - /// Once a reader of the track lost a group to eviction, a FETCH run writes its next group - /// only once a reader picked up the one before, leaving the stream unread meanwhile, so a - /// slow reader of a run far wider than the cache gets all of it. Until then the run moves - /// at the stream's speed and evicts what the reader has yet to take. - #[kio::test] - async fn a_fetch_run_waits_for_its_reader_once_one_lost_a_group() { - for order in [track::Order::Ascending, track::Order::Descending] { - let paced = read_a_fetch_run_slowly(true, order).await; - assert_eq!(paced, (0..40).collect::>(), "{order:?}"); - let unpaced = read_a_fetch_run_slowly(false, order).await; - assert!( - unpaced.len() < 40, - "the unpaced run outran its {order:?} reader: {unpaced:?}" - ); - } - } - #[kio::test] async fn internal_group_fetch_setup_cancellation_is_cancel() { let mut run = GroupFetchRun::new(VERSION, Vec::new()).await; @@ -17341,9 +17205,7 @@ mod stitch_tests { tasks.0.clone(), Default::default(), ); - // Through the subscriber's transport, so it pauses as a session's stream does where - // the session grants a receive window. - let stream = Stream::open(&subscriber.session, version).await.unwrap(); + let (_, recv) = session.open_bi(Default::default()).await.unwrap(); let track = track::Producer::new( std::sync::Arc::new(crate::broadcast::Info::default()), "video", @@ -17352,7 +17214,7 @@ mod stitch_tests { Self { subscriber, - stream: stream.reader, + stream: Reader::new(crate::transport::boxed::RecvStream::new(recv), version), track, _tasks: tasks, } diff --git a/rs/moq-net/src/lite/test_transport.rs b/rs/moq-net/src/lite/test_transport.rs index 8f9adc42d0a..3480c8db5ed 100644 --- a/rs/moq-net/src/lite/test_transport.rs +++ b/rs/moq-net/src/lite/test_transport.rs @@ -974,8 +974,6 @@ pub struct ScriptedSession { groups: bool, /// Set by [`Self::with_send_window`]. send_window: Option, - /// Set by [`Self::with_receive_window`]. - receive_window: Option, } impl ScriptedSession { @@ -1016,17 +1014,9 @@ impl ScriptedSession { unacked_unis: Default::default(), groups: false, send_window: None, - receive_window: None, } } - /// Report `window` as the receive windows in force, so a stream the session stops reading - /// holds credit. - pub fn with_receive_window(mut self, window: crate::transport::ReceiveWindow) -> Self { - self.receive_window = Some(window); - self - } - /// Let each opened bidi stream send only its first `bytes`, then park its writes for good, /// like a peer that never grants more send credit. pub fn with_send_window(mut self, bytes: usize) -> Self { @@ -1157,10 +1147,6 @@ impl poll::Session for ScriptedSession { type RecvStream = ScriptedRecv; type Error = SinkError; - fn receive_window(&self) -> Option { - self.receive_window - } - fn poll_accept_uni(&self, waiter: &kio::Waiter) -> Poll> { let Some(script) = self.incoming_unis.lock().unwrap().pop_front() else { return self.log.poll_closed(waiter).map(Err); diff --git a/rs/moq-net/src/model/track/fill.rs b/rs/moq-net/src/model/track/fill.rs index e06dfccb910..56aba61e3ce 100644 --- a/rs/moq-net/src/model/track/fill.rs +++ b/rs/moq-net/src/model/track/fill.rs @@ -1060,17 +1060,6 @@ impl Fill { .map(drop) } - /// Poll until a run's next group may be written: at once until a reader of the track lost - /// a group to eviction, then as [`Self::poll_paced`]. An unpaced run moves at its source's - /// speed, which is fine while every reader keeps up. - #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] - pub(crate) fn poll_run_paced(&self, waiter: &kio::Waiter) -> Poll<()> { - if self.inner.state.read().evictions == 0 { - return Poll::Ready(()); - } - self.poll_paced(waiter) - } - /// Refuse every group still owed with `err`, which says nothing about whether the source /// has them, so nothing is recorded dropped. #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))]