From af966a3825bd9c048778b1c064fbf81a6b981971 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 9 Nov 2026 00:07:33 -0800 Subject: [PATCH 1/7] chore(quest): claim quest/m0/nightly/moxygen-conformance.md Quest-Claim: 1ecdffaad3b3e236 From 3bba509c21034fccab48007e0b4e5aeaebe31900 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 9 Nov 2026 00:51:04 -0800 Subject: [PATCH 2/7] fix(net): relay egress waits for a group's relay state before describing it A relay ingest publishes a group before it reads the header that describes it: a lite-07 edge creates the group on its stream header and decodes Group State afterwards, and moq-transport ingest sets it just after create_group. An egress that opened in between described a plain group, dropping FIRST_OBJECT and the extensions flag and skipping by frame index instead of Object ID. That failed Moxygen's cluster cells. group::Consumer::poll_wire is ready once the ingest has settled that state: the first frame, the end object, or the close. The moq-transport group header and the lite-07 Group State both wait on it. Co-Authored-By: Claude Opus 5.5 --- quest/m0/nightly/README.md | 1 - quest/m0/nightly/moxygen-conformance.md | 25 ------ rs/moq-net/src/ietf/publisher.rs | 108 ++++++++++++++++++++---- rs/moq-net/src/lite/ietf.rs | 44 +++++----- rs/moq-net/src/lite/publisher.rs | 25 +++--- rs/moq-net/src/model/group.rs | 30 ++++++- 6 files changed, 157 insertions(+), 76 deletions(-) delete mode 100644 quest/m0/nightly/moxygen-conformance.md diff --git a/quest/m0/nightly/README.md b/quest/m0/nightly/README.md index 3a82a9d0589..b31d28be0ca 100644 --- a/quest/m0/nightly/README.md +++ b/quest/m0/nightly/README.md @@ -54,4 +54,3 @@ near the paired threshold (re-check if one repeats), a one-off - [The qmux startup benchmark's fake peer sends transport parameters](/quest/m0/nightly/qmux-bench-peer.md) - Audio quality's WebSocket startup step stops timing out - [The moq-net session bench completes moq-transport-22 at 16 broadcasts](/quest/m0/nightly/session-bench-handshake.md) - the bench workload stops panicking on a handshake timeout - [Bisect the moq-audio bus and moq-mux parameter_sets regressions](/quest/m0/nightly/bench-regressions.md) - two real benchmark regressions are explained and fixed or accepted -- [Moxygen conformance cells pass again](/quest/m0/nightly/moxygen-conformance.md) - the first-object signal and integer extensions survive, or moxygen's divergence is skipped with an upstream link diff --git a/quest/m0/nightly/moxygen-conformance.md b/quest/m0/nightly/moxygen-conformance.md deleted file mode 100644 index e7ea1aa9536..00000000000 --- a/quest/m0/nightly/moxygen-conformance.md +++ /dev/null @@ -1,25 +0,0 @@ -# [M] Moxygen conformance cells pass again - -## Goal - -Nightly's `ietf-conformance / moxygen` job passes. Today its cells fail with -`Missing Begins With First Object Signal for group=0 subgroup=0`, and with -`Extension Error=2 ... Expected size: 1 Actual size: 0` in the Extensions 1/2 -and Object/Group Counts 3/4 cells. - -## Plan - -Planned 2026-11-09 (maintainer, /quest-complete from the triage of Nightly -runs [42377867523](https://github.com/moq-dev/moq/actions/runs/42377867523) -and [42487375545](https://github.com/moq-dev/moq/actions/runs/42487375545); -also red on 2026-11-06). ✅ Plan it (rejected: drop the lane), since it -keeps Nightly red, though moq-transport compatibility is low priority by the -repository's rules. - -Find which side is wrong before changing anything: our relay dropping the -subgroup's first-object flag and an integer extension's value, or moxygen's -expectations diverging from the draft we implement. Fix ours when it is -ours. When moxygen is wrong, record it upstream and skip just those cells -with a link, rather than adding cost to match it. - -Public API: none expected. Wire: moq-transport only, if ours is wrong. diff --git a/rs/moq-net/src/ietf/publisher.rs b/rs/moq-net/src/ietf/publisher.rs index 343b588eeba..d9d59fa7c0b 100644 --- a/rs/moq-net/src/ietf/publisher.rs +++ b/rs/moq-net/src/ietf/publisher.rs @@ -6705,7 +6705,6 @@ impl TrackServe { fn serve_group(&mut self, group: group::Consumer, slice: GroupSlice) -> GroupServe { let group = if self.compression { group.compressed() } else { group }; let sequence = group.sequence; - let wire = group.wire(); let msg = ietf::GroupHeader { track_alias: self.request_id.0, group_id: sequence, @@ -6715,17 +6714,10 @@ impl TrackServe { // model ranks higher-first and this wire field lower-first. publisher_priority: super::priority::to_wire(self.track.info().priority), // Carry per-object timestamps as extension headers (the Timestamp - // Object Property) only when TIMESCALE was declared. + // Object Property) only when TIMESCALE was declared. The relay state adds + // to these once it settles (see `GroupServe::poll_open`). flags: ietf::GroupFlags { - has_extensions: self.compression - || self.timescale.is_some() - || wire.as_ref().is_some_and(|wire| wire.extensions), - first_object: wire - .as_ref() - .map_or(slice.skip == 0, |wire| wire.first_object && slice.skip <= wire.first_id), - // A stream capped by the range stops before the group may end, so its - // FIN cannot claim END_OF_GROUP. - has_end: slice.until.is_none() && wire.as_ref().is_none_or(|wire| wire.has_end), + has_extensions: self.compression || self.timescale.is_some(), ..Default::default() }, }; @@ -7534,6 +7526,8 @@ struct GroupServe { version: Version, prior_object: Option, slice: GroupSlice, + /// Whether `msg` and the read slice reflect the group's settled relay state. + described: bool, bounds: Option>, /// Set when a narrowing gives this stream up. retired: Arc, @@ -7602,17 +7596,11 @@ impl GroupServe { session: Transport, msg: ietf::GroupHeader, rank: Rank>, - mut group: group::Consumer, + group: group::Consumer, timescale: Option, version: Version, slice: GroupSlice, ) -> Self { - if group.wire().is_none() { - // Only the end: a start would clamp past a prefix the group never held, - // which `skip_to` leaves to fail as `Lagged`. - group.skip_to(slice.skip); - group = group.with_end(slice.until); - } Self { session, opened: Default::default(), @@ -7624,6 +7612,7 @@ impl GroupServe { version, prior_object: None, slice, + described: false, bounds: None, retired: Default::default(), ended: false, @@ -7682,6 +7671,25 @@ impl GroupServe { self } + /// Fill in the header flags and the read slice from the group's relay state. + fn describe(&mut self, wire: Option) { + let flags = &mut self.msg.flags; + flags.has_extensions |= wire.as_ref().is_some_and(|wire| wire.extensions); + flags.first_object = wire.as_ref().map_or(self.slice.skip == 0, |wire| { + wire.first_object && self.slice.skip <= wire.first_id + }); + // A stream capped by the range stops before the group may end, so its FIN cannot + // claim END_OF_GROUP. + flags.has_end = self.slice.until.is_none() && wire.as_ref().is_none_or(|wire| wire.has_end); + if wire.is_none() { + // Only the end: a start would clamp past a prefix the group never held, which + // `skip_to` leaves to fail as `Lagged`. + self.group.skip_to(self.slice.skip); + self.group.end_at(self.slice.until); + } + self.described = true; + } + /// Wait for stream credit, then write the group header, leaving the machine serving. /// Gives up once the group can no longer be sent, so a parked group never spends the /// credit it was waiting for on a reset. @@ -7699,6 +7707,12 @@ impl GroupServe { } // The current rank, so a move while parked applies to the stream as it opens. let _ = self.rank.poll_moved(waiter); + // Before the stream, whose header describes it: a relayed group is visible before + // its own header has been read. + if !self.described { + let wire = ready!(self.group.poll_wire(waiter)); + self.describe(wire); + } let stream = match ready!(self.session.poll_open_group( &mut self.open, waiter, @@ -8634,6 +8648,64 @@ mod group_priority_test { .await; } + /// A relay ingest publishes a group before it reads the header that describes it, so the + /// egress header waits for that state rather than describing a plain group. + #[kio::test] + async fn a_group_header_waits_for_its_relay_state() { + let log = crate::lite::test_transport::Log::default(); + let session = SinkSession::new(log.clone()); + let track = track::Producer::new( + std::sync::Arc::new(crate::broadcast::Info::default()), + "test", + track::Info::default(), + ); + let mut serve = TrackServe::new( + crate::driver::Transport::new(session.clone()), + track.subscribe(None), + RequestId(0), + Version::Draft18, + ServeRange::default(), + None, + ); + + let group = track.create_group(group::Info { sequence: 0 }).unwrap(); + assert!(futures::poll!(kio::wait(|waiter| serve.poll(waiter))).is_pending()); + group + .set_wire(group::Wire { + sparse: false, + first_object: false, + first_id: 3, + extensions: true, + has_end: true, + fetchable: true, + last: None, + }) + .unwrap(); + let mut frame = group + .create_object(frame::Header { + info: frame::Info { + size: 1, + timestamp: None, + }, + fields: Some(std::sync::Arc::new(crate::model::object::Fields { + id: 3, + properties: Default::default(), + })), + inflated: None, + }) + .unwrap(); + frame.write(b"x".as_slice()).unwrap(); + frame.finish().unwrap().finish().unwrap(); + track.finish().unwrap(); + kio::wait(|waiter| serve.poll(waiter)).await.unwrap(); + + let mut buf = bytes::Bytes::from(log.writes.lock().unwrap().clone()); + let header = crate::coding::decode_buf(&mut buf, Version::Draft18, |r, v| ietf::GroupHeader::decode(r, v)) + .expect("a group header"); + assert!(header.flags.has_extensions); + assert!(!header.flags.first_object); + } + /// Serve one group of a track with `info` and decode the subgroup header it opens with. async fn serve_group_header(info: track::Info) -> ietf::GroupHeader { let log = crate::lite::test_transport::Log::default(); diff --git a/rs/moq-net/src/lite/ietf.rs b/rs/moq-net/src/lite/ietf.rs index 6d18d27a276..d9583c6558d 100644 --- a/rs/moq-net/src/lite/ietf.rs +++ b/rs/moq-net/src/lite/ietf.rs @@ -214,6 +214,8 @@ pub(crate) fn decode_end(body: &[u8], framing: super::Framing) -> Result, /// The stream stops at a frame cap, so its Group State promised no END_OF_GROUP. @@ -224,29 +226,33 @@ pub(crate) struct Records { #[cfg(feature = "async")] impl Records { - /// Buffer the Group State for a stream serving `group` from its current index, and - /// return the records its frames need. - /// - /// `capped` when the stream stops before the group may end. Writes nothing and returns - /// `None` unless the session negotiated the extension. - pub fn start( + /// The records a group stream needs, or `None` unless the session negotiated the + /// extension. `capped` when the stream stops before the group may end. + pub fn new(ietf: bool, capped: bool, timescale: Option) -> Option { + ietf.then_some(Self { + stated: false, + prior: None, + capped, + timescale, + }) + } + + /// Buffer the Group State for a stream serving `group` from its current index, once the + /// ingest has settled its relay state. Call before any record. + pub fn poll_state( + &mut self, writer: &mut crate::coding::Writer, - ietf: bool, group: &group::Consumer, - capped: bool, - timescale: Option, - ) -> Result, Error> { - if !ietf { - return Ok(None); + waiter: &kio::Waiter, + ) -> std::task::Poll> { + if self.stated { + return std::task::Poll::Ready(Ok(())); } - let wire = group.wire(); + let wire = std::task::ready!(group.poll_wire(waiter)); let whole = group.index() <= group.first_frame(); - writer.buffer_varint(encode_state(wire.as_ref(), whole, capped))?; - Ok(Some(Self { - prior: None, - capped, - timescale, - })) + writer.buffer_varint(encode_state(wire.as_ref(), whole, self.capped))?; + self.stated = true; + std::task::Poll::Ready(Ok(())) } /// Buffer the record for the frame at `index`, ahead of its timestamp and size. diff --git a/rs/moq-net/src/lite/publisher.rs b/rs/moq-net/src/lite/publisher.rs index ddb380a6fee..535c54cb6e1 100644 --- a/rs/moq-net/src/lite/publisher.rs +++ b/rs/moq-net/src/lite/publisher.rs @@ -3224,7 +3224,7 @@ impl Request for FetchServe { } let capped = msg.end_frame.is_some(); let timescale = stamp.map(|stamp| stamp.timescale); - let records = lite::ietf::Records::start(writer, ietf, &group, capped, timescale)?; + let records = lite::ietf::Records::new(ietf, capped, timescale); *self = Self::Serve { group, @@ -3248,6 +3248,9 @@ impl Request for FetchServe { records, } => loop { ready!(writer.poll_flush(waiter))?; + if let Some(records) = records { + ready!(records.poll_state(writer, group, waiter))?; + } if let Some(pending) = chunk { ready!(writer.poll_write(waiter, pending))?; if !bytes::Buf::has_remaining(pending) { @@ -6127,17 +6130,8 @@ impl GroupServe { frame_start: self.frame_start, }; let header = writer.buffer(&lite::DataType::Group).and_then(|()| writer.buffer(&msg)); - let records = header.and_then(|()| { - lite::ietf::Records::start( - &mut writer, - self.ctx.ietf, - &self.group, - self.capped, - self.ctx.stamp.map(|stamp| stamp.timescale), - ) - }); - let records = match records { - Ok(records) => records, + let records = match header { + Ok(()) => lite::ietf::Records::new(self.ctx.ietf, self.capped, self.ctx.stamp.map(|stamp| stamp.timescale)), Err(err) => { // The header wrote nothing, so the group-stream reset has nothing to pin // it to this subscription. The run loop reads the slot and resets the @@ -6228,6 +6222,13 @@ impl GroupServe { return Poll::Pending; } } + if let Some(records) = records { + match records.poll_state(writer, &self.group, waiter) { + Poll::Ready(Ok(())) => {} + Poll::Ready(Err(err)) => break 'serve Err(err), + Poll::Pending => return Poll::Pending, + } + } if let Some(pending) = chunk { match writer.poll_write(waiter, pending) { Poll::Ready(Ok(_)) => { diff --git a/rs/moq-net/src/model/group.rs b/rs/moq-net/src/model/group.rs index bfdb76d219d..6aea1288977 100644 --- a/rs/moq-net/src/model/group.rs +++ b/rs/moq-net/src/model/group.rs @@ -1234,6 +1234,20 @@ impl GroupState { } } + /// The relay state once the ingest has settled it, which it does before the first frame, + /// the end object, or the close: a group is visible before its header is read. + #[cfg(feature = "async")] + fn poll_wire(&self) -> Poll>> { + let settled = self.next_index > self.offset + || self.partial.is_some() + || self.relay.as_ref().is_some_and(|relay| relay.end_object.is_some()) + || !matches!(self.outcome, Outcome::Open); + match settled { + true => Poll::Ready(Ok(self.wire().cloned())), + false => Poll::Pending, + } + } + /// The group's outcome once final: `Ok` once finished, which a later abort only frees /// the cache of, or the abort error. fn poll_outcome(&self) -> Poll> { @@ -3679,6 +3693,15 @@ impl Consumer { self.cursor.state.read().wire().cloned() } + /// The relay state an egress header describes, once the ingest has set it. + #[cfg(feature = "async")] + pub(crate) fn poll_wire(&self, waiter: &kio::Waiter) -> Poll> { + // A dropped producer settled whatever it was going to. + self.cursor + .poll(waiter, |state| state.poll_wire()) + .map(|res| res.unwrap_or_else(|_| self.wire())) + } + /// Read a compressed group's stored DEFLATE slices instead of plain frames, with each /// frame's inflated size beside it ([`frame::Object::inflated`], /// [`frame::Consumer::inflated`]), for egress that carries compression. A no-op on a @@ -4009,9 +4032,14 @@ impl Consumer { /// Cap reads before frame `end`, or remove the cap with `None`, without moving the /// start, which [`Self::with_range`] would clamp up to the first available frame. pub(crate) fn with_end(mut self, end: impl Into>) -> Self { + self.end_at(end); + self + } + + /// [`Self::with_end`] in place. + pub(crate) fn end_at(&mut self, end: impl Into>) { Idle::disarm(&mut self.idle); self.cursor.end = end.into().map(|end| usize::try_from(end).unwrap_or(usize::MAX)); - self } /// Advance the read cursor to `index`, skipping every frame below it. From 2b4b6305760549a1ef31aed0ab4069042600b71b Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 9 Nov 2026 01:03:08 -0800 Subject: [PATCH 3/7] fix(net): describe a moq-transport group on its own stream, not in the opening slot Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/ietf/publisher.rs | 86 ++++++++++++++++++++++---------- 1 file changed, 59 insertions(+), 27 deletions(-) diff --git a/rs/moq-net/src/ietf/publisher.rs b/rs/moq-net/src/ietf/publisher.rs index d9d59fa7c0b..dc6195b23ec 100644 --- a/rs/moq-net/src/ietf/publisher.rs +++ b/rs/moq-net/src/ietf/publisher.rs @@ -6715,7 +6715,7 @@ impl TrackServe { publisher_priority: super::priority::to_wire(self.track.info().priority), // Carry per-object timestamps as extension headers (the Timestamp // Object Property) only when TIMESCALE was declared. The relay state adds - // to these once it settles (see `GroupServe::poll_open`). + // to these once it settles (see `GroupState::Describe`). flags: ietf::GroupFlags { has_extensions: self.compression || self.timescale.is_some(), ..Default::default() @@ -7526,8 +7526,6 @@ struct GroupServe { version: Version, prior_object: Option, slice: GroupSlice, - /// Whether `msg` and the read slice reflect the group's settled relay state. - described: bool, bounds: Option>, /// Set when a narrowing gives this stream up. retired: Arc, @@ -7551,6 +7549,11 @@ struct GroupServe { enum GroupState { /// Waiting for stream credit on this machine's own session handle. Open, + /// The stream is open, and its header waits for the group's relay state, which a relayed + /// group settles after it becomes visible. + Describe { + writer: Writer, + }, /// Streaming objects: the write buffer drains first, then the pending chunk, /// then the pending frame, then the next frame. Serve { @@ -7583,7 +7586,7 @@ impl Drop for GroupServe { fn drop(&mut self) { // The writer's own fallback would say CANCELLED, which a lapse is not. if self.lapse.as_ref().is_some_and(Lapse::lapsed) - && let GroupState::Serve { writer, .. } | GroupState::Closed { writer } = + && let GroupState::Describe { writer } | GroupState::Serve { writer, .. } | GroupState::Closed { writer } = std::mem::replace(&mut self.state, GroupState::Done) { writer.reset(super::error::EXPIRED_AUTH_TOKEN); @@ -7612,7 +7615,6 @@ impl GroupServe { version, prior_object: None, slice, - described: false, bounds: None, retired: Default::default(), ended: false, @@ -7687,10 +7689,9 @@ impl GroupServe { self.group.skip_to(self.slice.skip); self.group.end_at(self.slice.until); } - self.described = true; } - /// Wait for stream credit, then write the group header, leaving the machine serving. + /// Wait for stream credit, leaving the machine to describe the group on its stream. /// Gives up once the group can no longer be sent, so a parked group never spends the /// credit it was waiting for on a reset. fn poll_open(&mut self, waiter: &kio::Waiter) -> Poll> { @@ -7707,12 +7708,6 @@ impl GroupServe { } // The current rank, so a move while parked applies to the stream as it opens. let _ = self.rank.poll_moved(waiter); - // Before the stream, whose header describes it: a relayed group is visible before - // its own header has been read. - if !self.described { - let wire = ready!(self.group.poll_wire(waiter)); - self.describe(wire); - } let stream = match ready!(self.session.poll_open_group( &mut self.open, waiter, @@ -7727,17 +7722,8 @@ impl GroupServe { }; self.opened.fetch_add(1, Ordering::Relaxed); - let mut writer = Writer::new(stream, self.version); - if let Err(err) = writer.buffer(&self.msg) { - self.state = GroupState::Done; - return Poll::Ready(Err(err)); - } - self.state = GroupState::Serve { - writer, - frame: None, - chunk: None, - batch: Box::new(arrayvec::ArrayVec::new()), - batch_pos: 0, + self.state = GroupState::Describe { + writer: Writer::new(stream, self.version), }; Poll::Ready(Ok(())) } @@ -7759,6 +7745,30 @@ impl GroupServe { // The current rank, which already includes anything `moved` saw. moved = None; } + GroupState::Describe { writer } => { + if let Some(priority) = moved.take() { + writer.set_priority(priority); + } + // The peer closing first cancels the group. + if writer.poll_closed(waiter).is_ready() { + self.state = GroupState::Done; + return Poll::Ready(Err(Error::Cancel)); + } + let wire = ready!(self.group.poll_wire(waiter)); + let GroupState::Describe { mut writer } = std::mem::replace(&mut self.state, GroupState::Done) + else { + unreachable!("matched above"); + }; + self.describe(wire); + writer.buffer(&self.msg)?; + self.state = GroupState::Serve { + writer, + frame: None, + chunk: None, + batch: Box::new(arrayvec::ArrayVec::new()), + batch_pos: 0, + }; + } GroupState::Serve { writer, frame, @@ -8670,6 +8680,17 @@ mod group_priority_test { let group = track.create_group(group::Info { sequence: 0 }).unwrap(); assert!(futures::poll!(kio::wait(|waiter| serve.poll(waiter))).is_pending()); + // A later group is served meanwhile, its stream independent of the one waiting. + let mut later = track.create_group(group::Info { sequence: 1 }).unwrap(); + later.write_frame(None, b"later".as_slice()).unwrap(); + later.finish().unwrap(); + for _ in 0..8 { + assert!(futures::poll!(kio::wait(|waiter| serve.poll(waiter))).is_pending()); + kio::clock::sim::yield_now().await; + } + let written = log.writes.lock().unwrap().clone(); + assert!(written.windows(5).any(|window| window == b"later")); + group .set_wire(group::Wire { sparse: false, @@ -8699,9 +8720,20 @@ mod group_priority_test { track.finish().unwrap(); kio::wait(|waiter| serve.poll(waiter)).await.unwrap(); - let mut buf = bytes::Bytes::from(log.writes.lock().unwrap().clone()); - let header = crate::coding::decode_buf(&mut buf, Version::Draft18, |r, v| ietf::GroupHeader::decode(r, v)) - .expect("a group header"); + let mut streams = std::collections::BTreeMap::>::new(); + for (stream, sent) in log.trail() { + if let crate::lite::test_transport::Sent::Write(bytes) = sent { + streams.entry(stream).or_default().extend(bytes); + } + } + let header = streams + .into_values() + .filter_map(|bytes| { + let mut buf = bytes::Bytes::from(bytes); + crate::coding::decode_buf(&mut buf, Version::Draft18, |r, v| ietf::GroupHeader::decode(r, v)).ok() + }) + .find(|header| header.group_id == 0) + .expect("group 0's header"); assert!(header.flags.has_extensions); assert!(!header.flags.first_object); } From 8cfe4ec100a5f8ca7bc0439277a0bb1c8153f323 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Mon, 9 Nov 2026 10:40:47 -0800 Subject: [PATCH 4/7] fix(net): relay-state wait ignores adopted frames and honors the drift budget Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/ietf/publisher.rs | 15 ++++++++++++--- rs/moq-net/src/lite/ietf.rs | 4 ++-- rs/moq-net/src/lite/publisher.rs | 2 +- rs/moq-net/src/model/group.rs | 15 ++++++++++----- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/rs/moq-net/src/ietf/publisher.rs b/rs/moq-net/src/ietf/publisher.rs index dc6195b23ec..5de669832aa 100644 --- a/rs/moq-net/src/ietf/publisher.rs +++ b/rs/moq-net/src/ietf/publisher.rs @@ -7754,7 +7754,13 @@ impl GroupServe { self.state = GroupState::Done; return Poll::Ready(Err(Error::Cancel)); } - let wire = ready!(self.group.poll_wire(waiter)); + let wire = match ready!(self.group.poll_wire(waiter)) { + Ok(wire) => wire, + Err(err) => { + self.state = GroupState::Done; + return Poll::Ready(Err(err)); + } + }; let GroupState::Describe { mut writer } = std::mem::replace(&mut self.state, GroupState::Done) else { unreachable!("matched above"); @@ -8667,11 +8673,14 @@ mod group_priority_test { let track = track::Producer::new( std::sync::Arc::new(crate::broadcast::Info::default()), "test", - track::Info::default(), + // Keeps a superseded group, so the later group landing does not give up on this one. + track::Info::default().with_max_age(None), ); let mut serve = TrackServe::new( crate::driver::Transport::new(session.clone()), - track.subscribe(None), + track.subscribe(Some( + track::Subscription::default().with_delay(track::Delay::default().with_max(None)), + )), RequestId(0), Version::Draft18, ServeRange::default(), diff --git a/rs/moq-net/src/lite/ietf.rs b/rs/moq-net/src/lite/ietf.rs index d9583c6558d..42827ff79c4 100644 --- a/rs/moq-net/src/lite/ietf.rs +++ b/rs/moq-net/src/lite/ietf.rs @@ -242,13 +242,13 @@ impl Records { pub fn poll_state( &mut self, writer: &mut crate::coding::Writer, - group: &group::Consumer, + group: &mut group::Consumer, waiter: &kio::Waiter, ) -> std::task::Poll> { if self.stated { return std::task::Poll::Ready(Ok(())); } - let wire = std::task::ready!(group.poll_wire(waiter)); + let wire = std::task::ready!(group.poll_wire(waiter))?; let whole = group.index() <= group.first_frame(); writer.buffer_varint(encode_state(wire.as_ref(), whole, self.capped))?; self.stated = true; diff --git a/rs/moq-net/src/lite/publisher.rs b/rs/moq-net/src/lite/publisher.rs index 535c54cb6e1..2087b8dfd13 100644 --- a/rs/moq-net/src/lite/publisher.rs +++ b/rs/moq-net/src/lite/publisher.rs @@ -6223,7 +6223,7 @@ impl GroupServe { } } if let Some(records) = records { - match records.poll_state(writer, &self.group, waiter) { + match records.poll_state(writer, &mut self.group, waiter) { Poll::Ready(Ok(())) => {} Poll::Ready(Err(err)) => break 'serve Err(err), Poll::Pending => return Poll::Pending, diff --git a/rs/moq-net/src/model/group.rs b/rs/moq-net/src/model/group.rs index 6aea1288977..f8a8545c969 100644 --- a/rs/moq-net/src/model/group.rs +++ b/rs/moq-net/src/model/group.rs @@ -1238,7 +1238,9 @@ impl GroupState { /// the end object, or the close: a group is visible before its header is read. #[cfg(feature = "async")] fn poll_wire(&self) -> Poll>> { - let settled = self.next_index > self.offset + // Frames adopted below the log (see [`Handle::adopt_head`]) came from another copy, + // so only one this ingest wrote proves it read the header. + let settled = self.next_index > self.offset + self.front.len() || self.partial.is_some() || self.relay.as_ref().is_some_and(|relay| relay.end_object.is_some()) || !matches!(self.outcome, Outcome::Open); @@ -3693,13 +3695,16 @@ impl Consumer { self.cursor.state.read().wire().cloned() } - /// The relay state an egress header describes, once the ingest has set it. + /// The relay state an egress header describes, once the ingest has set it, or + /// [`Error::Old`] once the drift budget gives up on the group first. #[cfg(feature = "async")] - pub(crate) fn poll_wire(&self, waiter: &kio::Waiter) -> Poll> { + pub(crate) fn poll_wire(&mut self, waiter: &kio::Waiter) -> Poll>> { // A dropped producer settled whatever it was going to. - self.cursor + let res = self + .cursor .poll(waiter, |state| state.poll_wire()) - .map(|res| res.unwrap_or_else(|_| self.wire())) + .map(|res| Ok(res.unwrap_or_else(|_| self.wire()))); + self.poll_expired_if_blocked(waiter, res) } /// Read a compressed group's stored DEFLATE slices instead of plain frames, with each From be112f0b5f1c59e9a901343586f495fa2cc6aebb Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Mon, 9 Nov 2026 10:58:04 -0800 Subject: [PATCH 5/7] fix(net): relay-state readiness keys off the ingest's own writes Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/model/group.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/rs/moq-net/src/model/group.rs b/rs/moq-net/src/model/group.rs index f8a8545c969..65480509d73 100644 --- a/rs/moq-net/src/model/group.rs +++ b/rs/moq-net/src/model/group.rs @@ -275,6 +275,10 @@ pub(super) struct GroupState { // cache policy moves the frames to them rather than dropping them. handoff: Mutex>, + // Whether this copy's ingest wrote a frame itself, which it does only after settling the + // relay state; adopted frames (see [`Handle::adopt_head`]) prove nothing about it. + wrote: bool, + // Whether an adopted head (see [`Handle::adopt_head`]) begins at the group's first // object, for a wire header that arrives after it. adopted: Option, @@ -1238,9 +1242,7 @@ impl GroupState { /// the end object, or the close: a group is visible before its header is read. #[cfg(feature = "async")] fn poll_wire(&self) -> Poll>> { - // Frames adopted below the log (see [`Handle::adopt_head`]) came from another copy, - // so only one this ingest wrote proves it read the header. - let settled = self.next_index > self.offset + self.front.len() + let settled = self.wrote || self.partial.is_some() || self.relay.as_ref().is_some_and(|relay| relay.end_object.is_some()) || !matches!(self.outcome, Outcome::Open); @@ -1861,6 +1863,7 @@ impl Producer { } let now = state.commit(entry); state.next_index = next_index; + state.wrote = true; let bound = state.settle(origin); self.handle.alive.checked.store(true, Ordering::Relaxed); self.advance_largest(&state); @@ -1994,6 +1997,7 @@ impl Producer { // A batch past the tail on its own, payloads or slots, sheds its own front. state.trim(0); state.next_index = next_index; + state.wrote = true; let bound = state.settle(origin); if count > 0 { self.handle.alive.checked.store(true, Ordering::Relaxed); @@ -2143,6 +2147,7 @@ impl Producer { wire.sparse |= object_id != (next_index - 1) as u64; } state.next_index = next_index; + state.wrote = true; // Opening the frame is enough: the header carries the timestamp, so the group's // place in time is known before a single payload byte streams in. state.stamp(timestamp); From abc2182be5b75453e034bb59bc59e5db628c711c Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Mon, 9 Nov 2026 13:19:09 -0800 Subject: [PATCH 6/7] test(net): a group waiting on its relay state expires once a successor lands Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/ietf/publisher.rs | 42 ++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/rs/moq-net/src/ietf/publisher.rs b/rs/moq-net/src/ietf/publisher.rs index 5de669832aa..2e542331826 100644 --- a/rs/moq-net/src/ietf/publisher.rs +++ b/rs/moq-net/src/ietf/publisher.rs @@ -8938,6 +8938,48 @@ mod group_priority_test { assert!(matches!(serving.await, Err(Error::Old))); } + /// A group whose stream opened but whose relay state never settled still expires once a + /// successor lands, rather than holding the stream until its ingest ends. + #[kio::test] + async fn a_group_waiting_for_its_relay_state_expires() { + let session = SinkSession::new(crate::lite::test_transport::Log::default()); + let track = track::Producer::new( + std::sync::Arc::new(crate::broadcast::Info::default()), + "test", + track::Info::default(), + ); + let mut subscriber = track.subscribe(None); + let _stalled = track.create_group(group::Info { sequence: 0 }).unwrap(); + let group = subscriber.recv_group().await.unwrap().expect("stalled group"); + + let mut serve = GroupServe::new( + crate::driver::Transport::new(session.clone()), + ietf::GroupHeader { + track_alias: 0, + group_id: 0, + sub_group_id: 0, + publisher_priority: 0, + flags: Default::default(), + }, + Rank::solo(kio::Producer::new(0).consume()), + group, + None, + Version::Draft18, + GroupSlice::default(), + ); + let mut serving = std::pin::pin!(kio::wait(|waiter| serve.poll_serve(waiter))); + assert!( + futures::poll!(serving.as_mut()).is_pending(), + "the relay state is unsettled" + ); + + let mut edge = track.create_group(group::Info { sequence: 1 }).unwrap(); + edge.write_frame(None, b"edge".as_slice()).unwrap(); + edge.finish().unwrap(); + + assert!(matches!(serving.await, Err(Error::Old))); + } + /// A local group that never held the requested prefix fails rather than serving its /// tail as the whole group, with or without an end inside it. #[kio::test] From e76dd492805506d126b3bd75fbc0655c3ca321aa Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Mon, 9 Nov 2026 15:10:45 -0800 Subject: [PATCH 7/7] test(net): hold the finished track handle Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/ietf/publisher.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rs/moq-net/src/ietf/publisher.rs b/rs/moq-net/src/ietf/publisher.rs index 960dd56b0ad..4a006716cd8 100644 --- a/rs/moq-net/src/ietf/publisher.rs +++ b/rs/moq-net/src/ietf/publisher.rs @@ -8741,7 +8741,7 @@ mod group_priority_test { .unwrap(); frame.write(b"x".as_slice()).unwrap(); frame.finish().unwrap().finish().unwrap(); - track.finish().unwrap(); + let _finished = track.finish().unwrap(); kio::wait(|waiter| serve.poll(waiter)).await.unwrap(); let mut streams = std::collections::BTreeMap::>::new();