From 509d1aa2c96a3b82c493c588a77e5cc587127453 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 18:17:19 -0800 Subject: [PATCH 01/11] chore(quest): claim quest/m1/interop-coverage/js-ietf-fetch.md Quest-Claim: c3e2e536c96cc735 From 449ace13d783fe0cae7d61069819616b2715f0b5 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 18:43:23 -0800 Subject: [PATCH 02/11] feat(net): fetch past group ranges with the IETF JS subscriber Co-Authored-By: GPT-6.1 Sol --- js/net/MIGRATE.md | 4 + js/net/src/fill.ts | 7 + js/net/src/goaway-requests.test.ts | 5 +- js/net/src/ietf/range.test.ts | 258 ++++++++++++++ js/net/src/ietf/range.ts | 206 ++++++++++++ js/net/src/ietf/subscriber.test.ts | 14 +- js/net/src/ietf/subscriber.ts | 369 +++++++++++++++++++-- js/net/src/integration.test.ts | 50 ++- js/net/src/track.ts | 16 +- quest/m1/README.md | 1 - quest/m1/ietf-drop/README.md | 4 - quest/m1/interop-coverage/README.md | 58 ---- quest/m1/interop-coverage/js-ietf-fetch.md | 27 -- quest/m2/audit-interop.md | 1 - test/ietf-conformance/README.md | 13 + test/ietf-conformance/run.sh | 41 ++- test/interop/README.md | 6 +- test/interop/clients/js-native/ranges.ts | 94 ++++++ test/interop/clients/js-native/tail.ts | 133 ++++---- test/interop/interop.sh | 70 ++-- test/justfile | 5 +- 21 files changed, 1141 insertions(+), 241 deletions(-) create mode 100644 js/net/src/ietf/range.test.ts create mode 100644 js/net/src/ietf/range.ts delete mode 100644 quest/m1/interop-coverage/README.md delete mode 100644 quest/m1/interop-coverage/js-ietf-fetch.md create mode 100644 test/interop/clients/js-native/ranges.ts diff --git a/js/net/MIGRATE.md b/js/net/MIGRATE.md index a2b0e96e2be..1fd09fc27ae 100644 --- a/js/net/MIGRATE.md +++ b/js/net/MIGRATE.md @@ -4,6 +4,10 @@ How to update your code for each breaking change, newest first. ## Unreleased +### Past group ranges work over moq-transport ([#7793](https://github.com/moq-dev/moq/pull/7793)) + +`track.Consumer.fetchGroup()` and subscriptions to past group ranges now use standalone FETCH on drafts 18, 20, and 22. No API migration is needed. First-party publishers serve one group per FETCH; multi-group ranges require a publisher that serves them. + ### A timestamp out of range at the track's timescale is a `TimestampMismatch` ([#7702](https://github.com/moq-dev/moq/pull/7702)) A frame or datagram whose timestamp leaves the safe range once converted to the track's timescale is refused at the write with `TimestampMismatch`, as Rust refuses it, rather than with a `RangeError` when it is encoded. diff --git a/js/net/src/fill.ts b/js/net/src/fill.ts index 8350b652dbe..3a329599436 100644 --- a/js/net/src/fill.ts +++ b/js/net/src/fill.ts @@ -339,6 +339,11 @@ function subtract(gap: Run, run: Run): Run[] { ].filter((part) => part.start < part.end); } +/** The still-wanted runs of a fill, in ascending order. @internal */ +export let wantedRuns: (fill: Fill) => Run[]; +/** Wait for a change to the groups or readers of a fill. @internal */ +export let fillChanged: (fill: Fill) => Promise; + // Constructs the public handles from within this module; assigned in their static blocks. let makeFill: (state: FillState, pending: Pending) => Fill; let makeRequests: (state: FillState) => Requests; @@ -443,6 +448,8 @@ export class Fill { static { makeFill = (state, pending) => new Fill(state, pending); + wantedRuns = (fill) => fill.#pending.owed(); + fillChanged = (fill) => Promise.resolve(fill.#pending.revision.changed()); } /** The most urgent delivery priority among the readers waiting on it now. */ diff --git a/js/net/src/goaway-requests.test.ts b/js/net/src/goaway-requests.test.ts index 7bebb5f4ef9..b781fe6c4b4 100644 --- a/js/net/src/goaway-requests.test.ts +++ b/js/net/src/goaway-requests.test.ts @@ -181,8 +181,9 @@ async function handover(kind: "lite" | "ietf"): Promise { // A fresh consumer caches nothing, so the publisher's answer proves the FETCH reached the wire. const fetched = wireOf(client).consume(Path.from("room")).track("video").fetchGroup(0n); - if (kind === "lite") expect(await (await fetched).readString()).toBe("one"); - else await expect(fetched).rejects.toThrow(/not supported/); + const group = await fetched; + expect(await group.readString()).toBe("one"); + group.close(); // A new announce-interest opens too, and sees the route at the drain cost. const interest = client.announced(); diff --git a/js/net/src/ietf/range.test.ts b/js/net/src/ietf/range.test.ts new file mode 100644 index 00000000000..3ad55fec5e6 --- /dev/null +++ b/js/net/src/ietf/range.test.ts @@ -0,0 +1,258 @@ +import { expect, onTestFinished, test } from "bun:test"; +import { StreamCode, StreamError } from "../error.ts"; +import { createMockTransportPair } from "../mock.ts"; +import * as Path from "../path.ts"; +import { Reader, Stream, Writer } from "../stream.ts"; +import type { Subscription } from "../track.ts"; +import { Fetch, FetchOk } from "./fetch.ts"; +import { FetchFrame } from "./object.ts"; +import { RequestError } from "./request.ts"; +import { NativeSession } from "./session.ts"; +import { Subscriber } from "./subscriber.ts"; +import { TrackStatusOk, TrackStatusRequest } from "./track.ts"; +import { ALPN, type IetfVersion, Version } from "./version.ts"; + +const VERSIONS = [Version.DRAFT_18, Version.DRAFT_20, Version.DRAFT_22] as const; +const ALPNS = { + [Version.DRAFT_18]: ALPN.DRAFT_18, + [Version.DRAFT_20]: ALPN.DRAFT_20, + [Version.DRAFT_22]: ALPN.DRAFT_22, +}; +const ranges = (start: bigint, end: bigint): Subscription => ({ + ranges: [{ start: { absolute: start }, end: { absolute: end } }], + delay: { max: null }, + order: "ascending", +}); + +function fixture(version: IetfVersion) { + const pair = createMockTransportPair(ALPNS[version]); + const session = new NativeSession(pair.server, version, true); + const subscriber = new Subscriber({ session }); + const broadcast = subscriber.consume(Path.from("room")); + const incoming = pair.client.incomingBidirectionalStreams.getReader(); + const readers: { close(): void }[] = []; + onTestFinished(() => { + for (const reader of readers) reader.close(); + broadcast.close(); + session.close(); + incoming.releaseLock(); + }); + const next = async () => { + const stream = await incoming.read(); + if (stream.done) throw new Error("missing request"); + return new Stream({ ...stream.value, version }); + }; + const status = async (largest = 5n, provided?: Stream, typed = false) => { + const stream = provided ?? (await next()); + if (!typed) expect(await stream.reader.u53()).toBe(TrackStatusRequest.id); + const request = await TrackStatusRequest.decode(stream.reader, version); + expect([request.trackNamespace, request.trackName]).toEqual([Path.from("room"), "video"]); + await stream.writer.u53(TrackStatusOk.id); + await new TrackStatusOk({ largest: { groupId: largest, objectId: 2n } }).encode(stream.writer, version); + stream.writer.close(); + }; + const fetch = async (allowStatus = false) => { + let stream = await next(); + let type = await stream.reader.u53(); + if (type === TrackStatusRequest.id && allowStatus) { + await status(5n, stream, true); + stream = await next(); + type = await stream.reader.u53(); + } + expect(type).toBe(Fetch.id); + return { stream, request: await Fetch.decode(stream.reader, version) }; + }; + const answer = async (stream: Stream, group: bigint, object = 2n, ended = false) => { + await stream.writer.u53(FetchOk.id); + await new FetchOk({ + endOfTrack: ended, + endLocation: { group, object: version === Version.DRAFT_18 ? object + 1n : object }, + }).encode(stream.writer, version); + }; + const data = async (id: bigint, groups: bigint[], objects = ["a", "", "c"]) => { + const bytes = await Writer.collect(version, async (writer) => { + await writer.u62(id); + let previousGroup: bigint | undefined; + for (const group of groups) { + for (const [object, payload] of objects.entries()) + await new FetchFrame({ payload: new TextEncoder().encode(`${payload && group}${payload}`) }).encode( + writer, + { + group, + object, + first: previousGroup === undefined && object === 0, + previousGroup: object === 0 ? previousGroup : undefined, + }, + undefined, + version, + ); + previousGroup = group; + } + }); + return subscriber.handleFetch(new Reader(undefined, bytes, version)); + }; + return { subscriber, broadcast, next, status, fetch, answer, data, readers }; +} + +async function payloads(group: { readFrame(): Promise<{ payload: Uint8Array } | undefined> }) { + const out: string[] = []; + for (let frame = await group.readFrame(); frame; frame = await group.readFrame()) + out.push(new TextDecoder().decode(frame.payload)); + return out; +} + +for (const version of VERSIONS) { + test(`${version}: a one-group FETCH waits for FETCH_OK even when its stream overtakes it`, async () => { + const fx = fixture(version); + const pending = fx.broadcast.track("video").fetchGroup(1n); + await fx.status(); + const { stream, request } = await fx.fetch(); + expect(request.groupOrder).toBe("ascending"); + expect(request.type).toEqual( + version === Version.DRAFT_18 + ? { + kind: "standalone", + trackNamespace: Path.from("room"), + trackName: "video", + start: { group: 1n, object: 0n }, + end: { group: 1n, object: 0n }, + } + : { + kind: "filtered", + trackNamespace: Path.from("room"), + trackName: "video", + filter: { + kind: "absolute", + startGroup: 1n, + startObject: 0n, + endGroup: 1n, + endObject: undefined, + }, + }, + ); + const receiving = fx.data(request.requestId, [1n]); + await fx.answer(stream, 1n); + stream.writer.close(); + const group = await pending; + fx.readers.push(group); + expect(await payloads(group)).toEqual(["1a", "", "1c"]); + await receiving; + }); + + test(`${version}: one standalone FETCH answers a past range, including a missing group`, async () => { + const fx = fixture(version); + const reader = fx.broadcast.track("video").subscribe(ranges(1n, 5n)); + fx.readers.push(reader); + const read = reader.recvGroup(); + await fx.status(); + const { stream, request } = await fx.fetch(); + await fx.answer(stream, 4n); + await fx.data(request.requestId, [1n, 3n, 4n]); + const first = await read; + expect(first?.sequence).toBe(1n); + if (!first) throw new Error("missing first group"); + expect(await payloads(first)).toEqual(["1a", "", "1c"]); + first.close(); + for (const sequence of [3n, 4n]) { + const group = await reader.recvGroup(); + expect(group?.sequence).toBe(sequence); + if (!group) throw new Error("missing group"); + expect(await payloads(group)).toEqual([`${sequence}a`, "", `${sequence}c`]); + group.close(); + } + expect(await reader.recvGroup()).toBeUndefined(); + reader.update(ranges(0n, 1n)); + const more = reader.recvGroup(); + const second = await fx.fetch(); + await fx.answer(second.stream, 0n); + await fx.data(second.request.requestId, [0n]); + const group = await more; + expect(group?.sequence).toBe(0n); + group?.close(); + }); + + test(`${version}: a refusal fails its reader and a later reader can ask again`, async () => { + const fx = fixture(version); + const pending = fx.broadcast.track("video").fetchGroup(1n); + const failed = pending.catch((error) => error); + await fx.status(); + const { stream } = await fx.fetch(); + await stream.writer.u53(RequestError.id); + await new RequestError({ errorCode: 0x10, reasonPhrase: "missing" }).encode(stream.writer, version); + expect(await failed).toBeInstanceOf(Error); + expect((await failed).message).toContain("missing"); + const retry = fx.broadcast.track("video").fetchGroup(1n); + const second = await fx.fetch(true); + await fx.answer(second.stream, 1n); + await fx.data(second.request.requestId, [1n]); + const group = await retry; + group.close(); + }); + + test(`${version}: a request reset after FETCH_OK refuses the still-missing data stream`, async () => { + const fx = fixture(version); + const pending = fx.broadcast.track("video").fetchGroup(1n); + const failed = pending.catch((error) => error); + await fx.status(); + const { stream } = await fx.fetch(); + await fx.answer(stream, 1n); + stream.abort(new StreamError(StreamCode.Cancel)); + expect(await failed).toBeInstanceOf(Error); + }); + test(`${version}: abandoning a partial group stops its FETCH data stream`, async () => { + const fx = fixture(version); + const pending = fx.broadcast.track("video").fetchGroup(1n); + await fx.status(); + const { stream, request } = await fx.fetch(); + await fx.answer(stream, 1n); + const prefix = await Writer.collect(version, async (writer) => { + await writer.u62(request.requestId); + await new FetchFrame({ payload: new Uint8Array([42]) }).encode( + writer, + { group: 1n, object: 0, first: true }, + undefined, + version, + ); + }); + const cancelled = Promise.withResolvers(); + const readable = new ReadableStream({ + start(controller) { + controller.enqueue(prefix); + }, + cancel: cancelled.resolve, + }); + const receiving = fx.subscriber.handleFetch(new Reader(readable, new Uint8Array(), version)); + const group = await pending; + expect((await group.readFrame())?.payload).toEqual(new Uint8Array([42])); + group.close(); + await cancelled.promise; + await receiving; + }); + + test(`${version}: cancellation before FETCH_OK ends the outstanding request`, async () => { + const fx = fixture(version); + const controller = new AbortController(); + const pending = fx.broadcast + .track("video") + .fetchGroup(1n, { signal: controller.signal }) + .catch((error) => error); + await fx.status(); + const { stream } = await fx.fetch(); + controller.abort(new Error("caller left")); + expect(await pending).toBeInstanceOf(Error); + await stream.reader.closed.catch(() => undefined); + }); + + test(`${version}: a FETCH object outside the accepted range fails the request`, async () => { + const fx = fixture(version); + const pending = fx.broadcast + .track("video") + .fetchGroup(1n) + .catch((error) => error); + await fx.status(); + const { stream, request } = await fx.fetch(); + await fx.answer(stream, 1n); + await fx.data(request.requestId, [2n]); + expect(await pending).toBeInstanceOf(Error); + }); +} diff --git a/js/net/src/ietf/range.ts b/js/net/src/ietf/range.ts new file mode 100644 index 00000000000..c36c0273af4 --- /dev/null +++ b/js/net/src/ietf/range.ts @@ -0,0 +1,206 @@ +import { race, Signal } from "@moq/signals"; +import { error, NotFound, ProtocolViolation, StreamCode, StreamError } from "../error.ts"; +import { type Fill, fillChanged, wantedRuns } from "../fill.ts"; +import type * as group from "../group.ts"; +import { receiveFrame, skipPayload } from "../payload.ts"; +import type { Cursor, Reader } from "../stream.ts"; +import type { Timescale } from "../time.ts"; +import type * as track from "../track.ts"; +import { untilAborted } from "../util/abort.ts"; +import { decodeFetchObject, EndOfRange } from "./object.ts"; + +/** The groups one standalone FETCH writes, sharing the joining FETCH's object and payload decoder. @internal */ +export class RangeFetch { + readonly fill: Fill; + readonly first: bigint; + readonly last: bigint; + readonly bound?: number; + readonly #track: track.Producer; + readonly #timescale?: Timescale; + readonly #legacy: boolean; + readonly #changed = new Signal(0); + readonly #stop = new AbortController(); + readonly #done = Promise.withResolvers(); + #next: bigint; + #current?: { sequence: bigint; producer?: group.Producer }; + #taken = false; + #finished = false; + + constructor(options: { + fill: Fill; + first: bigint; + track: track.Producer; + timescale?: Timescale; + last: bigint; + bound?: number; + legacy: boolean; + }) { + this.fill = options.fill; + this.first = this.#next = options.first; + this.last = options.last; + this.bound = options.bound; + this.#track = options.track; + this.#timescale = options.timescale; + this.#legacy = options.legacy; + } + + /** Settles when the stream finishes or the request cancels it. */ + get done(): Promise { + return this.#done.promise; + } + + /** Stop once no reader wants the remaining groups or the unfinished group already handed out. */ + async unwanted(): Promise { + for (;;) { + const demand = this.#current?.producer?.demand(); + if ( + this.#finished || + (!wantedRuns(this.fill).some((run) => run.start <= this.last && run.end > this.first) && + !demand?.wanted.peek()) + ) + return; + await race([fillChanged(this.fill), Signal.race(this.#changed, ...(demand ? [demand.wanted] : []))]); + } + } + + /** Abort only this stream's unfinished group and refuse what it still owes. Complete history stays cached. */ + cancel(err: Error): void { + if (this.#finished) return; + this.#current?.producer?.abort(err); + this.fill.refuseGroups(this.#next, this.last + 1n, err); + this.#finish(err); + } + + #finish(err?: Error): void { + this.#finished = true; + this.#stop.abort(err ?? new StreamError(StreamCode.Cancel, { message: "fetch complete" })); + this.#changed.update((n) => n + 1); + this.#done.resolve(); + } + + #closeGroup(): void { + this.#current?.producer?.finish(); + this.#current = undefined; + this.#changed.update((n) => n + 1); + } + + #open(sequence: bigint): void { + if (sequence < this.#next || sequence > this.last) + throw new ProtocolViolation("FETCH group is out of order or past FETCH_OK's End Location"); + this.#closeGroup(); + this.fill.dropGroups(this.#next, sequence); + // A live stream may have answered this sequence while the FETCH was in flight. + const producer = this.fill.isWanted(sequence) ? this.fill.accept(sequence) : undefined; + this.#current = { sequence, producer }; + this.#next = sequence + 1n; + this.#changed.update((n) => n + 1); + } + + /** Read one fetch stream after its header, bounded by FETCH_OK, accepting each group at its first object. */ + async receive(stream: Reader): Promise { + if (this.#taken || this.#finished) throw new Error("FETCH stream no longer wanted"); + this.#taken = true; + let prior: bigint | undefined; + let next = 0; + let first = true; + try { + const decode = (c: Cursor) => decodeFetchObject(c, this.#timescale); + for (;;) { + const object = await untilAborted( + Promise.resolve(stream.tryDecode(decode) ?? stream.decodeMaybe(decode)), + this.#stop.signal, + ); + if (object === undefined) break; + if (object.kind === "endOfRange") { + if ( + object.group < (prior ?? this.first) || + object.group > this.last || + (this.bound !== undefined && object.group === this.last && object.object >= this.bound) + ) + throw new ProtocolViolation("End of Range is outside FETCH_OK's range"); + if (this.#current?.sequence === object.group) { + // The model cannot carry holes between frame ordinals. Refuse this group whole. + this.#current.producer?.abort(new NotFound("FETCH omitted objects within a group")); + this.#current.producer = undefined; + } else { + this.#closeGroup(); + if (object.reason === EndOfRange.NonExistent) this.fill.dropGroups(this.#next, object.group); + else this.fill.refuseGroups(this.#next, object.group, new NotFound("FETCH range unavailable")); + this.fill.refuseGroups( + object.group, + object.group + 1n, + new NotFound("FETCH omitted a group prefix"), + ); + this.#current = { sequence: object.group }; + this.#next = object.group + 1n; + } + prior = object.group; + next = object.object + 1; + first = true; + continue; + } + if ( + first && + (object.group === undefined || + object.object === undefined || + object.priority === undefined || + object.subgroup === "prior" || + object.subgroup === "next") + ) + throw new ProtocolViolation("the first fetch object refers to a prior object"); + if ( + object.subgroup === "datagram" || + object.subgroup === "next" || + (object.subgroup === "explicit" && object.subgroupId !== 0) + ) + throw new Error("FETCH subgroups and datagrams are unsupported"); + const sequence = + object.group === undefined ? prior : prior === undefined ? object.group : prior + object.group + 1n; + if (sequence === undefined || sequence > 0xffff_ffff_ffff_ffffn) + throw new ProtocolViolation("invalid FETCH Group ID"); + if (this.#current?.sequence !== sequence) { + this.#open(sequence); + next = 0; + } + const id = + object.group === undefined + ? object.object === undefined + ? next + : next - 1 + object.object + : object.object; + if (id === undefined || id !== next || !Number.isSafeInteger(id)) + throw new Error("FETCH object gap is unsupported"); + if (sequence === this.last && this.bound !== undefined && id >= this.bound) + throw new ProtocolViolation("FETCH continued past FETCH_OK's End Location"); + if (this.#timescale !== undefined && object.timestamp === undefined) + throw new StreamError(StreamCode.MalformedTrack, { + message: `object without a Timestamp on a track with TIMESCALE: group=${sequence}`, + }); + const producer = this.#current?.producer; + if (producer) { + if (object.payload) producer.writeFrame({ payload: object.payload, timestamp: object.timestamp }); + else if (!(await untilAborted(receiveFrame(stream, producer, object), this.#stop.signal))) + throw new Error("FETCH group was abandoned"); + } else if (!object.payload) await untilAborted(skipPayload(stream, object.size), this.#stop.signal); + prior = sequence; + next = id + 1; + first = false; + } + if ( + this.#legacy && + this.bound !== undefined && + (this.#current?.sequence !== this.last || next < this.bound) + ) + throw new ProtocolViolation("FETCH ended before FETCH_OK's End Location"); + this.#closeGroup(); + this.fill.dropGroups(this.#next, this.last + 1n); + this.#finish(); + } catch (cause) { + const err = error(cause); + this.cancel(err); + if (err instanceof StreamError && err.code === StreamCode.MalformedTrack) this.#track.abort(err); + stream.stop(err); + throw err; + } + } +} diff --git a/js/net/src/ietf/subscriber.test.ts b/js/net/src/ietf/subscriber.test.ts index a649a2dccbb..a072afa190e 100644 --- a/js/net/src/ietf/subscriber.test.ts +++ b/js/net/src/ietf/subscriber.test.ts @@ -24,6 +24,7 @@ import { NativeSession } from "./session.ts"; import { Subscribe, SubscribeOk, SubscribeUpdate } from "./subscribe.ts"; import { SubscribeNamespace, SubscribeNamespaceEntry, SubscribeNamespaceEntryDone } from "./subscribe_namespace.ts"; import { Subscriber } from "./subscriber.ts"; +import { TrackStatusOk, TrackStatusRequest } from "./track.ts"; import { ALPN, type IetfVersion, Version } from "./version.ts"; const VERSION = Version.DRAFT_18; @@ -903,19 +904,18 @@ test("older peer without priority property inherits the default publisher priori track.close(); }); -test("an info-only lookup waits for SUBSCRIBE_OK instead of abandoning", async () => { +test("an info-only lookup waits for TRACK_STATUS_OK instead of abandoning", async () => { const pair = createMockTransportPair(ALPN.DRAFT_18); const session = new NativeSession(pair.server, VERSION, true); const subscriber = new Subscriber({ session }); const info = subscriber.consume(Path.from("room")).track("video").info(); const peer = await nextStream(pair.client); - if (!peer) throw new Error("missing SUBSCRIBE stream"); - expect(await peer.reader.u53()).toBe(Subscribe.id); - await Subscribe.decode(peer.reader, VERSION); + if (!peer) throw new Error("missing TRACK_STATUS stream"); + expect(await peer.reader.u53()).toBe(TrackStatusRequest.id); + await TrackStatusRequest.decode(peer.reader, VERSION); - await peer.writer.u53(SubscribeOk.id); - await new SubscribeOk({ - trackAlias: ALIAS, + await peer.writer.u53(TrackStatusOk.id); + await new TrackStatusOk({ properties: { priority: 37 }, }).encode(peer.writer, VERSION); expect((await info).priority).toBe(127 - 37); diff --git a/js/net/src/ietf/subscriber.ts b/js/net/src/ietf/subscriber.ts index c181b66a7f0..abcb092aa81 100644 --- a/js/net/src/ietf/subscriber.ts +++ b/js/net/src/ietf/subscriber.ts @@ -10,6 +10,7 @@ import * as DatagramStream from "../datagram_stream.ts"; import { closeError, error, + NotFound, ProtocolViolation, reason, SessionCode, @@ -18,6 +19,7 @@ import { sessionCause, unauthorized, } from "../error.ts"; +import { type Fill, fillChanged, type Requests, wantedRuns } from "../fill.ts"; import type * as netGroup from "../group.ts"; import { Cost, type Route, routesEqual, UNKNOWN_HOP } from "../hop.ts"; import * as Instance from "../instance.ts"; @@ -34,8 +36,9 @@ import { closeUnwanted } from "../util/announce.ts"; import { Deadline, requestOptions } from "../util/deadline.ts"; import { abandoned as demandAbandoned, isAbandoned, unwanted } from "../util/demand.ts"; import { LIMITS, type Limits, SlotMap, Slots } from "../util/limits.ts"; -import { wireSpan } from "../window.ts"; -import { overrideBroadcastWire, wireOf } from "../wire.ts"; +import { min } from "../util/sequence.ts"; +import { bounded, wireSpan } from "../window.ts"; +import { wireOf } from "../wire.ts"; import { DuplicateTrackAlias, RetiredTrackAlias, TrackAliases } from "./aliases.ts"; import * as Cluster from "./cluster.ts"; import { ObjectDatagram } from "./datagram.ts"; @@ -57,12 +60,14 @@ import { Parameters } from "./parameters.ts"; import { DEFAULT_WIRE, fromWire, toWire } from "./priority.ts"; import { type Publish, PublishDone, PublishDoneStatus, publishDoneClean } from "./publish.ts"; import { type AdvertParams, type PublishNamespace, PublishNamespaceUpdate } from "./publish_namespace.ts"; +import { RangeFetch } from "./range.ts"; import { RequestError, RequestOk } from "./request.ts"; -import { type Framed, RequestStream, refuseReserved, refuseUpdate } from "./request_stream.ts"; +import { type Framed, malformed, RequestStream, refuseReserved, refuseUpdate } from "./request_stream.ts"; import type { Session } from "./session.ts"; import { joinFilter, Subscribe, SubscribeOk, SubscribeUpdate } from "./subscribe.ts"; import { SubscribeNamespace, SubscribeNamespaceEntry, SubscribeNamespaceEntryDone } from "./subscribe_namespace.ts"; import { MalformedAuthToken } from "./token.ts"; +import { TrackStatusOk, TrackStatusRequest } from "./track.ts"; // Wire ceiling (2^62-1). A draining session stamps it on every live route so any other // candidate outranks it, while the route stays selectable as the last path. Matches Rust @@ -103,6 +108,7 @@ type SubscribeSetupState = { // The accepted subscription, which a registered alias names. subscription?: Subscription; registeredAlias?: bigint; + requests?: Requests; /** * Whether the caller has given up. Setup checks this once the stream exists so a request * opened after the timeout still unwinds: nothing else settles setup if the peer has @@ -165,6 +171,8 @@ export class Subscriber { // a draft-18 joining FETCH's own request ID, or a draft-22 SUBSCRIBE's, whose fill can // overtake SUBSCRIBE_OK and so waits on it. A fetch stream needs no track alias. #fetches = new Map>(); + #ranges = new Map>(); + #joins = new WeakMap(); // Dedup consumed broadcasts per path: repeat consume() calls share one subscription. #consumes = new BroadcastCache(); @@ -684,7 +692,6 @@ export class Subscriber { } #createConsume(path: Path.Valid, instance: ReturnType): broadcast.Consumer { - // moq-transport resolves metadata through SUBSCRIBE and has no one-shot group fetch here. const consumer = new ConsumeBroadcast(); // Registered before anyone can list the broadcast, so no reader syncs on an empty answer. void this.#refuseListing(wireOf(consumer).lister()); @@ -727,7 +734,7 @@ export class Subscriber { ]); } - async #runSubscribe(broadcast: Path.Valid, request: track.Request, valid?: AbortSignal) { + async #runSubscribe(broadcast: Path.Valid, request: track.Request, valid?: AbortSignal, known?: track.Producer) { const refused = unauthorized(broadcast); try { for (;;) { @@ -750,6 +757,11 @@ export class Subscriber { return; } + if (!known && (bounded(request.subscription.ranges ?? [{}]) || request.demand().wanted.peek() === undefined)) { + await this.#runHistory(broadcast, request, valid); + return; + } + let requestId: bigint | undefined; try { valid?.throwIfAborted(); @@ -773,7 +785,7 @@ export class Subscriber { // and any registration if setup eventually finishes. const state: SubscribeSetupState = {}; const deadline = new Deadline(); - const setup = this.#openSubscribe(state, broadcast, request, requestId, deadline); + const setup = this.#openSubscribe(state, broadcast, request, requestId, deadline, known); // The publisher can be serving before it answers, so waiting only on the response // would miss the local side going away and leave it serving a track nobody reads. @@ -828,6 +840,7 @@ export class Subscriber { state.fill?.(undefined); this.#fetches.delete(requestId); state.subscription?.join?.cancel(e); + state.requests?.close(); if ( state.registeredAlias !== undefined && @@ -853,6 +866,7 @@ export class Subscriber { } const producer = subscription.track; + if (state.requests) void this.#runFills(broadcast, producer, state.requests, valid); let disposeGrant: Dispose | undefined; // Ends the joining FETCH with the subscription. const joining = new AbortController(); @@ -944,6 +958,294 @@ export class Subscriber { } } + // A bounded read can be entirely below Largest, including on a finished track that refuses + // SUBSCRIBE. Learn its properties without subscribing, then let its misses ask FETCHes. + async #runHistory(broadcast: Path.Valid, request: track.Request, valid?: AbortSignal) { + const stop = new AbortController(); + const signal = valid ? AbortSignal.any([valid, stop.signal]) : stop.signal; + const revoked = this.#grant?.subscribe(() => { + if (this.#denied(broadcast)) stop.abort(unauthorized(broadcast)); + }); + let stream: RequestStream | undefined; + let producer: track.Producer | undefined; + let fills: Promise | undefined; + const deadline = new Deadline(); + try { + const setup = async () => { + const id = await this.#session.nextRequestId(signal); + if (id === undefined) throw await this.#closedSession(); + stream = await RequestStream.open(this.#session, deadline, this.#quic); + if (signal.aborted) { + stream.abort(signal.reason); + signal.throwIfAborted(); + } + await Message.write( + stream.writer, + TrackStatusRequest.id, + new TrackStatusRequest({ + requestId: id, + trackNamespace: broadcast, + trackName: request.name, + }), + this.#session.version, + ); + const response = await stream.next(); + if (response?.type === RequestError.id) { + const err = await RequestError.decode(response.reader, this.#session.version); + throw new Error( + requestReason(err.errorCode, err.reasonPhrase, "track_status", this.#session.version), + ); + } + if (response?.type !== TrackStatusOk.id) throw new ProtocolViolation("expected TRACK_STATUS_OK"); + try { + return await TrackStatusOk.decode(response.reader, this.#session.version); + } catch (err) { + throw malformed(err, "TRACK_STATUS_OK"); + } + }; + const ok = await untilAborted( + race([ + deadline.wait(setup()), + demandAbandoned(request.demand()).then((): never => { + throw new Error("history read abandoned"); + }), + ]), + signal, + ); + stream?.close(); + if (this.#denied(broadcast)) throw unauthorized(broadcast); + const cache = ok.properties.maxCacheDuration; + if (cache !== undefined && cache > BigInt(Number.MAX_SAFE_INTEGER)) + throw new RangeError("max cache duration exceeds safe milliseconds"); + const staged = hooks.stageRequest(request, { + timescale: ok.properties.timescale, + priority: fromWire(ok.properties.priority ?? DEFAULT_WIRE), + maxAge: cache === undefined ? undefined : Milli(Number(cache)), + ietf: this.#session.version, + }); + producer = staged.producer; + hooks.receiveTrack(producer); + hooks.startTrack(producer, { start: null }); + if (ok.largest) hooks.reportedGroup(producer, ok.largest.groupId); + const requests = producer.requests(); + fills = this.#runFills(broadcast, producer, requests, signal); + staged.commit(); + for (;;) { + if (hooks.trackReleased(producer).peek() !== undefined) return; + const subscription = producer.subscription.peek(); + if (!subscription) { + hooks.releaseTrack(producer); + return; + } + if (subscription) { + const span = wireSpan(subscription.ranges ?? [{}]); + if ( + !bounded(subscription.ranges ?? [{}]) || + (span.end !== undefined && span.end > (ok.largest ? ok.largest.groupId + 1n : 0n)) + ) { + await this.#runSubscribe(broadcast, request, signal, producer); + return; + } + } + await untilAborted( + Promise.resolve(Signal.race(producer.subscription, hooks.trackReleased(producer))), + signal, + ); + } + } catch (cause) { + const err = await sessionCause(this.#quic, cause); + stream?.abort(err); + request.reject(err); + } finally { + stop.abort(); + revoked?.(); + if (producer) hooks.releaseTrack(producer); + await fills; + } + } + + // One handler per received track. Each fill owns its network request, and cancellation of + // the track stops and joins every job before releasing the handler. + async #runFills(broadcast: Path.Valid, producer: track.Producer, requests: Requests, valid?: AbortSignal) { + const stop = new AbortController(); + const signal = valid ? AbortSignal.any([valid, stop.signal]) : stop.signal; + const released = hooks + .trackReleased(producer) + .subscribe(() => stop.abort(hooks.trackReleased(producer).peek())); + const jobs = new Set>(); + try { + for (;;) { + const fill = await untilAborted(requests.requestedFill(), signal); + if (!fill) break; + const run = async () => { + try { + // The join may already bring a miss in this run. Let it answer first instead + // of fetching the same head twice. + const join = this.#joins.get(producer); + if (join && fill.start <= join.sequence && fill.end > join.sequence) { + await untilAborted(join.settled, signal); + // A failed join costs that head. Retrying it as standalone would hide a publisher bug. + if (fill.isWanted(join.sequence)) + fill.refuseGroups( + join.sequence, + join.sequence + 1n, + new NotFound("joining FETCH did not provide the head"), + ); + } + for (let run = wantedRuns(fill)[0]; run; run = wantedRuns(fill)[0]) { + await this.#runRangeFetch(broadcast, producer, { fill, ...run, signal }); + } + } catch (cause) { + fill.refuseGroups(fill.start, fill.end, error(cause)); + } finally { + fill.close(); + } + }; + const job = run(); + jobs.add(job); + void job.then(() => jobs.delete(job)); + } + } catch (cause) { + if (!signal.aborted) producer.abort(error(cause)); + } finally { + stop.abort(); + released(); + requests.close(); + await Promise.all(jobs); + } + } + + async #runRangeFetch( + broadcast: Path.Valid, + producer: track.Producer, + options: { fill: Fill; start: bigint; end: bigint; signal: AbortSignal }, + ) { + const { fill, start, end: until, signal } = options; + const version = this.#session.version; + let stream: RequestStream | undefined; + let id: bigint | undefined; + let receiving: RangeFetch | undefined; + const accepted = Promise.withResolvers(); + const stop = new AbortController(); + const active = AbortSignal.any([signal, stop.signal]); + const abandoned = async (): Promise => { + while (!receiving) { + if (!wantedRuns(fill).some((run) => run.start < until && run.end > start)) + throw new StreamError(StreamCode.Cancel); + await untilAborted(fillChanged(fill), active); + } + await untilAborted(receiving.unwanted(), active); + throw new StreamError(StreamCode.Cancel); + }; + const run = async () => { + id = await this.#session.nextRequestId(active); + active.throwIfAborted(); + if (id === undefined) throw await this.#closedSession(); + this.#ranges.set(id, accepted.promise); + stream = new RequestStream( + await this.#session.openBi({ ...requestOptions, waitUntilAvailable: true }), + this.#session, + this.#quic, + ); + if (active.aborted) { + stream.abort(active.reason); + active.throwIfAborted(); + } + const last = until - 1n; + const namespace = { trackNamespace: broadcast, trackName: producer.name }; + await Message.write( + stream.writer, + Fetch.id, + new Fetch({ + requestId: id, + subscriberPriority: toWire(fill.priority), + groupOrder: "ascending", + type: isDraft20(version) + ? { + kind: "filtered", + ...namespace, + filter: { kind: "absolute", startGroup: start, startObject: 0n, endGroup: last }, + } + : { + kind: "standalone", + ...namespace, + start: { group: start, object: 0n }, + end: { group: last, object: 0n }, + }, + }), + version, + ); + const response = await stream.next(); + if (response?.type === RequestError.id) { + const err = await RequestError.decode(response.reader, version); + throw new Error(requestReason(err.errorCode, err.reasonPhrase, "fetch", version)); + } + if (response?.type !== FetchOk.id) throw new ProtocolViolation("expected FETCH_OK"); + let ok: FetchOk; + try { + ok = await FetchOk.decode(response.reader, version); + } catch (err) { + throw new ProtocolViolation(`malformed FETCH_OK: ${reason(error(err))}`); + } + active.throwIfAborted(); + const end = ok.endLocation; + const whole = !isDraft20(version) && end.group === last && end.object === 0n; + if (isDraft20(version) && (end.group < start || end.group > last)) + throw new ProtocolViolation("FETCH_OK's End Location is outside the requested range"); + if (!whole && (end.group < start || (end.group === start && end.object === 0n && !isDraft20(version)))) + throw new NotFound("empty FETCH"); + const covered = whole + ? last + : end.object === 0n && !isDraft20(version) + ? min(end.group - 1n, last) + : min(end.group, last); + const bound = + whole || end.group > last || (end.object === 0n && !isDraft20(version)) + ? undefined + : end.object + (isDraft20(version) ? 1n : 0n); + if (bound !== undefined && bound > BigInt(Number.MAX_SAFE_INTEGER)) + throw new ProtocolViolation("FETCH_OK Object ID exceeds the model's safe range"); + if (ok.endOfTrack) + hooks.endTrack(producer, { + group: end.group + (whole || isDraft20(version) || end.object > 0n ? 1n : 0n), + frame: 0, + }); + if (covered < last) + fill.refuseGroups(covered + 1n, until, new NotFound("FETCH ended before the requested range")); + const info = await producer.info(); + active.throwIfAborted(); + receiving = new RangeFetch({ + fill, + first: start, + track: producer, + timescale: info.timescale ?? undefined, + last: covered, + bound: bound === undefined ? undefined : Number(bound), + legacy: !isDraft20(version), + }); + accepted.resolve(receiving); + const ended = stream.next().then((message) => { + if (message !== undefined) throw new ProtocolViolation("unexpected message after FETCH_OK"); + return receiving?.done; + }); + await race([receiving.done, ended]); + stream.close(); + }; + try { + await untilAborted(race([run(), abandoned()]), signal); + } catch (cause) { + const err = await sessionCause(this.#quic, cause); + receiving?.cancel(err); + fill.refuseGroups(start, until, err); + stream?.abort(err); + if (err instanceof ProtocolViolation) this.#fail(err.code, err.message); + } finally { + stop.abort(); + accepted.resolve(undefined); + if (id !== undefined) this.#ranges.delete(id); + } + } + /** * Read the PUBLISH_DONE that ends a subscription, then wait for the data streams it counts. * @@ -1180,6 +1482,7 @@ export class Subscriber { request: track.Request, requestId: bigint, deadline: Deadline, + known?: track.Producer, ): Promise<{ stream: RequestStream; subscription: Subscription; @@ -1248,16 +1551,20 @@ export class Subscriber { } // Staged until the answer is written in below, so no reader sees the track before its // Largest and start. - const staged = hooks.stageRequest(request, { - // No TIMESCALE means no timeline, and the track must not claim one when served onward. - timescale: ok.properties.timescale, - priority: fromWire(ok.properties.priority ?? DEFAULT_WIRE), - maxAge: maxCacheDuration === undefined ? undefined : Milli(Number(maxCacheDuration)), - // A moq-transport peer may stamp arrival times, and nothing on the wire says it didn't. - ietf: version, - }); - const producer = staged.producer; + const staged = known + ? undefined + : hooks.stageRequest(request, { + // No TIMESCALE means no timeline, and the track must not claim one when served onward. + timescale: ok.properties.timescale, + priority: fromWire(ok.properties.priority ?? DEFAULT_WIRE), + maxAge: maxCacheDuration === undefined ? undefined : Milli(Number(maxCacheDuration)), + // A moq-transport peer may stamp arrival times, and nothing on the wire says it didn't. + ietf: version, + }); + const producer = known ?? staged?.producer; + if (!producer) throw new Error("subscription has no track"); hooks.receiveTrack(producer); + if (!known) state.requests = producer.requests(); const tail = new Tail(); const subscription: Subscription = { track: producer, tail, timescale: ok.properties.timescale, fetchIds: [] }; // The subscription starts after Largest, so the joining FETCH or the fill brings its @@ -1265,6 +1572,7 @@ export class Subscriber { // is one of the subscription's own streams, so the Stream Count already waits for it. if (ok.largest) { subscription.join = new Join(ok.largest.groupId, tail, { counted: msg.fill !== undefined }); + this.#joins.set(producer, subscription.join); } if (msg.fill) subscription.fetchIds.push(requestId); state.subscription = subscription; @@ -1281,7 +1589,7 @@ export class Subscriber { start: ok.largest ? ok.largest.groupId : 0n, requested: wireSpan(request.subscription.ranges ?? [{}]).start, }); - staged.commit(); + staged?.commit(); state.fill?.(subscription); try { @@ -1659,10 +1967,10 @@ export class Subscriber { } /** - * Handles a fetch stream, with its type already read: the head of a join, answering a - * draft-18 joining FETCH or a draft-22 fill. + * Handles a fetch stream, with its type already read: a standalone range, a draft-18 + * joining FETCH, or a draft-22 fill. * - * Either asked for one group from object 0, so the first object must spell + * A joining FETCH or fill asked for one group from object 0, so its first object must spell * `{G, 0}` and every later one follow it in that group. The head is created as soon as its * first object arrives and written as the objects do, so readers see it at once; the live * tail takes the group over through the {@link Join}. Anything the head cannot stitch, @@ -1673,6 +1981,20 @@ export class Subscriber { async handleFetch(stream: Reader) { const version = this.#session.version; const { requestId } = await FetchHeader.decode(stream, version); + const range = this.#ranges.get(requestId); + if (range) { + const receiving = await range; + if (!receiving) { + stream.stop(new StreamError(StreamCode.Cancel)); + return; + } + try { + await receiving.receive(stream); + } catch (err) { + if (err instanceof ProtocolViolation) this.#fail(err.code, err.message); + } + return; + } const subscription = await this.#fetches.get(requestId); // Nothing of ours asked: the publisher is answering a FETCH or fill we never sent. if (!subscription?.join) throw new Error(`unexpected fetch stream: request=${requestId}`); @@ -1854,18 +2176,11 @@ export class Subscriber { } } -/** - * A broadcast consumed from a moq-transport session. Track info is resolved by the - * subscribe path (the inherited `resolveTrackInfo`), but this client has no one-shot - * group fetch, so the wire offers none and `track.Consumer.fetchGroup()` is rejected. - */ +// The protected broadcast constructor keeps network-backed consumers package-private. class ConsumeBroadcast extends broadcast.Consumer { constructor(state?: never) { super(state); - overrideBroadcastWire(this, { fetchGroup: undefined }); } - - // Preserve the subclass when the consume cache shares this broadcast across callers. override clone(): ConsumeBroadcast { return new ConsumeBroadcast(this.shareState()); } diff --git a/js/net/src/integration.test.ts b/js/net/src/integration.test.ts index 063438c8dc2..281d522de18 100644 --- a/js/net/src/integration.test.ts +++ b/js/net/src/integration.test.ts @@ -1448,23 +1448,39 @@ test("integration: lite draft-07 fetch uses the republished track's timescale", server.abort(); }); -test("integration: ietf fetch group is unsupported", async () => { - const pair = createMockTransportPair(Ietf.ALPN.DRAFT_18); - const origin = new OriginProducer(); - - const [client, server] = await Promise.all([ - connect(url, { transport: pair.client }), - accept(pair.server, url, { publish: origin.consume() }), - ]); - - const remote = wireOf(client).consume(Path.from("test")); - await expect(remote.track("video").fetchGroup(0n)).rejects.toThrow( - "fetch group is not supported by this session's version", - ); - - remote.close(); - client.abort(); - server.abort(); +test("integration: ietf fetches a past group of a finished track", async () => { + for (const protocol of [Ietf.ALPN.DRAFT_18, Ietf.ALPN.DRAFT_20, Ietf.ALPN.DRAFT_22]) { + const pair = createMockTransportPair(protocol); + const origin = new OriginProducer(); + const publication = origin.createBroadcast(Path.from("test")); + publication.announce(); + const published = publication.broadcast.createTrack("video", { timescale: Timescale.MILLI }); + for (let sequence = 0; sequence < 3; sequence++) { + const group = published.appendGroup(); + group.writeFrame({ + payload: new Uint8Array([sequence]), + timestamp: new Timestamp(sequence * 1000, Timescale.MILLI), + }); + group.finish(); + } + published.finish(); + const [client, server] = await Promise.all([ + connect(url, { transport: pair.client }), + accept(pair.server, url, { publish: origin.consume() }), + ]); + const remote = wireOf(client).consume(Path.from("test")); + const group = await remote.track("video").fetchGroup(1n); + expect(group.sequence).toBe(1n); + const frame = await group.readFrame(); + expect(frame?.payload).toEqual(new Uint8Array([1])); + expect(frame?.timestamp).toEqual(new Timestamp(1000, Timescale.MILLI)); + expect(await group.readFrame()).toBeUndefined(); + group.close(); + remote.close(); + client.abort(); + server.abort(); + origin.close(); + } }); // We list no tracks by PUBLISH, so a SUBSCRIBE_TRACKS is refused NOT_SUPPORTED on its own stream, and diff --git a/js/net/src/track.ts b/js/net/src/track.ts index 74c246c66f7..c35e2cce28b 100644 --- a/js/net/src/track.ts +++ b/js/net/src/track.ts @@ -2570,6 +2570,15 @@ export class Subscriber { #askFills(start: bigint, end: bigint, drift?: Drift): bigint | undefined { const producer = this.#state.producer; if (this.#resume || !producer || this.#closed) return undefined; + // An IETF live join supplies the current group, not all history. An explicit past + // anchor still fetches below it, while an implicit live join starts where it was served. + if ( + this.#state.info.peek()?.ietf !== undefined && + this.#window.ranges.every((range) => range.start === undefined || range.start.relative === 0) + ) { + const floor = sourceStart(producer); + if (typeof floor === "bigint") start = max(start, max(floor, this.#state.first ?? floor)); + } const fills = fillsOf(producer); // A fill already out can be joined even once its handler's handle closed. if (fills.serving || fills.active) { @@ -2582,7 +2591,10 @@ export class Subscriber { // `NotFetchable`. const gone = [...this.#state.drops.peek()]; for (const sequence of heldDatagrams(producer)) insertRun(gone, sequence, sequence + 1n); - for (const run of this.#wants(start, min(end, this.#state.received.peek()))) { + for (const run of this.#wants( + start, + min(end, max(this.#state.received.peek(), (this.#state.largest.peek()?.group ?? -1n) + 1n)), + )) { for (const open of runGaps(gone, run.start, run.end)) { let next = open.start; for (let i = timelineIndex(timeline, open.start); i < timeline.length; i++) { @@ -2710,7 +2722,7 @@ export class Subscriber { // A fill still owes a group it reads. if (this.#askFills(this.#window.floor() ?? 0n, end) !== undefined) return false; const held = this.#state.groups.peek(); - const received = this.#state.received.peek(); + const received = max(this.#state.received.peek(), (this.#state.largest.peek()?.group ?? -1n) + 1n); const drops = this.#state.drops.peek(); const producer = this.#state.producer; for (const run of this.#window.runs(this.#window.floor() ?? 0n, end)) { diff --git a/quest/m1/README.md b/quest/m1/README.md index c337183922c..345897d8706 100644 --- a/quest/m1/README.md +++ b/quest/m1/README.md @@ -166,7 +166,6 @@ per-frame CPU growth since #5926. - [crates.io trusts the workflow](/quest/m1/crates-trusted-publisher.md) - maintainer action: every published crate gets a trusted publisher for `release-rs.yml` - [Rust releases publish through OIDC](/quest/m1/release-rs-oidc.md) - release-plz publishes with trusted publishing and `CARGO_REGISTRY_TOKEN` is revoked - [Main is no slower than release](/quest/m1/release-perf/README.md) - every benchmark where main is slower than release is fixed or accepted with a reason, checked by a final paired run before the cut -- [Interop coverage](/quest/m1/interop-coverage/README.md) - the riskiest moq-transport features moq-net exposes get cross-implementation tests over drafts 18, 20, and 22 - [Calibrate the paired nightly benchmarks](/quest/m1/bench-ci.md) - A/A and deliberately slowed Nightly runs set the paired comparison's threshold, so its regression alerts can be trusted - [Unbounded groups](/quest/m1/unbounded-groups/README.md) - groups and frames lose their size caps; a group keeps a 32 MB tail, and readers behind it replay through paced flights or refresh - [Poll-first async](/quest/m1/poll-first/README.md) - library crates compile no coroutines by default: async wrappers are generated from `poll_*` and gated behind an `async` feature diff --git a/quest/m1/ietf-drop/README.md b/quest/m1/ietf-drop/README.md index 3f91d98eb92..55b65ae06b8 100644 --- a/quest/m1/ietf-drop/README.md +++ b/quest/m1/ietf-drop/README.md @@ -44,7 +44,3 @@ protocol implementation or release work remains here. ## Waiting - englishm/moq-interop-runner: review and merge [englishm/moq-interop-runner#183](https://github.com/englishm/moq-interop-runner/pull/183); verify both registry entries and README rows list drafts 18, 20, and 22 before deleting this quest - -## Related - -- [Interop coverage](/quest/m1/interop-coverage/README.md) - cross-implementation cases target drafts 18, 20, and 22 diff --git a/quest/m1/interop-coverage/README.md b/quest/m1/interop-coverage/README.md deleted file mode 100644 index f5a07d7c1d9..00000000000 --- a/quest/m1/interop-coverage/README.md +++ /dev/null @@ -1,58 +0,0 @@ -# Interop coverage for moq-transport - -## Goal - -The moq-transport features moq-net exposes with the most interop bug -history have cross-implementation tests: Rust, JS, and the bindings exchange -hang media and exercise subgroup data, namespace discovery, late joins, -FETCH, GOAWAY, TRACK_STATUS, and datagrams over drafts 18, 20, and 22. Our -upstream runner clients implement the runner's existing cases for those -features. - -Boundaries: - -- Only what moq-net can do. Subgroups other than 0, rendezvous, and - per-request authorization tokens are not exposed, so they are out of - scope, and runner cells that need them stay red by design. -- PUBLISH (push) and outbound forward=0 are out of scope (decided - 2026-10-25, maintainer, reversing the 2026-10-22 decision): no child - quest owned them, and the cases above carry the interop bug history. -- Media stays hang. No MSF catalog in our runner clients. -- New cases live in-tree (`test/interop`), not in the runner's spec. -- Not covered: mid-subscription updates (`Subscription::update` in Rust and - JS, sent as SUBSCRIBE_UPDATE or REQUEST_UPDATE) for priority, max age, - NEW_GROUP_REQUEST, and group order. The maintainer did not pick them on - 2026-10-21; plan them separately if their bug history grows. - -## Plan - -Decided 2026-11-02 (maintainer, follow-up planning after the 2026-11-02 /quest-complete run): draft 20 joins the covered drafts, since it came back in -[moq-dev/moq#7190](https://github.com/moq-dev/moq/pull/7190) and every published moq-dev client and relay already offers it (verified on -[moq-dev/moq#6972](https://github.com/moq-dev/moq/pull/6972)). - - -Decided with the maintainer on 2026-10-21, from an inventory of the -coverage on `main` at `3ab6cbf81d`. - -- `just test interop --versions ietf` runs the matrix on each supported draft; - every new case runs on it. Beyond it, moq-transport is covered by - in-process codec tests (`rs/moq-net/src/test_interop.rs`), the public - relays page (published clients), and the Cloudflare and Moxygen smoke - lanes. -- Drafts 18, 20, and 22 only, nightly. Protocol removal and draft-20 - restoration have landed; only the - [runner registry correction](/quest/m1/ietf-drop/README.md) remains. - The request-limits case went with drafts 14 and 16, the only ones with - MAX_REQUEST_ID. -- Case ranking follows interop bug history: subgroup data and namespace - discovery, then late join and FETCH, then GOAWAY, TRACK_STATUS, - and datagrams. - -## Required - -- [JS subscribers FETCH](/quest/m1/interop-coverage/js-ietf-fetch.md) - `@moq/net` fetches past groups over moq-transport, and joins the CLI FETCH round - -## Related - -- [Runner client bump](/quest/m2/release/runner-client-bump.md) - after the cut publishes #5083, the runner's Rust client stops stamping every object -- [Interop audit](/quest/m2/audit-interop.md) - classifies the red cells these cases produce diff --git a/quest/m1/interop-coverage/js-ietf-fetch.md b/quest/m1/interop-coverage/js-ietf-fetch.md deleted file mode 100644 index dcaf9307ffe..00000000000 --- a/quest/m1/interop-coverage/js-ietf-fetch.md +++ /dev/null @@ -1,27 +0,0 @@ -# [M] JS subscribers FETCH over moq-transport - -## Goal - -`@moq/net`'s moq-transport subscriber fetches a past group with a standalone -FETCH, so `track.Consumer.fetchGroup()` works on moq-transport. JS subscribers -join the CLI FETCH interop round beside Rust. - -## Plan - -Found by [moq-dev/moq#7015](https://github.com/moq-dev/moq/pull/7015). Today -`track.Consumer.fetchGroup()` is rejected on moq-transport. The mid-group -join already recovers the current group's head, with a joining FETCH on -draft 18 or a fill on draft 22 -([moq-dev/moq#7089](https://github.com/moq-dev/moq/pull/7089)), and its -fetch-stream decoder and head stitching are what a standalone FETCH reuses. - -Decided 2026-10-28 (maintainer): one [M] quest in m1, after -JS ranges ([moq-dev/moq#7696](https://github.com/moq-dev/moq/pull/7696)), which turns `fetchGroup` into -a one-range subscription. Map a past range to a standalone FETCH, the way -Rust's subscriber does. Then add the native JS runtimes as subscribers to the -`run_fetch_round` cells in the tail suite. Our publishers answer only one -group ([moq-dev/moq#7204](https://github.com/moq-dev/moq/pull/7204), 2026-10-28), so a -past-range FETCH against them is refused. Test ranges against a third-party -publisher, and one group against ours. - -Public API: none beyond JS ranges' surface. Wire: none. diff --git a/quest/m2/audit-interop.md b/quest/m2/audit-interop.md index 3fd93f7f433..d16ddae4d68 100644 --- a/quest/m2/audit-interop.md +++ b/quest/m2/audit-interop.md @@ -191,4 +191,3 @@ cells of the 2026-10-31 nightly. Classify it. - [Runner client bump](/quest/m2/release/runner-client-bump.md) - the runner's Rust client moves to the cut and its API - [Runner teardown](/quest/m3/interop-runner-approval.md) - the runner's moq.dev clients move to the withdrawing `close()` once it ships -- [Interop coverage](/quest/m1/interop-coverage/README.md) - the runner cases whose red cells this audit classifies diff --git a/test/ietf-conformance/README.md b/test/ietf-conformance/README.md index a2e81df6593..1fb68017941 100644 --- a/test/ietf-conformance/README.md +++ b/test/ietf-conformance/README.md @@ -35,6 +35,19 @@ reviewing the selected cases, rebasing the profile patch, and rerunning the full matrix. The build recipe adds the client's missing Folly ManualExecutor link dependency and patches dependency script interpreters for Nix. +## Native JS FETCH ranges + +The same run also has Node and Bun read multi-group past ranges directly from the pinned +Moxygen publisher on draft 18. A separate live connection advances the publisher beyond +the requested groups, so the FETCH connection shares none of its cache. Both readers check +the group sequences, every object and its payload, overlapping ranges, missing groups, and +bounded EOF. First-party publishers serve only one group per FETCH and are covered by the +interop tail matrix instead. + +Run only this lane with `just test ietf-conformance --fetch`. It also runs in the full +nightly conformance recipe. The fixture pins draft 18 at SETUP because this Moxygen revision's +HTTP/3 listener predates WebTransport subprotocol negotiation. + ## Conformance profile The client runs under a relay conformance profile, applied by diff --git a/test/ietf-conformance/run.sh b/test/ietf-conformance/run.sh index 6a8023d7429..7da74b6522b 100755 --- a/test/ietf-conformance/run.sh +++ b/test/ietf-conformance/run.sh @@ -7,6 +7,13 @@ if [[ "${GITHUB_ACTIONS:-}" != true && "${LOCAL_SUPERVISED:-}" != 1 ]]; then exec bash "$(dirname "$0")/../../sh/local.sh" bash "$0" "$@" fi +fetch_only=0 +case "${1:-}" in + "") ;; + --fetch) fetch_only=1 ;; + *) echo "usage: run.sh [--fetch]" >&2; exit 2 ;; +esac + CONFORMANCE_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) WORKSPACE=$(cd "$CONFORMANCE_DIR/../.." && pwd) # shellcheck source-path=SCRIPTDIR source=../lib/harness.sh @@ -20,7 +27,8 @@ relay="$WORKSPACE/${CARGO_TARGET_DIR:-target}/debug/moq-relay" # Cargo accepts an absolute target directory too. [[ "${CARGO_TARGET_DIR:-}" != /* ]] || relay="$CARGO_TARGET_DIR/debug/moq-relay" -harness_begin ietf-conformance "$(harness_env HARNESS_RESULTS)just test ietf-conformance" +bun install --frozen-lockfile +harness_begin ietf-conformance "$(harness_env HARNESS_RESULTS)just test ietf-conformance$(harness_argv "$@")" python3 "$CONFORMANCE_DIR/prepare.py" "$package/share/moxygen/conformance_test.sh" "$HARNESS_RUN/conformance.sh" # LibreSSL in the dev shell has no system-wide openssl.cnf. cat >"$HARNESS_RUN/openssl.cnf" <<'EOF' @@ -112,10 +120,34 @@ run_suite() { fi } +# Fetch directly from Moxygen: first-party publishers intentionally serve one group only. +run_js_ranges() { + local runtime status + for runtime in node bun; do + status=0 + local command=(bun) + [[ "$runtime" != node ]] || command=(node --import tsx) + harness_spawn "fetch-$runtime" "$HARNESS_RUN/fetch-$runtime.log" \ + timeout -k 3 30 "${command[@]}" "$WORKSPACE/test/interop/clients/js-native/ranges.ts" \ + "https://127.0.0.1:$publisher_port/test" "$HARNESS_RUN/cert.pem" + harness_wait "$HARNESS_PID" || status=$? + cat "$HARNESS_RUN/fetch-$runtime.log" + local cell=(suite=ietf-conformance case="JS FETCH ranges" version=moq-transport-18 transport=quic publisher=moxygen subscriber="js-native-$runtime" log="$HARNESS_RUN/fetch-$runtime.log") + if ((status == 0)) && publisher_healthy; then + harness_result pass "${cell[@]}" + else + harness_result fail "${cell[@]}" + failed=1 + fi + done +} + # Moxygen's MoQVersions.h uses moqt-20-meta-02 for draft 20; use shared moqt-18. failed=0 version=18 -for topology in single cluster; do +topologies=(single cluster) +((fetch_only == 0)) || topologies=(single) +for topology in "${topologies[@]}"; do label="$topology-$version" start_relay "$label-origin" "$version" ingress="$HARNESS_PORT" @@ -137,9 +169,10 @@ for topology in single cluster; do namespace_ready # A direct-origin control distinguishes suite/pin failures from relay behavior. if [[ "$topology" == single ]]; then - run_suite "reference-$version" "https://127.0.0.1:$publisher_port/test" + run_js_ranges + ((fetch_only == 1)) || run_suite "reference-$version" "https://127.0.0.1:$publisher_port/test" fi - run_suite "$label" "https://127.0.0.1:$egress/" + ((fetch_only == 1)) || run_suite "$label" "https://127.0.0.1:$egress/" harness_reap "$publisher_pid" [[ -z "$egress_pid" ]] || harness_reap "$egress_pid" harness_reap "$ingress_pid" diff --git a/test/interop/README.md b/test/interop/README.md index 03eaaf3895f..f9f5e31c59c 100644 --- a/test/interop/README.md +++ b/test/interop/README.md @@ -51,9 +51,9 @@ The normal run also checks a finite raw track through the relay. Its publisher announces end 4 before writing four 256 KiB groups; the reader verifies every byte, exactly groups 0 through 3, and a clean end at 4. Rust-to-Rust always runs. Selecting native JS adds both Rust-to-JS and JS-to-Rust under that runtime, so `--all` covers -Node and Bun. The current CLI also FETCHes group 1 of a finished track from the Rust -publisher and each selected native JS runtime, requires exactly its three objects, each -with its own bytes, and closes under the relay idle-out check. Each native JS runtime also serves +Node and Bun. The FETCH round crosses Rust and each selected native JS runtime as both +publisher and subscriber. Each reader fetches group 1 of a finished track, requires exactly +its three objects, each with its own bytes, and closes under the relay idle-out check. Each native JS runtime also serves that FETCH from history (`CLI FETCH history`): its publisher writes only group 3 live and answers groups 0 through 2, which it never cached, from an in-memory responder on `track.requests()`. A moq-transport pass skips it, since JavaScript does not route an IETF FETCH to the responder yet. diff --git a/test/interop/clients/js-native/ranges.ts b/test/interop/clients/js-native/ranges.ts new file mode 100644 index 00000000000..25cac270ee6 --- /dev/null +++ b/test/interop/clients/js-native/ranges.ts @@ -0,0 +1,94 @@ +/** Standalone multi-group FETCH against the pinned Moxygen publisher. @module */ +import assert from "node:assert/strict"; +import { readFileSync } from "node:fs"; +import * as Moq from "@moq/net"; +import WebTransport from "@moq/web-transport"; +import { offered } from "../../../../js/net/src/connection/extensions.ts"; +import { exchangeSetup } from "../../../../js/net/src/connection/handshake.ts"; +import { Connection } from "../../../../js/net/src/ietf/connection.ts"; +import { Version } from "../../../../js/net/src/ietf/version.ts"; +import { wireOf } from "../../../../js/net/src/wire.ts"; + +console.debug = console.error; +console.info = console.error; +const [address, certificate] = process.argv.slice(2); +assert(address && certificate, "usage: ranges.ts URL CERTIFICATE"); +const url = new URL(address); +const cert = readFileSync(certificate, "utf8"); +// MoQTest's 16 namespace fields: subgroup zero, groups 0,2,...,1000, three objects per +// group, 1024/513-byte payloads, 10 ms between objects, and no status markers or properties. +const path = Moq.Path.from("moq-test-00/0/0/0/1000/2/3/1024/513/10/2/1/0/-1/-1/0"); +async function connect() { + const transport = new WebTransport(url, { + protocols: ["moqt-18"], + serverCertificateHashes: [{ algorithm: "sha-256", value: await Moq.Connection.certificateHash(cert) }], + }); + await transport.ready; + // Moxygen's pinned HTTP/3 server predates subprotocol negotiation. This fixture's + // server offers draft 18 alone, so exchange that SETUP directly on its WebTransport. + const extensions = offered({ auth: false, solicit: false }); + const setup = await exchangeSetup(transport, Version.DRAFT_18, "interop-ranges", { client: true, extensions }); + return new Connection({ url, quic: transport, version: Version.DRAFT_18, client: true, extensions, ...setup }); +} + +function payload(bytes: Uint8Array, size: number) { + assert.equal(bytes.byteLength, size, "wrong object size"); + for (const [offset, byte] of bytes.entries()) + assert.equal(byte, offset % 256 === 0 ? (offset >> 8) & 255 : 0x74, `corrupt object at ${offset}`); +} + +const live = await connect(); +const source = wireOf(live).consume(path); +const holder = source.track("test").subscribe({ delay: { max: null } }); +try { + // Give TRACK_STATUS a real live edge without sharing this connection's cache with FETCH. + for (;;) { + const group = await holder.recvGroup(); + assert(group, "publisher ended before its past range existed"); + while (await group.readFrame()) {} + group.close(); + if (group.sequence >= 8n) break; + } + const history = await connect(); + const broadcast = wireOf(history).consume(path); + try { + for (const [start, end, expected] of [ + [2n, 7n, [2n, 4n, 6n]], + [0n, 5n, [0n, 2n, 4n]], + ] as const) { + const reader = broadcast.track("test").subscribe({ + ranges: [{ start: { absolute: start }, end: { absolute: end } }], + delay: { max: null }, + order: "ascending", + }); + try { + const seen: bigint[] = []; + for (let group = await reader.recvGroup(); group; group = await reader.recvGroup()) { + seen.push(group.sequence); + try { + for (const size of [1024, 513, 513]) { + const frame = await group.readFrame(); + assert(frame, "FETCH omitted an object"); + payload(frame.payload, size); + } + assert.equal(await group.readFrame(), undefined, "FETCH repeated an object"); + } finally { + group.close(); + } + } + assert.deepEqual(seen, expected, "FETCH omitted, repeated, or renumbered a group"); + } finally { + reader.close(); + } + } + console.error("moxygen ranges clean groups=2,4,6;0,2,4 frames=18"); + } finally { + broadcast.close(); + await history.close(); + } +} finally { + holder.close(); + source.close(); + await live.close(); +} +process.exit(0); diff --git a/test/interop/clients/js-native/tail.ts b/test/interop/clients/js-native/tail.ts index 5ff5fabae80..0b40dd68fad 100644 --- a/test/interop/clients/js-native/tail.ts +++ b/test/interop/clients/js-native/tail.ts @@ -35,14 +35,15 @@ const status = mode === "status"; const cached = mode === "cached"; const history = mode === "history"; const late = mode === "late"; +const fetch = mode === "fetch"; if ( !url || !path || !["publish", "subscribe"].includes(role) || - ![undefined, "drop", "join", "compress", "datagram", "status", "cached", "history", "late"].includes(mode) + ![undefined, "drop", "join", "compress", "datagram", "status", "cached", "history", "late", "fetch"].includes(mode) ) { throw new Error( - "usage: tail.ts publish|subscribe URL BROADCAST [VERSION [drop|join|compress|datagram|status|cached|history|late]]", + "usage: tail.ts publish|subscribe URL BROADCAST [VERSION [drop|join|compress|datagram|status|cached|history|late|fetch]]", ); } @@ -54,7 +55,7 @@ if ( function frames(sequence: number): Uint8Array[] { if (compress) return [new Uint8Array(BYTES / 2).fill(sequence), new Uint8Array(0), new Uint8Array(BYTES / 2).fill(sequence)]; - if (cached || history || late) + if (cached || history || late || fetch) return [0, 1, 2].map((index) => new Uint8Array(BYTES / 4).fill(sequence * 16 + index)); return [new Uint8Array(BYTES).fill(sequence)]; } @@ -170,68 +171,78 @@ try { await request.active.changed(); broadcast = request.active.peek(); } - // `late` names no start, joining the latest group as a player does: group 0, whose - // head predates the subscription. - const track = broadcast.track("tail").subscribe({ - delay: { max: Milli(drop ? 60_000 : 5000) }, - ...(late ? {} : { ranges: [{ start: { absolute: 0n } }] }), - }); - if (compress) assert.equal((await track.info()).compress, version === "moq-lite-07-wip"); - const seen: number[] = []; - try { - if (datagram) { - await track.info(); - process.stdout.write("datagram ready\n"); - for (let sequence = 0; sequence < GROUPS; sequence++) { - const frame = await track.recvDatagram(); - assert(frame, "missing datagram"); - assert.equal(frame.sequence, BigInt(sequence), "wrong datagram sequence"); - assert.equal(frame.payload.byteLength, 900, "truncated datagram"); - assert( - frame.payload.every((byte) => byte === sequence), - "corrupt datagram", - ); - assert.equal(frame.timestamp, undefined, "unexpected IETF timestamp"); - process.stdout.write(`datagram ${sequence}\n`); - } - console.error("datagram clean groups=0,1,2,3 bytes=3600"); - } else if (late) { - for (let sequence = 0; sequence < LATE_GROUPS; sequence++) { - const group = await track.recvGroup(); - assert(group, "missing group"); - try { - assert.equal(group.sequence, BigInt(sequence), "joined the wrong group"); - await read(group); - } finally { - group.close(); + if (fetch) { + const group = await broadcast.track("tail").fetchGroup(1n); + try { + await read(group); + } finally { + group.close(); + } + console.error("fetch clean group=1 frames=3 bytes=196608"); + } else { + // `late` names no start, joining the latest group as a player does: group 0, whose + // head predates the subscription. + const track = broadcast.track("tail").subscribe({ + delay: { max: Milli(drop ? 60_000 : 5000) }, + ...(late ? {} : { ranges: [{ start: { absolute: 0n } }] }), + }); + if (compress) assert.equal((await track.info()).compress, version === "moq-lite-07-wip"); + const seen: number[] = []; + try { + if (datagram) { + await track.info(); + process.stdout.write("datagram ready\n"); + for (let sequence = 0; sequence < GROUPS; sequence++) { + const frame = await track.recvDatagram(); + assert(frame, "missing datagram"); + assert.equal(frame.sequence, BigInt(sequence), "wrong datagram sequence"); + assert.equal(frame.payload.byteLength, 900, "truncated datagram"); + assert( + frame.payload.every((byte) => byte === sequence), + "corrupt datagram", + ); + assert.equal(frame.timestamp, undefined, "unexpected IETF timestamp"); + process.stdout.write(`datagram ${sequence}\n`); } - } - assert.equal(await track.recvGroup(), undefined, "extra group"); - assert.deepEqual(await track.finished(), { group: BigInt(LATE_GROUPS), frame: 0 }); - console.error("late join clean groups=0,1 frames=6"); - } else { - for (;;) { - const group = await track.recvGroup(); - if (!group) break; - try { - assert(group.sequence < GROUPS, `unexpected group ${group.sequence}`); - await read(group); - seen.push(Number(group.sequence)); - } finally { - group.close(); + console.error("datagram clean groups=0,1,2,3 bytes=3600"); + } else if (late) { + for (let sequence = 0; sequence < LATE_GROUPS; sequence++) { + const group = await track.recvGroup(); + assert(group, "missing group"); + try { + assert.equal(group.sequence, BigInt(sequence), "joined the wrong group"); + await read(group); + } finally { + group.close(); + } + } + assert.equal(await track.recvGroup(), undefined, "extra group"); + assert.deepEqual(await track.finished(), { group: BigInt(LATE_GROUPS), frame: 0 }); + console.error("late join clean groups=0,1 frames=6"); + } else { + for (;;) { + const group = await track.recvGroup(); + if (!group) break; + try { + assert(group.sequence < GROUPS, `unexpected group ${group.sequence}`); + await read(group); + seen.push(Number(group.sequence)); + } finally { + group.close(); + } } + seen.sort((a, b) => a - b); + const first = join ? (seen[0] ?? 0) : 0; + const all = Array.from({ length: GROUPS - first }, (_, i) => first + i); + assert.deepEqual(seen, drop ? [0, 2, 3] : all); + assert.deepEqual(await track.finished(), { group: BigInt(GROUPS), frame: 0 }); + if (join) console.error(`tail join clean end=4 groups=${seen.join(",")}`); + else if (drop) console.error("tail drop clean end=4 groups=0,2,3 bytes=786432"); + else console.error("tail clean end=4 groups=0,1,2,3 bytes=1048576"); } - seen.sort((a, b) => a - b); - const first = join ? (seen[0] ?? 0) : 0; - const all = Array.from({ length: GROUPS - first }, (_, i) => first + i); - assert.deepEqual(seen, drop ? [0, 2, 3] : all); - assert.deepEqual(await track.finished(), { group: BigInt(GROUPS), frame: 0 }); - if (join) console.error(`tail join clean end=4 groups=${seen.join(",")}`); - else if (drop) console.error("tail drop clean end=4 groups=0,2,3 bytes=786432"); - else console.error("tail clean end=4 groups=0,1,2,3 bytes=1048576"); + } finally { + track.close(); } - } finally { - track.close(); } } finally { request.close(); diff --git a/test/interop/interop.sh b/test/interop/interop.sh index ee23c7580a5..425b10fa564 100755 --- a/test/interop/interop.sh +++ b/test/interop/interop.sh @@ -498,12 +498,17 @@ plan_pass() { done fi [[ "$FINISH_ONLY" -eq 0 ]] || return 0 - record "not run" case="CLI FETCH" publisher=rust subscriber=rust + for pub in rust js-native-node js-native-bun; do + [[ "$pub" == rust ]] || needs "$pub" || continue + for sub in rust js-native-node js-native-bun; do + [[ "$sub" == rust ]] || needs "$sub" || continue + record "not run" case="CLI FETCH" publisher="$pub" subscriber="$sub" + done + done record "not run" case="late join" publisher=rust subscriber=rust record "not run" case=tail publisher=rust subscriber=rust for runtime in js-native-node js-native-bun; do needs "$runtime" || continue - record "not run" case="CLI FETCH" publisher="$runtime" subscriber=rust # run_tails skips it on moq-transport, so only plan it where it runs. [[ "$VERSION" == moq-transport-* ]] || record "not run" case="CLI FETCH history" publisher="$runtime" subscriber=rust record "not run" case="late join" publisher=rust subscriber="$runtime" @@ -2054,18 +2059,18 @@ run_late_pair() { rm "$fifo" "$heads" } -# This checkout's CLI FETCHes a past group of a finished track, under the same relay close check as +# Rust and native JS FETCH a past group of a finished track, under the same relay close check as # live readers. Every object has its own bytes, so a FETCH that drops, repeats, or reorders one fails. # The `history` mode (native JS only) serves the group from the publisher's request handler: it # was never in its cache. run_fetch_round() { - local pub="$1" mode="${2:-cached}" pid from version - local name="fetch-$1${2:+-$2}" fifo="$LOGS/fetch-ack" broadcast="fetch-$1-$$-$RANDOM" - local label="CLI FETCH${2:+ $2}" + local pub="$1" sub="$2" mode="${3:-cached}" pid from version + local name="fetch-$1-$2${3:+-$3}" fifo="$LOGS/fetch-ack" broadcast="fetch-$1-$$-$RANDOM" + local label="CLI FETCH${3:+ $3}" local started=$SECONDS why="" - local cell=(case="$label" publisher="$pub" subscriber=rust log="$LOGS/$name-pub.log") - if is_broken "$pub"; then - echo " FAIL $label $pub (client unavailable)" + local cell=(case="$label" publisher="$pub" subscriber="$sub" log="$LOGS/$name-sub.log") + if is_broken "$pub" || is_broken "$sub"; then + echo " FAIL $label $pub -> $sub (client unavailable)" record fail "${cell[@]}" detail="client unavailable" overall=1 return @@ -2076,30 +2081,22 @@ run_fetch_round() { exec 9<>"$fifo" harness_spawn "$name-pub" "$LOGS/$name-pub.log" run_tail_publisher "$fifo" "$pub" publish "$broadcast" "$(token_url --publish "$(publish_grant "$broadcast")")" "$version" "$mode" pid="$HARNESS_PID" - if timeout -k 3 "$TIMEOUT" "$MOQ" --connect "$(token_url --subscribe "$(subscribe_grant "$broadcast")")" ${version:+--connect-version "$version"} \ - --broadcast "$broadcast" fetch tail --group 1 --json >"$LOGS/$name.json" && - python3 - "$LOGS/$name.json" <<'PYCODE' -import base64, json, sys -frames = [json.loads(line) for line in open(sys.argv[1])] -assert [(frame["group"], frame["frame"], frame["size"]) for frame in frames] == [(1, index, 64 * 1024) for index in range(3)], frames -assert [base64.b64decode(frame["payload"], validate=True) for frame in frames] == [bytes([16 + index]) * (64 * 1024) for index in range(3)], "incorrect FETCH payload" -PYCODE - then + if run_fetch_subscriber "$sub" "$broadcast" "$version" "$name"; then printf 'clean end\n' >&9 harness_wait "$pid" || true if grep -qx 'tail acknowledged' "$LOGS/$name-pub.log"; then - echo " PASS $label $pub (group 1; 3 objects)" + echo " PASS $label $pub -> $sub (group 1; 3 objects)" else - echo " FAIL $label $pub (publisher did not acknowledge)" + echo " FAIL $label $pub -> $sub (publisher did not acknowledge)" why="publisher did not acknowledge" overall=1 cat "$LOGS/$name-pub.log" fi else - echo " FAIL $label $pub" + echo " FAIL $label $pub -> $sub" why="incorrect or missing FETCH payload" overall=1 - cat "$LOGS/$name-pub.log" + cat "$LOGS/$name-pub.log" "$LOGS/$name-sub.log" harness_reap "$pid" fi exec 9>&- @@ -2113,6 +2110,23 @@ PYCODE if [[ -z "$why" ]]; then record pass "${cell[@]}"; else record fail "${cell[@]}" detail="$why"; fi } +run_fetch_subscriber() { + local sub="$1" broadcast="$2" version="$3" name="$4" + if [[ "$sub" != rust ]]; then + run_tail_client "$sub" subscribe "$broadcast" "$(token_url --subscribe "$(subscribe_grant "$broadcast")")" "$version" fetch >"$LOGS/$name-sub.log" 2>&1 && + grep -qx 'fetch clean group=1 frames=3 bytes=196608' "$LOGS/$name-sub.log" + return + fi + timeout -k 3 "$TIMEOUT" "$MOQ" --connect "$(token_url --subscribe "$(subscribe_grant "$broadcast")")" ${version:+--connect-version "$version"} \ + --broadcast "$broadcast" fetch tail --group 1 --json >"$LOGS/$name.json" 2>"$LOGS/$name-sub.log" && + python3 - "$LOGS/$name.json" <<'PYCODE' +import base64, json, sys +frames = [json.loads(line) for line in open(sys.argv[1])] +assert [(frame["group"], frame["frame"], frame["size"]) for frame in frames] == [(1, index, 64 * 1024) for index in range(3)], frames +assert [base64.b64decode(frame["payload"], validate=True) for frame in frames] == [bytes([16 + index]) * (64 * 1024) for index in range(3)], "incorrect FETCH payload" +PYCODE +} + # One media.ts invocation. It reports its own verdict (a negative control passes by failing on the # assertion it names), so the exit code is the whole answer. MEDIA_RUNS=0 @@ -2440,12 +2454,18 @@ run_hls_records() { run_tails() { local runtime version echo "=== CLI FETCH close ===" - run_fetch_round rust + local pub sub + for pub in rust js-native-node js-native-bun; do + [[ "$pub" == rust ]] || needs "$pub" || continue + for sub in rust js-native-node js-native-bun; do + [[ "$sub" == rust ]] || needs "$sub" || continue + run_fetch_round "$pub" "$sub" + done + done for runtime in js-native-node js-native-bun; do needs "$runtime" || continue - run_fetch_round "$runtime" # A moq-transport FETCH is not served from the request handler yet. - [[ "$(pinned_version)" == moq-transport-* ]] || run_fetch_round "$runtime" history + [[ "$(pinned_version)" == moq-transport-* ]] || run_fetch_round "$runtime" rust history done echo "=== late join ===" run_late_pair rust rust diff --git a/test/justfile b/test/justfile index 7b702810714..66ddf4244f4 100644 --- a/test/justfile +++ b/test/justfile @@ -95,8 +95,9 @@ wire-compat *args: ./interop/compat.sh "$@" # Pinned Moxygen sections 1-7, subgroup zero, through one relay under the conformance profile. -ietf-conformance: - ./ietf-conformance/run.sh +[positional-arguments] +ietf-conformance *args: + ./ietf-conformance/run.sh "$@" # Installs each client from its public registry, inside test/smoke's own Nix # shell rather than this repo's toolchain. The first argument picks a smoke From 3c3f318d4a2f64d572d9c93175fdea9c083fff13 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 18:44:04 -0800 Subject: [PATCH 03/11] test(interop): read overlapping FETCH ranges in sequence order Co-Authored-By: GPT-6.1 Sol --- test/interop/clients/js-native/ranges.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/interop/clients/js-native/ranges.ts b/test/interop/clients/js-native/ranges.ts index 25cac270ee6..b14015f79e0 100644 --- a/test/interop/clients/js-native/ranges.ts +++ b/test/interop/clients/js-native/ranges.ts @@ -63,7 +63,8 @@ try { }); try { const seen: bigint[] = []; - for (let group = await reader.recvGroup(); group; group = await reader.recvGroup()) { + const ordered = reader.ordered(); + for (let group = await ordered.nextGroup(); group; group = await ordered.nextGroup()) { seen.push(group.sequence); try { for (const size of [1024, 513, 513]) { From 130472a7e1df421e6b9756f56ff4886f2b3fd605 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 18:47:01 -0800 Subject: [PATCH 04/11] fix(net): stop fetch streams whose receiver is already settled Co-Authored-By: GPT-6.1 Sol --- js/net/src/ietf/range.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/js/net/src/ietf/range.ts b/js/net/src/ietf/range.ts index c36c0273af4..5fb4ed5d451 100644 --- a/js/net/src/ietf/range.ts +++ b/js/net/src/ietf/range.ts @@ -98,7 +98,10 @@ export class RangeFetch { /** Read one fetch stream after its header, bounded by FETCH_OK, accepting each group at its first object. */ async receive(stream: Reader): Promise { - if (this.#taken || this.#finished) throw new Error("FETCH stream no longer wanted"); + if (this.#taken || this.#finished) { + stream.stop(new StreamError(StreamCode.Cancel, { message: "FETCH stream no longer wanted" })); + return; + } this.#taken = true; let prior: bigint | undefined; let next = 0; From fa16088499fb4a6d3ded2ab6987bd2c20dab5db4 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 18:52:20 -0800 Subject: [PATCH 05/11] fix(net): fetch ordered history gaps without a phantom live feed Co-Authored-By: GPT-6.1 Sol --- js/net/src/ietf/range.test.ts | 34 ++++++++++++++++++++++++++-------- js/net/src/ietf/subscriber.ts | 3 +-- test/ietf-conformance/run.sh | 5 ++++- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/js/net/src/ietf/range.test.ts b/js/net/src/ietf/range.test.ts index 3ad55fec5e6..6422e31d3a1 100644 --- a/js/net/src/ietf/range.test.ts +++ b/js/net/src/ietf/range.test.ts @@ -143,7 +143,8 @@ for (const version of VERSIONS) { const fx = fixture(version); const reader = fx.broadcast.track("video").subscribe(ranges(1n, 5n)); fx.readers.push(reader); - const read = reader.recvGroup(); + const ordered = reader.ordered(); + const read = ordered.nextGroup(); await fx.status(); const { stream, request } = await fx.fetch(); await fx.answer(stream, 4n); @@ -154,20 +155,37 @@ for (const version of VERSIONS) { expect(await payloads(first)).toEqual(["1a", "", "1c"]); first.close(); for (const sequence of [3n, 4n]) { - const group = await reader.recvGroup(); + const group = await ordered.nextGroup(); expect(group?.sequence).toBe(sequence); if (!group) throw new Error("missing group"); expect(await payloads(group)).toEqual([`${sequence}a`, "", `${sequence}c`]); group.close(); } - expect(await reader.recvGroup()).toBeUndefined(); - reader.update(ranges(0n, 1n)); - const more = reader.recvGroup(); + expect(await ordered.nextGroup()).toBeUndefined(); + const overlapping = fx.broadcast.track("video").subscribe(ranges(0n, 5n)); + fx.readers.push(overlapping); + const overlap = overlapping.ordered(); + const missing = overlap.nextGroup(); + const backfill = await fx.fetch(); + await fx.answer(backfill.stream, 0n); + await fx.data(backfill.request.requestId, [0n]); + const zero = await missing; + expect(zero?.sequence).toBe(0n); + zero?.close(); + for (const sequence of [1n, 3n, 4n]) { + const group = await overlap.nextGroup(); + expect(group?.sequence).toBe(sequence); + group?.close(); + } + expect(await overlap.nextGroup()).toBeUndefined(); + overlapping.close(); + reader.update(ranges(5n, 6n)); + const more = ordered.nextGroup(); const second = await fx.fetch(); - await fx.answer(second.stream, 0n); - await fx.data(second.request.requestId, [0n]); + await fx.answer(second.stream, 5n); + await fx.data(second.request.requestId, [5n]); const group = await more; - expect(group?.sequence).toBe(0n); + expect(group?.sequence).toBe(5n); group?.close(); }); diff --git a/js/net/src/ietf/subscriber.ts b/js/net/src/ietf/subscriber.ts index abcb092aa81..390242b746d 100644 --- a/js/net/src/ietf/subscriber.ts +++ b/js/net/src/ietf/subscriber.ts @@ -1024,8 +1024,7 @@ export class Subscriber { ietf: this.#session.version, }); producer = staged.producer; - hooks.receiveTrack(producer); - hooks.startTrack(producer, { start: null }); + // Only FETCH feeds this copy. Mark it live if a later widening opens SUBSCRIBE. if (ok.largest) hooks.reportedGroup(producer, ok.largest.groupId); const requests = producer.requests(); fills = this.#runFills(broadcast, producer, requests, signal); diff --git a/test/ietf-conformance/run.sh b/test/ietf-conformance/run.sh index 7da74b6522b..a5fc3b3e5d2 100755 --- a/test/ietf-conformance/run.sh +++ b/test/ietf-conformance/run.sh @@ -11,7 +11,10 @@ fetch_only=0 case "${1:-}" in "") ;; --fetch) fetch_only=1 ;; - *) echo "usage: run.sh [--fetch]" >&2; exit 2 ;; + *) + echo "usage: run.sh [--fetch]" >&2 + exit 2 + ;; esac CONFORMANCE_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) From cd2a99bab965f5fc62eea5bd660715c20667ef5e Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 18:56:35 -0800 Subject: [PATCH 06/11] fix(net): keep one-shot FETCH independent of the reported live edge Co-Authored-By: GPT-6.1 Sol --- js/net/src/ietf/range.test.ts | 9 ++++++--- js/net/src/ietf/subscriber.ts | 7 +++++-- js/net/src/internal.ts | 5 +++++ js/net/src/track.ts | 8 ++++++++ 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/js/net/src/ietf/range.test.ts b/js/net/src/ietf/range.test.ts index 6422e31d3a1..2c52051764e 100644 --- a/js/net/src/ietf/range.test.ts +++ b/js/net/src/ietf/range.test.ts @@ -42,13 +42,16 @@ function fixture(version: IetfVersion) { if (stream.done) throw new Error("missing request"); return new Stream({ ...stream.value, version }); }; - const status = async (largest = 5n, provided?: Stream, typed = false) => { + const status = async (largest: bigint | null = 5n, provided?: Stream, typed = false) => { const stream = provided ?? (await next()); if (!typed) expect(await stream.reader.u53()).toBe(TrackStatusRequest.id); const request = await TrackStatusRequest.decode(stream.reader, version); expect([request.trackNamespace, request.trackName]).toEqual([Path.from("room"), "video"]); await stream.writer.u53(TrackStatusOk.id); - await new TrackStatusOk({ largest: { groupId: largest, objectId: 2n } }).encode(stream.writer, version); + await new TrackStatusOk({ largest: largest === null ? undefined : { groupId: largest, objectId: 2n } }).encode( + stream.writer, + version, + ); stream.writer.close(); }; const fetch = async (allowStatus = false) => { @@ -105,7 +108,7 @@ for (const version of VERSIONS) { test(`${version}: a one-group FETCH waits for FETCH_OK even when its stream overtakes it`, async () => { const fx = fixture(version); const pending = fx.broadcast.track("video").fetchGroup(1n); - await fx.status(); + await fx.status(null); const { stream, request } = await fx.fetch(); expect(request.groupOrder).toBe("ascending"); expect(request.type).toEqual( diff --git a/js/net/src/ietf/subscriber.ts b/js/net/src/ietf/subscriber.ts index 390242b746d..a14e2bddc7e 100644 --- a/js/net/src/ietf/subscriber.ts +++ b/js/net/src/ietf/subscriber.ts @@ -1029,6 +1029,7 @@ export class Subscriber { const requests = producer.requests(); fills = this.#runFills(broadcast, producer, requests, signal); staged.commit(); + const subscribing = hooks.subscribing(producer); for (;;) { if (hooks.trackReleased(producer).peek() !== undefined) return; const subscription = producer.subscription.peek(); @@ -1040,14 +1041,16 @@ export class Subscriber { const span = wireSpan(subscription.ranges ?? [{}]); if ( !bounded(subscription.ranges ?? [{}]) || - (span.end !== undefined && span.end > (ok.largest ? ok.largest.groupId + 1n : 0n)) + (subscribing.peek() && + span.end !== undefined && + span.end > (ok.largest ? ok.largest.groupId + 1n : 0n)) ) { await this.#runSubscribe(broadcast, request, signal, producer); return; } } await untilAborted( - Promise.resolve(Signal.race(producer.subscription, hooks.trackReleased(producer))), + Promise.resolve(Signal.race(producer.subscription, subscribing, hooks.trackReleased(producer))), signal, ); } diff --git a/js/net/src/internal.ts b/js/net/src/internal.ts index 0f503cff677..520593f4c7a 100644 --- a/js/net/src/internal.ts +++ b/js/net/src/internal.ts @@ -615,6 +615,8 @@ export const hooks: { groupChanged: (subscriber: Subscriber, fn: () => void) => Dispose; /** Apply a FETCH reader budget without inheriting SUBSCRIBE's zero default. */ fetchBudget: (subscriber: Subscriber, maxDelay: Milli | undefined) => void; + /** Whether a reader beyond one-shot fetches subscribes to this copy. */ + subscribing: (producer: Producer) => Getter; /** * A fetch's group `sequence`, before it reads: `true` once it is cached or asked of a fill, * written yet or not, as the Rust `fetch_group` queues one; `false` with no handler to ask; @@ -858,6 +860,9 @@ export const hooks: { groupChanged: () => { throw new Error("track.ts not loaded"); }, + subscribing: () => { + throw new Error("track module not loaded"); + }, fetchBudget: () => { throw new Error("track.ts not loaded"); }, diff --git a/js/net/src/track.ts b/js/net/src/track.ts index c35e2cce28b..72ad3f5b01e 100644 --- a/js/net/src/track.ts +++ b/js/net/src/track.ts @@ -653,6 +653,8 @@ class TrackState { dropsAnchors = new Signal(false); // Frames wake the sequence cursor only while an owed hole holds it. waitingOrdered = false; + // One-shot group reads need FETCH, even when metadata has not reported a live edge. + fetch = false; // Bumped when a wire subscription declares or resolves where its live feed starts, so a // publisher holding its first group for that answer wakes. startChanged = new Signal(0); @@ -869,6 +871,7 @@ export class Producer { // One past the highest group or datagram this producer received, like the Rust // `max_sequence`, and where the next append lands. #received = 0n; + #subscribing = new Signal(false); // Recently written source groups, retained for replay to late subscribers and // pruned once idle for longer than the cache window. Each entry tracks the mirror @@ -951,6 +954,7 @@ export class Producer { } static { + hooks.subscribing = (producer) => producer.#subscribing; hooks.receiveTrack = (producer) => { producer.#subscribed = true; }; @@ -1300,6 +1304,7 @@ export class Producer { // applies its own, as each reader's budget does, so the demand asked upstream is the same // before and after the info lands. #updateSubscription(): void { + this.#subscribing.set([...this.#sinks].some((sink) => !sink.fetch && sink.closed.peek() === undefined)); const combined = combineSubscriptions(this.#sinks); this.#settle(); this.#state.update.set(combined); @@ -2937,6 +2942,9 @@ export class Subscriber { hooks.askFetch = (subscriber, sequence) => subscriber.#askFetch(sequence); hooks.fetchBudget = (subscriber, maxDelay) => { subscriber.#fetchBudget = maxDelay ?? Number.POSITIVE_INFINITY; + subscriber.#state.fetch = true; + const update = subscriber.#state.update.peek(); + if (update) subscriber.#state.update.set(update, true); }; // The sequence cursor lives here (it shares the buffer and the drift anchor with // the arrival cursor); `Ordered` is the handle that reaches it. From e54d98c9a5a51acc01f99af03bf938c4f71de9f4 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 19:25:09 -0800 Subject: [PATCH 07/11] fix(net): preserve history across live subscription changes and range markers Co-Authored-By: GPT-6.1 Sol --- js/net/src/ietf/join.test.ts | 42 +++++++++++- js/net/src/ietf/range.test.ts | 86 +++++++++++++++++++++++- js/net/src/ietf/range.ts | 9 ++- js/net/src/ietf/subscriber.test.ts | 9 ++- js/net/src/ietf/subscriber.ts | 79 +++++++++++++++------- js/net/src/ietf/tail.test.ts | 2 +- js/net/src/internal.ts | 10 +++ js/net/src/track.ts | 67 ++++++++++++------ test/interop/clients/js-native/ranges.ts | 2 +- 9 files changed, 251 insertions(+), 55 deletions(-) diff --git a/js/net/src/ietf/join.test.ts b/js/net/src/ietf/join.test.ts index 2bb9938df14..e166f10c7b4 100644 --- a/js/net/src/ietf/join.test.ts +++ b/js/net/src/ietf/join.test.ts @@ -1,7 +1,8 @@ import { expect, jest, onTestFinished, test } from "bun:test"; -import { Elapsed, Instant, Milli, Nano, now, timeout } from "@moq/clock"; +import { Elapsed, Instant, Manual, Milli, Nano, now, timeout } from "@moq/clock"; import * as Connection from "../connection/index.ts"; import { StreamCode } from "../error.ts"; +import { hooks } from "../internal.ts"; import { GRACE } from "../ledger.ts"; import { createMockTransportPair, textFrame } from "../mock.ts"; import { Producer as OriginProducer } from "../origin.ts"; @@ -61,7 +62,10 @@ async function subscribed(version: IetfVersion = VERSION) { const pair = createMockTransportPair(ALPNS[version]); const session = new NativeSession(pair.server, version, true); const subscriber = new Subscriber({ session }); - const consumer = subscriber.consume(Path.from("room")).track("video").subscribe(); + const consumer = subscriber + .consume(Path.from("room")) + .track("video") + .subscribe({ ...track.Subscription.default(), ranges: [{ start: { relative: 0 } }] }); onTestFinished(() => { consumer.close(); session.close(); @@ -617,3 +621,37 @@ for (const version of VERSIONS) { expect(sent.mock.calls).toHaveLength(version === VERSION ? 2 : 0); }); } + +// A completed join must not remain a gate on the group's later cache misses. +test("an evicted joined group is fetched again as standalone history", async () => { + const clock = new Manual(); + const installed = clock.install(); + onTestFinished(() => installed.close()); + const { subscriber, consumer, fetching, fetch, client } = await join(); + if (!fetch) throw new Error("no joining FETCH"); + await accept(fetching); + await subscriber.handleFetch(await head(fetch.requestId, ["h0", "h1"])); + await subscriber.handleGroup(...liveStream(GROUP, 2, ["t2"])); + const first = await consumer.recvGroup(); + expect(await frames(first)).toEqual(["h0", "h1", "t2"]); + first?.close(); + await subscriber.handleGroup(...liveStream(GROUP + 1n, 0, ["new"])); + // Twice the model's 30-second idle cache window, with deterministic time. + await clock.advance(Nano.fromMilli(Milli(60_000))); + expect(hooks.cachedGroup(consumer, GROUP)).toBeUndefined(); + const broadcast = subscriber.consume(Path.from("room")); + onTestFinished(() => broadcast.close()); + const pending = broadcast.track("video").fetchGroup(GROUP); + const stream = await nextStream(client); + if (!stream) throw new Error("no standalone FETCH"); + expect(await stream.reader.u53()).toBe(Fetch.id); + const standalone = await Fetch.decode(stream.reader, VERSION); + expect(standalone.type.kind).toBe("standalone"); + await stream.writer.u53(FetchOk.id); + await new FetchOk({ endOfTrack: false, endLocation: { group: GROUP, object: 3n } }).encode(stream.writer, VERSION); + await subscriber.handleFetch(await head(standalone.requestId, ["h0", "h1", "t2"])); + const group = await pending; + expect(await frames(group)).toEqual(["h0", "h1", "t2"]); + group.close(); + consumer.close(); +}); diff --git a/js/net/src/ietf/range.test.ts b/js/net/src/ietf/range.test.ts index 2c52051764e..4aa288cbab7 100644 --- a/js/net/src/ietf/range.test.ts +++ b/js/net/src/ietf/range.test.ts @@ -1,13 +1,15 @@ import { expect, onTestFinished, test } from "bun:test"; import { StreamCode, StreamError } from "../error.ts"; +import { hooks } from "../internal.ts"; import { createMockTransportPair } from "../mock.ts"; import * as Path from "../path.ts"; import { Reader, Stream, Writer } from "../stream.ts"; -import type { Subscription } from "../track.ts"; +import { type Subscription, Producer as TrackProducer } from "../track.ts"; import { Fetch, FetchOk } from "./fetch.ts"; -import { FetchFrame } from "./object.ts"; +import { EndOfRange, FetchEndOfRange, FetchFrame } from "./object.ts"; import { RequestError } from "./request.ts"; import { NativeSession } from "./session.ts"; +import { Subscribe } from "./subscribe.ts"; import { Subscriber } from "./subscriber.ts"; import { TrackStatusOk, TrackStatusRequest } from "./track.ts"; import { ALPN, type IetfVersion, Version } from "./version.ts"; @@ -276,4 +278,84 @@ for (const version of VERSIONS) { await fx.data(request.requestId, [2n]); expect(await pending).toBeInstanceOf(Error); }); + test(`${version}: a refused live widening leaves history FETCHes and cached groups readable`, async () => { + const fx = fixture(version); + const history = fx.broadcast.track("video").subscribe(ranges(1n, 3n)); + fx.readers.push(history); + const ordered = history.ordered(); + const first = ordered.nextGroup(); + await fx.status(); + const fetching = await fx.fetch(); + await fx.answer(fetching.stream, 2n); + const live = fx.broadcast + .track("video") + .subscribe({ ranges: [{ start: { absolute: 6n } }], delay: { max: null } }); + fx.readers.push(live); + const failed = live.recvGroup().catch((error) => error); + const widening = await fx.next(); + expect(await widening.reader.u53()).toBe(Subscribe.id); + await Subscribe.decode(widening.reader, version); + await widening.writer.u53(RequestError.id); + await new RequestError({ errorCode: 0x10, reasonPhrase: "finished" }).encode(widening.writer, version); + expect(await failed).toBeInstanceOf(Error); + await fx.data(fetching.request.requestId, [1n, 2n]); + const group = await first; + expect(group?.sequence).toBe(1n); + if (!group) throw new Error("missing history group"); + expect(await payloads(group)).toEqual(["1a", "", "1c"]); + group?.close(); + const second = await ordered.nextGroup(); + expect(second?.sequence).toBe(2n); + if (!second) throw new Error("missing history group"); + expect(await payloads(second)).toEqual(["2a", "", "2c"]); + second?.close(); + expect(await ordered.nextGroup()).toBeUndefined(); + const cached = await fx.broadcast.track("video").fetchGroup(1n); + expect(await payloads(cached)).toEqual(["1a", "", "1c"]); + cached.close(); + }); + + test(`${version}: a nonexistent trailing object range preserves the group's payloads`, async () => { + const fx = fixture(version); + const pending = fx.broadcast.track("video").fetchGroup(1n); + await fx.status(); + const { stream, request } = await fx.fetch(); + await fx.answer(stream, 1n, 5n); + const bytes = await Writer.collect(version, async (writer) => { + await writer.u62(request.requestId); + for (const [object, value] of [1, 2, 3].entries()) + await new FetchFrame({ payload: new Uint8Array([value]) }).encode( + writer, + { group: 1n, object, first: object === 0 }, + undefined, + version, + ); + await new FetchEndOfRange({ reason: EndOfRange.NonExistent, group: 1n, object: 5n }).encode( + writer, + version, + ); + }); + await fx.subscriber.handleFetch(new Reader(undefined, bytes, version)); + const group = await pending; + for (const value of [1, 2, 3]) expect((await group.readFrame())?.payload).toEqual(new Uint8Array([value])); + expect(await group.readFrame()).toBeUndefined(); + group.close(); + }); +} + +for (const ietf of [undefined, Version.DRAFT_18]) { + test(`live metadata alone does not turn its pending data into a cache miss (${ietf ?? "lite"})`, async () => { + const producer = new TrackProducer("video").accept({ ietf }); + hooks.receiveTrack(producer); + hooks.reportedGroup(producer, 5n); + const requests = producer.requests(); + const reader = producer.subscribe(ranges(5n, 6n)); + const reading = reader.recvGroup(); + const missing = requests.requestedFill(); + requests.close(); + expect(await missing).toBeUndefined(); + reader.close(); + expect(await reading).toBeUndefined(); + hooks.releaseTrack(producer); + }); } diff --git a/js/net/src/ietf/range.ts b/js/net/src/ietf/range.ts index 5fb4ed5d451..79ecadb7187 100644 --- a/js/net/src/ietf/range.ts +++ b/js/net/src/ietf/range.ts @@ -106,6 +106,7 @@ export class RangeFetch { let prior: bigint | undefined; let next = 0; let first = true; + let trailing = false; try { const decode = (c: Cursor) => decodeFetchObject(c, this.#timescale); for (;;) { @@ -122,9 +123,9 @@ export class RangeFetch { ) throw new ProtocolViolation("End of Range is outside FETCH_OK's range"); if (this.#current?.sequence === object.group) { - // The model cannot carry holes between frame ordinals. Refuse this group whole. - this.#current.producer?.abort(new NotFound("FETCH omitted objects within a group")); - this.#current.producer = undefined; + if (object.reason !== EndOfRange.NonExistent) + throw new NotFound("FETCH group suffix unavailable"); + trailing = true; } else { this.#closeGroup(); if (object.reason === EndOfRange.NonExistent) this.fill.dropGroups(this.#next, object.group); @@ -164,7 +165,9 @@ export class RangeFetch { if (this.#current?.sequence !== sequence) { this.#open(sequence); next = 0; + trailing = false; } + if (trailing) throw new Error("FETCH object gap is unsupported"); const id = object.group === undefined ? object.object === undefined diff --git a/js/net/src/ietf/subscriber.test.ts b/js/net/src/ietf/subscriber.test.ts index a072afa190e..c1333899c8e 100644 --- a/js/net/src/ietf/subscriber.test.ts +++ b/js/net/src/ietf/subscriber.test.ts @@ -10,7 +10,7 @@ import * as Path from "../path.ts"; import { Reader, Stream } from "../stream.ts"; import { Tail } from "../tail.ts"; import { Timescale, Timestamp } from "../time.ts"; -import type * as track from "../track.ts"; +import * as track from "../track.ts"; import * as demandUtil from "../util/demand.ts"; import type * as Cluster from "./cluster.ts"; import { Connection } from "./connection.ts"; @@ -769,7 +769,10 @@ async function subscribeTrack({ const session = new NativeSession(pair.server, version, true); const subscriber = new Subscriber({ session }); - const track = subscriber.consume(Path.from("room")).track("video").subscribe(subscription); + const consumer = subscriber + .consume(Path.from("room")) + .track("video") + .subscribe(subscription ?? { ...track.Subscription.default(), ranges: [{ start: { relative: 0 } }] }); const peer = await nextStream(pair.client); if (!peer) throw new Error("the subscriber never opened a subscribe stream"); @@ -781,7 +784,7 @@ async function subscribeTrack({ await peer.writer.u53(SubscribeOk.id); await new SubscribeOk({ trackAlias: ALIAS, properties }).encode(peer.writer, version); - return { subscriber, track }; + return { subscriber, track: consumer }; } // A refusal already ended the request: a reset back would tell the publisher we failed. diff --git a/js/net/src/ietf/subscriber.ts b/js/net/src/ietf/subscriber.ts index a14e2bddc7e..444d93443ec 100644 --- a/js/net/src/ietf/subscriber.ts +++ b/js/net/src/ietf/subscriber.ts @@ -734,7 +734,12 @@ export class Subscriber { ]); } - async #runSubscribe(broadcast: Path.Valid, request: track.Request, valid?: AbortSignal, known?: track.Producer) { + async #runSubscribe( + broadcast: Path.Valid, + request: track.Request, + valid?: AbortSignal, + known?: { producer: track.Producer; edge: bigint }, + ) { const refused = unauthorized(broadcast); try { for (;;) { @@ -785,7 +790,7 @@ export class Subscriber { // and any registration if setup eventually finishes. const state: SubscribeSetupState = {}; const deadline = new Deadline(); - const setup = this.#openSubscribe(state, broadcast, request, requestId, deadline, known); + const setup = this.#openSubscribe(state, broadcast, request, requestId, deadline, known?.producer); // The publisher can be serving before it answers, so waiting only on the response // would miss the local side going away and leave it serving a track nobody reads. @@ -825,7 +830,8 @@ export class Subscriber { // A control request that timed out is not late content, so it carries its own code. // Local abandonment must commit without yielding after the demand check. const e = err === abandoned ? abandoned : await sessionCause(this.#quic, err); - request.reject(e); + if (known) hooks.refuseLive(known.producer, known.edge, e); + else request.reject(e); console.warn( `subscribe error: id=${requestId} broadcast=${broadcast} track=${request.name} error=${reason(e)}`, ); @@ -881,6 +887,9 @@ export class Subscriber { const localEnded = Symbol("local"); const revokedEnded = Symbol("revoked"); const idle = Symbol("idle"); + const historical = known + ? this.#historyOnly(producer, known.edge).then(() => idle) + : new Promise(() => {}); // Losing the grant ends the subscription, leaving the session alone. let revoke!: () => void; @@ -902,7 +911,16 @@ export class Subscriber { hooks.trackReleased(producer).then(() => localEnded), revoked, ]); - const updates = this.#runUpdates(stream, requestId, producer, priority, maxAge, unanswered, done); + const stopped = Promise.withResolvers(); + const updates = this.#runUpdates( + stream, + requestId, + producer, + priority, + maxAge, + unanswered, + race([done, stopped.promise]), + ); // Serve until a terminal condition fires or the last local subscriber leaves. The unused // wake is level-triggered: re-check demand so a subscriber that returns before we tear @@ -910,7 +928,7 @@ export class Subscriber { let terminal = localEnded; const demand = producer.demand(); for (;;) { - const reason = await race([done, unwanted(demand).then(() => idle)]); + const reason = await race([done, unwanted(demand).then(() => idle), historical]); if ( reason === idle && hooks.demandReleased(demand).peek() === undefined && @@ -925,16 +943,21 @@ export class Subscriber { // reopens the window the demand re-check above just closed, and a subscriber that // returned during it would be closed by this line. The lite subscriber closes // straight out of its loop for the same reason. + if (known && terminal === publisherEnded && !hooks.trackFinished(producer)) { + const largest = producer.largest(); + hooks.endTrack(producer, { group: largest ? largest.group + 1n : 0n, frame: 0 }); + } if (terminal === revokedEnded) { console.info(`subscription no longer authorized: broadcast=${broadcast} track=${request.name}`); producer.abort(refused); } else { // Only a received end declares one; a copy nobody wants anymore is released, not finished. - hooks.releaseTrack(producer); + if (!known) hooks.releaseTrack(producer); } // Closing settled `done`, so an update still being written finishes and nothing starts // another. Its bytes must not interleave with the close. + stopped.resolve(); await updates; stream.close(); @@ -942,12 +965,14 @@ export class Subscriber { } catch (err) { stream.abort(err); const e = await sessionCause(this.#quic, err); - producer.abort(e); + if (known) hooks.refuseLive(producer, known.edge, e); + else producer.abort(e); console.warn( `subscribe error: id=${requestId} broadcast=${broadcast} track=${request.name} error=${reason(e)}`, ); } finally { joining.abort(); + if (known) hooks.cacheTrack(producer); // A track end already settled the head; anything else leaves it for a later join. subscription.join?.cancel(new Error("subscription ended")); for (const id of subscription.fetchIds) this.#fetches.delete(id); @@ -958,6 +983,19 @@ export class Subscriber { } } + #needsLive(producer: track.Producer, edge: bigint): boolean { + if (hooks.trackFinished(producer) || !hooks.subscribing(producer).peek()) return false; + const ranges = producer.subscription.peek()?.ranges ?? []; + const span = wireSpan(ranges); + return !bounded(ranges) || (span.end !== undefined && span.end > edge); + } + + async #historyOnly(producer: track.Producer, edge: bigint): Promise { + while (this.#needsLive(producer, edge) && hooks.trackReleased(producer).peek() === undefined) { + await Signal.race(producer.subscription, hooks.subscribing(producer), hooks.trackReleased(producer)); + } + } + // A bounded read can be entirely below Largest, including on a finished track that refuses // SUBSCRIBE. Learn its properties without subscribing, then let its misses ask FETCHes. async #runHistory(broadcast: Path.Valid, request: track.Request, valid?: AbortSignal) { @@ -1037,17 +1075,10 @@ export class Subscriber { hooks.releaseTrack(producer); return; } - if (subscription) { - const span = wireSpan(subscription.ranges ?? [{}]); - if ( - !bounded(subscription.ranges ?? [{}]) || - (subscribing.peek() && - span.end !== undefined && - span.end > (ok.largest ? ok.largest.groupId + 1n : 0n)) - ) { - await this.#runSubscribe(broadcast, request, signal, producer); - return; - } + const edge = (producer.largest()?.group ?? ok.largest?.groupId ?? -1n) + 1n; + if (this.#needsLive(producer, edge)) { + await this.#runSubscribe(broadcast, request, signal, { producer, edge }); + continue; } await untilAborted( Promise.resolve(Signal.race(producer.subscription, subscribing, hooks.trackReleased(producer))), @@ -1144,11 +1175,7 @@ export class Subscriber { active.throwIfAborted(); if (id === undefined) throw await this.#closedSession(); this.#ranges.set(id, accepted.promise); - stream = new RequestStream( - await this.#session.openBi({ ...requestOptions, waitUntilAvailable: true }), - this.#session, - this.#quic, - ); + stream = new RequestStream(await this.#session.openBi(requestOptions), this.#session, this.#quic); if (active.aborted) { stream.abort(active.reason); active.throwIfAborted(); @@ -1574,7 +1601,11 @@ export class Subscriber { // is one of the subscription's own streams, so the Stream Count already waits for it. if (ok.largest) { subscription.join = new Join(ok.largest.groupId, tail, { counted: msg.fill !== undefined }); - this.#joins.set(producer, subscription.join); + const join = subscription.join; + this.#joins.set(producer, join); + void join.settled.then(() => { + if (this.#joins.get(producer) === join) this.#joins.delete(producer); + }); } if (msg.fill) subscription.fetchIds.push(requestId); state.subscription = subscription; diff --git a/js/net/src/ietf/tail.test.ts b/js/net/src/ietf/tail.test.ts index 03638dbe7c7..31d69abe76d 100644 --- a/js/net/src/ietf/tail.test.ts +++ b/js/net/src/ietf/tail.test.ts @@ -61,7 +61,7 @@ async function subscribed(largest?: bigint) { const reader = subscriber .consume(Path.from("room")) .track("video") - .subscribe({ delay: { max: Milli(60_000) } }); + .subscribe({ ranges: [{ start: { relative: 0 } }], delay: { max: Milli(60_000) } }); const peer = await Stream.accept(pair.client, VERSION); if (!peer) throw new Error("the subscriber never opened a subscribe stream"); diff --git a/js/net/src/internal.ts b/js/net/src/internal.ts index 520593f4c7a..a4af9cb1bf1 100644 --- a/js/net/src/internal.ts +++ b/js/net/src/internal.ts @@ -617,6 +617,10 @@ export const hooks: { fetchBudget: (subscriber: Subscriber, maxDelay: Milli | undefined) => void; /** Whether a reader beyond one-shot fetches subscribes to this copy. */ subscribing: (producer: Producer) => Getter; + /** Leave a wire copy serving its cache and fills without a live feed. */ + cacheTrack: (producer: Producer) => void; + /** Fail subscriptions reaching beyond `edge`, keeping history readers and one-shot fetches. */ + refuseLive: (producer: Producer, edge: bigint, error: Error) => void; /** * A fetch's group `sequence`, before it reads: `true` once it is cached or asked of a fill, * written yet or not, as the Rust `fetch_group` queues one; `false` with no handler to ask; @@ -860,6 +864,12 @@ export const hooks: { groupChanged: () => { throw new Error("track.ts not loaded"); }, + cacheTrack: () => { + throw new Error("track.ts not loaded"); + }, + refuseLive: () => { + throw new Error("track.ts not loaded"); + }, subscribing: () => { throw new Error("track module not loaded"); }, diff --git a/js/net/src/track.ts b/js/net/src/track.ts index 72ad3f5b01e..ac1237ceaa2 100644 --- a/js/net/src/track.ts +++ b/js/net/src/track.ts @@ -47,6 +47,7 @@ import { rescale } from "./rescale.ts"; import { Timescale, type Timestamp } from "./time.ts"; import { checkSequence, max, min, UNBOUNDED } from "./util/sequence.ts"; import { + bounded, type Holdings, hasTime, isWire, @@ -763,7 +764,9 @@ let reofferCached: ( let reofferSequences: (producer: Producer, sink: TrackState, sequences: readonly bigint[]) => void; // Whether a group may still land on the producer's live feed; assigned in its static block. let mayLand: (producer: Producer, land: Land) => boolean; +let owedRuns: (producer: Producer, start: bigint, end: bigint) => Iterable; let owedGroup: (producer: Producer, start: bigint, end: bigint) => { sequence: bigint; folds?: number } | undefined; +let fillEdge: (producer: Producer) => bigint | undefined; let sourceStart: (producer: Producer) => bigint | "pending" | undefined; // The producer's checked group starts, sorted by sequence; assigned in its static block. let startsOf: (producer: Producer) => readonly Start[]; @@ -955,6 +958,26 @@ export class Producer { static { hooks.subscribing = (producer) => producer.#subscribing; + hooks.cacheTrack = (producer) => { + producer.#subscribed = false; + producer.#served = undefined; + producer.#tailPending = false; + for (const state of [producer.#state, ...producer.#sinks]) state.owed.set(false); + producer.#settle(); + }; + hooks.refuseLive = (producer, edge, error) => { + for (const sink of producer.#sinks) { + if (sink.fetch) continue; + const ranges = sink.update.peek()?.ranges ?? [{}]; + const span = wireSpan(ranges); + if (bounded(ranges) && span.end !== undefined && span.end <= edge) continue; + closeTrackState(sink, error); + } + }; + fillEdge = (producer) => + !producer.#subscribed && producer.#state.info.peek()?.ietf !== undefined + ? producer.#state.largest.peek()?.group + : undefined; hooks.receiveTrack = (producer) => { producer.#subscribed = true; }; @@ -1023,27 +1046,38 @@ export class Producer { } }; mayLand = (producer, land) => producer.#landable(land) !== undefined; - owedGroup = (producer, start, end) => { - if (!producer.#subscribed) return undefined; + owedRuns = (producer, start, end) => { + if (!producer.#subscribed) return []; const feed = producer.#feedStart(); const floor = feed === "pending" ? producer.#served?.requested : feed; - return producer.#landable({ + return producer.#landing({ start: max(start, floor ?? 0n), end, floor: floor !== undefined, grace: producer.#grace(), }); }; + owedGroup = (producer, start, end) => { + for (const run of owedRuns(producer, start, end)) return { sequence: run.start, folds: run.folds }; + return undefined; + }; } // The first group that may still land from the live feed, by the rule a pending tail is judged // by; see {@link Land}. Mirrors the Rust `TrackState::may_land`. #landable(land: Land): { sequence: bigint; folds?: number } | undefined { - if (this.#state.closed.peek() !== undefined) return undefined; + for (const run of this.#landing(land)) { + if (!land.delivered?.covers(run.start, run.end)) return { sequence: run.start, folds: run.folds }; + } + return undefined; + } + + *#landing(land: Land): Generator { + if (this.#state.closed.peek() !== undefined) return; let start = land.start; if (!land.floor) { const first = this.#arrivals.first(); - if (first === undefined) return undefined; + if (first === undefined) return; start = max(start, first); } start = max(start, this.#served?.start ?? 0n); @@ -1056,10 +1090,9 @@ export class Producer { const folds = gap.since === undefined ? undefined : gap.since + limit; if (folds !== undefined && at >= folds) continue; for (const open of runGaps(drops, gap.start, gap.end)) { - if (!land.delivered?.covers(open.start, open.end)) return { sequence: open.start, folds }; + yield { ...open, folds }; } } - return undefined; } // Record `[start, end)` given up with `error`. An upstream drop (`open`) also ends the @@ -2575,15 +2608,6 @@ export class Subscriber { #askFills(start: bigint, end: bigint, drift?: Drift): bigint | undefined { const producer = this.#state.producer; if (this.#resume || !producer || this.#closed) return undefined; - // An IETF live join supplies the current group, not all history. An explicit past - // anchor still fetches below it, while an implicit live join starts where it was served. - if ( - this.#state.info.peek()?.ietf !== undefined && - this.#window.ranges.every((range) => range.start === undefined || range.start.relative === 0) - ) { - const floor = sourceStart(producer); - if (typeof floor === "bigint") start = max(start, max(floor, this.#state.first ?? floor)); - } const fills = fillsOf(producer); // A fill already out can be joined even once its handler's handle closed. if (fills.serving || fills.active) { @@ -2595,10 +2619,15 @@ export class Subscriber { // the Rust judge skips its track's datagram buffer; the Rust fetch names it // `NotFetchable`. const gone = [...this.#state.drops.peek()]; + // Reordered streams still owed by the live feed are not cache misses. + for (const run of owedRuns(producer, start, end)) { + insertRun(gone, run.start, run.end); + if (run.folds !== undefined) this.#wakeAt(run.folds); + } for (const sequence of heldDatagrams(producer)) insertRun(gone, sequence, sequence + 1n); for (const run of this.#wants( start, - min(end, max(this.#state.received.peek(), (this.#state.largest.peek()?.group ?? -1n) + 1n)), + min(end, max(this.#state.received.peek(), (fillEdge(producer) ?? -1n) + 1n)), )) { for (const open of runGaps(gone, run.start, run.end)) { let next = open.start; @@ -2727,9 +2756,9 @@ export class Subscriber { // A fill still owes a group it reads. if (this.#askFills(this.#window.floor() ?? 0n, end) !== undefined) return false; const held = this.#state.groups.peek(); - const received = max(this.#state.received.peek(), (this.#state.largest.peek()?.group ?? -1n) + 1n); - const drops = this.#state.drops.peek(); const producer = this.#state.producer; + const received = max(this.#state.received.peek(), ((producer && fillEdge(producer)) ?? -1n) + 1n); + const drops = this.#state.drops.peek(); for (const run of this.#window.runs(this.#window.floor() ?? 0n, end)) { let gaps = [run]; for (const delivered of taken) gaps = gaps.flatMap((gap) => delivered.gaps(gap.start, gap.end)); diff --git a/test/interop/clients/js-native/ranges.ts b/test/interop/clients/js-native/ranges.ts index b14015f79e0..8b7363f3572 100644 --- a/test/interop/clients/js-native/ranges.ts +++ b/test/interop/clients/js-native/ranges.ts @@ -57,7 +57,7 @@ try { [0n, 5n, [0n, 2n, 4n]], ] as const) { const reader = broadcast.track("test").subscribe({ - ranges: [{ start: { absolute: start }, end: { absolute: end } }], + ranges: [{ ...(start === 0n ? {} : { start: { absolute: start } }), end: { absolute: end } }], delay: { max: null }, order: "ascending", }); From 6de7779c813d73792ff18ac5cc5e1d1b7c3b244c Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 19:38:12 -0800 Subject: [PATCH 08/11] test(interop): cross native subscribers through FETCH history cells Keep upstream quest changes intact after the base merge and adapt FETCH fixtures to explicit publisher priorities. Co-Authored-By: GPT-6.1 Sol --- js/net/src/ietf/range.test.ts | 9 ++- quest/m1/README.md | 4 ++ quest/m1/ietf-drop/README.md | 4 ++ quest/m1/interop-coverage/README.md | 58 +++++++++++++++++++ quest/m1/interop-coverage/js-ietf-fetch.md | 27 +++++++++ quest/{m2 => m1}/rind/README.md | 12 ++-- quest/m1/rind/acme-remove.md | 14 +++++ quest/{m2 => m1}/rind/rtc.md | 4 +- quest/{m2 => m1}/rind/transport.md | 5 +- .../webrtc/rename.md => m1/webrtc-rename.md} | 2 + .../webrtc/vendor.md => m1/webrtc-vendor.md} | 10 ++-- quest/m2/README.md | 1 - quest/m2/audit-interop.md | 1 + quest/m2/p2p/native-quic.md | 2 +- quest/m2/rtc-pacing.md | 2 +- quest/m2/webrtc/README.md | 8 +-- quest/m2/webrtc/clock.md | 2 +- quest/m2/webrtc/dtls-after-ice.md | 2 +- quest/m2/webrtc/dtls-timeout.md | 6 +- quest/m2/webrtc/sdp-bandwidth.md | 2 +- quest/m3/README.md | 2 + quest/{m2/rind/acme.md => m3/relay-acme.md} | 16 ++--- .../rind-instant-acme.md} | 4 +- test/interop/README.md | 2 +- test/interop/clients/js-native/tail.ts | 4 +- test/interop/interop.sh | 14 ++++- 26 files changed, 173 insertions(+), 44 deletions(-) create mode 100644 quest/m1/interop-coverage/README.md create mode 100644 quest/m1/interop-coverage/js-ietf-fetch.md rename quest/{m2 => m1}/rind/README.md (88%) create mode 100644 quest/m1/rind/acme-remove.md rename quest/{m2 => m1}/rind/rtc.md (90%) rename quest/{m2 => m1}/rind/transport.md (94%) rename quest/{m2/webrtc/rename.md => m1/webrtc-rename.md} (79%) rename quest/{m2/webrtc/vendor.md => m1/webrtc-vendor.md} (74%) rename quest/{m2/rind/acme.md => m3/relay-acme.md} (60%) rename quest/{m2/rind/instant-acme.md => m3/rind-instant-acme.md} (78%) diff --git a/js/net/src/ietf/range.test.ts b/js/net/src/ietf/range.test.ts index 4aa288cbab7..4ec20b38e71 100644 --- a/js/net/src/ietf/range.test.ts +++ b/js/net/src/ietf/range.test.ts @@ -80,7 +80,10 @@ function fixture(version: IetfVersion) { let previousGroup: bigint | undefined; for (const group of groups) { for (const [object, payload] of objects.entries()) - await new FetchFrame({ payload: new TextEncoder().encode(`${payload && group}${payload}`) }).encode( + await new FetchFrame({ + payload: new TextEncoder().encode(`${payload && group}${payload}`), + priority: 0, + }).encode( writer, { group, @@ -230,7 +233,7 @@ for (const version of VERSIONS) { await fx.answer(stream, 1n); const prefix = await Writer.collect(version, async (writer) => { await writer.u62(request.requestId); - await new FetchFrame({ payload: new Uint8Array([42]) }).encode( + await new FetchFrame({ payload: new Uint8Array([42]), priority: 0 }).encode( writer, { group: 1n, object: 0, first: true }, undefined, @@ -324,7 +327,7 @@ for (const version of VERSIONS) { const bytes = await Writer.collect(version, async (writer) => { await writer.u62(request.requestId); for (const [object, value] of [1, 2, 3].entries()) - await new FetchFrame({ payload: new Uint8Array([value]) }).encode( + await new FetchFrame({ payload: new Uint8Array([value]), priority: 0 }).encode( writer, { group: 1n, object, first: object === 0 }, undefined, diff --git a/quest/m1/README.md b/quest/m1/README.md index 86af5ea3479..f64f2da4201 100644 --- a/quest/m1/README.md +++ b/quest/m1/README.md @@ -167,6 +167,7 @@ per-frame CPU growth since #5926. - [crates.io trusts the workflow](/quest/m1/crates-trusted-publisher.md) - maintainer action: every published crate gets a trusted publisher for `release-rs.yml` - [Rust releases publish through OIDC](/quest/m1/release-rs-oidc.md) - release-plz publishes with trusted publishing and `CARGO_REGISTRY_TOKEN` is revoked - [Main is no slower than release](/quest/m1/release-perf/README.md) - every benchmark where main is slower than release is fixed or accepted with a reason, checked by a final paired run before the cut +- [Interop coverage](/quest/m1/interop-coverage/README.md) - the riskiest moq-transport features moq-net exposes get cross-implementation tests over drafts 18, 20, and 22 - [Calibrate the paired nightly benchmarks](/quest/m1/bench-ci.md) - A/A and deliberately slowed Nightly runs set the paired comparison's threshold, so its regression alerts can be trusted - [Unbounded groups](/quest/m1/unbounded-groups/README.md) - groups and frames lose their size caps; a group keeps a 32 MB tail, and readers behind it replay through paced flights or refresh - [Poll-first async](/quest/m1/poll-first/README.md) - library crates compile no coroutines by default: async wrappers are generated from `poll_*` and gated behind an `async` feature @@ -174,6 +175,9 @@ per-frame CPU growth since #5926. - [HLS export lists a same-codec reconfigure's first group under the new init](/quest/m1/hls-reinit-same-codec.md) - the hand-over pick, whichever of the catalog and the records arrives first, after the catalog `hls` removal is planned - [Ordered reads can skip owed holes, and snapshot latest() does](/quest/m1/ordered-owed-holes.md) - moq-net's `Ordered` gains a read that skips past an owed hole to the newest buffered group, while keeping the reader's bounds - [A Rust relay never replays from group 0 to a lite-03/04 subscriber](/quest/m1/relay-inflight-replay.md) - A Rust relay or publisher serving a lite-03 or lite-04 SUBSCRIBE from a track copy that is still resolving starts at the newest group once the copy resolves +- [Rename moq-rtc to moq-webrtc](/quest/m1/webrtc-rename.md) - one published `moq-webrtc` crate holds the gateway, the ICE driver, and the data-channel transport +- [Vendor and trim the WebRTC stack](/quest/m1/webrtc-vendor.md) - str0m, dimpl, `is`, and sctp-proto live in moq-webrtc with unused code removed, so moq-rtc can take rind +- [MoQ on rind](/quest/m1/rind/README.md) - every MoQ crate takes its crypto from rind, a pure-Rust graviola fork, so no build compiles C crypto ## Related diff --git a/quest/m1/ietf-drop/README.md b/quest/m1/ietf-drop/README.md index 55b65ae06b8..3f91d98eb92 100644 --- a/quest/m1/ietf-drop/README.md +++ b/quest/m1/ietf-drop/README.md @@ -44,3 +44,7 @@ protocol implementation or release work remains here. ## Waiting - englishm/moq-interop-runner: review and merge [englishm/moq-interop-runner#183](https://github.com/englishm/moq-interop-runner/pull/183); verify both registry entries and README rows list drafts 18, 20, and 22 before deleting this quest + +## Related + +- [Interop coverage](/quest/m1/interop-coverage/README.md) - cross-implementation cases target drafts 18, 20, and 22 diff --git a/quest/m1/interop-coverage/README.md b/quest/m1/interop-coverage/README.md new file mode 100644 index 00000000000..f5a07d7c1d9 --- /dev/null +++ b/quest/m1/interop-coverage/README.md @@ -0,0 +1,58 @@ +# Interop coverage for moq-transport + +## Goal + +The moq-transport features moq-net exposes with the most interop bug +history have cross-implementation tests: Rust, JS, and the bindings exchange +hang media and exercise subgroup data, namespace discovery, late joins, +FETCH, GOAWAY, TRACK_STATUS, and datagrams over drafts 18, 20, and 22. Our +upstream runner clients implement the runner's existing cases for those +features. + +Boundaries: + +- Only what moq-net can do. Subgroups other than 0, rendezvous, and + per-request authorization tokens are not exposed, so they are out of + scope, and runner cells that need them stay red by design. +- PUBLISH (push) and outbound forward=0 are out of scope (decided + 2026-10-25, maintainer, reversing the 2026-10-22 decision): no child + quest owned them, and the cases above carry the interop bug history. +- Media stays hang. No MSF catalog in our runner clients. +- New cases live in-tree (`test/interop`), not in the runner's spec. +- Not covered: mid-subscription updates (`Subscription::update` in Rust and + JS, sent as SUBSCRIBE_UPDATE or REQUEST_UPDATE) for priority, max age, + NEW_GROUP_REQUEST, and group order. The maintainer did not pick them on + 2026-10-21; plan them separately if their bug history grows. + +## Plan + +Decided 2026-11-02 (maintainer, follow-up planning after the 2026-11-02 /quest-complete run): draft 20 joins the covered drafts, since it came back in +[moq-dev/moq#7190](https://github.com/moq-dev/moq/pull/7190) and every published moq-dev client and relay already offers it (verified on +[moq-dev/moq#6972](https://github.com/moq-dev/moq/pull/6972)). + + +Decided with the maintainer on 2026-10-21, from an inventory of the +coverage on `main` at `3ab6cbf81d`. + +- `just test interop --versions ietf` runs the matrix on each supported draft; + every new case runs on it. Beyond it, moq-transport is covered by + in-process codec tests (`rs/moq-net/src/test_interop.rs`), the public + relays page (published clients), and the Cloudflare and Moxygen smoke + lanes. +- Drafts 18, 20, and 22 only, nightly. Protocol removal and draft-20 + restoration have landed; only the + [runner registry correction](/quest/m1/ietf-drop/README.md) remains. + The request-limits case went with drafts 14 and 16, the only ones with + MAX_REQUEST_ID. +- Case ranking follows interop bug history: subgroup data and namespace + discovery, then late join and FETCH, then GOAWAY, TRACK_STATUS, + and datagrams. + +## Required + +- [JS subscribers FETCH](/quest/m1/interop-coverage/js-ietf-fetch.md) - `@moq/net` fetches past groups over moq-transport, and joins the CLI FETCH round + +## Related + +- [Runner client bump](/quest/m2/release/runner-client-bump.md) - after the cut publishes #5083, the runner's Rust client stops stamping every object +- [Interop audit](/quest/m2/audit-interop.md) - classifies the red cells these cases produce diff --git a/quest/m1/interop-coverage/js-ietf-fetch.md b/quest/m1/interop-coverage/js-ietf-fetch.md new file mode 100644 index 00000000000..dcaf9307ffe --- /dev/null +++ b/quest/m1/interop-coverage/js-ietf-fetch.md @@ -0,0 +1,27 @@ +# [M] JS subscribers FETCH over moq-transport + +## Goal + +`@moq/net`'s moq-transport subscriber fetches a past group with a standalone +FETCH, so `track.Consumer.fetchGroup()` works on moq-transport. JS subscribers +join the CLI FETCH interop round beside Rust. + +## Plan + +Found by [moq-dev/moq#7015](https://github.com/moq-dev/moq/pull/7015). Today +`track.Consumer.fetchGroup()` is rejected on moq-transport. The mid-group +join already recovers the current group's head, with a joining FETCH on +draft 18 or a fill on draft 22 +([moq-dev/moq#7089](https://github.com/moq-dev/moq/pull/7089)), and its +fetch-stream decoder and head stitching are what a standalone FETCH reuses. + +Decided 2026-10-28 (maintainer): one [M] quest in m1, after +JS ranges ([moq-dev/moq#7696](https://github.com/moq-dev/moq/pull/7696)), which turns `fetchGroup` into +a one-range subscription. Map a past range to a standalone FETCH, the way +Rust's subscriber does. Then add the native JS runtimes as subscribers to the +`run_fetch_round` cells in the tail suite. Our publishers answer only one +group ([moq-dev/moq#7204](https://github.com/moq-dev/moq/pull/7204), 2026-10-28), so a +past-range FETCH against them is refused. Test ranges against a third-party +publisher, and one group against ours. + +Public API: none beyond JS ranges' surface. Wire: none. diff --git a/quest/m2/rind/README.md b/quest/m1/rind/README.md similarity index 88% rename from quest/m2/rind/README.md rename to quest/m1/rind/README.md index cf6435cb00a..b9013cd7f91 100644 --- a/quest/m2/rind/README.md +++ b/quest/m1/rind/README.md @@ -47,8 +47,9 @@ instead, so every crate drops C, not just the relay. Decided 2026-10-31 (maintainer): each area waits only on the rind pieces it uses, so most areas switch on rind 0.1.2 (published 2026-11-01), which runs on CPUs without the crypto extensions (e2ee, which no binary links, switched - on 0.1.0), and only relay - ACME waits on `rind-instant-acme`. aws-lc-rs stays in the workspace until + on 0.1.0). Relay ACME, the one area that waited on `rind-instant-acme`, is + removed for now instead (maintainer, 2026-11-03), and returns on rind in m3. + aws-lc-rs stays in the workspace until the last area lands, which is when this epic removes it. - Split per area, each landing once rind covers it. Docs a change makes stale (CPU requirements, removed features) are edited inline in that area's PR; no @@ -64,7 +65,6 @@ The epic's own work, once every child has merged: ## Required -- [rind-instant-acme is on crates.io](/quest/m2/rind/instant-acme.md) - waiting on the adapter relay ACME needs -- [Transport on rind](/quest/m2/rind/transport.md) - moq-quic, moq-tokio, moq-uring, moq-rtmp, and qmux take rind, and the `aws-lc-rs`/`ring` features go -- [moq-rtc on rind](/quest/m2/rind/rtc.md) - str0m and dimpl run DTLS, SRTP, and STUN on rind -- [Relay ACME on instant-acme](/quest/m2/rind/acme.md) - moq-relay replaces rustls-acme with instant-acme on rind and owns renewal +- [Transport on rind](/quest/m1/rind/transport.md) - moq-quic, moq-tokio, moq-uring, moq-rtmp, and qmux take rind, and the `aws-lc-rs`/`ring` features go +- [moq-rtc on rind](/quest/m1/rind/rtc.md) - str0m and dimpl run DTLS, SRTP, and STUN on rind +- [moq-relay drops ACME for now](/quest/m1/rind/acme-remove.md) - the `acme` feature and rustls-acme go until ACME returns on rind diff --git a/quest/m1/rind/acme-remove.md b/quest/m1/rind/acme-remove.md new file mode 100644 index 00000000000..d1bf10de677 --- /dev/null +++ b/quest/m1/rind/acme-remove.md @@ -0,0 +1,14 @@ +# [S] moq-relay drops ACME for now + +## Goal + +moq-relay has no `acme` feature and no rustls-acme dependency, so the migration to rind no longer waits on instant-acme 0.9. Its config and docs no longer offer ACME; a relay serves certificates from files or generates self-signed ones, as without the feature today. + +## Plan + +Decided by the maintainer on 2026-11-03: ACME is a recent feature nobody uses yet, so it is removed until [relay ACME on instant-acme](/quest/m3/relay-acme.md) brings it back on rind. + +- Remove the `acme` feature, its rustls-acme dependency, the ACME config section, and the code behind it. +- Fix every doc and example that mentions it inline. + +Public API: moq-relay's `acme` feature and ACME config fields are removed (breaking for anyone setting them; the title gets `!`). Wire: none. diff --git a/quest/m2/rind/rtc.md b/quest/m1/rind/rtc.md similarity index 90% rename from quest/m2/rind/rtc.md rename to quest/m1/rind/rtc.md index 0f8be51688e..fc4c19d0670 100644 --- a/quest/m2/rind/rtc.md +++ b/quest/m1/rind/rtc.md @@ -10,7 +10,7 @@ hold no aws-lc-rs or str0m-aws-lc-rs, and a browser still connects. ## Plan Decided with the maintainer on 2026-10-26; see the -[epic](/quest/m2/rind/README.md). str0m's workspace dependency drops its +[epic](/quest/m1/rind/README.md). str0m's workspace dependency drops its `aws-lc-rs` feature, the test-only HMAC-SHA1 in `server/mux.rs` moves to rind, and reqwest switches to its no-provider feature. The existing browser interop tests prove the switch. @@ -30,4 +30,4 @@ offered. ## Required -- [Vendor and trim the stack](/quest/m2/webrtc/vendor.md) - where str0m and dimpl live once vendored +- [Vendor and trim the stack](/quest/m1/webrtc-vendor.md) - where str0m and dimpl live once vendored diff --git a/quest/m2/rind/transport.md b/quest/m1/rind/transport.md similarity index 94% rename from quest/m2/rind/transport.md rename to quest/m1/rind/transport.md index 02536ea7781..250928368b0 100644 --- a/quest/m2/rind/transport.md +++ b/quest/m1/rind/transport.md @@ -11,7 +11,7 @@ moq-tokio checks rind's CPU support at startup. ## Plan Decided with the maintainer on 2026-10-26; see the -[epic](/quest/m2/rind/README.md). +[epic](/quest/m1/rind/README.md). - moq-quic's direct calls move to rind's API: stateless reset HMAC-SHA256 and its HKDF-SHA256 key derivation, address-validation tokens (HKDF to @@ -28,7 +28,8 @@ Decided with the maintainer on 2026-10-26; see the - reqwest and axum-server switch to their no-provider features wherever these crates enable them. Decided 2026-10-31 (maintainer): this includes moq-relay's own reqwest, axum-server, and rustls `aws-lc-rs` features, which - no other area owns; relay ACME still owns rustls-acme. + no other area owns; rustls-acme leaves with + [ACME](/quest/m1/rind/acme-remove.md). - The roughly 100 test call sites that install aws-lc's provider install rind's. - The startup check runs where moq-tokio's crypto is first configured, and its diff --git a/quest/m2/webrtc/rename.md b/quest/m1/webrtc-rename.md similarity index 79% rename from quest/m2/webrtc/rename.md rename to quest/m1/webrtc-rename.md index fb2390acd78..0c31beae4e3 100644 --- a/quest/m2/webrtc/rename.md +++ b/quest/m1/webrtc-rename.md @@ -8,6 +8,8 @@ The published `moq-webrtc` crate holds what `moq-rtc`, `moq-ice`, and moq-tokio' Decided 2026-10-30 with the maintainer (planning interview); see the [epic](/quest/m2/webrtc/README.md). +Milestone: ✅ m1 (moved from m2, maintainer, 2026-11-03). Not chosen: keep it in m2, or send [moq-rtc on rind](/quest/m1/rind/rtc.md) back to m2. [Vendor and trim the WebRTC stack](/quest/m1/webrtc-vendor.md) requires this, and m1's rind epic requires the vendoring, so this sits at the m1 top level. It stays a child of the m2 [WebRTC epic](/quest/m2/webrtc/README.md). + - Move `rs/moq-rtc` to `rs/moq-webrtc` and merge `rs/moq-ice` in as a module. Keep the gateway's `server` feature; add a feature for the data-channel transport so WHIP/WHEP-only builds skip SCTP. - Move moq-tokio's `webrtc` module (`rs/moq-tokio/src/webrtc.rs`, host gathering, `.local` resolution) into moq-webrtc, built on moq-tokio's public session types. If the move needs something moq-tokio keeps private, bring the shape to the maintainer. - Update moq-cli's `rtc` subcommand, the bindings or examples that use the transport, `test/p2p`, and every doc and quest naming the old crates. diff --git a/quest/m2/webrtc/vendor.md b/quest/m1/webrtc-vendor.md similarity index 74% rename from quest/m2/webrtc/vendor.md rename to quest/m1/webrtc-vendor.md index d94aaba5fa3..2908aea189a 100644 --- a/quest/m2/webrtc/vendor.md +++ b/quest/m1/webrtc-vendor.md @@ -8,14 +8,16 @@ moq-webrtc builds str0m, dimpl, `is`, and sctp-proto from private in-tree module Decided 2026-10-30 with the maintainer (planning interview); see the [epic](/quest/m2/webrtc/README.md) for what goes and why. -- Vendor str0m and str0m-proto at the main-branch revision moq-dev/rind's `rind-str0m` targeted (`dc317173`, on dimpl 0.9 with str0m's pluggable crypto provider), with the dimpl, `is`, and sctp-proto versions it depends on (maintainer, 2026-10-31), so [moq-rtc on rind](/quest/m2/rind/rtc.md) can port rind's provider code unchanged. Commit them unchanged first so later diffs show only our changes, then trim. -- Remove: str0m's `bwe/`, leaky pacer, H.266, RED, DTMF, G.7xx and comfort noise, VLA and simulcast layers, RTCP XR and app feedback, stats, `_internal_test_exports`, the crypto backends other than the one rind will replace (keep the provider trait until [moq-rtc on rind](/quest/m2/rind/rtc.md)); dimpl's `dtls13/` and `auto.rs`. Keep upstream's tests for what remains. +Milestone: ✅ m1 (moved from m2, maintainer, 2026-11-03). Not chosen: keep it in m2, or send [moq-rtc on rind](/quest/m1/rind/rtc.md) back to m2. m1's [moq-rtc on rind](/quest/m1/rind/rtc.md) requires this, so it sits at the m1 top level. It stays a child of the m2 [WebRTC epic](/quest/m2/webrtc/README.md). + +- Vendor str0m and str0m-proto at the main-branch revision moq-dev/rind's `rind-str0m` targeted (`dc317173`, on dimpl 0.9 with str0m's pluggable crypto provider), with the dimpl, `is`, and sctp-proto versions it depends on (maintainer, 2026-10-31), so [moq-rtc on rind](/quest/m1/rind/rtc.md) can port rind's provider code unchanged. Commit them unchanged first so later diffs show only our changes, then trim. +- Remove: str0m's `bwe/`, leaky pacer, H.266, RED, DTMF, G.7xx and comfort noise, VLA and simulcast layers, RTCP XR and app feedback, stats, `_internal_test_exports`, the crypto backends other than the one rind will replace (keep the provider trait until [moq-rtc on rind](/quest/m1/rind/rtc.md)); dimpl's `dtls13/` and `auto.rs`. Keep upstream's tests for what remains. - Keep dimpl's typed `TimeoutError::Handshake` through the vendored `dtls.rs`, which str0m flattens into `CryptoError::Other(String)`, and replace moq-ice's text match for it with a typed match if [the typed DTLS timeout](/quest/m2/webrtc/dtls-timeout.md) has landed. - Keep the license files and record each upstream version in the module docs. - Drop the crates.io dependencies on str0m and friends from the workspace once nothing uses them. -Public API: none beyond what [rename](/quest/m2/webrtc/rename.md) changed. Wire: unchanged; the same DTLS 1.2 suites and SRTP profiles are offered. +Public API: none beyond what [rename](/quest/m1/webrtc-rename.md) changed. Wire: unchanged; the same DTLS 1.2 suites and SRTP profiles are offered. ## Required -- [Rename moq-rtc to moq-webrtc](/quest/m2/webrtc/rename.md) - the crate the stack is vendored into +- [Rename moq-rtc to moq-webrtc](/quest/m1/webrtc-rename.md) - the crate the stack is vendored into diff --git a/quest/m2/README.md b/quest/m2/README.md index e3c6bca8ba2..a0364c7a4d3 100644 --- a/quest/m2/README.md +++ b/quest/m2/README.md @@ -46,7 +46,6 @@ lite-07; bitrate enforcement is not part of this release. - [Generated C bindings](/quest/m2/c/README.md) - C generated from moq-ffi ships as `moq-c` 0.8.0 and replaces the hand-written crate - [A C origin can discover eagerly, like a relay](/quest/m2/c-origin-relay.md) - the C API puts an origin in relay mode, so forwarding a client session's routes needs no local announce watcher - [A runtime-free QUIC driver](/quest/m2/quic-sansio-driver.md) - a caller's own loop moves UDP datagrams and polls moq sessions over moq-quic, for rust2's bindings -- [MoQ on rind](/quest/m2/rind/README.md) - every MoQ crate takes its crypto from rind, a pure-Rust graviola fork, so no build compiles C crypto - [Benchmark sources](/quest/m2/bench-sources.md) - every measuring nightly benchmark feeds the regression table, and none is a smoke run - [QoS](/quest/m2/qos/README.md) - the relay's egress `lag` histogram and `dropped` counters on the stats totals and prefix tracks - [HLS and DASH browser playback](/quest/m2/hls-player-test.md) - hls.js and dash.js play, reload, switch, and survive reconfiguration nightly diff --git a/quest/m2/audit-interop.md b/quest/m2/audit-interop.md index d16ddae4d68..3fd93f7f433 100644 --- a/quest/m2/audit-interop.md +++ b/quest/m2/audit-interop.md @@ -191,3 +191,4 @@ cells of the 2026-10-31 nightly. Classify it. - [Runner client bump](/quest/m2/release/runner-client-bump.md) - the runner's Rust client moves to the cut and its API - [Runner teardown](/quest/m3/interop-runner-approval.md) - the runner's moq.dev clients move to the withdrawing `close()` once it ships +- [Interop coverage](/quest/m1/interop-coverage/README.md) - the runner cases whose red cells this audit classifies diff --git a/quest/m2/p2p/native-quic.md b/quest/m2/p2p/native-quic.md index fa85ec93ede..3ad34b16e62 100644 --- a/quest/m2/p2p/native-quic.md +++ b/quest/m2/p2p/native-quic.md @@ -23,7 +23,7 @@ Decided with the maintainer on 2026-10-13: are private to the data channel transport today, so move them into `moq-ice` rather than export them from `moq-tokio`. Decided 2026-10-30 (maintainer): `moq-ice`, the data-channel transport, and a vendored `is` all move into - `moq-webrtc` ([rename](/quest/m2/webrtc/rename.md)); take them from there. + `moq-webrtc` ([rename](/quest/m1/webrtc-rename.md)); take them from there. - QUIC is `moq-quic`, fed datagrams from the nominated pair. - Authentication: each side generates a self-signed certificate and sends its SHA-256 fingerprint in its offer or answer, as DTLS fingerprints ride diff --git a/quest/m2/rtc-pacing.md b/quest/m2/rtc-pacing.md index 9ff8235d0cc..201aac9ae93 100644 --- a/quest/m2/rtc-pacing.md +++ b/quest/m2/rtc-pacing.md @@ -63,7 +63,7 @@ its argument list rather than adding a fifth argument. Wire: none. ## Required -- [Vendor and trim the stack](/quest/m2/webrtc/vendor.md) - the vendored str0m this adds the NACK hook to +- [Vendor and trim the stack](/quest/m1/webrtc-vendor.md) - the vendored str0m this adds the NACK hook to ## Related diff --git a/quest/m2/webrtc/README.md b/quest/m2/webrtc/README.md index 2000042d4aa..4c24979304e 100644 --- a/quest/m2/webrtc/README.md +++ b/quest/m2/webrtc/README.md @@ -13,16 +13,16 @@ Decided 2026-10-30 with the maintainer (planning interview), after the str0m wor - **Vendor, then replace.** Copy the upstream crates in, trim them, and fix them in-tree. Replacing a layer with our own (SDP, RTP/RTCP, SRTP, SCTP) is a later child once a concrete need appears; none is planned yet. - **One crate.** `moq-ice` merges into it, since its only users are `moq-rtc` and moq-tokio's data-channel transport. moq-tokio's `webrtc` feature moves into `moq-webrtc` as well, which breaks the cycle (`moq-webrtc` depends on moq-tokio; moq-tokio would otherwise need ICE and SCTP). The vendored crates become private modules, not separate published crates, keeping their MIT/Apache-2.0 notices (str0m's `packet/` carries webrtc-rs's Apache notice). - **What goes** (from the 2026-10-30 inventory: we use frame mode, full ICE, and DTLS 1.2, and never enable str0m's BWE, pacer, or stats): GCC bandwidth estimation (8k lines; GCC is ported into `moq-congestion` as `moq_congestion::gcc`), the leaky pacer (replaced by moq-congestion's pacer, made public by [rtc-pacing](/quest/m2/rtc-pacing.md)), H.266, RED, DTMF, G.7xx and comfort noise, VLA and simulcast layers, RTCP XR and app feedback, stats, internal test exports, and dimpl's DTLS 1.3 and version auto-selection. Roughly 17k of str0m's 72k lines and 11k of dimpl's 33k. -- **DTLS 1.2 only.** Every browser negotiates 1.2 today. [moq-rtc on rind](/quest/m2/rind/rtc.md) narrows to 1.2 to match. +- **DTLS 1.2 only.** Every browser negotiates 1.2 today. [moq-rtc on rind](/quest/m1/rind/rtc.md) narrows to 1.2 to match. - **SCTP stays**, for browser data channels in [P2P](/quest/m2/p2p/README.md), but compiles only with the data-channel feature, so WHIP/WHEP builds carry none of it. Vendored, it can later be simplified or put on moq-congestion. - **Upstream fixes:** after vendoring, nobody merges upstream automatically. Record the vendored upstream versions in the crate docs; the release-cut audit checks the upstream changelogs for security fixes (malformed SRTP/RTCP input, for example) and ports them. - Docs a change makes stale (crate names, `doc/lib/rs`, `doc/setup/upgrade.md`, other quests naming `moq-rtc` or `moq-ice`) change in the PR that makes them stale. ## Required +- [Rename moq-rtc to moq-webrtc](/quest/m1/webrtc-rename.md) - one crate holds the gateway, the ICE driver, and the data-channel transport +- [Vendor and trim the stack](/quest/m1/webrtc-vendor.md) - str0m, dimpl, `is`, and sctp-proto live in moq-webrtc with unused code removed - [A typed DTLS handshake timeout error](/quest/m2/webrtc/dtls-timeout.md) - callers match a DTLS handshake timeout by variant, and session end treats it like an ICE timeout -- [Rename moq-rtc to moq-webrtc](/quest/m2/webrtc/rename.md) - one crate holds the gateway, the ICE driver, and the data-channel transport -- [Vendor and trim the stack](/quest/m2/webrtc/vendor.md) - str0m, dimpl, `is`, and sctp-proto live in moq-webrtc with unused code removed - [Several bandwidth lines per media section](/quest/m2/webrtc/sdp-bandwidth.md) - answers carry both `b=TIAS` and `b=AS` without splicing - [DTLS waits for ICE](/quest/m2/webrtc/dtls-after-ice.md) - DTLS flights start once ICE nominates a pair, so a late ICE path can't exhaust them - [The stack takes kio clock time](/quest/m2/webrtc/clock.md) - the vendored code takes `kio::clock::Instant`, so sim tests drive it directly @@ -30,4 +30,4 @@ Decided 2026-10-30 with the maintainer (planning interview), after the str0m wor ## Related - [moq-rtc paces WHEP viewers](/quest/m2/rtc-pacing.md) - adds the NACK hook and the shared pacer on the vendored stack -- [moq-rtc on rind](/quest/m2/rind/rtc.md) - the vendored DTLS and SRTP take rind's crypto +- [moq-rtc on rind](/quest/m1/rind/rtc.md) - the vendored DTLS and SRTP take rind's crypto diff --git a/quest/m2/webrtc/clock.md b/quest/m2/webrtc/clock.md index 832da2839e2..decf8794ed7 100644 --- a/quest/m2/webrtc/clock.md +++ b/quest/m2/webrtc/clock.md @@ -12,4 +12,4 @@ Public API: none. Wire: none. ## Required -- [Vendor and trim the stack](/quest/m2/webrtc/vendor.md) - the modules whose time type changes +- [Vendor and trim the stack](/quest/m1/webrtc-vendor.md) - the modules whose time type changes diff --git a/quest/m2/webrtc/dtls-after-ice.md b/quest/m2/webrtc/dtls-after-ice.md index 30f9c2597c1..af3d8fc1816 100644 --- a/quest/m2/webrtc/dtls-after-ice.md +++ b/quest/m2/webrtc/dtls-after-ice.md @@ -12,4 +12,4 @@ Public API: none. Wire: none. ## Required -- [Vendor and trim the stack](/quest/m2/webrtc/vendor.md) - the DTLS activation this moves +- [Vendor and trim the stack](/quest/m1/webrtc-vendor.md) - the DTLS activation this moves diff --git a/quest/m2/webrtc/dtls-timeout.md b/quest/m2/webrtc/dtls-timeout.md index 806137f9856..c1f6ea213fe 100644 --- a/quest/m2/webrtc/dtls-timeout.md +++ b/quest/m2/webrtc/dtls-timeout.md @@ -4,7 +4,7 @@ A DTLS handshake that times out after ICE connects surfaces as its own error variant in `moq-ice` and `moq-rtc` (or `moq-webrtc`, after the -[rename](/quest/m2/webrtc/rename.md)), so callers match it instead of the text +[rename](/quest/m1/webrtc-rename.md)), so callers match it instead of the text `rtc error: DTLS error: timeout: handshake` inside `Error::Rtc(String)`. Session-end handling and logging treat it like an ICE timeout: `session::end` logs it at debug as abandoned-session churn, not as a warning. @@ -18,7 +18,7 @@ dimpl's typed `Error::Timeout(TimeoutError::Handshake)` into before moq-ice sees it. - Classify it once at the str0m boundary in moq-ice, the only place that sees - str0m's error. Until the [vendored stack](/quest/m2/webrtc/vendor.md) lands, + str0m's error. Until the [vendored stack](/quest/m1/webrtc-vendor.md) lands, that is a text match there, pinned by a test against the crate's real message. If the vendoring lands first, carry dimpl's variant through the vendored `dtls.rs` typed instead, and add no text match. Otherwise the @@ -35,5 +35,5 @@ Public API: additive variants on non-exhaustive error enums. Wire: none. ## Related -- [Vendor and trim the WebRTC stack](/quest/m2/webrtc/vendor.md) - replaces this quest's text match with dimpl's typed timeout +- [Vendor and trim the WebRTC stack](/quest/m1/webrtc-vendor.md) - replaces this quest's text match with dimpl's typed timeout - [DTLS waits for ICE](/quest/m2/webrtc/dtls-after-ice.md) - after it, every DTLS handshake timeout comes after nomination, which is the case this types diff --git a/quest/m2/webrtc/sdp-bandwidth.md b/quest/m2/webrtc/sdp-bandwidth.md index d07b203d4df..18c8f26693f 100644 --- a/quest/m2/webrtc/sdp-bandwidth.md +++ b/quest/m2/webrtc/sdp-bandwidth.md @@ -12,4 +12,4 @@ Public API: none. Wire: capped answers gain `b=AS`. ## Required -- [Vendor and trim the stack](/quest/m2/webrtc/vendor.md) - the parser this changes +- [Vendor and trim the stack](/quest/m1/webrtc-vendor.md) - the parser this changes diff --git a/quest/m3/README.md b/quest/m3/README.md index 14cab45ef37..3a5233a004e 100644 --- a/quest/m3/README.md +++ b/quest/m3/README.md @@ -84,3 +84,5 @@ m4's upstream waits in here and moved m2 work with no consumer. - [Rust and JS end a lite-05 track the same way after an inclusive SUBSCRIBE_END](/quest/m3/lite05-subscribe-end.md) - after a legacy inclusive SUBSCRIBE_END, Rust and JS both end the track instead of Rust sending a FIN and JS only releasing - [Byte-at-a-time MKV input imports as fast as chunked input](/quest/m3/mkv-input-coalesce.md) - the MKV importer fed one byte at a time is no slower than before moq-dev/moq#7234 - [A transcode ladder probes an unseen source shape without stalling its other rungs](/quest/m3/transcode-parallel-open.md) - a source changing to an unseen size opens the new encoders without stalling the ladder's other rungs +- [rind-instant-acme is on crates.io](/quest/m3/rind-instant-acme.md) - waiting on instant-acme 0.9 and rind publishing its adapter +- [Relay ACME on instant-acme](/quest/m3/relay-acme.md) - moq-relay's ACME returns on instant-acme and rind, once a user needs it diff --git a/quest/m2/rind/acme.md b/quest/m3/relay-acme.md similarity index 60% rename from quest/m2/rind/acme.md rename to quest/m3/relay-acme.md index 69627b6dd60..734d24bad8f 100644 --- a/quest/m2/rind/acme.md +++ b/quest/m3/relay-acme.md @@ -2,9 +2,9 @@ ## Goal -moq-relay's default `acme` feature issues and renews certificates through +moq-relay's `acme` feature returns: it issues and renews certificates through instant-acme on `rind-instant-acme`, with no rustls-acme, and its graph holds -no aws-lc-rs. Existing config and the on-disk cache keep working. +no aws-lc-rs. ## Plan @@ -18,12 +18,14 @@ so moq-relay moves to instant-acme 0.9, which takes its crypto through its own - the TLS-ALPN-01 challenge resolver in its rustls config, - key and CSR generation through `rind-rcgen`. -The cache's file naming (SHA-256 today) moves to rind and stays compatible, so -an upgraded relay reuses its cached account and certificate. Test against a -local ACME server such as Pebble. +Its cache's file naming moves to rind. m1 removed the feature, its config, and +its cache because nobody used ACME yet (maintainer, 2026-11-03), so the cache +needs no compatibility with the rustls-acme layout. Test against a local ACME +server such as Pebble. -Public API: none; config unchanged. Wire: none. +Public API: moq-relay regains the `acme` feature and an ACME config section. +Wire: none. ## Required -- [rind-instant-acme is on crates.io](/quest/m2/rind/instant-acme.md) - the adapter this uses, waiting on instant-acme 0.9 +- [rind-instant-acme is on crates.io](/quest/m3/rind-instant-acme.md) - the adapter this uses, waiting on instant-acme 0.9 diff --git a/quest/m2/rind/instant-acme.md b/quest/m3/rind-instant-acme.md similarity index 78% rename from quest/m2/rind/instant-acme.md rename to quest/m3/rind-instant-acme.md index 20deda9ffec..d4ac278331f 100644 --- a/quest/m2/rind/instant-acme.md +++ b/quest/m3/rind-instant-acme.md @@ -4,12 +4,12 @@ `rind-instant-acme` is on crates.io, built on a published instant-acme 0.9. It holds once moq-dev/rind's -[Publish rind-instant-acme](https://github.com/moq-dev/rind/blob/main/quest/m1/moq/instant-acme-publish.md) +[Publish rind-instant-acme](https://github.com/moq-dev/rind/blob/main/quest/m3/instant-acme-publish.md) quest is deleted and `cargo search rind-instant-acme` shows it. This quest only waits; delete it once that holds. ## Plan rind's adapter waits on instant-acme's 0.9 release, which carries the -pluggable `CryptoProvider`. Only [relay ACME](/quest/m2/rind/acme.md) needs +pluggable `CryptoProvider`. Only [relay ACME](/quest/m3/relay-acme.md) needs it (maintainer, 2026-10-31). diff --git a/test/interop/README.md b/test/interop/README.md index f9f5e31c59c..d73c0fc53fd 100644 --- a/test/interop/README.md +++ b/test/interop/README.md @@ -54,7 +54,7 @@ native JS adds both Rust-to-JS and JS-to-Rust under that runtime, so `--all` cov Node and Bun. The FETCH round crosses Rust and each selected native JS runtime as both publisher and subscriber. Each reader fetches group 1 of a finished track, requires exactly its three objects, each with its own bytes, and closes under the relay idle-out check. Each native JS runtime also serves -that FETCH from history (`CLI FETCH history`): its publisher writes only group 3 live and answers +that FETCH to all three subscribers from history (`CLI FETCH history`): its publisher writes only group 3 live and answers groups 0 through 2, which it never cached, from an in-memory responder on `track.requests()`. A moq-transport pass skips it, since JavaScript does not route an IETF FETCH to the responder yet. diff --git a/test/interop/clients/js-native/tail.ts b/test/interop/clients/js-native/tail.ts index 0b40dd68fad..b209eed8769 100644 --- a/test/interop/clients/js-native/tail.ts +++ b/test/interop/clients/js-native/tail.ts @@ -1,7 +1,7 @@ /** * Finite raw-track interop: publish until the harness acknowledges, or read through clean EOF. * - * `drop` cuts group 1. `join` reads from whichever group the subscription starts at: a + * `fetch` reads one past group. `drop` cuts group 1. `join` reads from whichever group the subscription starts at: a * moq-transport subscription starts at the largest group rather than at the range asked for, so * it must read a contiguous run of groups through the last one. `compress` publishes a compressed * track with several frames, one empty, in each group. `cached` publishes every group before @@ -49,7 +49,7 @@ if ( /** * The frames of each group. A compressed track spans several frames, one empty, per window. - * `cached`, `history`, and `late` give every frame its own bytes, so a FETCH or join that drops, repeats, or + * `cached`, `history`, `fetch`, and `late` give every frame its own bytes, so a FETCH or join that drops, repeats, or * reorders one fails. */ function frames(sequence: number): Uint8Array[] { diff --git a/test/interop/interop.sh b/test/interop/interop.sh index 425b10fa564..dc126f269dc 100755 --- a/test/interop/interop.sh +++ b/test/interop/interop.sh @@ -510,7 +510,12 @@ plan_pass() { for runtime in js-native-node js-native-bun; do needs "$runtime" || continue # run_tails skips it on moq-transport, so only plan it where it runs. - [[ "$VERSION" == moq-transport-* ]] || record "not run" case="CLI FETCH history" publisher="$runtime" subscriber=rust + if [[ "$VERSION" != moq-transport-* ]]; then + for sub in rust js-native-node js-native-bun; do + [[ "$sub" == rust ]] || needs "$sub" || continue + record "not run" case="CLI FETCH history" publisher="$runtime" subscriber="$sub" + done + fi record "not run" case="late join" publisher=rust subscriber="$runtime" record "not run" case="late join" publisher="$runtime" subscriber=rust record "not run" case=tail publisher=rust subscriber="$runtime" @@ -2465,7 +2470,12 @@ run_tails() { for runtime in js-native-node js-native-bun; do needs "$runtime" || continue # A moq-transport FETCH is not served from the request handler yet. - [[ "$(pinned_version)" == moq-transport-* ]] || run_fetch_round "$runtime" rust history + if [[ "$(pinned_version)" != moq-transport-* ]]; then + for sub in rust js-native-node js-native-bun; do + [[ "$sub" == rust ]] || needs "$sub" || continue + run_fetch_round "$runtime" "$sub" history + done + fi done echo "=== late join ===" run_late_pair rust rust From 15b8eaa28430d4b64e86e809fef38da77d3791ed Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 19:38:22 -0800 Subject: [PATCH 09/11] chore(quest): complete JS IETF FETCH coverage and its epic Co-Authored-By: GPT-6.1 Sol --- quest/m1/README.md | 1 - quest/m1/ietf-drop/README.md | 4 -- quest/m1/interop-coverage/README.md | 58 ---------------------- quest/m1/interop-coverage/js-ietf-fetch.md | 27 ---------- quest/m2/audit-interop.md | 1 - 5 files changed, 91 deletions(-) delete mode 100644 quest/m1/interop-coverage/README.md delete mode 100644 quest/m1/interop-coverage/js-ietf-fetch.md diff --git a/quest/m1/README.md b/quest/m1/README.md index f64f2da4201..65c5ee24e2e 100644 --- a/quest/m1/README.md +++ b/quest/m1/README.md @@ -167,7 +167,6 @@ per-frame CPU growth since #5926. - [crates.io trusts the workflow](/quest/m1/crates-trusted-publisher.md) - maintainer action: every published crate gets a trusted publisher for `release-rs.yml` - [Rust releases publish through OIDC](/quest/m1/release-rs-oidc.md) - release-plz publishes with trusted publishing and `CARGO_REGISTRY_TOKEN` is revoked - [Main is no slower than release](/quest/m1/release-perf/README.md) - every benchmark where main is slower than release is fixed or accepted with a reason, checked by a final paired run before the cut -- [Interop coverage](/quest/m1/interop-coverage/README.md) - the riskiest moq-transport features moq-net exposes get cross-implementation tests over drafts 18, 20, and 22 - [Calibrate the paired nightly benchmarks](/quest/m1/bench-ci.md) - A/A and deliberately slowed Nightly runs set the paired comparison's threshold, so its regression alerts can be trusted - [Unbounded groups](/quest/m1/unbounded-groups/README.md) - groups and frames lose their size caps; a group keeps a 32 MB tail, and readers behind it replay through paced flights or refresh - [Poll-first async](/quest/m1/poll-first/README.md) - library crates compile no coroutines by default: async wrappers are generated from `poll_*` and gated behind an `async` feature diff --git a/quest/m1/ietf-drop/README.md b/quest/m1/ietf-drop/README.md index 3f91d98eb92..55b65ae06b8 100644 --- a/quest/m1/ietf-drop/README.md +++ b/quest/m1/ietf-drop/README.md @@ -44,7 +44,3 @@ protocol implementation or release work remains here. ## Waiting - englishm/moq-interop-runner: review and merge [englishm/moq-interop-runner#183](https://github.com/englishm/moq-interop-runner/pull/183); verify both registry entries and README rows list drafts 18, 20, and 22 before deleting this quest - -## Related - -- [Interop coverage](/quest/m1/interop-coverage/README.md) - cross-implementation cases target drafts 18, 20, and 22 diff --git a/quest/m1/interop-coverage/README.md b/quest/m1/interop-coverage/README.md deleted file mode 100644 index f5a07d7c1d9..00000000000 --- a/quest/m1/interop-coverage/README.md +++ /dev/null @@ -1,58 +0,0 @@ -# Interop coverage for moq-transport - -## Goal - -The moq-transport features moq-net exposes with the most interop bug -history have cross-implementation tests: Rust, JS, and the bindings exchange -hang media and exercise subgroup data, namespace discovery, late joins, -FETCH, GOAWAY, TRACK_STATUS, and datagrams over drafts 18, 20, and 22. Our -upstream runner clients implement the runner's existing cases for those -features. - -Boundaries: - -- Only what moq-net can do. Subgroups other than 0, rendezvous, and - per-request authorization tokens are not exposed, so they are out of - scope, and runner cells that need them stay red by design. -- PUBLISH (push) and outbound forward=0 are out of scope (decided - 2026-10-25, maintainer, reversing the 2026-10-22 decision): no child - quest owned them, and the cases above carry the interop bug history. -- Media stays hang. No MSF catalog in our runner clients. -- New cases live in-tree (`test/interop`), not in the runner's spec. -- Not covered: mid-subscription updates (`Subscription::update` in Rust and - JS, sent as SUBSCRIBE_UPDATE or REQUEST_UPDATE) for priority, max age, - NEW_GROUP_REQUEST, and group order. The maintainer did not pick them on - 2026-10-21; plan them separately if their bug history grows. - -## Plan - -Decided 2026-11-02 (maintainer, follow-up planning after the 2026-11-02 /quest-complete run): draft 20 joins the covered drafts, since it came back in -[moq-dev/moq#7190](https://github.com/moq-dev/moq/pull/7190) and every published moq-dev client and relay already offers it (verified on -[moq-dev/moq#6972](https://github.com/moq-dev/moq/pull/6972)). - - -Decided with the maintainer on 2026-10-21, from an inventory of the -coverage on `main` at `3ab6cbf81d`. - -- `just test interop --versions ietf` runs the matrix on each supported draft; - every new case runs on it. Beyond it, moq-transport is covered by - in-process codec tests (`rs/moq-net/src/test_interop.rs`), the public - relays page (published clients), and the Cloudflare and Moxygen smoke - lanes. -- Drafts 18, 20, and 22 only, nightly. Protocol removal and draft-20 - restoration have landed; only the - [runner registry correction](/quest/m1/ietf-drop/README.md) remains. - The request-limits case went with drafts 14 and 16, the only ones with - MAX_REQUEST_ID. -- Case ranking follows interop bug history: subgroup data and namespace - discovery, then late join and FETCH, then GOAWAY, TRACK_STATUS, - and datagrams. - -## Required - -- [JS subscribers FETCH](/quest/m1/interop-coverage/js-ietf-fetch.md) - `@moq/net` fetches past groups over moq-transport, and joins the CLI FETCH round - -## Related - -- [Runner client bump](/quest/m2/release/runner-client-bump.md) - after the cut publishes #5083, the runner's Rust client stops stamping every object -- [Interop audit](/quest/m2/audit-interop.md) - classifies the red cells these cases produce diff --git a/quest/m1/interop-coverage/js-ietf-fetch.md b/quest/m1/interop-coverage/js-ietf-fetch.md deleted file mode 100644 index dcaf9307ffe..00000000000 --- a/quest/m1/interop-coverage/js-ietf-fetch.md +++ /dev/null @@ -1,27 +0,0 @@ -# [M] JS subscribers FETCH over moq-transport - -## Goal - -`@moq/net`'s moq-transport subscriber fetches a past group with a standalone -FETCH, so `track.Consumer.fetchGroup()` works on moq-transport. JS subscribers -join the CLI FETCH interop round beside Rust. - -## Plan - -Found by [moq-dev/moq#7015](https://github.com/moq-dev/moq/pull/7015). Today -`track.Consumer.fetchGroup()` is rejected on moq-transport. The mid-group -join already recovers the current group's head, with a joining FETCH on -draft 18 or a fill on draft 22 -([moq-dev/moq#7089](https://github.com/moq-dev/moq/pull/7089)), and its -fetch-stream decoder and head stitching are what a standalone FETCH reuses. - -Decided 2026-10-28 (maintainer): one [M] quest in m1, after -JS ranges ([moq-dev/moq#7696](https://github.com/moq-dev/moq/pull/7696)), which turns `fetchGroup` into -a one-range subscription. Map a past range to a standalone FETCH, the way -Rust's subscriber does. Then add the native JS runtimes as subscribers to the -`run_fetch_round` cells in the tail suite. Our publishers answer only one -group ([moq-dev/moq#7204](https://github.com/moq-dev/moq/pull/7204), 2026-10-28), so a -past-range FETCH against them is refused. Test ranges against a third-party -publisher, and one group against ours. - -Public API: none beyond JS ranges' surface. Wire: none. diff --git a/quest/m2/audit-interop.md b/quest/m2/audit-interop.md index 3fd93f7f433..d16ddae4d68 100644 --- a/quest/m2/audit-interop.md +++ b/quest/m2/audit-interop.md @@ -191,4 +191,3 @@ cells of the 2026-10-31 nightly. Classify it. - [Runner client bump](/quest/m2/release/runner-client-bump.md) - the runner's Rust client moves to the cut and its API - [Runner teardown](/quest/m3/interop-runner-approval.md) - the runner's moq.dev clients move to the withdrawing `close()` once it ships -- [Interop coverage](/quest/m1/interop-coverage/README.md) - the runner cases whose red cells this audit classifies From df120cee897c8aea54447e17d4caf890cbdaaf5a Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 19:56:59 -0800 Subject: [PATCH 10/11] docs(quest): retain historical interop coverage decisions Co-Authored-By: GPT-6.1 Sol --- quest/m1/README.md | 6 +++--- quest/m2/ietf-hole-marker.md | 2 +- quest/m2/publish-done-codes.md | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/quest/m1/README.md b/quest/m1/README.md index 08ce693b49c..c8c11574737 100644 --- a/quest/m1/README.md +++ b/quest/m1/README.md @@ -174,12 +174,12 @@ per-frame CPU growth since #5926. - [HLS export lists a same-codec reconfigure's first group under the new init](/quest/m1/hls-reinit-same-codec.md) - the hand-over pick, whichever of the catalog and the records arrives first, after the catalog `hls` removal is planned - [Ordered reads can skip owed holes, and snapshot latest() does](/quest/m1/ordered-owed-holes.md) - moq-net's `Ordered` gains a read that skips past an owed hole to the newest buffered group, while keeping the reader's bounds - [A Rust relay never replays from group 0 to a lite-03/04 subscriber](/quest/m1/relay-inflight-replay.md) - A Rust relay or publisher serving a lite-03 or lite-04 SUBSCRIBE from a track copy that is still resolving starts at the newest group once the copy resolves -- [Rename moq-rtc to moq-webrtc](/quest/m1/webrtc-rename.md) - one published `moq-webrtc` crate holds the gateway, the ICE driver, and the data-channel transport -- [Vendor and trim the WebRTC stack](/quest/m1/webrtc-vendor.md) - str0m, dimpl, `is`, and sctp-proto live in moq-webrtc with unused code removed, so moq-rtc can take rind -- [MoQ on rind](/quest/m1/rind/README.md) - every MoQ crate takes its crypto from rind, a pure-Rust graviola fork, so no build compiles C crypto - [The resume model ends #7739's clean-end seed](/quest/m1/resume-seed-17893651.md) - replay seed 17893651 after #7705's wake fix, and fix it if a long-budget reader still never gets the end - [Every moq-mux consumer gets the catalog warmup from one entry point](/quest/m1/mux-warmup.md) - one moq-mux call widens the subscription and configures the consumer, adopted by moq-audio, moq-c, moq-ffi's raw consumer, and moqsrc - [Codex shells never load another checkout's dev environment](/quest/m1/codex-env-snapshot.md) - the Codex dev-shell snapshot is skipped when stale or inside `nix develop` +- [Rename moq-rtc to moq-webrtc](/quest/m1/webrtc-rename.md) - one published `moq-webrtc` crate holds the gateway, the ICE driver, and the data-channel transport +- [Vendor and trim the WebRTC stack](/quest/m1/webrtc-vendor.md) - str0m, dimpl, `is`, and sctp-proto live in moq-webrtc with unused code removed, so moq-rtc can take rind +- [MoQ on rind](/quest/m1/rind/README.md) - every MoQ crate takes its crypto from rind, a pure-Rust graviola fork, so no build compiles C crypto - [A hardware decoder's capability refusal is an unsupported config](/quest/m1/hw-decoder-refusal.md) - a GPU that can't decode a stream reports `UnsupportedConfig`, so callers fall back to another rendition - [A JS audio capture gap keeps the audio before it](/quest/m1/js-audio-gap-flush.md) - every capture gap flushes the `AudioEncoder` before restarting it, like a disable - [A draft-18 resume of a cached group under a finite max-age settles](/quest/m1/ietf18-resume-cached-start.md) - the read delivers the group or refuses at once, never hangs diff --git a/quest/m2/ietf-hole-marker.md b/quest/m2/ietf-hole-marker.md index 8a81a710bee..337da3f190f 100644 --- a/quest/m2/ietf-hole-marker.md +++ b/quest/m2/ietf-hole-marker.md @@ -65,7 +65,7 @@ Open, for this quest's interview: - How a publisher answering a range walks the drop set's runs in group order, and where FETCH_OK's End Location falls. -Test across Rust and JS on drafts 18, 20, and 22, with and without the extension. Draft 20 added 2026-11-03 (maintainer, /quest-plan of the follow-ups from [moq-dev/moq#7704](https://github.com/moq-dev/moq/pull/7704)), since draft 20 joined the covered drafts in [interop coverage](/quest/m1/interop-coverage/README.md). +Test across Rust and JS on drafts 18, 20, and 22, with and without the extension. Draft 20 added 2026-11-03 (maintainer, /quest-plan of the follow-ups from [moq-dev/moq#7704](https://github.com/moq-dev/moq/pull/7704)), since draft 20 joined the covered drafts in [interop coverage](https://github.com/moq-dev/moq/blob/acef90cf0425d9f0e4e699759cede07adfb2ecfb/quest/m1/interop-coverage/README.md). A range over a copy whose holes are all proven is answered with `0x8C` runs. A range with an unknown hole is still refused. Regression: an upstream reports G stale for a narrow subscriber while still holding G; a wider diff --git a/quest/m2/publish-done-codes.md b/quest/m2/publish-done-codes.md index 9b20315ae71..a884eecc519 100644 --- a/quest/m2/publish-done-codes.md +++ b/quest/m2/publish-done-codes.md @@ -8,6 +8,6 @@ A moq-transport PUBLISH_DONE carries GOING_AWAY (0x4), TOO_FAR_BEHIND (0x5), and Follow-up of [moq-dev/moq#7396](https://github.com/moq-dev/moq/pull/7396), which did this for MALFORMED_TRACK (0x12). The stream-reset codes already map both ways in `rs/moq-net/src/ietf/error.rs:30-75`; only PUBLISH_DONE doesn't use them. -Decided 2026-10-30 (maintainer, follow-up planning after the /quest-afk run). Reuse #7396's path: the publisher picks the PUBLISH_DONE code from the same error-to-code mapping that resets the track's streams, and the subscriber reads it back as the peer's stream code. Cover drafts 18, 20, and 22, both bindings, and JS, each test failing without its fix. Draft 20 added 2026-11-03 (maintainer, /quest-plan of the follow-ups from [moq-dev/moq#7704](https://github.com/moq-dev/moq/pull/7704)), since draft 20 joined the covered drafts in [interop coverage](/quest/m1/interop-coverage/README.md). +Decided 2026-10-30 (maintainer, follow-up planning after the /quest-afk run). Reuse #7396's path: the publisher picks the PUBLISH_DONE code from the same error-to-code mapping that resets the track's streams, and the subscriber reads it back as the peer's stream code. Cover drafts 18, 20, and 22, both bindings, and JS, each test failing without its fix. Draft 20 added 2026-11-03 (maintainer, /quest-plan of the follow-ups from [moq-dev/moq#7704](https://github.com/moq-dev/moq/pull/7704)), since draft 20 joined the covered drafts in [interop coverage](https://github.com/moq-dev/moq/blob/acef90cf0425d9f0e4e699759cede07adfb2ecfb/quest/m1/interop-coverage/README.md). Public API: none. Wire: existing registered codes only. From cbe9bb44b9c8ceb0ccc85a6977c729abe740ef15 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 22:45:24 -0800 Subject: [PATCH 11/11] fix(net): end a history-only widening and subscribe for an empty track's relative end The history wake shared the idle symbol, so a widened read narrowed back to history re-raced its settled promise forever. Give it its own terminal so the live SUBSCRIBE closes while history readers keep reading. A relative end on a track with no Largest resolves at the first group, which only the live feed delivers, so open SUBSCRIBE for it. Co-Authored-By: Claude Opus 5.5 --- js/net/src/ietf/range.test.ts | 79 ++++++++++++++++++++++++++++++++++- js/net/src/ietf/subscriber.ts | 12 ++++-- 2 files changed, 86 insertions(+), 5 deletions(-) diff --git a/js/net/src/ietf/range.test.ts b/js/net/src/ietf/range.test.ts index 4ec20b38e71..d3caba8d7e2 100644 --- a/js/net/src/ietf/range.test.ts +++ b/js/net/src/ietf/range.test.ts @@ -6,10 +6,10 @@ import * as Path from "../path.ts"; import { Reader, Stream, Writer } from "../stream.ts"; import { type Subscription, Producer as TrackProducer } from "../track.ts"; import { Fetch, FetchOk } from "./fetch.ts"; -import { EndOfRange, FetchEndOfRange, FetchFrame } from "./object.ts"; +import { EndOfRange, FetchEndOfRange, FetchFrame, Group } from "./object.ts"; import { RequestError } from "./request.ts"; import { NativeSession } from "./session.ts"; -import { Subscribe } from "./subscribe.ts"; +import { Subscribe, SubscribeOk } from "./subscribe.ts"; import { Subscriber } from "./subscriber.ts"; import { TrackStatusOk, TrackStatusRequest } from "./track.ts"; import { ALPN, type IetfVersion, Version } from "./version.ts"; @@ -318,6 +318,81 @@ for (const version of VERSIONS) { cached.close(); }); + test(`${version}: narrowing a widened read back to history ends its live SUBSCRIBE`, async () => { + const fx = fixture(version); + const history = fx.broadcast.track("video").subscribe(ranges(1n, 3n)); + fx.readers.push(history); + const ordered = history.ordered(); + const first = ordered.nextGroup(); + await fx.status(); + const fetching = await fx.fetch(); + await fx.answer(fetching.stream, 2n); + const live = fx.broadcast + .track("video") + .subscribe({ ranges: [{ start: { absolute: 6n } }], delay: { max: null } }); + const widening = await fx.next(); + expect(await widening.reader.u53()).toBe(Subscribe.id); + await Subscribe.decode(widening.reader, version); + await widening.writer.u53(SubscribeOk.id); + await new SubscribeOk({ trackAlias: 7n }).encode(widening.writer, version); + live.close(); + // The serve loop must stop and close the request rather than spin on its settled history wake. + expect(await widening.reader.done()).toBe(true); + await fx.data(fetching.request.requestId, [1n, 2n]); + const group = await first; + if (!group) throw new Error("missing history group"); + expect(await payloads(group)).toEqual(["1a", "", "1c"]); + group.close(); + const second = await ordered.nextGroup(); + if (!second) throw new Error("missing history group"); + expect(await payloads(second)).toEqual(["2a", "", "2c"]); + second.close(); + expect(await ordered.nextGroup()).toBeUndefined(); + }); + + test(`${version}: a relative end on an empty track subscribes for the first group`, async () => { + const fx = fixture(version); + const reader = fx.broadcast.track("video").subscribe({ + ranges: [{ start: { absolute: 0n }, end: { relative: 0 } }], + delay: { max: null }, + order: "ascending", + }); + fx.readers.push(reader); + const ordered = reader.ordered(); + const first = ordered.nextGroup(); + await fx.status(null); + const live = await fx.next(); + expect(await live.reader.u53()).toBe(Subscribe.id); + await Subscribe.decode(live.reader, version); + await live.writer.u53(SubscribeOk.id); + await new SubscribeOk({ trackAlias: 7n }).encode(live.writer, version); + const payload = new TextEncoder().encode("0a"); + const header = new Group({ + trackAlias: 7n, + groupId: 0n, + subGroupId: 0, + publisherPriority: 0, + flags: { + hasExtensions: false, + hasSubgroup: false, + hasSubgroupObject: false, + hasEnd: true, + hasPriority: true, + firstObject: true, + }, + }); + await fx.subscriber.handleGroup( + header, + new Reader(undefined, new Uint8Array([0, payload.byteLength, ...payload]), version), + ); + const group = await first; + expect(group?.sequence).toBe(0n); + if (!group) throw new Error("missing first group"); + expect(await payloads(group)).toEqual(["0a"]); + group.close(); + expect(await ordered.nextGroup()).toBeUndefined(); + }); + test(`${version}: a nonexistent trailing object range preserves the group's payloads`, async () => { const fx = fixture(version); const pending = fx.broadcast.track("video").fetchGroup(1n); diff --git a/js/net/src/ietf/subscriber.ts b/js/net/src/ietf/subscriber.ts index 444d93443ec..14a9dc6f2bb 100644 --- a/js/net/src/ietf/subscriber.ts +++ b/js/net/src/ietf/subscriber.ts @@ -887,8 +887,11 @@ export class Subscriber { const localEnded = Symbol("local"); const revokedEnded = Symbol("revoked"); const idle = Symbol("idle"); + // History readers may still want the track once its live part is no longer read, so + // this wake stops serving without the demand re-check `idle` takes. + const historyEnded = Symbol("history"); const historical = known - ? this.#historyOnly(producer, known.edge).then(() => idle) + ? this.#historyOnly(producer, known.edge).then(() => historyEnded) : new Promise(() => {}); // Losing the grant ends the subscription, leaving the session alone. @@ -986,8 +989,11 @@ export class Subscriber { #needsLive(producer: track.Producer, edge: bigint): boolean { if (hooks.trackFinished(producer) || !hooks.subscribing(producer).peek()) return false; const ranges = producer.subscription.peek()?.ranges ?? []; - const span = wireSpan(ranges); - return !bounded(ranges) || (span.end !== undefined && span.end > edge); + if (!bounded(ranges)) return true; + const end = wireSpan(ranges).end; + // A relative end resolves against Largest, or against the first group when none exists yet, + // which only the live feed delivers. + return end === undefined ? edge === 0n : end > edge; } async #historyOnly(producer: track.Producer, edge: bigint): Promise {