Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions quest/m2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ ranked just below deterministic TS legs, which it requires.
- [IETF request order](/quest/m2/ietf-request-order.md) - d14/15 requests take their ID after opening, legacy `control.sending()` races are gone, and SUBSCRIBE_NAMESPACE never closes over its own close
- [JS IETF request streams](/quest/m2/js-request-stream.md) - `RequestStream` owns deadlines and cancellation, and TRACK trailing bytes close the session like Rust
- [Join after a quick finish](/quest/m2/ietf-join-after-finish.md) - a pre-draft-20 joining FETCH that arrives after its subscription finished is still answered, within a bound the peer already negotiates
- [JS joining FETCH](/quest/m2/ietf-js-joining-fetch.md) - the JS publisher honors Largest Object before draft 20 and serves the head on a joining FETCH, as the Rust publisher does
- [ashpd uses maintained D-Bus crates](/quest/m2/ashpd-maintained.md) - wait for a stable zbus 6 port, then remove the portal dependency exceptions
- [Askama uses a maintained TOML parser](/quest/m2/askama-maintained.md) - wait for a stable parser migration, then remove the generator dependency exception
- [Dependency and alternatives audit](/quest/m2/audit-deps.md) - dependencies are current, deduplicated, needed, and the best maintained option
Expand Down
37 changes: 24 additions & 13 deletions quest/m2/ietf-join-after-finish.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,40 @@
On drafts 14 to 19, a joining FETCH that reaches our publisher after its
subscription finished cleanly is still answered from the subscription's
saved Largest group. A track that ends within about one RTT of SUBSCRIBE_OK
then finishes cleanly at the subscriber, head included, instead of failing.
then finishes cleanly at the subscriber, head included, instead of losing
its last group.
What the publisher retains for this is bounded by design (the session, the
subscription's request, or a limit the peer already negotiates), never by a
timer constant.

## Plan

Starts after [moq-dev/moq#6348](https://github.com/moq-dev/moq/pull/6348)
merges (open on 2026-10-22). It makes every pre-draft-20 join a SUBSCRIBE
followed, after SUBSCRIBE_OK, by a `RelativeJoining{0}` FETCH, and fails the
subscription when that FETCH is refused. If it is abandoned, re-judge this
quest.
Every pre-draft-20 join is a SUBSCRIBE followed, after SUBSCRIBE_OK, by a
`RelativeJoining{0}` FETCH ([moq-dev/moq#6348](https://github.com/moq-dev/moq/pull/6348)).
A refused one costs the subscriber that group's head and nothing more
([moq-dev/moq#6407](https://github.com/moq-dev/moq/pull/6407), decided with
the maintainer on 2026-10-22): a stream starting mid-group is dropped and
the subscription goes on.

State: `rs/moq-net/src/ietf/publisher.rs` registers a `Join` entry in
`Publisher::joins` when it dispatches the SUBSCRIBE, fills it with a `Joined`
snapshot as SUBSCRIBE_OK goes out, and drops it when the subscription ends,
before PUBLISH_DONE. A joining FETCH that arrives later finds no entry, waits
out the registration wait in `joined()`, and is refused as an unknown
subscription. Before #6348 the subscriber swallowed that refusal and lost the
head silently; after it, the subscriber errors. Short or already-finished
tracks hit this often.
subscription, so the subscriber loses the Largest group. Short or
already-finished tracks hit this often.

Fix it at the publisher. Accepting the refusal at the subscriber after a clean
PUBLISH_DONE would hide the lost head again, which is what #6348 fixed, and
other publishers may refuse the same way.
It flakes the pinned-pass interop `tail` cells with a Rust publisher, about
one run in six on draft 14 (seen 2026-10-22 while landing
[moq-dev/moq#6407](https://github.com/moq-dev/moq/pull/6407)): the tail test
finishes its track before SUBSCRIBE_OK, so PUBLISH_DONE follows within
milliseconds. The relay's settle grace (about a second) ends long before the
10 s registration wait refuses the FETCH, and the empty subscription stream
for the Largest group then becomes an empty group, which `rust -> rust` and
`rust -> js-native-*` read as "empty group".

Fix it at the publisher: the subscriber cannot recover a head nobody serves,
and other publishers may refuse the same way.

A finished entry holds a `track::Consumer`, which keeps the track's cache
alive, so retaining it costs memory a peer controls. Candidate bounds:
Expand Down Expand Up @@ -60,7 +69,8 @@ Tests, on mocked time with no sleeps, for each of drafts 14 to 19:

- A track that finishes right after SUBSCRIBE_OK, with the joining FETCH
delivered an RTT after PUBLISH_DONE: the FETCH returns the Largest group's
head and the subscriber's track finishes cleanly with it. Fails today.
head and the subscriber's track finishes cleanly with it. Today the FETCH
is refused and the group is lost.
- More finished subscriptions than the limit with no FETCH: retained entries
stay at the limit, the oldest are dropped, and their late FETCHes are
refused. New subscriptions are still admitted.
Expand All @@ -75,5 +85,6 @@ refused.

## Related

- [JS joining FETCH](/quest/m2/ietf-js-joining-fetch.md) - the JS publisher mirrors the bound settled here
- [Interop covers late join and FETCH](/quest/m1/interop-coverage/late-join.md) - the cross-implementation joining FETCH case
- [IETF request order](/quest/m2/ietf-request-order.md) - d14/15 request IDs and their ordering races
67 changes: 67 additions & 0 deletions quest/m2/ietf-js-joining-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# [M] The JS publisher serves the joining FETCH

## Goal

On drafts 14 to 19, the JS publisher answers a single-group joining FETCH
with the head of the group its SUBSCRIBE_OK named as Largest, the way the
Rust publisher does. A Largest Object subscription then gets exactly the
objects it asked for: the head on the fetch stream and the rest on the
subscription, with no gap or overlap. The `tail` interop cells with a
native JS or browser publisher keep passing on every draft, including a
track that finishes right after SUBSCRIBE_OK.

## Plan

Decided with the maintainer on 2026-10-22, after
[moq-dev/moq#6407](https://github.com/moq-dev/moq/pull/6407) made a refused
joining FETCH cost the Rust subscriber only that group's head. Until this
lands, `js/net/src/ietf/publisher.ts` refuses every FETCH, ignores the
filter before draft 20, and serves the latest group whole from object 0,
rounding SUBSCRIBE_OK's Largest to `{G, 0}`.

Three parts, which only work together:

1. **Honor Largest Object before draft 20.** `subscribeRange` serves the
`nextObject` filter from `edge.next`, as draft 20 already does, and
SUBSCRIBE_OK reports the true Largest on every draft. Otherwise the
FETCH's head duplicates the subscription's first objects, and the Rust
subscriber's "a whole group arrived for one the fill already headed" path
truncates the group to the head. JS subscribers send `unfiltered` before
draft 20 and are unaffected. A third-party Largest Object subscriber that
sends no joining FETCH then loses the head, as the draft says it should.
2. **Serve the head.** Keep a per-session registry of joinable SUBSCRIBEs:
their track, the advertised Largest, the SUBSCRIBE_OK properties and
timescale, the ranking, and the unsubscribe signal. `#runFetch` resolves a
joining FETCH against it: unknown subscription is
`invalid_joining_request_id`, no Largest or a start past it is
`invalid_range`, more than one group is `not_supported` (as in Rust and
the draft-20 fill), and a head evicted from the cache is refused before
FETCH_OK. Then it writes FETCH_OK (end `{G, k + 1}`, not end of track) and
a fetch stream named by the FETCH's own request ID, reusing
`#writeFillGroup`. It is not one of the subscription's counted streams.
Codec work: `Fetch` keeps the joining fields; a `FetchOk` encoder for
drafts 14 to 19 (request ID through 16, GROUP_ORDER on 14, empty
parameters, Track Properties from 15); `FetchFrame` writes draft-14's
explicit object layout and the status after an empty payload on 14 and 15.
3. **Answer a FETCH after the subscription ends.** In the tail test the track
is finished before SUBSCRIBE_OK goes out, so PUBLISH_DONE follows at once
and the FETCH arrives to no subscription. Keep a finished subscription's
join answerable under the bound
[Join after a quick finish](/quest/m2/ietf-join-after-finish.md) settles
for Rust, and mirror it here.

Tests: unit tests per draft for each refusal and for a served head (bytes the
Rust subscriber stitches), and the tail cells
`just test interop --tail --publishers js-native-node,js-native-bun --subscribers rust --versions ietf`
plus the browser publisher on drafts 14 to 18.

Public API: none. Wire: the JS publisher answers a joining FETCH it refused,
and serves a Largest Object subscription from past Largest.

## Required

- [Join after a quick finish](/quest/m2/ietf-join-after-finish.md) - settles the bound part 3 reuses

## Related

- [Headless moq-transport groups](/quest/m2/ietf-headless-group.md) - what a subscriber does with a tail whose head never comes
106 changes: 73 additions & 33 deletions rs/moq-net/src/ietf/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3343,7 +3343,6 @@ where
enum End {
Idle,
Revoked,
Unjoined(Error),
Done(Result<ietf::PublishDone<'static>, Error>),
Fetch(group::Request),
Update(Update),
Expand Down Expand Up @@ -3373,8 +3372,7 @@ where
let answered_here = !matches!(self.version, Version::Draft14 | Version::Draft15);

let mut fetch_done = fetching.is_none();
// Our grant stopped covering the track, or its join failed: it is aborted rather than
// kept lingering.
// Our grant stopped covering the track: it is aborted rather than kept lingering.
let mut failed = false;
// How the upstream subscription ended, which ends a listing entry it held.
let mut ended: Option<Result<(), Error>> = None;
Expand All @@ -3399,7 +3397,7 @@ where
{
fetch_done = true;
if let Err(err) = res {
return Poll::Ready(End::Unjoined(err));
tracing::debug!(%err, "joining FETCH failed, joining at the next whole group");
Comment thread
kixelated marked this conversation as resolved.
Resolved
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
Comment thread
kixelated marked this conversation as resolved.
Resolved
}
}
// An error is the track closing, which the arms below report.
Expand Down Expand Up @@ -3496,13 +3494,6 @@ where
ended = Some(Err(Error::Unauthorized));
break true;
}
End::Unjoined(err) => {
tracing::debug!(%err, "joining FETCH failed");
let _ = track.clone().abort(err.clone());
failed = true;
ended = Some(Err(err));
break true;
}
End::Fetch(request) => {
let fetch = self.clone().run_group_fetch(
broadcast_path.to_owned(),
Expand Down Expand Up @@ -3538,7 +3529,6 @@ where
.subscribes
.get(&request_id)
.map(|held| (held.tail.consume(), held.fill.clone()));
let mut unjoined = None;
if let Some((tail, fill)) = held {
let mut settle = Settle::new(&self.runtime, tail);
kio::wait(|waiter| {
Expand All @@ -3548,8 +3538,7 @@ where
{
fetch_done = true;
if let Err(err) = res {
unjoined = Some(err);
return Poll::Ready(());
tracing::debug!(%err, "joining FETCH failed, joining at the next whole group");
}
}
poll_settled(&mut settle, waiter, &fill, count)
Expand All @@ -3561,14 +3550,9 @@ where
fill.end();
}
}
if let Some(err) = unjoined {
tracing::debug!(%err, "joining FETCH failed");
let _ = track.clone().abort(err);
} else {
// A no-op once an END_OF_TRACK declared the end, whose readers wait
// for a missing group only as long as the grace.
let _ = track.finish();
}
// A no-op once an END_OF_TRACK declared the end, whose readers wait
// for a missing group only as long as the grace.
let _ = track.finish();
}
Err(err) => {
tracing::debug!(%err, "subscribe ended with error");
Expand Down Expand Up @@ -3632,7 +3616,7 @@ where
})
.await;
}
// A session abort took the copy too, and a revoked grant or a failed join ended it.
// A session abort took the copy too, and a revoked grant ended it.
if aborted || failed {
return None;
}
Expand Down Expand Up @@ -3876,7 +3860,9 @@ where
/// it: a publisher serves one group per FETCH, so an earlier start's groups are left to
/// group FETCHes of their own. The subscribe's request id names the FETCH. The data
/// arrives on its own fetch stream and [`Self::recv_fill`] stitches it. A refusal or a
/// failed send is an error, since the head it owes is never coming.
/// failed send settles the fill as [`Fill::Done`], as a failed draft-20 fill does: only
/// the head is lost, and a whole group still stands alone. A malformed answer closes
/// the session.
fn start_joining_fetch(&self, subscribe_id: RequestId, track: &track::Producer) -> Option<JoiningTask> {
let fill = self.state.lock().subscribes.get(&subscribe_id)?.fill.clone();
let track = track.clone();
Expand Down Expand Up @@ -3958,10 +3944,21 @@ where
this.finish_joining_fetch(stream, progress).await
}
.await;
// Release a mid-group tail parked on the head.
// A refusal costs only the head, but a malformed answer is the peer breaking the
// protocol, which closes the session as it would on any request.
if let Err(err) = &res
&& is_protocol_violation(err)
{
this.session.close(
super::error::to_session_code(&SessionError::from(err)),
err.to_string().as_ref(),
);
}
// Release a mid-group tail parked on the head, including one still being written:
// a request that failed after FETCH_OK cannot be trusted to finish its stream.
if res.is_err()
&& let Ok(mut state) = fill.write()
&& matches!(*state, Fill::Requested | Fill::Serving(_))
&& matches!(*state, Fill::Requested | Fill::Serving(_) | Fill::Active)
{
*state = Fill::Done;
Comment thread
kixelated marked this conversation as resolved.
Resolved
Comment thread
kixelated marked this conversation as resolved.
Resolved
}
Expand Down Expand Up @@ -15665,6 +15662,28 @@ mod joining_fetch_tests {
revoked_child_fetch(true).await;
}

/// From draft 18 the joining FETCH's request stays open after FETCH_OK. Its failure while
/// the head is still being written settles the fill, so a mid-group tail is not parked
/// on a head that may never finish.
#[moq_clock::test]
async fn a_request_failing_mid_head_settles_the_fill() {
for version in [Version::Draft18, Version::Draft19] {
let session = ScriptedSession::per_stream_reset(vec![fetch_ok(version)]);
let (subscriber, track, _tasks) = pending_join(session, version);
let fill = subscriber.state.lock().subscribes[&RequestId(99)].fill.clone();
// A fetch stream is writing the head.
if let Ok(mut state) = fill.write() {
*state = Fill::Active;
}
let mut joining = subscriber.start_joining_fetch(RequestId(99), &track).unwrap();
assert!(
kio::wait(|waiter| joining.poll(waiter)).await.is_err(),
"{version}: the reset request fails"
);
assert!(matches!(*fill.read(), Fill::Done), "{version}: the head is released");
}
}

#[moq_clock::test]
async fn invalid_joining_open_is_refused() {
for version in JOINING_DRAFTS {
Expand Down Expand Up @@ -15846,10 +15865,12 @@ mod joining_fetch_tests {
}
}

/// The peer refusing the joining FETCH fails the subscription with its reason, rather
/// than leaving readers waiting on a head that is never coming.
/// A publisher that serves no FETCH refuses the joining FETCH. That costs the head of
/// the Largest group and nothing more, as a failed draft-20 fill does: the fill settles,
/// so a stream starting mid-group no longer waits on it, and the subscription keeps
/// delivering whole groups.
#[moq_clock::test]
async fn a_refused_fetch_fails_the_subscription() {
async fn a_refused_fetch_joins_at_the_next_whole_group() {
let largest = Some(ietf::Location { group: 4, object: 1 });
for version in JOINING_DRAFTS {
let mut run = JoinRun::start(version, None, subscribe_ok(version, largest), fetch_error(version)).await;
Expand All @@ -15858,12 +15879,31 @@ mod joining_fetch_tests {
.expect("SUBSCRIBE_OK accepted the track")
.unwrap();
assert!(
matches!(received.finished().now_or_never(), Some(Err(Error::Unsupported))),
"{version}"
received.finished().now_or_never().is_none(),
"{version}: the track is still live"
);
assert!(!run.fill_outstanding(), "{version}: no head is coming");
assert!(run.session.log.closes().is_empty(), "{version}: the session stays up");
}
}

/// A malformed answer to the joining FETCH is not a refusal: the peer broke the
/// protocol, so the session closes.
#[moq_clock::test]
async fn a_malformed_fetch_answer_closes_the_session() {
let largest = Some(ietf::Location { group: 4, object: 1 });
for version in JOINING_DRAFTS {
// A SUBSCRIBE_OK where FETCH_OK or a refusal belongs.
let run = JoinRun::start(
version,
None,
subscribe_ok(version, largest),
subscribe_ok(version, largest),
)
.await;
assert!(
run.subscriber.state.lock().subscribes.is_empty(),
"{version}: the subscription is cancelled upstream"
!run.session.log.closes().is_empty(),
"{version}: an unexpected answer closes the session"
);
}
}
Expand Down
Loading