Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
bf0ec80
chore(quest): claim quest/m1/resolved-demand.md
kixelated Oct 25, 2026
9998e7a
fix(moq-net): re-offer cached groups a widened max age covers
kixelated Oct 25, 2026
4b2c30c
fix(net): re-offer skipped groups over the wire on a widened max age
kixelated Oct 25, 2026
9289701
Merge remote-tracking branch 'origin/main' into HEAD
kixelated Oct 25, 2026
e338785
quest: finish resolved-demand, defer the pool-billed record to drop-set
kixelated Oct 25, 2026
263b317
fix(net): keep re-offered skips owed until handled, respect a raised …
kixelated Oct 25, 2026
df1ce8d
Merge origin/main into quest/m1/resolved-demand
kixelated Oct 25, 2026
84e19c1
fix(net): wake a parked JS read when its budget widens
kixelated Oct 25, 2026
261b7f2
perf(net): skip the skipped-record work on hand-outs that need none
kixelated Oct 25, 2026
5812f10
fix(net): forget an evicted JS skip before it holds delivered gaps
kixelated Oct 25, 2026
d149156
fix(net): never fold groups a widened range still owes into the deliv…
kixelated Oct 25, 2026
847c510
Merge remote-tracking branch 'origin/main' into quest/m1/resolved-demand
kixelated Oct 25, 2026
67de1ec
test(net): build the widened max age update with ranges
kixelated Oct 25, 2026
61a82da
Merge remote-tracking branch 'origin/main' into quest/m1/resolved-demand
kixelated Oct 25, 2026
7e25635
quest: drop the finished resolved-demand link from relay-demand-gaps
kixelated Oct 25, 2026
f31a929
bench(net): drop scheduling domains from the schedule bench
kixelated Oct 25, 2026
2dada1a
fix(net): unreport below-start skips on every JS START path
kixelated Oct 25, 2026
236ad42
Merge remote-tracking branch 'origin/main' into quest/m1/resolved-demand
kixelated Oct 26, 2026
8d943f0
test(net): announce the widened max age broadcast through its publica…
kixelated Oct 26, 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
8 changes: 8 additions & 0 deletions js/net/src/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,11 @@ export const hooks: {
deliveredRuns: (subscriber: Subscriber) => number;
/** Forget the gaps in another reader's `delivered` below each group past this subscriber's budget. */
forgetPastBudget: (subscriber: Subscriber, delivered: Delivered) => void;
/**
* Take `[start, end)` back out of what a subscriber's wire cursor reported dropped: a drop
* below where SUBSCRIBE_START resolved never goes out, so a wider budget may still serve it.
*/
unreport: (subscriber: Subscriber, start: number, end: number) => void;
/** Whether this subscriber's budget gives up on `sequence`, judged by its successor; see {@link expireGroup}. */
staleAt: (subscriber: Subscriber, sequence: number) => Expiry;
/** A group the subscriber's track still caches, as a fresh read handle. */
Expand Down Expand Up @@ -572,6 +577,9 @@ export const hooks: {
forgetPastBudget: () => {
throw new Error("track.ts not loaded");
},
unreport: () => {
throw new Error("track.ts not loaded");
},
tryRecvDatagram: () => {
throw new Error("track.ts not loaded");
},
Expand Down
3 changes: 3 additions & 0 deletions js/net/src/lite/publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,9 @@ export class Publisher {
for (;;) {
if (startSequence !== undefined && skipped.length > 0) {
for (const range of skipped) {
// What was given up below the start is never named, so a wider budget may serve it.
if (range.start < startSequence)
hooks.unreport(track, range.start, Math.min(range.end, startSequence));
if (!(await drop(Math.max(range.start, startSequence), range.end, range.error))) return false;
}
skipped.length = 0;
Expand Down
63 changes: 63 additions & 0 deletions js/net/src/lite/widened_max_age.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// A subscriber widening its max age over the wire gets the cached groups the publisher skipped
// as stale, including those below where SUBSCRIBE_START resolved, and never one twice.

import { expect, test } from "bun:test";
import { Milli } from "@moq/clock";
import { accept, connect } from "../connection/index.ts";
import { createMockTransportPair } from "../mock.ts";
import { Producer as OriginProducer } from "../origin.ts";
import * as Path from "../path.ts";
import { Timescale, Timestamp } from "../time.ts";
import type { Subscriber as TrackSubscriber } from "../track.ts";
import { wireOf } from "../wire.ts";
import { ALPN_07_WIP, Version } from "./version.ts";

const url = new URL("https://localhost:4443/test");

/** The next `count` groups `reader` hands out, in sequence order. */
async function received(reader: TrackSubscriber, count: number): Promise<number[]> {
const got: number[] = [];
while (got.length < count) {
const group = await reader.recvGroup();
if (!group) throw new Error("the track ended");
got.push(group.sequence);
}
return got.sort((a, b) => a - b);
}

test("a widened maxDelay re-offers what the publisher skipped below the start", async () => {
const pair = createMockTransportPair(ALPN_07_WIP);
const origin = new OriginProducer();
const publication = origin.createBroadcast(Path.from("room"));
publication.announce();
const broadcast = publication.broadcast;
const producer = broadcast.createTrack("video", { timescale: Timescale.MILLI });
// One group per second, so a budget picks how far back a reader reaches.
for (let sequence = 0; sequence < 10; sequence++) {
const group = producer.appendGroup();
group.writeFrame({ payload: new Uint8Array([sequence]), timestamp: Timestamp.fromMillis(sequence * 1000) });
group.close();
}

const [client, server] = await Promise.all([
connect({ url, transport: pair.client }),
accept({ transport: pair.server, url, version: Version.DRAFT_07, publish: origin.consume() }),
]);
const remote = wireOf(client).consume(Path.from("room"));
// Group 5 ends at 6s, a full 3s behind the 9s edge.
const reader = remote.track("video").subscribe({ maxDelay: Milli(2500) });
expect(await received(reader, 4)).toEqual([6, 7, 8, 9]);

reader.update({ maxDelay: Milli(6500) });
expect(await received(reader, 4)).toEqual([2, 3, 4, 5]);
// Ending the track flushes anything else the publisher would send: nothing, not even a repeat.
producer.close();
expect(await reader.recvGroup()).toBeUndefined();

reader.close();
remote.close();
broadcast.close();
origin.close();
client.abort();
server.abort();
});
154 changes: 154 additions & 0 deletions js/net/src/track.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3611,3 +3611,157 @@ for (const abort of [false, true]) {
producer.close();
});
}

// A widened budget re-offers the cached groups the reader skipped as stale, and never one it
// already handed out.
test("a widened maxDelay re-offers what it skipped as stale", () => {
const producer = new TrackProducer("test").accept({ timescale: Timescale.MILLI });
const subscriber = producer.subscribe({ maxDelay: Milli(1500) });
stampGroup(producer, 0, 0);
expect(drainGroups(subscriber)).toEqual([0]);
for (const [sequence, ms] of [
[1, 1000],
[2, 2000],
[3, 3000],
[4, 6000],
]) {
stampGroup(producer, sequence, ms);
}
// Groups 1 and 2 reach 2s and 3s, at least 1.5s behind the 6s edge.
expect(drainGroups(subscriber)).toEqual([3, 4]);

subscriber.update({ maxDelay: Milli(10_000) });
expect(drainGroups(subscriber)).toEqual([1, 2]);
expect(drainGroups(subscriber)).toEqual([]);
producer.close();
});

// A read already parked when the budget widens wakes for the re-offer.
test("a widened maxDelay wakes a parked read", async () => {
const producer = new TrackProducer("test").accept({ timescale: Timescale.MILLI });
const subscriber = producer.subscribe({ maxDelay: Milli(1500) });
stampGroup(producer, 0, 0);
expect(drainGroups(subscriber)).toEqual([0]);
for (const [sequence, ms] of [
[1, 1000],
[2, 2000],
[3, 6000],
]) {
stampGroup(producer, sequence, ms);
}
// Group 1 reaches 2s, 4s behind the 6s edge.
expect(drainGroups(subscriber)).toEqual([2, 3]);

const parked = subscriber.recvGroup();
subscriber.update({ maxDelay: Milli(10_000) });
expect((await parked)?.sequence).toBe(1);
producer.close();
});

// A skip whose group the cache evicted can never be offered again, so it stops holding the
// delivered gaps above it.
test("an evicted stale skip lets the delivered gaps fold", () => {
const time = manualTime(1_000);
try {
const producer = new TrackProducer("test").accept({ timescale: Timescale.MILLI, maxAge: Milli(30_000) });
const subscriber = producer.subscribe({ maxDelay: Milli(10) });
stampGroup(producer, 0, 0);
expect(drainGroups(subscriber)).toEqual([0]);
// Group 1 reaches 5ms, past the 10ms budget behind the 30ms edge.
stampGroup(producer, 1, 1);
stampGroup(producer, 2, 5);
stampGroup(producer, 3, 30);
expect(drainGroups(subscriber)).toEqual([2, 3]);

// Past the cache window, so the next write evicts group 1.
time.set(1_000 + 2 * CACHE_WINDOW_MS);
let most = 0;
for (let sequence = 4; sequence < 300; sequence++) {
// Every third group never arrives.
if (sequence % 3 === 1) continue;
stampGroup(producer, sequence, sequence + 30);
expect(drainGroups(subscriber)).toEqual([sequence]);
most = Math.max(most, hooks.deliveredRuns(subscriber));
}
expect(most).toBeLessThan(10);
} finally {
time.installed.close();
}
});

// A re-offer never hands out a group below a floor raised in the same update.
test("a widened maxDelay re-offers nothing below a raised floor", () => {
const producer = new TrackProducer("test").accept({ timescale: Timescale.MILLI });
const subscriber = producer.subscribe({ maxDelay: Milli(1500) });
stampGroup(producer, 0, 0);
expect(drainGroups(subscriber)).toEqual([0]);
for (const [sequence, ms] of [
[1, 1000],
[2, 2000],
[3, 3000],
[4, 6000],
]) {
stampGroup(producer, sequence, ms);
}
expect(drainGroups(subscriber)).toEqual([3, 4]);

subscriber.update({ maxDelay: Milli(10_000), groups: { start: { included: 2 } } });
expect(drainGroups(subscriber)).toEqual([2]);
producer.close();
});

// A stale skip a drop-reading cursor has not reported yet is withdrawn when a widening re-offers
// its group, so the reader never gets both the group and its drop.
test("a widened maxDelay withdraws an unreported stale drop", () => {
const producer = new TrackProducer("test").accept({ timescale: Timescale.MILLI });
const subscriber = producer.subscribe({ maxDelay: Milli(1500) });
expect(hooks.tryDrop(subscriber)).toBeUndefined();
stampGroup(producer, 0, 0);
expect(drainGroups(subscriber)).toEqual([0]);
for (const [sequence, ms] of [
[1, 1000],
[2, 2000],
[3, 6000],
]) {
stampGroup(producer, sequence, ms);
}
// Group 1 reaches 2s, 4s behind the 6s edge.
expect(drainGroups(subscriber)).toEqual([2, 3]);

subscriber.update({ maxDelay: Milli(10_000) });
expect(drainGroups(subscriber)).toEqual([1]);
expect(hooks.tryDrop(subscriber)).toBeUndefined();
producer.close();
});

// A widening that covers only the newer of two skipped groups hands it out without folding the
// older one into the delivered floor: a further widening still re-offers it.
test("a partial maxDelay widening keeps the older skip owed", () => {
const producer = new TrackProducer("test").accept({ timescale: Timescale.MILLI });
const subscriber = producer.subscribe({ maxDelay: Milli(1500) });
stampGroup(producer, 0, 0);
expect(drainGroups(subscriber)).toEqual([0]);
for (const [sequence, ms] of [
[1, 1000],
[2, 2000],
[3, 4000],
]) {
stampGroup(producer, sequence, ms);
}
expect(drainGroups(subscriber)).toEqual([2, 3]);
for (const [sequence, ms] of [
[4, 5000],
[5, 6000],
[6, 9000],
]) {
stampGroup(producer, sequence, ms);
}
expect(drainGroups(subscriber)).toEqual([5, 6]);

// Group 4 reaches 6s, 3s behind the 9s edge; group 1 reaches 2s, 7s behind.
subscriber.update({ maxDelay: Milli(4000) });
expect(drainGroups(subscriber)).toEqual([4]);
subscriber.update({ maxDelay: Milli(10_000) });
expect(drainGroups(subscriber)).toEqual([1]);
producer.close();
});
Loading
Loading