Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
5d01132
chore(quest): claim quest/m1/stream-credit/rank-opening.md
kixelated Nov 13, 2026
2b6711c
fix(moq-net): a group waiting for stream credit gives way to one that…
kixelated Nov 13, 2026
50eab3f
test(js/net): a newer group passes a late one waiting for credit; fin…
kixelated Nov 13, 2026
d4c806d
fix(moq-net): newest first sheds a group ranked below one waiting for…
kixelated Nov 13, 2026
cd88000
chore(quest): claim quest/m1/stream-credit/yield-findings.md
kixelated Nov 13, 2026
1cdb024
Merge remote-tracking branch 'origin/quest/m1/stream-credit/rank-open…
kixelated Nov 13, 2026
7b60fe9
fix(moq-net): bound paused groups and fix the yield and resume review…
kixelated Nov 13, 2026
af7e4b4
fix(moq-net): supersede a pre-header stale drop on update, and rank o…
kixelated Nov 13, 2026
9db8d7f
Merge remote-tracking branch 'origin/main' into quest/m1/stream-credi…
kixelated Nov 13, 2026
caad387
quest: size stream-credit's remaining work now that its last child is…
kixelated Nov 13, 2026
a7e0123
perf(moq-net): wake only the paused group a frame lands on
kixelated Nov 13, 2026
2e122cf
test(moq-net): a re-paused group waits once, and the best paused grou…
kixelated Nov 13, 2026
2d1adc9
fix(moq-net): drop a paused group the cache released with nothing unread
kixelated Nov 13, 2026
105790b
style: cargo fmt
kixelated Nov 13, 2026
30f0447
fix(net): preserve finished groups after their writers drop
kixelated Nov 13, 2026
5fb55fb
refactor(net): keep the yielding verdict in one state
kixelated Nov 13, 2026
bdee146
test(net): gate the abort poll regression on async
kixelated Nov 13, 2026
5e4ba85
docs(net): resynchronize the subscription model coverage
kixelated Nov 13, 2026
caec521
test(net): settle the live stream before preempting the fill
kixelated Nov 13, 2026
47c5e2c
test(net): preempt every stream serving the archived group
kixelated Nov 13, 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
4 changes: 2 additions & 2 deletions .claude/skills/verify-subscribe/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Follow Reading a failure in `rs/moq-net/verify/README.md`. Replay the path on th

## Coverage

Sync commit: `1be43c735b4ddaf5811433d82390e377cd1fe15a`. Run `git log 1be43c735b.. -- rs/moq-net/src/lite/publisher.rs rs/moq-net/src/lite/subscriber.rs rs/moq-net/src/tail.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: `6aa4f9c1cad482aa86adcf3cf26bd7779697a01a`. Run `git log 6aa4f9c1ca.. -- rs/moq-net/src/lite/publisher.rs rs/moq-net/src/lite/subscriber.rs rs/moq-net/src/tail.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 |
| --- | --- |
Expand All @@ -58,7 +58,7 @@ Sync commit: `1be43c735b4ddaf5811433d82390e377cd1fe15a`. Run `git log 1be43c735b
| `rs/moq-net/src/tail.rs` `Tail::rebill`, `overtaken`, `updated`; `rs/moq-net/src/lite/subscriber.rs` `ServeLoop::apply_response`; `rs/moq-net/src/model/record.rs` `Record::folded` | `TailFold`, `forgot`, `PubFold`, `folded` |
| `rs/moq-net/src/model/track.rs` `Producer::give_up`, `skip_received` | `rec`, `cached` |
| `rs/moq-net/src/lite/publisher.rs` `GroupServe::settle_failed`, `TrackRun::open`; `rs/moq-net/src/transport/boxed.rs` `SendStream::preempted` | `StreamYield`, `PubContinue`, `PausedGiveUp` |
| `rs/moq-net/src/lite/subscriber.rs` `TrackEntry::pause`, `resume`, `dropped`, `read_yielding`, `end_yielding`, `GroupRecv::poll_serve`, `FrameIngest::dispatch` | the YIELDED branch of `SubReset`, `SubFrame`, `reading`, `sdrop`, `paused` |
| `rs/moq-net/src/lite/subscriber.rs` `TrackEntry::pause`, `resume`, `dropped`, `read_yielding`, `end_yielding`, `YieldVerdict`, `GroupRecv::poll_serve`, `FrameIngest::dispatch` | the YIELDED branch of `SubReset`, `SubFrame`, `reading`, `sdrop`, `paused` |

What the model asks of that code, each found by TLC as a broken rule without it:

Expand Down
31 changes: 22 additions & 9 deletions js/net/src/lite/copy_fill.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,11 @@ test("copy fill: a filled group nobody holds any more stops downloading", async
});

// Lite-07: a filled group whose stream the publisher yielded, then gave up, ends with the fill's
// drop naming it, as one on a subscription does, rather than waiting paused on a continuation that
// never comes.
// drop naming it with the group's own error, as one on a subscription does, rather than waiting
// paused on a continuation that never comes.
test("copy fill: a yielded group the fill's drop names ends", async () => {
const clock = new Manual();
const installed = clock.install();
const pair = createMockTransportPair(Lite.ALPN_07_WIP);
const origin = new OriginProducer();
const [client, server] = await Promise.all([
Expand All @@ -397,7 +399,11 @@ test("copy fill: a yielded group the fill's drop names ends", async () => {
const remote = wireOf(client).consume(Path.from("room"));
try {
const reader = remote.track("video").subscribe({ ranges: [{ start: { relative: 0n } }] });
expect((await reader.ordered().nextGroup())?.sequence).toBe(1n);
const live = await reader.ordered().nextGroup();
expect(live?.sequence).toBe(1n);
expect(dec.decode((await live?.readFrame())?.payload)).toBe("live 1");
expect(await live?.readFrame()).toBeUndefined();
live?.close();
const history = remote
.track("video")
.subscribe({ ...WIDE, ranges: [{ start: { absolute: 0n }, end: { absolute: 1n } }] });
Expand All @@ -408,15 +414,21 @@ test("copy fill: a yielded group the fill's drop names ends", async () => {

// The session resets the group's stream to make room, and the group is gone before a new
// stream could continue it, so the publisher drops it on the fill's subscription.
// The live stream has finished. The archive may be served on both the fill and
// the copy's expanded feed, so reset every stream still serving it.
await clock.advance(Duration.ZERO);
const open = lines(pair.server).streams.list();
expect(open.length).toBe(1);
open[0]?.preempt();
source.abort(new Error("gone"));
expect(open.length).toBeGreaterThan(0);
for (const stream of open) stream.preempt();
source.abort(new StreamError(StreamCode(70), { message: "gone" }));

// Still paused without it, which the deadline reports as elapsed.
const ended = await timeout(Duration.millis(1000), Promise.resolve(group?.closed)).catch((err: unknown) => err);
// Still paused without it, which the deadline, fired once every pending task settled,
// reports as elapsed.
const ended = await clock
.drive(timeout(Duration.millis(1000), Promise.resolve(group?.closed)))
.catch((err: unknown) => err);
expect(ended).toBeInstanceOf(StreamError);
expect((ended as StreamError).code).toBe(StreamCode.Old);
expect((ended as StreamError).code).toBe(StreamCode(70));
history.close();
reader.close();
} finally {
Expand All @@ -427,5 +439,6 @@ test("copy fill: a yielded group the fill's drop names ends", async () => {
client.abort();
server.abort();
origin.close();
installed.close();
}
});
27 changes: 26 additions & 1 deletion js/net/src/lite/group.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect, test } from "bun:test";
import { StreamCode, StreamError } from "../error.ts";
import { ProtocolViolation, StreamCode, StreamError } from "../error.ts";
import { Producer } from "../group.ts";
import { hooks } from "../internal.ts";
import { concat, encodeVarint, Reader } from "../stream.ts";
import { SEGMENT_BYTES } from "../util/limits.ts";
import * as Varint from "../varint.ts";
Expand Down Expand Up @@ -230,3 +231,27 @@ test("a lite-07 stream ending at the Payload Length ends the group", async () =>
readFrames(streamOf([cut], version), new Producer(0n), { scale: SCALE, lengthFirst: true }),
).rejects.toThrow("unexpected end of stream");
});

// A peer's huge Frame Start numbers a frame past what a number counts exactly, which is refused
// as a protocol violation rather than counted wrong. Mirrors the Rust
// `group_frame_start_past_any_count_is_refused`.
test("a lite-07 frame numbered past the safe integer range is refused", async () => {
const version = Version.DRAFT_07;
const frame = concat([frameHeader(version, 0n, undefined, 1, true), new Uint8Array([7])]);
const start = Number.MAX_SAFE_INTEGER - 1;
const producer = new Producer(0n);
hooks.startGroup(producer, start);
const err = await readFrames(
streamOf([frame, frame], version),
producer,
{ scale: SCALE, lengthFirst: true },
{
index: start,
},
).then(
() => undefined,
(err: unknown) => err,
);
expect(err).toBeInstanceOf(ProtocolViolation);
expect(producer.consume().frameCount).toBe(Number.MAX_SAFE_INTEGER);
});
24 changes: 24 additions & 0 deletions js/net/src/lite/publisher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,30 @@ test("lite-07 continues a yielded cached tail from its Frame Start", async () =>
}
});

// Lite-07: a yielded group the publisher aborts before its continuation is dropped with the
// publisher's error, not as stale. Mirrors the Rust `lite07_yielded_group_aborted_drops_with_its_error`.
test("lite-07 drops a yielded group the publisher aborted with its error", async () => {
const version = Version.DRAFT_07;
const sub = await servedSubscription({ version, startGroup: 0n });
try {
const group = sub.track.createGroup(0n);
group.writeFrame(textFrame("a", Timestamp.fromMillis(0)));
expect(await sub.servedHeader()).toBe(0n);
expect("start" in (await decodeSubscribeResponse(sub.client.reader, version))).toBe(true);

const [open] = lines(sub.quic).streams.list();
if (!open) throw new Error("the group stream is not open");
open.preempt();
group.abort(new StreamError(StreamCode(70), { message: "cut" }));

const resp = await decodeSubscribeResponse(sub.client.reader, version);
if (!("drop" in resp)) throw new Error("expected SUBSCRIBE_DROP");
expect([resp.drop.start, resp.drop.end, resp.drop.error]).toEqual([0n, 1n, 70]);
} finally {
await sub.close();
}
});

// A range an update adds learns where it starts from SUBSCRIBE_STARTED, and keeps that start however
// many later updates leave it live, rather than counting back from a newer latest group.
test("lite-07 SUBSCRIBE_STARTED reports an added range's start, which later updates keep", async () => {
Expand Down
13 changes: 10 additions & 3 deletions js/net/src/lite/publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2062,7 +2062,12 @@ export class Publisher {
// The subscriber keeps what arrived, and a new stream continues the group from
// the reset one's Frame Start, owing no drop. Mirrors the Rust `GroupServe::settle_failed`.
if (!(writer instanceof Error) && writer.preempted && hasYield(this.version)) {
const resumed = continuation(serving);
// The group's own failure, such as the publisher's abort or an eviction, ends
// it with that error, as the Rust continuation reads it off the group. Read
// before the release replaces it with the reset's.
const fate = serving.group.closed.peek();
hooks.releaseGroupReader(serving.group, failed);
const resumed = fate instanceof Error ? undefined : continuation(serving);
if (resumed) {
console.debug(
`continuing paused group: track=${track.name} sequence=${group.sequence} frame_start=${serving.start}`,
Expand All @@ -2071,7 +2076,7 @@ export class Publisher {
continue;
}
// Given up meanwhile, such as by the subscription's budget: the usual stale drop.
failed = new StreamError(StreamCode.Old);
failed = fate instanceof Error ? fate : new StreamError(StreamCode.Old);
}
if (emitRange) {
pendingDrops.push({ start: group.sequence, end: group.sequence + 1n, error: failed });
Expand Down Expand Up @@ -2645,7 +2650,9 @@ export class Publisher {
} catch (err: unknown) {
const e = error(err);
stream.reset(e);
hooks.releaseGroupReader(group, e);
// A reset that pauses the group leaves the reader to the caller, which reads its fate
// first. A reset stream is never preempted after, so the caller sees the same flag.
if (!(stream.preempted && hasYield(this.version))) hooks.releaseGroupReader(group, e);
return e;
} finally {
priority.remove(stream);
Expand Down
95 changes: 95 additions & 0 deletions js/net/src/lite/subscriber.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1556,6 +1556,101 @@ test("a yielded group a drop named ends", async () => {
}
});

// Lite-07: a stale drop that overtook the YIELDED reset of the stream it names holds only under the
// update it names: once the subscriber sends another, the reset pauses the group, which the
// publisher then continues or drops again. Mirrors the Rust
// `a_yielded_group_pauses_once_an_update_supersedes_its_stale_drop`.
test("a yielded group pauses once an update supersedes its stale drop", async () => {
const version = Version.DRAFT_07;
const { quic, streams, opened } = fakeSession();
const subscriber = new Subscriber(quic, version, HopSchema.parse(1n));
const track = subscriber
.consume(Path.from("room"))
.track("video")
.subscribe({ delay: { max: Duration.millis(60_000) } });
try {
await opened(0);
await answerTrackInfo(streams[0], version, 1000);
const request = await opened(1);
await request.reading;
await respond(request, version, [{ start: new SubscribeStart([0n]) }]);

const first = handStream(version);
first.write(await liteFrame(300, new Uint8Array([1])));
const yielded = subscriber.runGroup(new Group({ subscribe: 0n, sequence: 3n }), first.reader);
const group = await track.recvGroup();
expect(group?.sequence).toBe(3n);
expect((await group?.readFrame())?.payload).toEqual(new Uint8Array([1]));

await respond(request, version, [{ drop: new SubscribeDrop({ start: 3n, end: 4n, error: StreamCode.Old }) }]);
await drainReactions();
track.update({ priority: 1, delay: { max: Duration.millis(60_000) } });
await drainReactions();
first.reset(StreamCode.Yielded);
await yielded;
await drainReactions();

expect(group?.closed.peek()).toBeUndefined();
// The continuation picks the group up where the reset left it.
const second = handStream(version);
second.write(await liteFrame(10, new Uint8Array([2])));
second.finish();
await subscriber.runGroup(new Group({ subscribe: 0n, sequence: 3n, frameStart: 1 }), second.reader);
expect((await group?.readFrame())?.payload).toEqual(new Uint8Array([2]));
expect(await group?.readFrame()).toBeUndefined();
} finally {
track.close();
subscriber.close();
}
});

// Lite-07: a stale drop that overtook the header of the stream it names holds only under the update
// it names: once the subscriber sends another, a YIELDED reset of that stream pauses the group.
// Mirrors the Rust `a_yielded_group_pauses_once_an_update_supersedes_a_stale_drop_before_its_header`.
test("a yielded group pauses once an update supersedes a stale drop before its header", async () => {
const version = Version.DRAFT_07;
const { quic, streams, opened } = fakeSession();
const subscriber = new Subscriber(quic, version, HopSchema.parse(1n));
const track = subscriber
.consume(Path.from("room"))
.track("video")
.subscribe({ delay: { max: Duration.millis(60_000) } });
try {
await opened(0);
await answerTrackInfo(streams[0], version, 1000);
const request = await opened(1);
await request.reading;
await respond(request, version, [{ start: new SubscribeStart([0n]) }]);

await respond(request, version, [{ drop: new SubscribeDrop({ start: 3n, end: 4n, error: StreamCode.Old }) }]);
await drainReactions();
const first = handStream(version);
first.write(await liteFrame(300, new Uint8Array([1])));
const yielded = subscriber.runGroup(new Group({ subscribe: 0n, sequence: 3n }), first.reader);
const group = await track.recvGroup();
expect(group?.sequence).toBe(3n);
expect((await group?.readFrame())?.payload).toEqual(new Uint8Array([1]));

track.update({ priority: 1, delay: { max: Duration.millis(60_000) } });
await drainReactions();
first.reset(StreamCode.Yielded);
await yielded;
await drainReactions();

expect(group?.closed.peek()).toBeUndefined();
// The continuation picks the group up where the reset left it.
const second = handStream(version);
second.write(await liteFrame(10, new Uint8Array([2])));
second.finish();
await subscriber.runGroup(new Group({ subscribe: 0n, sequence: 3n, frameStart: 1 }), second.reader);
expect((await group?.readFrame())?.payload).toEqual(new Uint8Array([2]));
expect(await group?.readFrame()).toBeUndefined();
} finally {
track.close();
subscriber.close();
}
});

// Lite-07: a malformed FRAME on a Group Stream ends only that stream and its group, never the
// session: a Payload Length of 0, or a continuation that resends the cut frame at another size, ends
// before completing it, or starts past the frames held. Mirrors the Rust `UniState::Group`.
Expand Down
69 changes: 57 additions & 12 deletions js/net/src/lite/subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,30 @@ interface PausedGroup {

// Whether a YIELDED reset of a stream being read pauses its group.
interface Yielding {
// The publisher still owed the group when the stream arrived: no drop named it first.
owed: boolean;
// The error a drop named the group with while the stream was read.
dropped?: Error;
verdict: YieldVerdict;
}

// Stale drops expire on the next update. An already accounted header stays accounted.
type YieldVerdict =
| { kind: "owed" }
| { kind: "accounted" }
| { kind: "stale"; under: bigint; error: Error }
| { kind: "accounted-stale"; under: bigint; error: Error }
| { kind: "dropped"; error: Error };

function yieldError(verdict: YieldVerdict, update: bigint): Error | undefined {
switch (verdict.kind) {
case "owed":
return undefined;
case "accounted":
return new StreamError(StreamCode.Old);
case "stale":
return verdict.under < update ? undefined : verdict.error;
case "accounted-stale":
return verdict.under < update ? new StreamError(StreamCode.Old) : verdict.error;
case "dropped":
return verdict.error;
}
}

// The paused groups of `entry`, created on first use.
Expand Down Expand Up @@ -2936,7 +2956,7 @@ export class Subscriber {
const overtaken = stale ? entry.tail.overtaken(start, end) : [];
entry.tail.account(start, end);
// A paused group the drop names ends there: no continuation follows.
this.#dropPaused(entry, start, end, error);
this.#dropPaused(entry, start, end, error, stale ? update : undefined);
// Judged under the budget this subscriber sent with that update.
const hole = stale ? staleHole(entry.maxDelay ?? 0) : { error };
// A group whose stream finished under this update was served over a stale drop, so it
Expand Down Expand Up @@ -3249,6 +3269,12 @@ export class Subscriber {
const yields = hasYield(this.version);
// Asked before this stream accounts for the group: a drop that overtook it named it.
let owed = !tail.covers(group.sequence, group.sequence + 1n);
// A stale drop that overtook this stream: the next update supersedes that verdict, so a
// YIELDED reset after it pauses the group.
const unowedUnder =
!owed && entry.stale?.some((run) => run.start <= group.sequence && group.sequence < run.end)
? entry.update
: undefined;
let producer: netGroup.Producer | undefined;
let ingest: Ingest | undefined;
let yielding: Yielding | undefined;
Expand Down Expand Up @@ -3296,7 +3322,13 @@ export class Subscriber {
});
if (yields) {
ingest ??= { index: group.frameStart };
yielding = { owed };
yielding = {
verdict: owed
? { kind: "owed" }
: unowedUnder !== undefined
? { kind: "stale", under: unowedUnder, error: new StreamError(StreamCode.Old) }
: { kind: "accounted" },
};
entry.yielding ??= new Map();
entry.yielding.set(group.sequence, yielding);
}
Expand Down Expand Up @@ -3325,7 +3357,8 @@ export class Subscriber {
this.#endYielding(entry, group.sequence, yielding);
// A drop named the group first: the publisher gave it up, so nothing continues it. One
// that overtook the stream's header carried a stale verdict.
const given = yielding.dropped ?? (yielding.owed ? undefined : new StreamError(StreamCode.Old));
// A stale drop an update sent since superseded no longer ends the group.
const given = yieldError(yielding.verdict, entry.update);
if (given) {
producer.abort(given);
return;
Expand Down Expand Up @@ -3390,12 +3423,24 @@ export class Subscriber {
if (entry.yielding?.get(sequence) === yielding) entry.yielding.delete(sequence);
}

// A SUBSCRIBE_DROP named `[start, end)` with `error`: a paused group ends there, and one a stream
// is reading ends with it if a YIELDED reset would otherwise pause it, since no continuation
// follows. Mirrors the Rust `TrackEntry::dropped`.
#dropPaused(entry: SubscribeEntry, start: bigint, end: bigint, error: Error): void {
// A SUBSCRIBE_DROP named `[start, end)` with `error`, under update `staleUnder` when it is a
// lite-07 stale verdict: a paused group ends there, and one a stream is reading ends with it if
// a YIELDED reset would otherwise pause it, since no continuation follows, unless an update
// supersedes a stale drop first. Mirrors the Rust `TrackEntry::dropped`.
#dropPaused(entry: SubscribeEntry, start: bigint, end: bigint, error: Error, staleUnder?: bigint): void {
for (const [sequence, yielding] of entry.yielding ?? []) {
if (sequence >= start && sequence < end) yielding.dropped = error;
if (sequence < start || sequence >= end) continue;
const verdict = yielding.verdict;
if (staleUnder === undefined) yielding.verdict = { kind: "dropped", error };
else if (verdict.kind !== "dropped")
yielding.verdict = {
kind:
verdict.kind === "accounted" || verdict.kind === "accounted-stale"
? "accounted-stale"
: "stale",
under: staleUnder,
error,
};
}
const paused = entry.paused;
if (!paused) return;
Expand Down
Loading