Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
0559864
chore(quest): claim quest/m1/waiting-time-start-reads.md
kixelated Nov 19, 2026
0b0521d
fix(moq-net): a waiting time start reads its owed group first, and a …
kixelated Nov 19, 2026
64fd64b
fix(moq-net): a time start folded into an earlier range places from t…
kixelated Nov 19, 2026
28df1d8
fix(moq-net): an ordered read parked at a waiting time start wakes wh…
kixelated Nov 19, 2026
b608dc1
Merge origin/main: unplaced runs leave out what the feed's accounting…
kixelated Nov 19, 2026
f39227d
perf(moq-net): bound a copy's landing span from its highest place, no…
kixelated Nov 19, 2026
59bbe4d
fix(moq-net): a waiting time start holds an ordered read within its f…
kixelated Nov 19, 2026
868fe85
fix(moq-net): a range answered empty holds back no later group within…
kixelated Nov 19, 2026
47c026d
fix(moq-net): a waiting time start holds back a gap above its group, …
kixelated Nov 19, 2026
ad5a12a
Merge origin/main: fill accept answers None for a group already answered
kixelated Nov 19, 2026
4cd53b8
fix(moq-net): answer CodeRabbit's waiting-time-start findings
kixelated Nov 19, 2026
a290bd9
fix(moq-net): a stale verdict narrower than a read keeps its time sta…
kixelated Nov 19, 2026
5650182
fix(moq-net): a time start's barrier counts a verdict only for a read…
kixelated Nov 20, 2026
b5ae538
Merge origin/main: keep this PR's time-start answers with main's earl…
kixelated Nov 20, 2026
98ac671
quest: the time-start follow-up asks upstream for what a copy cannot …
kixelated Nov 20, 2026
b15f570
style: format
kixelated Nov 20, 2026
da9fea4
fix(moq-net): an empty range releases by its wire terms, and a widene…
kixelated Nov 20, 2026
ce843d8
style: format
kixelated Nov 20, 2026
5c23fd8
Merge origin/main into quest/m1/waiting-time-start-reads
kixelated Nov 20, 2026
61652b7
test(moq-net): a fill below the live edge stays history; plan the wid…
kixelated Nov 20, 2026
077572b
Merge origin/main (#9228's time start as a group fill) into quest/m1/…
kixelated Nov 21, 2026
9f70e08
quest: time-start-asks-upstream covers the relay's poll_start stall o…
kixelated Nov 21, 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
11 changes: 6 additions & 5 deletions js/net/src/fill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -735,11 +735,12 @@ export class FillGroups {

/**
* Insert group `key` into the track's cache, handing it to the readers waiting on it,
* and return the producer to write its frames into. `info` commits the track's {@link Info}
* if it has none yet. A key from the {@link floor} up to the start answers the start with that
* group. A cached copy missing its first frames, which a reader asked whole, is replaced. Returns
* `undefined` if the group was already answered or cached whole. Throws a `RangeError` outside
* the fill, and an error if the track is closed.
* and return the producer to write its frames into. A live subscription covering it receives
* it too. `info` commits the track's {@link Info} if it has none yet. A key from the
* {@link floor} up to the start answers the start with that group. A cached copy missing its
* first frames, which a reader asked whole, is replaced. Returns `undefined` if the group was
* already answered or cached whole. Throws a `RangeError` outside the fill, and an error if the
* track is closed.
*/
accept(start: bigint, info?: Info): GroupProducer | undefined {
checkKey(start);
Expand Down
27 changes: 24 additions & 3 deletions js/net/src/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,8 @@ export interface ResumeSource {
resolved(): (Resolved | undefined)[];
/** The runs of `[start, end)` the serving copy reads, undefined without one. */
runs(start: bigint, end: bigint): Run[] | undefined;
/** Whether a time start the serving copy still waits to place holds back a gap; see `hooks.gapHeld`. */
gapHeld(at: bigint, end: bigint): boolean;
/** Whether a route's copy serves the reader now. */
serving(): boolean;
/** Where the run of keys from `key` the serving copy says no group arrives at ends; see `hooks.holeEnd`. */
Expand Down Expand Up @@ -711,6 +713,8 @@ export const hooks: {
subscriberEndError: (subscriber: Subscriber) => Error | undefined;
/** What this subscriber resolves its ranges against, for a test. Assigned by `track.ts`. */
subscriberHoldings: (subscriber: Subscriber) => Holdings;
/** The times a received copy's feed accounting may place, for a test. Assigned by `track.ts`. */
landingSpan: (producer: Producer) => Run | undefined;
/**
* How many keys just below `key` the publisher declared it never produced: the skip run
* ending at `key`, which a moq-transport Prior Group ID Gap names. Mirrors the Rust
Expand Down Expand Up @@ -750,11 +754,17 @@ export const hooks: {
startsAtKeys: (producer: Producer) => void;
/**
* Record where the upstream publisher started each of a lite-07 copy's live wire ranges, as
* `[time, start]` pairs by the time each asked from, replacing the last set: a reader's time
* start the copy cannot place among its own groups resolves to it. Mirrors the Rust
* `[time, start, through]` by the time each asked from (0 for the oldest group), `start`
* undefined for one with no group to deliver, replacing the last set: a reader's time start the
* copy cannot place among its own groups resolves to it. An empty answer holds for a reader
* within `budget`, the narrowest the subscription asked in milliseconds. Mirrors the Rust
* `track::Producer::time_starts`; assigned by `track.ts`.
*/
timeStarts: (producer: Producer, starts: Iterable<readonly [bigint, bigint]>) => void;
timeStarts: (
producer: Producer,
starts: Iterable<readonly [bigint, bigint | undefined, (bigint | undefined)?]>,
budget: number,
) => void;
/**
* Tell a lite-07 copy where its publisher started each live range counting back, as
* `[back, start, latest]` triples, replacing the last set: the copy holds only part of the
Expand Down Expand Up @@ -822,6 +832,11 @@ export const hooks: {
* Assigned by `track.ts`.
*/
servingRuns: (subscriber: Subscriber, start: bigint, end: bigint) => Run[];
/**
* Whether a time start still waiting below `end` holds back a gap an ordered read at `at` would
* return. Assigned by `track.ts`.
*/
gapHeld: (subscriber: Subscriber, at: bigint, end: bigint) => boolean;
/**
* The exclusive end past every group a subscriber reads, or undefined while one of its ranges
* stays open. Assigned by `track.ts`.
Expand Down Expand Up @@ -1169,6 +1184,9 @@ export const hooks: {
subscriberHoldings: () => {
throw new Error("track.ts not loaded");
},
landingSpan: () => {
throw new Error("track.ts not loaded");
},
skippedBelow: () => {
throw new Error("track.ts not loaded");
},
Expand All @@ -1190,6 +1208,9 @@ export const hooks: {
servingRuns: () => {
throw new Error("track.ts not loaded");
},
gapHeld: () => {
throw new Error("track.ts not loaded");
},
servingEnd: () => {
throw new Error("track.ts not loaded");
},
Expand Down
6 changes: 3 additions & 3 deletions js/net/src/lite/publisher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1663,7 +1663,7 @@ for (const version of [Version.DRAFT_05, Version.DRAFT_06, Version.DRAFT_07]) {
try {
hooks.receiveTrack(sub.track);
// A lite-07 source reports where it started the time asked for.
if (hasRanges(version)) hooks.timeStarts(sub.track, [[2n, source]]);
if (hasRanges(version)) hooks.timeStarts(sub.track, [[2n, source]], NO_MAX_DELAY);
hooks.startTrack(sub.track, { start: source, requested: 2n });
sub.serve(6n);
expect(await sub.servedSequence()).toBe(6n);
Expand Down Expand Up @@ -1691,7 +1691,7 @@ test("lite draft-07: a time start a copy's oldest range covers starts where that
try {
hooks.receiveTrack(sub.track);
await flush();
hooks.timeStarts(sub.track, [[0n, 6n]]);
hooks.timeStarts(sub.track, [[0n, 6n]], NO_MAX_DELAY);
hooks.startTrack(sub.track, { start: 6n });
sub.serve(6n);
expect(await sub.servedSequence()).toBe(6n);
Expand All @@ -1714,7 +1714,7 @@ for (const version of [Version.DRAFT_06, Version.DRAFT_07]) {
hooks.startTrack(sub.track, { requested: 2n });
sub.serve(6n);
await flush();
if (hasRanges(version)) hooks.timeStarts(sub.track, [[2n, 3n]]);
if (hasRanges(version)) hooks.timeStarts(sub.track, [[2n, 3n]], NO_MAX_DELAY);
hooks.startTrack(sub.track, { start: 3n, requested: 2n });
const response = await decodeSubscribeResponse(sub.client.reader, version);
if (!("start" in response)) throw new Error("expected SUBSCRIBE_START");
Expand Down
47 changes: 46 additions & 1 deletion js/net/src/lite/subscriber.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
import type { Consumer as GroupConsumer } from "../group.ts";
import { type Hop, isAnonymous, MAX_HOPS, toHop, UNKNOWN_HOP, WireRoute } from "../hop.ts";
import * as Instance from "../instance.ts";
import { hooks } from "../internal.ts";
import { hooks, NO_MAX_DELAY } from "../internal.ts";
import { GRACE } from "../ledger.ts";
import * as Path from "../path.ts";
import { Reader, Writer } from "../stream.ts";
Expand Down Expand Up @@ -2972,6 +2972,51 @@ test("a widened range's SUBSCRIBE_STARTED resolves the feed's start", async () =
}
});

// A range the publisher answers with no group to deliver lands none of its groups, so the copy is
// told, and an ordered read holds no later group back for its time. Only one whose end takes in its
// time says so: one ending by a count back may still have skipped the group containing it.
test("a lite-07 range answered empty is reported only for a range reaching its time", async () => {
const version = Version.DRAFT_07;
const { quic, streams, opened } = fakeSession();
const subscriber = new Subscriber(quic, version, toHop(1n));
const broadcast = subscriber.consume(Path.from("room"));
const reported: (readonly [bigint, bigint | undefined, (bigint | undefined)?])[][] = [];
const timeStarts = hooks.timeStarts;
const budgets: number[] = [];
hooks.timeStarts = (producer, starts, budget) => {
reported.push([...starts]);
budgets.push(budget);
timeStarts(producer, starts, budget);
};
const track = broadcast.track("video").subscribe({
delay: { max: null },
ranges: [
{ start: { time: 10n }, end: { time: 20n } },
{ start: { time: 30n }, end: { relative: 0n } },
{ start: { time: 66n } },
],
});
try {
await opened(0);
await answerTrackInfo(streams[0], version);
const request = await opened(1);
await request.reading;
await respond(request, version, [{ start: new SubscribeStart([undefined, undefined, 66n]) }]);
await drainReactions();
expect(reported.at(-1)).toEqual([
[10n, undefined, 20n],
[66n, 66n, undefined],
]);
// Under the narrowest budget the subscription asked with, here none.
expect(budgets.at(-1)).toEqual(NO_MAX_DELAY);
} finally {
hooks.timeStarts = timeStarts;
track.close();
broadcast.close();
subscriber.close();
}
});

// A lite-07 stale (OLD) drop accounts for its groups for good, whichever of it and a group's stream
// lands first: an update owes none of them again, and a group still arriving, such as one another
// subscription sharing the copy delivers, is never aborted by the drop.
Expand Down
45 changes: 36 additions & 9 deletions js/net/src/lite/subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ import {
Subscribe,
SubscribeUpdate,
toWireRanges,
type WireAnchor,
type WireRange,
} from "./subscribe.ts";
import { TrackInfo, Track as TrackMessage } from "./track.ts";
Expand Down Expand Up @@ -2870,24 +2871,30 @@ export class Subscriber {
// requested floor, pending, while SUBSCRIBE_START or a range's SUBSCRIBE_STARTED has yet to
// say where one starts. Mirrors the Rust `SubStream::declare`.
#declare(entry: SubscribeEntry): void {
// Where the publisher started each live range asked from a group's start, which a reader's
// time start there resolves to when the copy holds no group at it, and one asked from the
// oldest group as asked from 0. Mirrors the Rust `SubStream::report_starts`.
const times: [bigint, bigint][] = [];
// Where the publisher started each live range asked from a group's start or the oldest group
// (time 0), with the last time it reaches, which a reader's time start there or folded into it
// resolves to when the copy holds no group at it. Mirrors the Rust `SubStream::report_starts`.
const times: [bigint, bigint | undefined, bigint | undefined][] = [];
// And each one counting back, which the copy, holding only part of the track, can't count,
// with the latest group it counted back from.
const relative: [bigint, bigint, bigint | undefined][] = [];
for (const id of entry.live.ids()) {
const range = entry.live.get(id);
const time = range?.start?.time ?? range?.start?.absolute;
const back = range?.start?.relative;
if (!entry.starts.has(id)) continue;
// Undefined for a range with no group to deliver.
const at = entry.starts.get(id);
if (at === undefined) continue;
if (time !== undefined) times.push([time, at]);
else if (back !== undefined) relative.push([back, at, entry.edges.get(id)]);
else if (range !== undefined && range.start === undefined) times.push([0n, at]);
if (back !== undefined) {
if (at !== undefined) relative.push([back, at, entry.edges.get(id)]);
} else if (time !== undefined || range?.start === undefined) {
const asked = time ?? 0n;
if (at !== undefined || reaches(range?.end, asked)) times.push([asked, at, through(range?.end, asked)]);
}
}
hooks.timeStarts(entry.track, times);
// The wire does not say which budget a range resolved under, so an empty one holds only for the
// narrowest asked.
hooks.timeStarts(entry.track, times, entry.staleBudget);
hooks.relativeStarts(entry.track, relative);

let start: bigint | null = null;
Expand Down Expand Up @@ -3427,3 +3434,23 @@ class ConsumeBroadcast extends broadcast.Consumer {
return new ConsumeBroadcast(this.#subscriber, this.#path, this.#consumed, this.shareState());
}
}

// The last time a lite-07 range ending at `end` reaches, undefined while it follows the live edge:
// an exclusive group end stops at the time before it, and a relative end, unknown here, at the
// range's own time `asked`. Mirrors the Rust `SubStream::report_starts`.
// Whether a lite-07 range with no group to deliver says its publisher held none at or before its
// reach: only one whose end takes in the group containing its time, which a range that ends before
// its time, or by a count back, may not. Mirrors the Rust `SubStream::report_starts`.
function reaches(end: WireAnchor | undefined, asked: bigint): boolean {
if (end === undefined) return false;
if (end.time !== undefined) return end.time >= asked;
if (end.absolute !== undefined) return end.absolute > asked;
return false;
}

function through(end: WireAnchor | undefined, asked: bigint): bigint | undefined {
if (end === undefined) return undefined;
if (end.time !== undefined) return end.time;
if (end.absolute !== undefined) return end.absolute > asked ? end.absolute - 1n : asked;
return asked;
}
Loading