diff --git a/quest/m0/nightly/README.md b/quest/m0/nightly/README.md index 1d4c42b2dea..0affc73cc09 100644 --- a/quest/m0/nightly/README.md +++ b/quest/m0/nightly/README.md @@ -52,4 +52,3 @@ near the paired threshold (re-check if one repeats), a one-off - [Nightly's macOS platform job passes](/quest/m0/nightly/macos.md) - `moq-audio`'s tests compile on macOS again and the websocket version test's timeout is fixed if it recurs - [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 -- [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 5a54457d7de..4a006716cd8 100644 --- a/rs/moq-net/src/ietf/publisher.rs +++ b/rs/moq-net/src/ietf/publisher.rs @@ -6719,7 +6719,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, @@ -6729,17 +6728,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 `GroupState::Describe`). 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() }, }; @@ -7571,6 +7563,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 { @@ -7603,7 +7600,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); @@ -7616,17 +7613,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(), @@ -7696,7 +7687,25 @@ impl GroupServe { self } - /// Wait for stream credit, then write the group header, leaving the machine serving. + /// 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); + } + } + + /// 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> { @@ -7727,17 +7736,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 +7759,36 @@ 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 = 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"); + }; + 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, @@ -8649,6 +8679,89 @@ 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", + // 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(Some( + track::Subscription::default().with_delay(track::Delay::default().with_max(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()); + // 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, + 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(); + let _finished = track.finish().unwrap(); + kio::wait(|waiter| serve.poll(waiter)).await.unwrap(); + + 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); + } + /// 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(); @@ -8840,6 +8953,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] diff --git a/rs/moq-net/src/lite/ietf.rs b/rs/moq-net/src/lite/ietf.rs index 6d18d27a276..42827ff79c4 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( - writer: &mut crate::coding::Writer, - ietf: bool, - group: &group::Consumer, - capped: bool, - timescale: Option, - ) -> Result, Error> { - if !ietf { - return Ok(None); - } - let wire = group.wire(); - let whole = group.index() <= group.first_frame(); - writer.buffer_varint(encode_state(wire.as_ref(), whole, capped))?; - Ok(Some(Self { + /// 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, + 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 whole = group.index() <= group.first_frame(); + 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 f54da0d9379..fbf5666ffa9 100644 --- a/rs/moq-net/src/lite/publisher.rs +++ b/rs/moq-net/src/lite/publisher.rs @@ -3237,7 +3237,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, @@ -3261,6 +3261,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) { @@ -6284,17 +6287,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 @@ -6385,6 +6379,13 @@ impl GroupServe { return Poll::Pending; } } + if let Some(records) = records { + 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, + } + } 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 f03171766a4..22b4c0bd4f8 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, @@ -1234,6 +1238,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.wrote + || 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> { @@ -1845,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); @@ -1978,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); @@ -2127,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); @@ -3724,6 +3745,18 @@ impl Consumer { self.cursor.state.read().wire().cloned() } + /// 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(&mut self, waiter: &kio::Waiter) -> Poll>> { + // A dropped producer settled whatever it was going to. + let res = self + .cursor + .poll(waiter, |state| state.poll_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 /// frame's inflated size beside it ([`frame::Object::inflated`], /// [`frame::Consumer::inflated`]), for egress that carries compression. A no-op on a @@ -4054,9 +4087,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.