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
14 changes: 11 additions & 3 deletions js/net/src/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,16 +359,22 @@ export interface Hole {
* does not depend on it. Only a widening past it reverses the verdict.
*/
stale?: number;
/**
* The exclusive group end the upstream subscription judged a stale verdict within, undefined
* when it followed the live edge or its end is not known to be the one it judged under. A
* reader capped at the same end reads the groups the verdict rests on, so it settles on it.
*/
cap?: bigint;
}

/** A key never produced; see {@link Hole.skip}. */
export function skipHole(): Hole {
return { error: new StreamError(StreamCode.NotFound, { message: "group never produced" }), skip: true };
}

/** A group judged stale under `budget` milliseconds. */
export function staleHole(budget: number): Hole {
return { error: new StreamError(StreamCode.Old, { message: "group is past the budget" }), stale: budget };
/** A group judged stale under `budget` milliseconds, within the exclusive group end `cap` when it has one. */
export function staleHole(budget: number, cap?: bigint): Hole {
return { error: new StreamError(StreamCode.Old, { message: "group is past the budget" }), stale: budget, cap };
}

/** A run of keys given up, with why. */
Expand All @@ -385,6 +391,7 @@ export function sameHole(a: DropRun, b: DropRun): boolean {
toStreamCode(a.error) === toStreamCode(b.error) &&
!a.skip === !b.skip &&
a.stale === b.stale &&
a.cap === b.cap &&
!a.received === !b.received &&
!a.own === !b.own
);
Expand All @@ -411,6 +418,7 @@ export function insertDrop(
error: hole.error,
skip: hole.skip,
stale: hole.stale,
cap: hole.cap,
received: hole.received,
own: hole.own,
});
Expand Down
23 changes: 22 additions & 1 deletion js/net/src/lite/subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ interface SubscribeEntry {
// the publisher's max age, which binds every reader alike. Too narrow costs a wider reader a
// request of its own; too wide would settle it on a group it could still get.
staleBudget: number;
// The exclusive group end every live range the SUBSCRIBE and each SUBSCRIBE_UPDATE asked ended at,
// undefined once one followed the live edge or two ended apart: the cap a lite-07 stale drop is
// recorded within, so a reader capped alike settles on it. Like the budget, the wire does not say
// which update a drop crossed, so a cap that ever varied settles no capped reader.
staleCap: bigint | undefined;
// The subscribe stream, from the setup that registered this entry to its end.
stream: SubscribeStream;
// How many SUBSCRIBE_UPDATEs went out, so a tail settling past SUBSCRIBE_END waits a fresh
Expand Down Expand Up @@ -1754,6 +1759,7 @@ export class Subscriber {
const entry: SubscribeEntry = {
track: producer,
staleBudget: narrowest(live),
staleCap: capOf(live),
...framing,
// The effective max delay is the stopgap grace: the wrong clock (it bounds
// presentation-time drift), but it is how long the subscriber was willing to wait
Expand Down Expand Up @@ -2230,6 +2236,7 @@ export class Subscriber {
const entry: SubscribeEntry = {
track: producer,
staleBudget: narrowest(live),
staleCap: capOf(live),
compress: copy.compress,
timescale: copy.timescale,
tail: new Tail({ grace: () => hooks.tailGrace(producer) }),
Expand Down Expand Up @@ -2709,7 +2716,7 @@ export class Subscriber {
// judged under: a reader wider than that does not settle on it, and asks for the group
// with a request of its own.
const stale = hasSkip(this.version) && toStreamCode(error) === StreamCode.Old;
const hole = stale ? staleHole(entry.staleBudget) : { error };
const hole = stale ? staleHole(entry.staleBudget, entry.staleCap) : { error };
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
hooks.dropTrackGroups(entry.track, start, end, hole);
entry.fills?.refuse(start, end, error);
} else if ("skip" in resp) {
Expand Down Expand Up @@ -3012,6 +3019,7 @@ export class Subscriber {
for (const id of entry.joinTicks.keys()) if (!entry.live.get(id)) entry.joinTicks.delete(id);
for (const id of entry.joinBudgets.keys()) if (!entry.live.get(id)) entry.joinBudgets.delete(id);
entry.staleBudget = Math.min(entry.staleBudget, narrowest(entry.live));
if (capOf(entry.live) !== entry.staleCap) entry.staleCap = undefined;
for (const id of entry.fillIds) if (!entry.live.get(id)) entry.fillIds.delete(id);
for (const id of edited.fillIds) entry.fillIds.add(id);
for (const id of entry.probeIds) if (!entry.live.get(id)) entry.probeIds.delete(id);
Expand Down Expand Up @@ -3769,6 +3777,19 @@ function narrowest(live: LiveRanges): number {
return narrowest;
}

// The exclusive group end past every range among `live`, undefined when one follows the live edge
// or `live` holds none: the cap a stale drop is judged within. Mirrors the Rust `cap_of`.
function capOf(live: LiveRanges): bigint | undefined {
let cap: bigint | undefined;
for (const range of live.ranges()) {
if (range.end === undefined) return undefined;
const last = through(range.end);
// A range ending before the first group reaches none.
cap = max(cap ?? 0n, last === undefined ? 0n : last + 1n);
}
return cap;
}

// The one `Subscriber Max Age` a wire before lite-07 carries for `ranges`, in milliseconds: `null`
// (no limit) while a history range is asked for, and otherwise the largest live join's max.
// Mirrors the Rust `Subscription::max_age`.
Expand Down
28 changes: 28 additions & 0 deletions js/net/src/track.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4629,6 +4629,34 @@ test("a received stale drop settles only the readers it covers", () => {
producer.close();
});

// The group streams and a stale drop are unordered, so a drop may reach the copy before the groups
// it rests on. A reader capped where the upstream judged reads the same groups above the run, so it
// takes the verdict instead of fetching a group the groups above would still convict.
test("a received stale drop settles a reader capped where the upstream judged it", () => {
const producer = new TrackProducer("video").accept({ timescale: Timescale.MILLI, maxAge: null });
putGroup(producer, 0n, 0);
const reader = (max: number, end: bigint) =>
producer.subscribe(withMax({ delay: { max: Duration.millis(max) }, ranges: [{ end: end - 1n }] }));
const same = reader(500, 4n);
const narrower = reader(100, 4n);
const wider = reader(5000, 4n);
const lower = reader(500, 3n);
const higher = reader(500, 5n);
hooks.dropTrackGroups(producer, 1n, 3n, staleHole(500, 4n));
const dropped = (subscriber: typeof same) => {
const runs: [bigint, bigint][] = [];
for (let run = hooks.tryDrop(subscriber); run; run = hooks.tryDrop(subscriber)) runs.push([run.start, run.end]);
return runs;
};
expect(dropped(same)).toEqual([[1n, 3n]]);
expect(dropped(narrower)).toEqual([[1n, 3n]]);
// A wider budget still asks, and a cap apart from the verdict's may see other groups above it.
for (const subscriber of [wider, lower, higher]) expect(dropped(subscriber)).toEqual([]);
for (const subscriber of [same, narrower, wider, lower, higher]) subscriber.close();
producer.finish();
producer.close();
});

test("a superseded stale run is unknown again, and its group is handed out", () => {
const producer = new TrackProducer("video").accept({});
const reader = producer.subscribe(withMax({ delay: { max: Duration.millis(500) }, ranges: [{ start: 0n }] }));
Expand Down
26 changes: 16 additions & 10 deletions js/net/src/track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1236,14 +1236,6 @@ function reaches(received: bigint, drops: DropSet, end: End, refused: readonly R
return runGaps(given, received, final).length === 0;
}

/**
* Whether `run` settles a reader judging under `budget` with `coverage`. Any run but a received
* stale one does. A stale verdict holds for a reader no wider than the budget it was judged under
* that reads every group above the run's start, past the live edge: its own successor and edge are
* then no older than those the verdict was judged against, since a group's verdict looks only
* above it. A reader whose budget varies by group is held to its widest. Mirrors the Rust
* `settles`.
*/
// The parts of `drops` within `[start, end)`, each clipped there.
function intersectDrops(drops: readonly DropRun[], start: bigint, end: bigint): DropRun[] {
const out: DropRun[] = [];
Expand All @@ -1253,13 +1245,26 @@ function intersectDrops(drops: readonly DropRun[], start: bigint, end: bigint):
return out;
}

/**
* Whether `run` settles a reader judging under `budget` with `coverage`. Any run but a received
* stale one does. A stale verdict holds for a reader no wider than the budget it was judged under
* that reads every group above the run's start: its own successor and edge are then no older than
* those the verdict was judged against, since a group's verdict looks only above it. An uncapped
* reader reads them past the live edge; a capped one only when the upstream judged within the very
* cap it has (`run.cap`), else the verdict may rest on groups above the cap it never sees. A reader
* whose budget varies by group is held to its widest. Mirrors the Rust `settles`.
*/
function settles(run: DropRun, budget: Budget, coverage: Coverage): boolean {
if (run.stale === undefined) return true;
if ((budget.isUniform() ? budget.at(run.start) : budget.widest()) > run.stale) return false;
if (coverage === undefined || coverage.cap !== undefined) return false;
if (coverage === undefined) return false;
const { cap } = coverage;
if (cap !== undefined && run.cap !== cap) return false;
const above = run.start + 1n;
const end = cap ?? UNBOUNDED;
if (above >= end) return true;
const held = coverage.runs.find((run) => run.start <= above && above < run.end);
return held !== undefined && held.end >= UNBOUNDED;
return held !== undefined && held.end >= end;
}
// Actual object metadata outlives cached payloads, unlike empty group heads in model largest.
let objectLargest: (producer: Producer) => Position | undefined;
Expand Down Expand Up @@ -6330,6 +6335,7 @@ export class Subscriber {
const hole: Hole = { error: drop.error };
if (drop.skip) hole.skip = true;
if (drop.stale !== undefined) hole.stale = drop.stale;
if (drop.cap !== undefined) hole.cap = drop.cap;
this.#adopted = insertDrop(this.#adopted, start, end, hole);
}

Expand Down
2 changes: 1 addition & 1 deletion quest/m0/nightly/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ Triaged 2026-11-25 (pre-0.22 recurring audits), from run
`Tests (test resume-model)` at seed `1465722607` was fixed by
[moq-dev/moq#9509](https://github.com/moq-dev/moq/pull/9509); `Nightly (JS coverage)`'s
`widened_max_age.test.ts` failure is
[widened-bounded-reader-js](/quest/m0/test-flakes-4/widened-bounded-reader-js.md); and
[moq-dev/moq#9607](https://github.com/moq-dev/moq/pull/9607); and
`Shipping sizes`' +10% `moq_ffi.dll.lib` is the Windows import library growing with the
exports [moq-dev/moq#9359](https://github.com/moq-dev/moq/pull/9359) added, while every
shipped library stayed under the 5% bound. Already owned: `Tests (rs quic-sim)`'s
Expand Down
31 changes: 0 additions & 31 deletions quest/m0/test-flakes-4/widened-bounded-reader-js.md

This file was deleted.

2 changes: 1 addition & 1 deletion quest/m3/audit-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Run the `tests` audit: `quest audit tests` prints what it checks, what each find

Baseline: 2026-11-23 at `890ea4e531` (Nightly `45242597151` `rust-coverage` at `b29b90be29`, measured via `just rs coverage`):
`moq-auth` 98.1%, `moq-mux` 97.7%, `moq-hls` 97.6%, `hang` 97.5%, `moq-net` 96.1%, `moq-quic` 96.0%, `libmoq` 96.0%, `moq-audio` 95.9%, `moq-gst` 95.7%, `moq-relay` 95.3%, `moq-congestion` 95.0%, `moq-json` 94.4%, `kio` 93.9%, `qmux` 93.6%, `moq-ffi` 93.2%, `moq-rtmp` 93.1%, `moq-webrtc` 93.0%, `moq-tokio` 92.4%, `moq-uring` 89.6%, `moq-cli` 87.2%, `moq-e2ee` 86.2%, `moq-video` 65.3%, `moq-nvenc` 44.9%, `moq-v4l` 17.4%, `moq-vaapi` 12.2%.
In Nightly `45242597151`, `js-coverage` stopped at `js/net` (`lite` 96.7%, `ietf` 94.3%, `origin` 97.8%, `track` 97.9%, `resume` 94.9%) due to a failure in `widened_max_age.test.ts`; the next night's passed, so start from a Nightly whose `js-coverage` covered every package. The flake is [widened-bounded-reader-js](/quest/m0/test-flakes-4/widened-bounded-reader-js.md).
In Nightly `45242597151`, `js-coverage` stopped at `js/net` (`lite` 96.7%, `ietf` 94.3%, `origin` 97.8%, `track` 97.9%, `resume` 94.9%) due to a failure in `widened_max_age.test.ts`; the next night's passed, so start from a Nightly whose `js-coverage` covered every package. The flake was fixed by [moq-dev/moq#9607](https://github.com/moq-dev/moq/pull/9607).

Previous run: [moq-dev/moq#6175](https://github.com/moq-dev/moq/pull/6175). Test cost belongs to [audit-cost](/quest/m3/audit-cost.md).

Expand Down
Loading