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
5 changes: 3 additions & 2 deletions doc/concept/moq-lite.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,9 @@ moq-lite-07 carries range by range and older wire versions as the single span
covering them. A relative or time anchor resolves on the hop that publishes the
track, and over moq-lite-07, which carries a relative or time start upstream and
reports the live edge and media time, so a copy resolves the ends itself. A Rust
moq-transport copy accepts anchors its cache can already
resolve and sends group bounds upstream; it refuses an unknown time end. Older
moq-transport copy resolves a relative anchor from the Largest Object its live join
reports, accepts time anchors its cache can already resolve, and sends group bounds
upstream; it refuses any other time anchor. Older
moq-lite versions accept absolute anchors but refuse time anchors and relative anchors other
than the live and default starts. An untimed track refuses a time anchor. At the live
edge, a time end
Expand Down
2 changes: 1 addition & 1 deletion quest/m1/lite07-finalize.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ timestamp bound in [#6168](https://github.com/moq-dev/moq/pull/6168).

- [Routes and announces](/quest/m1/cluster-routing/routes.md) - lite-07 carries the route layer: ROUTE per origin node and path-less ANNOUNCE, with the hop list gone
- [Drop set](/quest/m1/drop-set.md) - lite-07's SUBSCRIBE_DROP carries `Max Age`, so a widening re-offers groups reported dropped
- [Lite-07 ranges](/quest/m1/subscribe-ranges/lite.md) - a relay fills a lite-07 upstream through the subscription, and moq-transport carries the anchors it can
- [Lite-07 ranges](/quest/m1/subscribe-ranges/lite.md) - a relay fills a lite-07 upstream through the subscription
- [JS ranges](/quest/m1/subscribe-ranges/js.md) - JS speaks lite-07 ranges
- [Remove FETCH from lite-07](/quest/m1/subscribe-ranges/lite07-fetch.md) - lite FETCH is gone from lite-07, in Rust and JS
- [Lite-07 by start](/quest/m1/time-addressing/lite07.md) - lite-07 carries group starts, previous-start links, GROUP_END, and time bounds instead of sequence numbers
Expand Down
4 changes: 2 additions & 2 deletions quest/m1/subscribe-ranges/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ relay bounds a sparse FETCH only if the model can request ranges:
still caps every range, so `Absolute(0)..` means everything not stale.
A relay that cannot resolve a relative end locally forwards it upstream as
relative over lite-07; a moq-transport bridge resolves it to an absolute
Group ID first ([Lite-07 ranges](/quest/m1/subscribe-ranges/lite.md),
decided 2026-10-27).
Group ID first, from its cache or the Largest Object of a live join
(decided 2026-10-27).
- **Time ends** (maintainer, 2026-10-17, for DVR seek in the
[archive line](/quest/m1/archive/README.md)). A range end may also be
`Time(pts)`, in the track's timescale. Whoever holds the track resolves it:
Expand Down
22 changes: 1 addition & 21 deletions quest/m1/subscribe-ranges/lite.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

## Goal

A relay fills a lite-07 upstream by subscribing to the missing ranges. Older
wires and moq-transport carry the anchors they can, and refuse only the rest. FETCH stays on lite-07 until
A relay fills a lite-07 upstream by subscribing to the missing ranges. FETCH stays on lite-07 until
[Remove FETCH from lite-07](/quest/m1/subscribe-ranges/lite07-fetch.md)
removes it from both implementations.

Expand Down Expand Up @@ -51,25 +50,6 @@ resolve no SUBSCRIBE_START, so a FIN overtaking them leaves the receiver no
owed range to wait on. Datagram fills need the receiver told what is owed
first.

### moq-transport anchors

Decided 2026-10-27 (maintainer): a bridge never sends a relative anchor to
moq-transport. It resolves `Relative(n)` to an absolute Group ID, from its
cache or the live edge, before sending, replacing the planned mapping of
`Relative(n)..` onto draft-22's `Filter::Relative(n + 1)` and draft 18's
relative joining FETCH. Reason: both count back by Group ID arithmetic, which
breaks once [time addressing](/quest/m1/time-addressing/model.md) makes legacy
Group IDs sparse start ticks. A range with a bounded end
resolves both bounds against the Largest Object and goes upstream as an
absolute range. Live keeps today's join (`ietf::subscriber::subscribe_join`). A copy already
resolves what its cache settles (`ResolvedRanges`, from
[moq-dev/moq#6815](https://github.com/moq-dev/moq/pull/6815)) and refuses the
rest (`anchored_cached`); what remains is a cold copy resolving `Relative(n)`
from the Largest Object of a live join instead of refusing it.
Each mapping that makes a wire carry an anchor lifts that wire's
`Unsupported` refusal for it, and extends the per-wire table in
`rs/moq-net/tests/integration/range_anchors.rs`.

Update `drafts/draft-lcurley-moq-lite.md` with each wire change here. Run
`just drafts check` and `just test interop --all`.

Expand Down
78 changes: 74 additions & 4 deletions rs/moq-net/src/ietf/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2943,8 +2943,16 @@ impl Subscriber {
None => Ok(subscription),
})
.transpose();
// A relative anchor the copy cannot settle yet counts back from the Largest Object, so
// the live join that names it goes first and the answer resolves the anchor. No Group ID
// arithmetic spells it upstream. A time anchor names no group the answer settles.
let deferred = matches!(subscription, Err(Error::Unsupported))
&& target
.subscription()
.is_some_and(|subscription| !has_time(&subscription));
let subscription = match subscription {
Ok(subscription) => subscription,
Err(_) if deferred => None,
Err(err) => {
target.fail(err);
return None;
Expand Down Expand Up @@ -3420,6 +3428,11 @@ impl Subscriber {
// the group carries over: its first frame is the edge a reader can count on.
if let Some(largest) = largest {
track.report_object(largest.group, largest.object);
// A live join's Largest is where its feed is, which a relative anchor counts back
// from even when a newer group lands before the joined one.
if live {
track.report_edge(largest.group);
}
}
// A live join starts at the publisher's edge; an absolute one where it asked. With
// no Largest the join skips nothing, so every group is owed: a lower one's stream
Expand All @@ -3431,6 +3444,14 @@ impl Subscriber {
if let Some(staged) = staged {
staged.commit();
}
// Resolved while the answer's Largest is still the live edge: no data stream reaches
// the copy before its alias is bound below.
let settled = match deferred {
true => track
.subscription()
.map(|subscription| (settle_bounds(&mut resolved, &track, &subscription), subscription)),
false => None,
};
let mut fetching: Option<JoiningTask> = None;
{
let mut state = self.state.lock();
Expand Down Expand Up @@ -3490,6 +3511,17 @@ impl Subscriber {
let mut priority = priority;
let mut sent_bounds = (start, subscription.as_ref().and_then(|subscription| subscription.end()));
let mut wanted_bounds = Ok(sent_bounds);
// A deferred relative anchor, until the copy learns the live edge it counts back from:
// an answer with no Largest leaves it to the first group. The bounds it then resolves
// to go upstream as an update, absolute like any other.
let mut unsettled = None;
match settled {
Some((Ok(Some(bounds)), _)) => wanted_bounds = Ok(bounds),
Some((Ok(None), subscription)) => unsettled = Some(subscription),
Some((Err(err), _)) => wanted_bounds = Err(err),
None => {}
}
let mut edge = track.consume();
// REQUEST_UPDATEs sent and not yet answered.
let unanswered = AtomicU64::new(0);

Expand Down Expand Up @@ -3561,16 +3593,30 @@ impl Subscriber {
subscribed = subscription
.as_ref()
.is_some_and(|subscription| !subscription.ranges.is_empty());
unsettled = None;
if let Some(subscription) = subscription {
priority = subscription.priority;
wanted_bounds = resolved
.resolve(&track, &subscription)
.map(|subscription| wire_bounds(&subscription));
match settle_bounds(&mut resolved, &track, &subscription) {
Ok(Some(bounds)) => wanted_bounds = Ok(bounds),
Ok(None) => unsettled = Some(subscription.clone()),
Err(err) => wanted_bounds = Err(err),
}
if max_age_supported {
wanted_max_age = Some(super::max_age::millis(subscription.budget()));
}
}
}
if let Some(subscription) = &unsettled {
while let Poll::Ready(Some(_)) = edge.poll_largest(waiter) {}
match settle_bounds(&mut resolved, &track, subscription) {
Ok(Some(bounds)) => {
wanted_bounds = Ok(bounds);
unsettled = None;
}
Ok(None) => {}
Err(err) => return Poll::Ready(End::Invalid(err)),
}
}
loop {
match demand.poll_wanted_changed(waiter) {
Poll::Ready(Ok(next)) => wanted = next,
Expand Down Expand Up @@ -12004,6 +12050,27 @@ impl ResolvedRanges {
}
}

/// The wire bounds `subscription` resolves to, `None` while a relative anchor still waits
/// for the live edge it counts back from.
fn settle_bounds(
resolved: &mut ResolvedRanges,
track: &track::Producer,
subscription: &track::Subscription,
) -> Result<Option<WireBounds>, Error> {
match resolved.resolve(track, subscription) {
Ok(subscription) => Ok(Some(wire_bounds(&subscription))),
Err(Error::Unsupported) if !has_time(subscription) => Ok(None),
Err(err) => Err(err),
}
}

fn has_time(subscription: &track::Subscription) -> bool {
subscription
.ranges
.iter()
.any(|range| matches!(range.start, track::Anchor::Time(_)) || matches!(range.end, Some(track::Anchor::Time(_))))
}

fn needs_resolution(subscription: &track::Subscription) -> bool {
subscription.ranges.iter().any(|range| {
let start = match range.start {
Expand All @@ -12015,8 +12082,11 @@ fn needs_resolution(subscription: &track::Subscription) -> bool {
})
}

/// A subscription's single wire span: its start and exclusive end group, each open when `None`.
type WireBounds = (Option<u64>, Option<u64>);

/// The single wire span covers mixed absolute/live starts from group zero.
fn wire_bounds(subscription: &track::Subscription) -> (Option<u64>, Option<u64>) {
fn wire_bounds(subscription: &track::Subscription) -> WireBounds {
let start = subscription.start().or_else(|| {
subscription
.ranges
Expand Down
5 changes: 3 additions & 2 deletions rs/moq-net/src/model/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ pub enum Order {
/// it answers, never from the groups an ended feed left in its cache.
///
/// Over moq-lite-07, a copy resolves them from the reported live edge and media time.
/// A Rust moq-transport copy accepts anchors its cache can already resolve, translating
/// them to group bounds upstream; an unknown time end is refused. Older moq-lite versions
/// A Rust moq-transport copy resolves a relative anchor from the Largest Object its live
/// join reports, and accepts time anchors its cache can already resolve, translating both
/// to group bounds upstream; any other time anchor is refused. Older moq-lite versions
/// accept absolute anchors but refuse time anchors and relative anchors other
/// than [`Range::live`] and [`Range::oldest`] with [`Error::Unsupported`](crate::Error::Unsupported)
/// rather than guess from a partial copy.
Expand Down
42 changes: 38 additions & 4 deletions rs/moq-net/src/model/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@ pub(crate) struct TrackState {
// Whether a received copy's wire tells it what relative and time anchors resolve
// against, so they resolve here as at the publisher.
anchored: bool,
// This copy can translate only anchors its cache has already settled.
// This copy can translate only time anchors its cache has already settled. A relative one
// waits for the live edge its wire reports, as on an `anchored` copy.
cached_anchors: bool,
// Whether readers ask no fills below `start_sequence`: its publisher resolved it from the
// budget, but neither this copy's timestamps nor a fill can judge an older group against
Expand Down Expand Up @@ -3349,7 +3350,8 @@ impl Producer {
}
}

/// Let readers use only anchors this cache can already translate to group bounds.
/// Let readers use only time anchors this cache can already translate to group bounds. A
/// relative anchor counts back from the live edge the wire reports, once it does.
#[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))]
pub(crate) fn anchored_cached(&self) {
if let Ok(mut state) = self.modify() {
Expand Down Expand Up @@ -3416,6 +3418,18 @@ impl Producer {
}
}

/// The live feed's route answered that it reaches `group`: a relative start counts back
/// from it, rather than from whichever group lands first. A no-op unless live.
#[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))]
pub(crate) fn report_edge(&self, group: u64) {
if let Ok(mut state) = self.modify()
&& let Feed::Live { first, edge } = &mut state.feed
{
*edge = (*edge).max(Some(group));
first.get_or_insert(group);
Comment on lines +3425 to +3429

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the answered edge when resuming an idle copy

When a returning subscriber requests Relative(2) on an idle moq-transport copy, subscribe_once defers resolution, but this guard discards the answer's Largest because the feed is still Feed::Idle. If Largest names group 4 and group 5 arrives before group 4, the resume loop's set_live calls go_live, which initializes first from the newest produced group, 5. Both the reader and the deferred upstream bounds then resolve the start to 3 instead of 2, silently omitting requested history. Preserve the answered anchor across the idle-to-live transition without making stale cached data readable prematurely. This also violates the warm/cold upstream-state invariant in rs/moq-net/AGENTS.md.

AGENTS.md reference: rs/moq-net/AGENTS.md:L8-L8

Useful? React with 👍 / 👎.

}
}

/// Record the upstream Object ID separately from the frame ordinal readers count.
#[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))]
pub(crate) fn report_object(&self, group: u64, object: u64) {
Expand Down Expand Up @@ -7009,9 +7023,9 @@ impl Control {
}
}

/// A group-only wire refuses an unresolved anchor before changing shared demand.
/// A group-only wire refuses an unresolved time anchor before changing shared demand.
fn refuse_cached_anchors(state: &TrackState, subscription: &Subscription) -> Result<()> {
if state.cached_anchors && subscription.ranges.iter().any(|range| !range.is_wire()) {
if state.cached_anchors && subscription.has_time() {
let window = Window::new(&subscription.ranges, state.latest_live(), state)?;
if !window.is_settled() {
return Err(Error::Unsupported);
Expand Down Expand Up @@ -9054,6 +9068,26 @@ mod test {
assert_eq!(ready_groups(&mut reader), vec![5]);
}

/// A live join's answer anchors a relative start where it says the feed is, both for the
/// copy's readers and for the bounds sent upstream, even once a newer group lands before
/// the one it named.
#[test]
fn a_relative_start_counts_from_the_answered_edge() {
let producer = track_producer("test", Info::default());
let back = Range {
start: super::super::subscription::Anchor::Relative(2),
end: None,
};
let mut reader = producer.subscribe(replay().with_ranges([back]));
producer.report_edge(4);
let upstream = producer.resolve_subscription(&replay().with_ranges([back])).unwrap();
assert_eq!(upstream.start(), Some(2), "the answer resolves the upstream bounds");

framed(&producer, 5, 1).finish().unwrap();
assert_eq!(ready_groups(&mut reader), vec![5]);
assert_eq!(reader.floor(), Some(2), "the answer anchors the start");
}

/// An idle copy forgets the edge its previous feed answered with, which only a datagram
/// it dropped showed: when it ends without going live, a relative start counts back
/// from its newest cached group.
Expand Down
14 changes: 11 additions & 3 deletions rs/moq-net/tests/integration/range_anchors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

//! A range anchored relative to the latest group or at a presentation time resolves where
//! the track is held, and on a copy received over a wire that tells it enough to resolve
//! the anchor the same way. A copy received over any other wire refuses the anchor instead
//! of resolving it against the part of the track it happens to hold.
//! the anchor the same way. A moq-transport copy resolves a relative anchor from the
//! Largest Object its live join reports. A copy received over any other wire refuses the
//! anchor instead of resolving it against the part of the track it happens to hold.

use crate::support;

Expand Down Expand Up @@ -128,8 +129,15 @@ async fn each_wire_refuses_only_the_anchors_it_drops() {
Some("moq-lite-03" | "moq-lite-04" | "moq-lite-05" | "moq-lite-06")
);
for (range, held) in anchored() {
let result = read(version, range).await;
let mut result = read(version, range).await;
let time = matches!(range.start, Anchor::Time(_)) || matches!(range.end, Some(Anchor::Time(_)));
// A moq-transport copy joins live and resolves a relative anchor from the Largest
// Object, so the groups below it arrive as fills, after the live one.
let transport = matches!(version, Some(version) if version.starts_with("moq-transport"));
let carried = carried || (transport && !time);
if transport && let Ok(read) = &mut result {
read.sort_unstable();
}
match (&result, time && !timed, carried) {
(Err(Error::TimestampMismatch), true, _) => {}
(Err(Error::Unsupported), false, false) => {}
Expand Down
Loading