Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
85ab682
chore(quest): claim quest/m1/arrival-group-order.md
kixelated Nov 24, 2026
34de93f
feat(net): an arrival read picks its held groups in Group Order
kixelated Nov 24, 2026
c868570
feat(net): order held groups for every reader and publisher test
kixelated Nov 24, 2026
0d82ee4
test: read held backlogs oldest first where a test drains them in order
kixelated Nov 24, 2026
68aaa77
feat(js/net): an arrival read picks its held groups in Group Order
kixelated Nov 24, 2026
d143989
chore: model the Group Order pick in verify-resume and finish the quest
kixelated Nov 24, 2026
6adda2d
docs: link the follow-up quests and verify-resume coverage to the PR
kixelated Nov 24, 2026
38c254f
fix(net): bound an arrival read's owed runs by the cache, and read be…
kixelated Nov 24, 2026
eeda18c
chore(quest): file the track benches already broken on main
kixelated Nov 24, 2026
5082801
Merge origin/main into quest/m1/arrival-group-order
kixelated Nov 24, 2026
c1d327a
chore(quest): record the maintainer's keep answers for the follow-ups
kixelated Nov 24, 2026
e6289d7
fix(net): an arrival peek and a JS publisher's start pass a group the…
kixelated Nov 24, 2026
6c6107f
perf(net): a JS publisher's start walks its given-up runs once
kixelated Nov 24, 2026
b457817
fix(net): address CodeRabbit's findings on the arrival Group Order
kixelated Nov 25, 2026
ee51884
Merge remote-tracking branch 'origin/main' into HEAD
kixelated Nov 25, 2026
ce74677
fix(net): a front's lowest unread group comes from the copy serving m…
kixelated Nov 25, 2026
2fd1028
fix(net): a peek through an inner front offers its copies' first grou…
kixelated Nov 25, 2026
52cc9a8
Merge remote-tracking branch 'origin/main' into HEAD
kixelated Nov 25, 2026
3ab4b32
test(net): main's new resume tests read held groups in Group Order
kixelated Nov 25, 2026
8dc01c0
fix(net): keep a fresh buffered group past a write-off, and peek a re…
kixelated Nov 25, 2026
66fabf4
fix(net): judge filled groups in the oldest write-off, and re-offer o…
kixelated Nov 25, 2026
aa6bc17
perf(net): seek past excluded ranges and skip an unchanged re-offer
kixelated Nov 25, 2026
28fd24e
fix(net): judge compaction on every route copy still feeding the reader
kixelated Nov 25, 2026
e986e82
fix(net): a widened budget re-offers a stale group a fill answered
kixelated Nov 25, 2026
7f2c4e7
perf(net): seek to the admitted group below a key in one descent
kixelated Nov 25, 2026
187c2af
fix(net): keep compaction below a feeding copy's unread group
kixelated Nov 25, 2026
b15d60c
quest: plan one delivery start the subscriber reports
kixelated Nov 25, 2026
97d3ae8
fix(net): compaction keeps what a widened budget reads again from an …
kixelated Nov 25, 2026
6aafb28
fix(net): a skipped run holding only a fill's answer stays for a wide…
kixelated Nov 25, 2026
1b33577
perf(net): compaction caps at a replaced copy's unread group in place
kixelated Nov 25, 2026
e2229f8
perf(net): judge the widest budget once per copy walk
kixelated Nov 25, 2026
fd20ece
Merge branch 'base' into pr-9529
Nov 25, 2026
09e7e2a
test(hang): main's new legacy cut-span test reads held groups in Grou…
Nov 25, 2026
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
6 changes: 3 additions & 3 deletions .cargo/mutants.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ exclude_re = [
# Polling a covered copy hands out nothing, so polling it anyway only costs work. An
# expired copy's groups are past the reader's own budget too: the copy expires a budget
# after the newer group that makes them stale, and `let_go` arms the same timer.
':\d+:13: replace \|\| with && in Reader::poll_lowest$',
':\d+:13: replace \|\| with && in Reader::poll_first$',
# A run starting at the window's end or the resume point clips to an empty range, which
# has no gaps.
'replace < with <= in Reader::(exhausted|lacking)$',
Expand Down Expand Up @@ -76,9 +76,9 @@ exclude_re = [
'replace == with != in Consumer::subscribe$',
# 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.
# `poll_first` records that refusal for the skip.
':\d+:19: replace <= with > in Reader::backfill$',
':\d+:30: replace == with != in Reader::poll_lowest$',
':\d+:30: replace == with != in Reader::poll_first$',
# 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$',
Expand Down
11 changes: 6 additions & 5 deletions .claude/skills/verify-resume/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: Model-check logical track resume across route switches (`rs/moq-net

# Verify track resume

`rs/moq-net/verify/resume/ResumeReader.tla` models one `Reader` of a logical track that `resume::Producer` serves across route changes. Each route is a received track whose groups land in any order, even below an end its session already settled. The front serves one route at a time, switches to another live route at will, and ends the track cleanly once the serving route completes, or unroutable once no route is left. One reader poll (`poll_lowest`, through `sync` and `backfill_gaps`) is one atomic step, as the reader's lock makes it; so is a switch, which the reader follows at once as `serve_from` does. TLC checks every ordering of arrivals, route failures, switches, polls, and finished reads under the bounds in each config.
`rs/moq-net/verify/resume/ResumeReader.tla` models one `Reader` of a logical track that `resume::Producer` serves across route changes. Each route is a received track whose groups land in any order, even below an end its session already settled. The front serves one route at a time, switches to another live route at will, and ends the track cleanly once the serving route completes, or unroutable once no route is left. Each copy's cursor holds what landed in its window and picks the newest first, as an arrival read in the default Group Order does, and a poll takes the newest any copy offers, a tie going to the newer copy. One reader poll (`poll_first`, through `sync` and `backfill_gaps`) is one atomic step, as the reader's lock makes it; so is a switch, which the reader follows at once as `serve_from` does. TLC checks every ordering of arrivals, route failures, switches, polls, and finished reads under the bounds in each config.

## Rules

Expand All @@ -30,7 +30,7 @@ quest gate just rs tla moq-net/verify/resume/ResumeReader.tla
quest gate just rs tla moq-net/verify/resume/ResumeReader.tla -config rs/moq-net/verify/resume/ThreeRoutes.cfg
```

The first checks every rule over two routes, three groups, two switches, and a reader holding each group until it finishes it: about 21.3M distinct states, in about six minutes. The second trades a group for a third route, so a route can come up after another failed: about 5.4M states, in about a minute. Both pass at the sync commit. Nightly runs every config here and fails if a config with an `\* Open finding:` line passes.
The first checks every rule over two routes, three groups, two switches, and a reader holding each group until it finishes it: about 18.7M distinct states, in about seven minutes. The second trades a group for a third route, so a route can come up after another failed: about 4.9M states, in about a minute and a half. Both pass at the sync commit. Nightly runs every config here and fails if a config with an `\* Open finding:` line passes.

## Open findings

Expand All @@ -42,18 +42,19 @@ Follow Reading a failure in `rs/moq-net/verify/README.md`. Replay the path as a

## Coverage

Sync commit: `8c939bc9d05e5e882fb4e042a9efbf2db227b721`, plus [moq-dev/moq#9103](https://github.com/moq-dev/moq/pull/9103), which reads a group landing late on a drained copy, and [moq-dev/moq#9276](https://github.com/moq-dev/moq/pull/9276), which splits a switch at one boundary. Run `git log 8c939bc9d0.. -- rs/moq-net/src/model/resume.rs rs/moq-net/src/model/track.rs` to see what changed since. Follow Coverage in `rs/moq-net/verify/README.md` after a change to a covered function.
Sync commit: `8c939bc9d05e5e882fb4e042a9efbf2db227b721`, plus [moq-dev/moq#9103](https://github.com/moq-dev/moq/pull/9103), which reads a group landing late on a drained copy, [moq-dev/moq#9276](https://github.com/moq-dev/moq/pull/9276), which splits a switch at one boundary, and [moq-dev/moq#9529](https://github.com/moq-dev/moq/pull/9529), which picks in Group Order. Run `git log 8c939bc9d0.. -- rs/moq-net/src/model/resume.rs rs/moq-net/src/model/track.rs` to see what changed since. Follow Coverage in `rs/moq-net/verify/README.md` after a change to a covered function.

| Code | Model |
| --- | --- |
| `rs/moq-net/src/model/resume.rs` `Reader::sync`, `boundary`, `Copy::cap` (reuse of a route's copy, new copy at the boundary, replaced copies capped there) | `Sync`, `Boundary`, `Cap`, `Serve` |
| `rs/moq-net/src/model/resume.rs` `Reader::backfill`, `backfill_gaps` | `Backfill`, `BackfillGaps` |
| `rs/moq-net/src/model/resume.rs` `Reader::poll_lowest`, `deliverable`, `take`, `Copy::done` | `Poll`, `Pass`, `Scan`, `Peek`, `Deliverable`, `Take` |
| `rs/moq-net/src/model/resume.rs` `Reader::poll_first`, `deliverable`, `take`, `Copy::done` | `Poll`, `Pass`, `Scan`, `Peek`, `Deliverable`, `Take` |
| `rs/moq-net/src/model/track.rs` `Cursor::poll_recv_with` (the pick in Group Order) | `Peek` |
| `rs/moq-net/src/model/resume.rs` `Reader::let_go`, `Copy::retains` | `LetGo`, `Retains` |
| `rs/moq-net/src/model/resume.rs` `Reader::poll_end` | `PollEnd` |
| `rs/moq-net/src/model/resume.rs` `Producer::splice`, `serve_from`, `Producer::end`, `Phase::Finished` | `Serve`, `FrontFinish`, `FrontFail` |
| `rs/moq-net/src/model/track.rs` `TrackState::is_complete`, `may_land`, `max_key`, `Consumer::latest_key`, `Consumer::poll_arrived`, `track::Subscriber::has_unread_group`, `Producer::finish_shared` | `Seal`, `Held`, `MayLand`, `Latest`, `Landed`, `HasUnread`, `Settle` |

## Not covered

Whole groups only, so no frames and no `Recover`: a group whose copy stalls or fails mid-read continuing on another copy is left out, as are compressed groups and fetches. The subscription is unbounded from the oldest group with an hour's budget, so nothing goes stale or expires (nor is the budget clock a replaced copy runs on, `since` and `drained`, modeled), and local ranges (`set_range`, a lowered floor's backfill), ordered reads, caps, refusals, drops and their reports, and re-offers are left out. Copies answer at once (no `Sub::Pending`), the reader joins before any group lands, a route declares its end only once it holds the last group, and a route that declared its end never fails. A pass covers two routes with three groups or three routes with two, two switches between live routes, and one reader. `resume_model.rs`'s proptest and the tests in `resume.rs` own the rest.
Whole groups only, so no frames and no `Recover`: a group whose copy stalls or fails mid-read continuing on another copy is left out, as are compressed groups and fetches. The subscription is unbounded from the oldest group with an hour's budget, so nothing goes stale or expires (nor is the budget clock a replaced copy runs on, `since` and `drained`, modeled), and local ranges (`set_range`, a lowered floor's backfill), ordered reads, ascending order, caps, refusals, drops and their reports, and re-offers are left out. Copies answer at once (no `Sub::Pending`), the reader joins before any group lands, a route declares its end only once it holds the last group, and a route that declared its end never fails. A pass covers two routes with three groups or three routes with two, two switches between live routes, and one reader. `resume_model.rs`'s proptest and the tests in `resume.rs` own the rest.
3 changes: 2 additions & 1 deletion dart/moq/lib/src/aliases.dart
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ Subscription defaultSubscription() => Subscription._(moqSubscriptionDefaults());
/// following the live edge.
typedef Range = MoqRange;

/// Which pending group the publisher sends first.
/// Which group comes first, as the publisher sends them and `recvGroup` returns those held.
/// Before moq-lite-07 the publisher sends newest first whatever this asks.
typedef Order = MoqOrder;

/// A location within a track: a group start and a frame index in it.
Expand Down
3 changes: 2 additions & 1 deletion doc/lib/dart/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ so a raw byte stream needs no other importer.
`ContainerFormat.fmp4()` splits each fragment into one frame per sample.
`media.CatalogConsumer.subscribe`, `media.TrackConsumer.subscribe`, and `media.GroupConsumer.fetch`
construct the read side from a broadcast; the last two take a catalog `media.Rendition` and
follow its broadcast and track themselves. For arrival-order reads, decode each group from
follow its broadcast and track themselves. For arrival reads, which take the groups already held in
the subscription's group order, newest first unless it asks ascending, decode each group from
`TrackConsumer.recvGroup()` with `media.GroupConsumer(group: ..., container: ...)`; frames
carry container media time as they land.
`package:moq/video.dart` and `package:moq/audio.dart` encode raw pixels and PCM inside the
Expand Down
8 changes: 5 additions & 3 deletions go/wrapper/subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ type TrackConsumer struct {
}

// RecvGroup returns the next group in arrival order (possibly out of start order),
// or (nil, nil) when the track ends. Prefer this for live, latency-sensitive
// consumption.
// or (nil, nil) when the track ends. Groups already held come in the
// subscription's group order, newest first unless it asks ascending. Prefer this
// for live, latency-sensitive consumption.
func (t *TrackConsumer) RecvGroup(ctx context.Context) (*GroupConsumer, error) {
return t.group(ctx, t.inner.RecvGroup)
}
Expand Down Expand Up @@ -175,7 +176,8 @@ func (t *TrackConsumer) Groups(ctx context.Context) iter.Seq2[*GroupConsumer, er
}

// GroupsAsArrived ranges over groups in arrival order, including
// out-of-order deliveries.
// out-of-order deliveries. Groups already held come in the subscription's
// order, newest first unless it asks ascending, as RecvGroup returns them.
func (t *TrackConsumer) GroupsAsArrived(ctx context.Context) iter.Seq2[*GroupConsumer, error] {
return bridge.Seq(ctx, t.inner.Cancel, t.RecvGroup)
}
Expand Down
7 changes: 5 additions & 2 deletions go/wrapper/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ type (
// live join that far behind the live edge (zero is the latest group), and an unstated one
// reaches back as far as Max allows. A nil End keeps following the live edge.
Range = ffi.MoqRange
// Order is which of a subscription's pending groups the publisher sends first.
// Order is which of a subscription's groups comes first, as the publisher sends them and
// RecvGroup returns those held. Before moq-lite-07 the publisher sends newest first whatever
// this asks.
Order = ffi.MoqOrder
// Compression is how a track's frames are compressed on the wire. Build one with
// DeflateCompression, and compare a received one by Name; a new compression joins as a
Expand Down Expand Up @@ -143,7 +145,8 @@ func NamedEncoder(name string) VideoEncoderKind {
return VideoEncoderKindNamed{Name: name}
}

// Order values: which pending group the publisher sends first.
// Order values: which group comes first, as the publisher sends them and RecvGroup returns
// those held.
const (
// OrderAscending sends the oldest first, draining a backlog in start order.
OrderAscending = ffi.MoqOrderAscending
Expand Down
3 changes: 2 additions & 1 deletion js/e2ee/src/e2ee.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ function netTrack(name: string, timed = true): NetTrack.Producer {
return defined(new Broadcast.Producer().createTrack(name, { timescale, maxAge: null }));
}

// Every group, oldest first, as the tests read their backlogs in order.
function subscribe(net: NetTrack.Producer): NetTrack.Subscriber {
return net.subscribe({ ranges: [{}] });
return net.subscribe({ order: "ascending", ranges: [{}] });
}

interface Pair {
Expand Down
3 changes: 2 additions & 1 deletion js/e2ee/src/track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ export class Consumer {
}

/**
* Receive the next protected group in arrival order, or `undefined` once the track ends.
* Receive the next protected group in arrival order, or `undefined` once the track ends. Groups
* already held come in the subscription's Group Order, newest first unless it asks ascending.
*
* Rejects with {@link Failure} `authentication` once a grouped frame has failed to open, or a net error.
*/
Expand Down
16 changes: 8 additions & 8 deletions js/hang/src/container/consumer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ async function poll<T>(read: Promise<T>): Promise<T | "pending"> {
// These tests write every group up front and only then read, so they ask for history
// rather than the live edge.
function replay(track: Track.Producer): Track.Subscriber {
return track.subscribe({ ranges: [{}] });
return track.subscribe({ order: "ascending", ranges: [{}] });
}
// A subscription from group `from` on whose missing groups an unserved fill owes, as a session's
// feed would, so its ordered read waits `max` for each hole before giving it up.
Expand Down Expand Up @@ -205,7 +205,7 @@ test("Legacy Producer accepts open-GOP leading pictures above the previous group

test("Legacy Producer continues a group at a keyframe overlapping it, and drops a leading picture before it with those after it", async () => {
const track = micro("test");
const subscriber = track.subscribe({ ranges: [{}] });
const subscriber = track.subscribe({ order: "ascending", ranges: [{}] });
const producer = new LegacyProducer(track, new LegacyFormat("video"));
for (const [timestamp, keyframe] of [
[100_000, true],
Expand Down Expand Up @@ -248,7 +248,7 @@ test("Legacy Producer drops a keyframe overlapping a closed group", () => {

test("Legacy Producer writes a duration marker at the next keyframe", async () => {
const track = micro("test");
const subscriber = track.subscribe({ ranges: [{}] });
const subscriber = track.subscribe({ order: "ascending", ranges: [{}] });
const producer = new LegacyProducer(track, new LegacyFormat("video"));
producer.encode(new Uint8Array([0xde, 0xad]), Duration.micros(0), true);
producer.encode(new Uint8Array([0xbe, 0xef]), Duration.micros(10_000), false);
Expand All @@ -273,7 +273,7 @@ test("Legacy Producer writes a duration marker at the next keyframe", async () =

test("Legacy Producer omits a reordered group's presentation endpoint marker", async () => {
const track = micro("test");
const subscriber = track.subscribe({ ranges: [{}] });
const subscriber = track.subscribe({ order: "ascending", ranges: [{}] });
const producer = new LegacyProducer(track, new LegacyFormat("video"));
for (const [index, timestamp] of [0, 120_000, 40_000, 80_000].entries()) {
producer.encode(new Uint8Array([1]), Duration.micros(timestamp), index === 0);
Expand All @@ -299,7 +299,7 @@ test("Legacy Producer omits a reordered group's presentation endpoint marker", a

test("Legacy Producer estimates the tail from the current cadence", async () => {
const track = micro("test");
const subscriber = track.subscribe({ ranges: [{}] });
const subscriber = track.subscribe({ order: "ascending", ranges: [{}] });
const producer = new LegacyProducer(track, new LegacyFormat("video"));
for (const [index, timestamp] of [0, 16_000, 32_000, 65_000, 98_000].entries()) {
producer.encode(new Uint8Array([1]), Duration.micros(timestamp), index === 0);
Expand All @@ -319,7 +319,7 @@ test("Legacy Producer estimates the tail from the current cadence", async () =>

test("Legacy Producer rejects a backwards discontinuity without closing the group", async () => {
const track = micro("test");
const subscriber = track.subscribe({ ranges: [{}] });
const subscriber = track.subscribe({ order: "ascending", ranges: [{}] });
const producer = new LegacyProducer(track, new LegacyFormat("video"));
producer.encode(new Uint8Array([1]), Duration.micros(20_000), true);
expect(() => producer.discontinuity(Duration.micros(10_000))).toThrow();
Expand All @@ -338,7 +338,7 @@ test("Legacy Producer rejects a backwards discontinuity without closing the grou

test("Legacy Producer keeps the cadence after rejecting a backwards discontinuity", async () => {
const track = micro("test");
const subscriber = track.subscribe({ ranges: [{}] });
const subscriber = track.subscribe({ order: "ascending", ranges: [{}] });
const producer = new LegacyProducer(track, new LegacyFormat("video"));
producer.encode(new Uint8Array([1]), Duration.micros(20_000), true);
producer.encode(new Uint8Array([2]), Duration.micros(30_000), false);
Expand Down Expand Up @@ -516,7 +516,7 @@ test("Legacy Producer discontinuity keeps pre-pause media from reading as live",
producer.encode(new Uint8Array([1]), Duration.micros(5_000_000), true);
producer.finish();

const subscriber = track.subscribe(within(Duration.millis(1_000)));
const subscriber = track.subscribe({ ...within(Duration.millis(1_000)), order: "ascending" });
expect((await readGroups(subscriber, 5_000_000n)).map(([start]) => start)).toEqual([33_000n, 5_000_000n]);
});

Expand Down
Loading