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
8 changes: 8 additions & 0 deletions .cargo/mutants.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ exclude_re = [
# they place and backfill as before, and each copy's replace of equal ranges is a no-op,
# so treating them as unchanged only saves that work.
'replace match guard ranges == self.mirrored.ranges with false in Reader::sync$',
# A backfill fails only with its route's track, so asking that route again for what it
# refused fails at once too and is let go: skipping the ask only saves the subscribe.
# `poll_lowest` records that refusal for the skip.
':\d+:19: replace <= with > in Reader::backfill$',
':\d+:30: replace == with != in Reader::poll_lowest$',
# With no resume point `raised` names no start, and a settled window has no unsettled
# range: each guard only skips the walk.
'replace \|\| with && in Reader::raised$',
# Dead: every write of `until` also writes `since`, so the superseded check
# never runs. `ResumeReader.tla` models it, so it goes with the model.
'replace >= with < in Copy::retains$',
Expand Down
80 changes: 51 additions & 29 deletions quest/m0/nightly/resume-route-mutants.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [S] No resume or relay route mutant survives
# [M] No resume or relay route mutant survives

## Goal

Expand All @@ -7,35 +7,57 @@ Nightly's mutants shards report no survivors in

## Plan

Found by the 2026-11-20 triage of Nightly run
[44767045952](https://github.com/moq-dev/moq/actions/runs/44767045952).
[moq-dev/moq#9294](https://github.com/moq-dev/moq/pull/9294) killed or excluded
27 of its 30 survivors. Three remain in `resume.rs`, in `unraised`: `start < floor`
to `<=`, and the `end < floor` guard as `true` or `<=`. They decide only an anchor
exactly at the resume point, or a time end above it; probes of both, with the
replacement holding and lacking the floor group, read the same groups.
[moq-dev/moq#9278](https://github.com/moq-dev/moq/pull/9278) deletes `unraised` for
`raised`, which keeps only the `time < floor` guard: once it lands or closes, rerun
`cargo mutants -f rs/moq-net/src/model/resume.rs --re raised` and kill or exclude
what survives.

[moq-dev/moq#9276](https://github.com/moq-dev/moq/pull/9276) resumes every reader
at the switch's boundary, the largest group held. So
`the_fronts_subscription_resumes_at_the_boundary_whichever_reader_is_behind`
(formerly `..._past_the_reader_furthest_behind`) no longer tells readers apart,
and `Resume::add`'s `at <= next` may survive again. To reach the comparison, both
readers need a held head at their boundary: `held_at` returns `None` for a reader
that handed out a group past every group its copies hold, and `Resume::add` then
takes `Whole` first. So readers' positions differ only when their copies differ,
such as one still holding a replaced or backfill copy with a later group, or more
of the boundary group's frames. Kill it with two such readers, or exclude it as
equivalent if no such pair is reachable.

Line numbers drift; rerun `cargo mutants -f <file>` on current main first.
A local run on 2026-11-21 (`cargo mutants --in-diff` over `resume.rs` and `route/`
since Nightly's base 9df4313a, plus `--re 'in (Resume::add|Reader::resumed)$'`) found 34
survivors, most from [moq-dev/moq#9278](https://github.com/moq-dev/moq/pull/9278) and
[moq-dev/moq#9307](https://github.com/moq-dev/moq/pull/9307). The first PR on this quest
killed or excluded 18. Line numbers are from that run; rerun
`cargo mutants -f rs/moq-net/src/model/resume.rs` on current main first, since they drift.
Kill each with a unit test, or exclude it in `.cargo/mutants.toml` when it changes nothing
observable.

These 16 remain, with what is known about each:

- `Reader::resumed` (1792:16 `&&` to `||`, 1796:9 guard `failed` to `false`, 1799:10
guard `current` to `true` and to `false`, 1803:5 and 1804:5 deleting `ranges` and
`delay`): the resolution here mostly vanishes under `clamped`'s raise to the boundary.
A resolved start is never past the boundary, and an end past it does not resolve. Only
a live join resolves to `None` rather than a raised start, which is the only case that can
kill these. Under the test helpers, a group's start, its key, and its timestamp coincide,
which hides any difference between a time and a key.
- `Reader::window` 1867:68 `<` to `>`, the cap filter on a resolved end: the serving copy
usually resolves the same end, so a test needs a capped copy to be the only one that can
place it.
- `Reader::resolve` 1901:26 `>` to `>=`, a time start of 0 waiting on a copy: a probe from
time 0 under the resume point placed the range at 0 and read the same groups either
way, because `backfill_gaps` places a raised start the reader holds at its own time.
Probably equivalent.
- `Reader::drained` returning `true`, and 2303:21 `&&` to `||` (resetting `since` on
replaced copies a group already superseded): the reader's own delivery budget gives up
the same gaps at the same time, so a test needs a gap younger than the copy's `since`.
Returning `true` differs only when the route ended cleanly while the serving copy failed
or no copy serves, where the track then waits for the replaced copies instead of ending.
- `Reader::poll_lowest` 2544:33 `&&` to `||` (a backfill copy of the serving route that
reads late counts as serving): that copy reruns `backfill_gaps`, whose widening of a
reused backfill resets that copy's `since`. A test would need that later budget to matter.
- `Reader::backfill` 2928:18 `|=` to `&=`: needs a b→c→b flap that widens a reused
backfill with a raised start.
- `Reader::backfill_gaps` 2999:17 `<` to `<=` (probably equivalent, since `resolve` with an
empty map differs from `window()` only while no copy has answered), 3025:19 guard to
`false` and 3025:56 `>` to `<` (no reachable case found where the replaced copy's
resolution of a start differs from the window's floor), 3073:71 `<` to `<=` (a range
starting exactly at the resume point. It is delivered or drained either way, so this looks
equivalent).

Whoever kills the `resolve` and `backfill_gaps` survivors also settles a possible
late-group ordering bug found while probing them, with a test, and fixes it if it is one.
Setup: a reader updates to `from(8)`, exactly at the replacement's resume point, while
the replacement is an empty received copy. Its window placed the range at start 0 rather
than floored, so a late group 7 went out after group 8 (which holds time 8) was already
delivered from the old route. It may match what a plain reader of that empty route does.

Public API: none. Wire: none.

## Waiting
## Required

- moq-dev/moq: [moq-dev/moq#9278](https://github.com/moq-dev/moq/pull/9278) lands or
closes; check with `gh pr view 9278 --json state`.
- [Resumed read ends once its window is accounted for](/quest/m0/nightly/resume-exhausted-skips.md) - its rework of `model/resume.rs` must land first, since these survivors' lines and behavior move with it
207 changes: 207 additions & 0 deletions rs/moq-net/src/model/resume.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5084,6 +5084,38 @@ mod test {
);
}

/// A verdict from the copy serving now ends the group, though the replaced copy it moved
/// off still holds the rest: only a newer route or a delivery failure looks past it.
#[test]
#[cfg(feature = "async")]
fn the_serving_copys_verdict_stands_over_a_replaced_copy_holding_the_group() {
let routes = Producer::new();
let logical = logical(&routes);
let a = copy();
routes.serve(a.consume());
let mut sub = subscribe(&logical, Duration::from_secs(10));
let mut open = a.create_group(group::Info { start: 0 }).unwrap();
open.write_frame(ts(0), b"a".as_ref()).unwrap();
let mut reading = recv(&mut sub);
assert_eq!(read(&mut reading), Some(b"a".to_vec()));

let b = copy();
let mut repeat = b.create_group(group::Info { start: 0 }).unwrap();
for (ms, frame) in [(0, b"a"), (1, b"b")] {
repeat.write_frame(ts(ms), frame.as_ref()).unwrap();
}
routes.serve(b.consume());
assert_eq!(read(&mut reading), Some(b"b".to_vec()), "the stall moved to b");

for (ms, frame) in [(1, b"b"), (2, b"c")] {
open.write_frame(ts(ms), frame.as_ref()).unwrap();
}
open.finish().unwrap();
repeat.abort(Error::WrongSize).unwrap();
let res = reading.read_frame().now_or_never();
assert!(matches!(res, Some(Err(Error::WrongSize))), "{res:?}");
}

/// A group the replaced copy closed short (a FIN without GROUP_END) continues from the
/// replacement at the next frame, whichever of the close and the switch the reader sees
/// first, and ends where the replacement ends it.
Expand Down Expand Up @@ -10169,6 +10201,74 @@ mod test {
assert_eq!(sub.resolved_range(0).map(|resolved| resolved.start), Some(6));
}

/// A reader of time 5 on, which read groups 5 to 8 from copy `a` before the switch to `b`,
/// an empty received copy that resumes at 8: the routes, the logical track, `a`, `b`, and
/// the reader.
fn read_to_8() -> (
Producer,
track::Producer,
track::Producer,
track::Producer,
track::Subscriber,
) {
let routes = Producer::new();
let logical = logical(&routes);
let a = received_copy();
for key in 5..=8 {
write(&a, key);
}
routes.serve(a.consume());
let mut sub = logical
.consume()
.subscribe(from_times(&[5]))
.now_or_never()
.unwrap()
.unwrap();
let mut read = drain(&mut sub, false);
read.sort_unstable();
assert_eq!(read, [5, 6, 7, 8]);
let b = received_copy();
routes.serve(b.consume());
assert_eq!(drain(&mut sub, false), Vec::<u64>::new());
(routes, logical, a, b, sub)
}

/// A subscription of a range from each time, within an hour.
fn from_times(times: &[u64]) -> Subscription {
Subscription::default()
.with_delay(Delay::default().with_max(HOUR))
.with_ranges(times.iter().map(|time| track::Range {
start: Some(*time),
end: None,
}))
}

/// A raised time start whose groups from its time the reader already holds is placed at
/// its time, with no backfill.
#[test]
fn a_raised_start_the_reader_holds_places_at_its_time() {
let (routes, _logical, a, _b, mut sub) = read_to_8();
a.abort(Error::Cancel).unwrap();
sub.update(from_times(&[6])).unwrap();
assert_eq!(drain(&mut sub, false), Vec::<u64>::new());
assert_eq!(sub.resolved_range(0).map(|resolved| resolved.start), Some(6));
assert_eq!(copies(&routes), 1, "nothing is backfilled");
}

/// As [`a_raised_start_the_reader_holds_places_at_its_time`], beside a range still waiting
/// on its anchors: the raised start is placed only once every other range is.
#[test]
fn a_held_raised_start_waits_for_a_range_beside_it() {
let (_routes, _logical, a, b, mut sub) = read_to_8();
a.abort(Error::Cancel).unwrap();
sub.update(from_times(&[6, 20])).unwrap();
assert_eq!(drain(&mut sub, false), Vec::<u64>::new());
assert_eq!(sub.resolved_range(0), None, "waits for the range beside it");
write(&b, 20);
assert_eq!(drain(&mut sub, false), [20]);
assert_eq!(sub.resolved_range(0).map(|resolved| resolved.start), Some(6));
}

/// As [`a_backfill_places_a_time_start_its_serving_copy_raised`], for a range that ends
/// past the resume point: the backfill, capped under it, places only the start, and the
/// read ends at the range's own end.
Expand Down Expand Up @@ -11242,6 +11342,113 @@ mod test {
}
}

/// A group a replaced copy got past its cap is no group it drains: a later switch asks the
/// next route for it, though that copy stays for a group still read from it.
#[test]
fn a_group_past_a_replaced_copys_cap_is_backfilled() {
let routes = Producer::new();
let logical = logical(&routes);
let a = received_copy();
routes.serve(a.consume());
let mut sub = subscribe(&logical, HOUR);
for key in 0..=4 {
write(&a, key);
}
assert_eq!(drain(&mut sub, false), [0, 1, 2, 3, 4]);
let mut open = a.create_group(group::Info { start: 5 }).unwrap();
open.write_frame(ts(5), b"x".as_ref()).unwrap();
let reading = recv(&mut sub);
assert_eq!(reading.start, 5);
let b = received_copy();
routes.serve(b.consume());
write(&b, 7);
assert_eq!(drain(&mut sub, false), [7]);
// Past the cap at 5, so a never hands it out.
write(&a, 6);
assert_eq!(drain(&mut sub, false), Vec::<u64>::new());
let c = received_copy();
routes.serve(c.consume());
assert_eq!(drain(&mut sub, false), Vec::<u64>::new());
write(&c, 6);
assert_eq!(drain(&mut sub, false), [6]);
drop(reading);
}

/// A group one route refused to backfill is still asked of the next route, though the
/// reader's preferences never changed.
#[test]
fn a_group_one_route_refused_is_backfilled_by_the_next() {
let routes = Producer::new();
let logical = logical(&routes);
let a = received_copy();
routes.serve(a.consume());
let mut sub = subscribe(&logical, HOUR);
for key in 0..=4 {
write(&a, key);
}
assert_eq!(drain(&mut sub, false), [0, 1, 2, 3, 4]);
let mut open = a.create_group(group::Info { start: 5 }).unwrap();
open.write_frame(ts(5), b"x".as_ref()).unwrap();
let reading = recv(&mut sub);
let b = received_copy();
routes.serve(b.consume());
write(&b, 7);
assert_eq!(drain(&mut sub, false), [7]);
write(&a, 6);
assert_eq!(drain(&mut sub, false), Vec::<u64>::new());
// c's backfill of group 6 fails with its route.
let c = received_copy();
routes.serve(c.consume());
assert_eq!(drain(&mut sub, false), Vec::<u64>::new());
c.abort(Error::Cancel).unwrap();
assert_eq!(drain(&mut sub, false), Vec::<u64>::new());
let d = received_copy();
routes.serve(d.consume());
write(&d, 6);
assert_eq!(drain(&mut sub, false), [6]);
drop(reading);
}

/// A front asks its next route from the lowest boundary among its readers, though only one
/// still keeps a replaced copy holding a group past that copy's cap.
#[test]
fn the_fronts_subscription_resumes_at_the_lowest_boundary_when_one_reader_keeps_a_replaced_copy() {
for keeper_first in [true, false] {
let routes = Producer::new();
let front = logical(&routes);
let a = received_copy();
routes.serve(a.consume());
let mut first = subscribe(&front, HOUR);
let mut second = subscribe(&front, HOUR);
for key in 0..=4 {
write(&a, key);
}
assert_eq!(drain(&mut first, false), [0, 1, 2, 3, 4]);
assert_eq!(drain(&mut second, false), [0, 1, 2, 3, 4]);
let mut open = a.create_group(group::Info { start: 5 }).unwrap();
open.write_frame(ts(5), b"x".as_ref()).unwrap();
let (keeper, other) = match keeper_first {
true => (&mut first, &mut second),
false => (&mut second, &mut first),
};
// Only the keeper still reads group 5, so only it keeps `a` after the switch.
let reading = recv(keeper);
drop(recv(other));
let b = received_copy();
routes.serve(b.consume());
write(&b, 7);
assert_eq!(drain(keeper, false), [7]);
assert_eq!(drain(other, false), [7]);
// Past a's cap: only the keeper's boundary sees it.
write(&a, 8);
assert_eq!(drain(keeper, false), Vec::<u64>::new());
assert_eq!(drain(other, false), Vec::<u64>::new());
let resume = routes.subscription(front.subscription().unwrap(), 2).resume;
assert_eq!(resume, Some(Position::new(7, 1)), "keeper_first={keeper_first}");
drop(reading);
}
}

/// A stalled read still waiting for the new route to continue it is judged within the
/// reader's window too: the new route's groups in it expire the read, though its
/// subscription starts past them.
Expand Down