From 2c00e217c9b24d46333de36ac773ad3d79458c95 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 13 Oct 2026 19:11:46 -0700 Subject: [PATCH 1/3] chore: claim accepted group demand quest Co-Authored-By: GPT-6 From 4fd066d3a9815c1f6fb94243e6c415289584eead Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 13 Oct 2026 19:24:14 -0700 Subject: [PATCH 2/3] fix(moq-net): close accepted group request demand cleanly Co-Authored-By: GPT-6 --- go/wrapper/publish.go | 5 ++- py/moq-rs/moq/publish.py | 6 ++-- quest/m1/README.md | 1 - quest/m1/group-demand-accept.md | 26 --------------- rs/moq-ffi/src/demand.rs | 4 +-- rs/moq-ffi/src/test.rs | 25 +++++--------- rs/moq-net/src/model/group.rs | 3 ++ rs/moq-net/src/model/track.rs | 58 ++++++++++++++++++++++++++++----- swift/Sources/Moq/Dynamic.swift | 4 +-- 9 files changed, 70 insertions(+), 62 deletions(-) delete mode 100644 quest/m1/group-demand-accept.md diff --git a/go/wrapper/publish.go b/go/wrapper/publish.go index 6a8139d9495..6481aab6941 100644 --- a/go/wrapper/publish.go +++ b/go/wrapper/publish.go @@ -409,9 +409,8 @@ func (r *GroupRequest) Abort(errorCode uint16) error { // // It is weak: holding it does not keep the request alive. The last caller to // leave withdraws the request, so once unused, demand never returns: drop the -// request. Waits fail once the request is answered: ErrClosed if it was -// dropped, otherwise the error the accept or reject left for the waiting -// fetches. +// request. Waits fail with ErrClosed after the request is accepted or dropped, +// and keep the rejection reason after it is rejected. type GroupDemand struct { inner *ffi.MoqGroupDemand } diff --git a/py/moq-rs/moq/publish.py b/py/moq-rs/moq/publish.py index 31eff150de2..5492ddd1faa 100644 --- a/py/moq-rs/moq/publish.py +++ b/py/moq-rs/moq/publish.py @@ -204,9 +204,9 @@ class GroupDemand: Returned by ``GroupRequest.demand()``. Weak: holding it does not keep the request alive. The last caller to leave withdraws the request, so once - unused, demand never returns: drop the request. Waits raise once the - request is answered: ``moq.Error.Closed`` if it was dropped, otherwise the - error the accept or reject left for the waiting fetches. + unused, demand never returns: drop the request. Waits raise + ``moq.Error.Closed`` after the request is accepted or dropped, and keep + the rejection reason after it is rejected. """ def __init__(self, inner: MoqGroupDemand) -> None: diff --git a/quest/m1/README.md b/quest/m1/README.md index 96443d8c4c5..e62b287850d 100644 --- a/quest/m1/README.md +++ b/quest/m1/README.md @@ -168,7 +168,6 @@ above them. - [Refuse rewinds](/quest/m1/refuse-rewinds.md) - a timed track refuses a group whose first frame is earlier than the previous group's, in Rust and js/net, on every hop - [Feed fetch index](/quest/m1/feed-fetch-index.md) - held feed fetches wake per group and are capped per peer session, on main then release - [JS pending tail](/quest/m1/js-pending-tail.md) - a JS reader holds for a track's pending tail like Rust -- [Group demand after accept](/quest/m1/group-demand-accept.md) - an accepted group request's demand ends cleanly instead of failing with NotFound - [WebGPU on Safari](/quest/m1/webgpu-safari.md) - the WebGPU renderer is verified on Safari 26 for macOS and iOS - [A/V sync across a break](/quest/m1/watch-break-av-sync.md) - `@moq/watch` never plays pre-break audio out of sync with pre-break video - [moqsrc reconnect](/quest/m1/moqsrc-reconnect.md) - `moqsrc` redials after losing its relay and resumes on the same pads diff --git a/quest/m1/group-demand-accept.md b/quest/m1/group-demand-accept.md deleted file mode 100644 index 599f53a7ea5..00000000000 --- a/quest/m1/group-demand-accept.md +++ /dev/null @@ -1,26 +0,0 @@ -# [S] An accepted group request's demand ends cleanly - -## Goal - -Once a group request is answered with `accept`, its `group::Demand` ends the -way a dropped request's does: `used()`, `unused()`, and `closed()` return -`Error::Dropped`, which moq-ffi's `MoqGroupDemand` reports as `Closed`. A rejected request's demand -still fails with the reject reason. - -## Plan - -Today `group::Request::accept` stores `rejected = NotFound` so a fetch that -joins the answered request fails, and `Demand::abort_reason` -(`rs/moq-net/src/model/group.rs`, `DemandSource::Fetch`) reads that same -field, so every binding sees `NotFound` after an accept. Keep the -joined-fetch refusal in its own field and let the demand read only an actual -reject. - -Decided 2026-10-10 (found in #5139): clean close after accept, reject keeps -its error. Add a moq-net test that both outcomes hold for `used()`, -`unused()`, and `closed()`, flip moq-ffi's -`group_request_demand_fails_after_accept`, and update the `MoqGroupDemand` -docs in Rust, Go, Python, and Swift. Hand-written moq-c is frozen, so it gets -no change. - -Public API: behavior only (the error a demand wait returns). Wire: none. diff --git a/rs/moq-ffi/src/demand.rs b/rs/moq-ffi/src/demand.rs index 72223a44532..c1ef89b5562 100644 --- a/rs/moq-ffi/src/demand.rs +++ b/rs/moq-ffi/src/demand.rs @@ -49,8 +49,8 @@ impl MoqTrackDemand { /// /// Weak: holding it does not keep the request alive. The last caller to leave withdraws the /// request, and a later fetch of the group queues a fresh one, so once unused, demand never -/// returns: drop the request. Waits fail once the request is answered: with `Closed` if it was -/// dropped, otherwise with the error the accept or reject left for the waiting fetches. +/// returns: drop the request. Waits fail with `Closed` after the request is accepted or dropped, +/// and keep the rejection reason after it is rejected. #[derive(uniffi::Object)] pub struct MoqGroupDemand { inner: moq_net::group::Demand, diff --git a/rs/moq-ffi/src/test.rs b/rs/moq-ffi/src/test.rs index ff7e6dce576..d79c7831706 100644 --- a/rs/moq-ffi/src/test.rs +++ b/rs/moq-ffi/src/test.rs @@ -1659,33 +1659,26 @@ async fn group_request_demand_ends_when_the_fetcher_leaves() { assert!(matches!(request.demand(), Err(MoqError::Closed))); } -/// An accepted request's demand ends with the `NotFound` the accept leaves for joined fetches -/// it can't cover, not `Closed`. +/// An accepted request's demand closes cleanly while its fetch gets the group. #[tokio::test] -async fn group_request_demand_fails_after_accept() { +async fn group_request_demand_closes_after_accept() { + tokio::time::pause(); let broadcast = MoqBroadcastProducer::new().unwrap(); let track = broadcast.publish_track("events".into(), None).unwrap(); let dynamic = track.dynamic().unwrap(); let consumer = broadcast.consume().unwrap(); let fetch = tokio::spawn(async move { consumer.fetch_group("events".into(), 5, None).await }); - let request = tokio::time::timeout(TIMEOUT, dynamic.requested_group()) - .await - .expect("timed out waiting for group request") - .unwrap(); + let request = dynamic.requested_group().await.unwrap(); let demand = request.demand().unwrap(); let group = request.accept().unwrap(); group.finish().unwrap(); - let used = tokio::time::timeout(TIMEOUT, demand.used()) - .await - .expect("timed out waiting for an accepted demand to end"); - assert!(matches!(used, Err(MoqError::NotFound)), "got {used:?}"); - tokio::time::timeout(TIMEOUT, fetch) - .await - .expect("timed out waiting for fetch") - .expect("fetch task panicked") - .unwrap(); + for result in [demand.used().await, demand.unused().await] { + assert!(matches!(result, Err(MoqError::Closed)), "got {result:?}"); + } + assert!(!demand.is_used()); + fetch.await.expect("fetch task panicked").unwrap(); } #[tokio::test] diff --git a/rs/moq-net/src/model/group.rs b/rs/moq-net/src/model/group.rs index e43cba217a7..11783daa92d 100644 --- a/rs/moq-net/src/model/group.rs +++ b/rs/moq-net/src/model/group.rs @@ -1104,6 +1104,9 @@ impl Producer { } /// A cloneable, watch-only handle to a group's readers or pending fetch callers. +/// +/// An accepted or dropped request ends waits with [`Error::Dropped`]; a rejected request keeps +/// its rejection reason. #[derive(Clone)] pub struct Demand { sequence: u64, diff --git a/rs/moq-net/src/model/track.rs b/rs/moq-net/src/model/track.rs index 3429e5333b1..1cf0ceba2d3 100644 --- a/rs/moq-net/src/model/track.rs +++ b/rs/moq-net/src/model/track.rs @@ -486,18 +486,19 @@ pub(crate) struct PendingFetch { // has taken it, its range is already on the wire. frame_start: u64, - // Result channel back to the joined fetches. Written only on rejection; a - // successful accept resolves them through the track cache instead. Dropping - // every producer without writing (a vanished handler) closes the channel, - // which a [`Fetching`] reads as [`Error::NotFound`]. + // Result channel for joined fetches. An accept resolves covered callers through + // the track cache and refuses uncovered ones. Dropping every producer closes + // an unserved attempt, which a [`Fetching`] reads as [`Error::NotFound`]. result: kio::Producer, } -/// The result of a fetch attempt. Stays empty on success (the group lands in the -/// track cache); a handler writes `rejected` to fail every joined fetch. +/// Whether a fetch attempt was accepted, or why it was rejected. #[derive(Default)] pub(crate) struct FetchOutcome { pub(crate) rejected: Option, + // An accept still refuses joined fetches the cached group cannot cover, without + // giving the request's demand watcher a rejection reason. + accepted: bool, } impl TrackState { @@ -3443,7 +3444,7 @@ impl group::Request { // the range went on the wire) fails rather than waits. Closing the channel says // the same, but a handler tracking the joined demand keeps it open. if let Ok(mut outcome) = self.result.write() { - outcome.rejected = Some(Error::NotFound); + outcome.accepted = true; } res } @@ -3626,10 +3627,11 @@ impl kio::Task for Fetching { }; }; - // A written rejection fails every joined fetch. The channel closing without - // one means the attempt was dropped unserved (its handlers went away). + // An answered attempt fails joined fetches the cache cannot cover. The channel + // closing without an answer means its handlers went away. let err = match result.outcome.poll(waiter, |outcome| match &outcome.rejected { Some(err) => Poll::Ready(err.clone()), + None if outcome.accepted => Poll::Ready(Error::NotFound), None => Poll::Pending, }) { Poll::Ready(Ok(err)) => err, @@ -10619,6 +10621,44 @@ mod test { assert!(matches!(demand.used().now_or_never(), Some(Err(Error::Cancel)))); } + #[test] + fn accepted_group_request_demand_ends_cleanly() { + let producer = track_producer("test", Info::timed()); + let dynamic = producer.dynamic(); + let consumer = producer.consume(); + let fetch = consumer.fetch_group(3, None); + let request = dynamic.requested_group().now_or_never().unwrap().unwrap(); + let demand = request.demand(); + let group = request.accept(Info::timed()).unwrap(); + + assert!(!demand.is_used()); + assert!(matches!(demand.used().now_or_never(), Some(Err(Error::Dropped)))); + assert!(matches!(demand.unused().now_or_never(), Some(Err(Error::Dropped)))); + assert!(matches!(demand.closed().now_or_never(), Some(Error::Dropped))); + assert!( + fetch.now_or_never().unwrap().is_ok(), + "the fetch still gets the accepted group" + ); + group.finish().unwrap(); + } + + #[test] + fn rejected_group_request_demand_keeps_its_reason() { + let producer = track_producer("test", Info::timed()); + let dynamic = producer.dynamic(); + let consumer = producer.consume(); + let fetch = consumer.fetch_group(3, None); + let request = dynamic.requested_group().now_or_never().unwrap().unwrap(); + let demand = request.demand(); + request.reject(Error::NotFound); + + assert!(!demand.is_used()); + assert!(matches!(demand.used().now_or_never(), Some(Err(Error::NotFound)))); + assert!(matches!(demand.unused().now_or_never(), Some(Err(Error::NotFound)))); + assert!(matches!(demand.closed().now_or_never(), Some(Error::NotFound))); + assert!(matches!(fetch.now_or_never(), Some(Err(Error::NotFound)))); + } + #[moq_net_sim::test] async fn fetch_aborts_with_track() { let producer = track_producer("test", Info::timed()); diff --git a/swift/Sources/Moq/Dynamic.swift b/swift/Sources/Moq/Dynamic.swift index 3dc7e49ff29..8dc8c5539f9 100644 --- a/swift/Sources/Moq/Dynamic.swift +++ b/swift/Sources/Moq/Dynamic.swift @@ -41,8 +41,8 @@ public final class TrackRequest: Sendable { /// /// Returned by `GroupRequest.demand()`. Weak: holding it does not keep the request alive. The last /// caller to leave withdraws the request, so once unused, demand never returns: drop the request. -/// Waits throw once the request is answered: `MoqError.Closed` if it was dropped, otherwise the -/// error the accept or reject left for the waiting fetches. +/// Waits throw `MoqError.Closed` after the request is accepted or dropped, and keep the rejection +/// reason after it is rejected. public final class GroupDemand: Sendable { let ffi: MoqGroupDemand From 6ef9d5164424b798d32650962c766952f903fa3a Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 13 Oct 2026 22:18:23 -0700 Subject: [PATCH 3/3] Test group request demand through the core poll APIs Co-Authored-By: GPT-6 --- rs/moq-net/src/model/track.rs | 55 +++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/rs/moq-net/src/model/track.rs b/rs/moq-net/src/model/track.rs index 1cf0ceba2d3..fbcf09f77d9 100644 --- a/rs/moq-net/src/model/track.rs +++ b/rs/moq-net/src/model/track.rs @@ -10619,6 +10619,30 @@ mod test { assert!(matches!(demand.poll_unused(&kio::Waiter::noop()), Poll::Ready(Ok(())))); request.reject(Error::Cancel); assert!(matches!(demand.used().now_or_never(), Some(Err(Error::Cancel)))); + + // The async close helper reports clean acceptance separately from rejection. + for accepted in [true, false] { + let producer = track_producer("test", Info::timed()); + let dynamic = producer.dynamic(); + let consumer = producer.consume(); + let fetch = consumer.fetch_group(3, None); + let request = dynamic.requested_group().now_or_never().unwrap().unwrap(); + let demand = request.demand(); + let group = if accepted { + Some(request.accept(Info::timed()).unwrap()) + } else { + request.reject(Error::NotFound); + None + }; + assert!(matches!( + (accepted, demand.closed().now_or_never()), + (true, Some(Error::Dropped)) | (false, Some(Error::NotFound)) + )); + drop(fetch); + if let Some(group) = group { + group.finish().unwrap(); + } + } } #[test] @@ -10626,17 +10650,19 @@ mod test { let producer = track_producer("test", Info::timed()); let dynamic = producer.dynamic(); let consumer = producer.consume(); - let fetch = consumer.fetch_group(3, None); - let request = dynamic.requested_group().now_or_never().unwrap().unwrap(); + let mut fetch = consumer.fetch_group(3, None); + let waiter = kio::Waiter::noop(); + let Poll::Ready(Ok(request)) = dynamic.poll_requested_group(&waiter) else { + panic!("the fetch request is ready"); + }; let demand = request.demand(); let group = request.accept(Info::timed()).unwrap(); assert!(!demand.is_used()); - assert!(matches!(demand.used().now_or_never(), Some(Err(Error::Dropped)))); - assert!(matches!(demand.unused().now_or_never(), Some(Err(Error::Dropped)))); - assert!(matches!(demand.closed().now_or_never(), Some(Error::Dropped))); + assert!(matches!(demand.poll_used(&waiter), Poll::Ready(Err(Error::Dropped)))); + assert!(matches!(demand.poll_unused(&waiter), Poll::Ready(Err(Error::Dropped)))); assert!( - fetch.now_or_never().unwrap().is_ok(), + matches!(kio::Task::poll(&mut *fetch, &waiter), Poll::Ready(Ok(_))), "the fetch still gets the accepted group" ); group.finish().unwrap(); @@ -10647,16 +10673,21 @@ mod test { let producer = track_producer("test", Info::timed()); let dynamic = producer.dynamic(); let consumer = producer.consume(); - let fetch = consumer.fetch_group(3, None); - let request = dynamic.requested_group().now_or_never().unwrap().unwrap(); + let mut fetch = consumer.fetch_group(3, None); + let waiter = kio::Waiter::noop(); + let Poll::Ready(Ok(request)) = dynamic.poll_requested_group(&waiter) else { + panic!("the fetch request is ready"); + }; let demand = request.demand(); request.reject(Error::NotFound); assert!(!demand.is_used()); - assert!(matches!(demand.used().now_or_never(), Some(Err(Error::NotFound)))); - assert!(matches!(demand.unused().now_or_never(), Some(Err(Error::NotFound)))); - assert!(matches!(demand.closed().now_or_never(), Some(Error::NotFound))); - assert!(matches!(fetch.now_or_never(), Some(Err(Error::NotFound)))); + assert!(matches!(demand.poll_used(&waiter), Poll::Ready(Err(Error::NotFound)))); + assert!(matches!(demand.poll_unused(&waiter), Poll::Ready(Err(Error::NotFound)))); + assert!(matches!( + kio::Task::poll(&mut *fetch, &waiter), + Poll::Ready(Err(Error::NotFound)) + )); } #[moq_net_sim::test]