From c48b10433fe5b13d58262757c36fba0064dfa27b Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 19 Nov 2026 21:02:26 -0800 Subject: [PATCH 1/5] chore(quest): claim quest/m1/precut-fixes/resume-js-sweep.md Quest-Claim: e5d5295b43b51210 From 7b360436d34194987e562bdf93dcdcf47da30afc Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 19 Nov 2026 21:36:45 -0800 Subject: [PATCH 2/5] wip(net): JS resume sweep fixes, part 1 Co-Authored-By: Claude Opus 5.5 --- js/net/src/internal.ts | 6 +++--- js/net/src/resume.ts | 17 ++++++++++------- js/net/src/track.ts | 42 ++++++++++++++++++++++++++++++++---------- 3 files changed, 45 insertions(+), 20 deletions(-) diff --git a/js/net/src/internal.ts b/js/net/src/internal.ts index bbde94521e..1be885f01a 100644 --- a/js/net/src/internal.ts +++ b/js/net/src/internal.ts @@ -496,11 +496,11 @@ export interface ResumeSource { */ tryDrop(delivered: Delivered, passing?: bigint): (Recv & { kind: "drop" }) | undefined; /** - * Whether the reader's bounded `window` has nothing left to deliver, judged by the serving - * copy against what it and the logical reader (`delivered`) handed out. A copy that may still + * Whether the reader's bounded window has nothing left to deliver, judged by the serving copy + * against what it and the logical reader (`delivered`) handed out. A copy that may still * deliver keeps it open. Mirrors the Rust `Reader::exhausted`. */ - exhausted(delivered: Delivered, window: Window): boolean; + exhausted(delivered: Delivered): boolean; /** Wake once a read may go differently; fires at most once. */ changed(fn: () => void): Dispose; /** Forget the gaps in `delivered` below each group past the budget, judged on the newest copy. */ diff --git a/js/net/src/resume.ts b/js/net/src/resume.ts index d2310a9c78..2a9c557985 100644 --- a/js/net/src/resume.ts +++ b/js/net/src/resume.ts @@ -1076,15 +1076,15 @@ class Reader implements ResumeSource { } /** - * Whether the reader's bounded `window` has nothing left to deliver, once no replaced copy may - * still deliver a group under its bound. The serving copy reads every group of the window from - * its resume point, so it judges those, against what it and the reader (`delivered`) handed - * out. What lies under its resume point was the copies' it replaced, each let go once it had - * nothing more, though one there that the local floor or cap keeps out stays owed, as on one + * Whether the reader's bounded {@link #window} has nothing left to deliver, once no replaced + * copy may still deliver a group under its bound. The serving copy reads every group of the + * window from its resume point, so it judges those, against what it and the reader (`delivered`) + * handed out. What lies under its resume point was the copies' it replaced, each let go once it + * had nothing more, though one there that the local floor or cap keeps out stays owed, as on one * cursor. A backfill still to ask is not judged yet, and a route between copies has nothing to * judge. Mirrors the Rust `Reader::exhausted`. */ - exhausted(delivered: Delivered, window: Window): boolean { + exhausted(delivered: Delivered): boolean { this.sync(); if (this.#closed || this.#ended || this.#resumed) return false; const serving = this.#copies.at(-1); @@ -1092,9 +1092,12 @@ class Reader implements ResumeSource { return false; } if (this.#letGo(delivered)) return false; + // The reader's own window, as its copies placed it: the subscriber's leaves its anchors to them. + const window = this.#window(); const end = window.end(); + if (end === undefined || window.pending) return false; const resumed = resumePoint(serving); - if (resumed !== undefined && end !== undefined) { + if (resumed !== undefined) { const cursor = this.#shell.cursor.peek(); for (const run of window.runs(window.floor() ?? 0n, min(resumed, end))) { for (const gap of delivered.gaps(run.start, run.end)) { diff --git a/js/net/src/track.ts b/js/net/src/track.ts index a3af08b498..2ec4fa800a 100644 --- a/js/net/src/track.ts +++ b/js/net/src/track.ts @@ -1434,12 +1434,20 @@ export class Producer { // them again, and a reader that wants one asks a fill or judges it by its budget. A reclaim // never adds a run to the arrivals: a run touching no accounted one takes the gap below it // too, given up early as a fold would. Nothing below the tail's floor is accounted, since - // accounting it would lower the floor onto gaps nobody waited for. Mirrors the Rust + // accounting it would lower the floor onto gaps nobody waited for. Without a declared start + // the first arrival stands in for that floor, which a lower arrival still moves down, so a + // run reaching it extends it down instead: that opens no gap. Mirrors the Rust // `TrackState::forget_drops`. #forgot(forgotten: readonly Run[]): void { const feed = this.#feedStart(); + const declared = feed === "pending" ? this.#wire?.served?.requested : feed; for (const run of forgotten) { - const floor = (feed === "pending" ? this.#wire?.served?.requested : feed) ?? this.#arrivals.first() ?? 0n; + const first = this.#arrivals.first(); + if (declared === undefined && first !== undefined && run.start < first && first <= run.end) { + this.#arrive(run.start, run.end); + continue; + } + const floor = declared ?? first ?? 0n; let start = max(run.start, floor); if (start >= run.end) continue; // The highest run starting at or below the run's end touches it when it ends at or past @@ -1701,9 +1709,10 @@ export class Producer { if (hole.stale === undefined) this.#fills.dropped(start, end); for (const run of runs) this.#setDrops(run.start, run.end, hole); for (const group of arriving) group.abort(hole.error); - // A pending tail owes nothing the publisher gave up. A stale verdict is not receipt: a new - // upstream subscription supersedes it, leaving those groups unknown again, as in Rust. - if (hole.stale === undefined) this.#arrive(start, end); + // A pending tail owes nothing the publisher gave up (see `#owes`). The arrivals leave the + // run out while it is held, as in Rust: arriving it would open a gap below it, dated now, + // which folds before a group still landing there arrives. + this.#owe(); // Giving up the last keys below the end reaches it, as writing them would. this.#endLargest(); return runs; @@ -2671,7 +2680,9 @@ export class Producer { // for, since an update gets no fresh START: a moved floor stands on its own, and moving // back restores the START. Without either, the first arrival stands in for it. // Until the START arrives, the feed start is pending; the requested floor still bounds it. + // A local track has no feed, so what its subscribers ask bounds nothing, as in Rust. #feedStart(): bigint | "pending" | undefined { + if (!this.#wire) return undefined; const ranges = this.#requested.peek()?.ranges; const requested = ranges && wireSpan(ranges).start; const served = this.#wire?.served; @@ -2708,9 +2719,14 @@ export class Producer { #owes(final: bigint): boolean { if (!this.#wire || !this.#state.end.peek()?.tail) return false; const feed = this.#feedStart(); - const floor = (feed === "pending" ? this.#wire?.served?.requested : feed) ?? this.#arrivals.first(); - if (floor === undefined) return final > 0n; - return !this.#arrivals.covers(min(floor, final), final); + const floor = (feed === "pending" ? this.#wire?.served?.requested : feed) ?? this.#arrivals.first() ?? 0n; + // A key the publisher gave up is owed no more. A stale verdict is not receipt: a new + // upstream subscription supersedes it, leaving those groups unknown again, as in Rust. + const drops = this.#state.drops; + return this.#arrivals.gaps(min(floor, final), final).some((gap) => { + const given = drops.overlapping(gap.start, gap.end).filter((run) => run.stale === undefined); + return runGaps(given, gap.start, gap.end).length > 0; + }); } #declareEnd(end: Position, error: Error | undefined, tail: boolean): void { @@ -4204,7 +4220,7 @@ export class Subscriber { // {@link #drained}. A wire publisher's reader never ends there. #exhausted(): boolean { if (this.#parks) return false; - if (this.#resume) return this.#resume.exhausted(this.#delivered, this.#window); + if (this.#resume) return this.#resume.exhausted(this.#delivered); return this.#drained([this.#delivered]); } @@ -4219,6 +4235,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 cursor = this.#cursor.peek(); const producer = this.#state.producer; const received = max(this.#state.received.peek(), ((producer && fillEdge(producer)) ?? -1n) + 1n); // A received stale run that does not settle this reader is unknown to it (see `settles`): @@ -4242,6 +4259,11 @@ export class Subscriber { const unknown = overlapping.filter((run) => !settles(run, budget, coverage)); for (const open of runGaps(drops, gap.start, gap.end)) { if (unknown.some((run) => run.start < open.end && open.start < run.end)) return false; + // Cached under the local floor, which lowering offers again, unless a key-order read + // already passed it: an ordered take let go of it, so it is not held. + const under = { start: max(open.start, this.#nextKey), end: min(open.end, cursor.start) }; + if (producer && under.start < under.end && cachedIn(producer, under.start, under.end).length > 0) + return false; // Not received yet, so it may still arrive. if (open.end > received) return false; // Held, so a read still hands it out, skips it, or waits for the cap to rise. @@ -4295,7 +4317,7 @@ export class Subscriber { // handed out itself counts too. A copy that is itself a front judges across its own copies. hooks.exhaustedFor = (subscriber, delivered) => subscriber.#resume - ? subscriber.#resume.exhausted(subscriber.#delivered.union(delivered), subscriber.#window) + ? subscriber.#resume.exhausted(subscriber.#delivered.union(delivered)) : subscriber.#drained([subscriber.#delivered, delivered]); hooks.tryDrop = (subscriber) => subscriber.#tryDrop(); // A reader following route copies leaves its ranges to the serving copy, which resolves From e0f52c5cb27aaf9634ef32d0713f8d305de1d6a3 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 19 Nov 2026 21:55:24 -0800 Subject: [PATCH 3/5] wip(net): JS resume sweep fixes, part 2 Co-Authored-By: Claude Opus 5.5 --- js/net/src/resume.ts | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/js/net/src/resume.ts b/js/net/src/resume.ts index 2a9c557985..0dc1d9d596 100644 --- a/js/net/src/resume.ts +++ b/js/net/src/resume.ts @@ -404,6 +404,20 @@ function resumePoint(copy: Pick): bigint | undefined return copy.dropped === undefined ? copy.floor : max(copy.floor ?? 0n, copy.dropped); } +/** + * Where `range` resolved, as `at`, on a copy whose resume point is `floor`. One above the range's + * time start asked the copy from the floor, so its resolution says nothing of + * which group the range starts at, nor of an end under the floor too. The range is placed at its + * own anchors, which names the groups under the floor that only a backfill reads. Mirrors the + * Rust `unraised`. + */ +function unraised(range: track.Range | undefined, floor: bigint | undefined, at: Resolved): Resolved { + const start = range?.start?.time; + if (floor === undefined || start === undefined || start >= floor) return at; + const end = range?.end?.time; + return { ...at, start, end: end !== undefined && end < floor ? end + 1n : at.end, floored: true }; +} + /** The first group past where `copy` was replaced: 0 for one replaced before any group. */ function copyEnd(copy: Pick): bigint | undefined { if (copy.until === undefined) return undefined; @@ -694,8 +708,10 @@ class Reader implements ResumeSource { // A failover cap at or below where a range starts empties the copy's range, which then // says nothing of where the reader's own range starts. One at or below where it ends cut // that end short, so it says nothing of where the reader's range ends. - const resolved = own.map((at) => { - if (!at || (cap !== undefined && at.end !== undefined && at.end <= at.start)) return undefined; + const resolved = own.map((own, index) => { + if (!own) return undefined; + const at = unraised(ranges[index], copy.floor, own); + if (cap !== undefined && at.end !== undefined && at.end <= at.start) return undefined; return cap === undefined || (at.end !== undefined && at.end < cap) ? at : { ...at, end: undefined }; }); this.#resolve(resolved); @@ -1420,9 +1436,11 @@ class Reader implements ResumeSource { // From where it was asked to start, or else from what it first got. const start = max(cursor.start, copy.floor ?? 0n); const floor = copy.floor !== undefined; - // A group still to land is waited for once something superseded it, as a gap is. - const land = { start, end, floor, grace: wait, delivered }; - if (copy.since !== undefined && hooks.mayLand(copy.sub, land)) return "wait"; + // A group still to land in the reader's window is waited for once something superseded + // it, as a gap is. + const lands = (run: { start: bigint; end: bigint }) => + hooks.mayLand(copy.sub, { ...run, floor, grace: wait, delivered }); + if (copy.since !== undefined && this.#window().runs(start, end).some(lands)) return "wait"; if (hooks.hasUnreadGroup(copy.sub, cursor.start, end, delivered)) return "keep"; } if (copy.lease > 0) return "keep"; From 66e48023a2e10829a0392f7297f55a9fa6158827 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 19 Nov 2026 22:41:42 -0800 Subject: [PATCH 4/5] fix(net): JS resume sweep passes seeds 1 to 13 Port the window placement below a raised time start (`unraised`) and the forgotten run reaching the first arrival to Rust, with regressions that fail on the old Rust. Leave held drops out of the JS arrivals, as Rust does, and match the Rust model's end oracle. Document why `Copy.dropped` has no Rust counterpart. This finishes the quest and the pre-cut fixes epic. Co-Authored-By: Claude Opus 5.5 --- js/net/src/internal.ts | 2 +- js/net/src/resume.model.test.ts | 138 ++++++++++++++++++++++- js/net/src/resume.ts | 21 ++-- js/net/src/track.ts | 11 +- quest/m1/precut-fixes/README.md | 47 -------- quest/m1/precut-fixes/resume-js-sweep.md | 81 ------------- quest/m3/release/cut.md | 1 - rs/moq-net/src/model/resume.rs | 28 ++++- rs/moq-net/src/model/resume_model.rs | 62 ++++++++++ rs/moq-net/src/model/track.rs | 24 +++- 10 files changed, 265 insertions(+), 150 deletions(-) delete mode 100644 quest/m1/precut-fixes/README.md delete mode 100644 quest/m1/precut-fixes/resume-js-sweep.md diff --git a/js/net/src/internal.ts b/js/net/src/internal.ts index 1be885f01a..5d233ac2e2 100644 --- a/js/net/src/internal.ts +++ b/js/net/src/internal.ts @@ -34,7 +34,7 @@ import type { } from "./track.ts"; import { max, min } from "./util/key.ts"; import * as Varint from "./varint.ts"; -import type { Holdings, Resolved, Window } from "./window.ts"; +import type { Holdings, Resolved } from "./window.ts"; import type { Advertised, Advertisements } from "./wire.ts"; /** A null {@link Delay.max} in milliseconds, which the model holds as the largest value every peer can read. */ diff --git a/js/net/src/resume.model.test.ts b/js/net/src/resume.model.test.ts index 12a67e8f69..176706191d 100644 --- a/js/net/src/resume.model.test.ts +++ b/js/net/src/resume.model.test.ts @@ -626,7 +626,7 @@ class Model { if (!instance.ended && reader.ranges === undefined) { throw fail(index, "the track ended cleanly though no route declared an end"); } - const covered = (group: number) => (instance.ended ? true : within(reader.ranges, group)); + const covered = (group: number) => (instance.ended ? covers(reader, group) : within(reader.ranges, group)); reader.carried = new Set(); for (let group = 0; group < GROUPS; group++) { if (covered(group) && instance.live().every((copy) => complete(copy, group))) reader.carried.add(group); @@ -1190,6 +1190,142 @@ test("regressions", async () => { ], finish: false, }, + // An ordered reader reads a cached group its local floor kept out once the floor is lowered: + // the read stays open while the floor keeps it out. + { + ops: [ + { kind: "join", reader: 3, spec: spec(true, "hour", [0, 1], false) }, + { kind: "bounds", reader: 3, range: [1, 2] }, + { kind: "write", instance: 0, slot: 0, group: undefined, frames: 1 }, + { kind: "bounds", reader: 3, range: undefined }, + { kind: "read", reader: 0 }, + ], + finish: false, + }, + // A bounded read ends by the window its copies placed, so a group under the resume point that + // the local floor keeps out stays owed. + { + ops: [ + { kind: "join", reader: 2, spec: spec(false, "hour", [1, 4], false) }, + { kind: "write", instance: 0, slot: 0, group: 2, frames: 1 }, + { kind: "bounds", reader: 2, range: [2, 4] }, + { kind: "up", instance: 0, slot: 1 }, + { kind: "join", reader: 0, spec: spec(false, "short", undefined, false) }, + ], + finish: false, + }, + // A route's give-up is no arrival, so the gap below it does not age from then: a group landing + // there later still reaches the backfill asked for it. + { + ops: [ + { kind: "up", instance: 1, slot: 1 }, + { kind: "giveUp", instance: 1, slot: 1, group: 2 }, + { kind: "expire" }, + { kind: "up", instance: 1, slot: 2 }, + { kind: "join", reader: 0, spec: spec(false, "hour", undefined, false) }, + { kind: "write", instance: 1, slot: 1, group: undefined, frames: 1 }, + { kind: "write", instance: 1, slot: 2, group: 2, frames: 1 }, + { kind: "down", instance: 1, slot: 2 }, + { kind: "leave", reader: 1 }, + ], + finish: false, + }, + // What a local track's subscribers ask for is no feed floor, so a drop it forgets under that is + // still accounted and the read ends with the track. + { + ops: [ + { kind: "up", instance: 0, slot: 1 }, + { kind: "join", reader: 0, spec: spec(false, "hour", [9, 12], false) }, + { kind: "up", instance: 0, slot: 2 }, + { kind: "giveUp", instance: 0, slot: 1, group: 1 }, + { kind: "expire" }, + { kind: "write", instance: 0, slot: 0, group: undefined, frames: 1 }, + ], + finish: true, + }, + // A local floor holds a read open only for a group the cache holds under it, so a range whose + // groups never arrived ends. + { + ops: [ + { kind: "join", reader: 1, spec: spec(false, "hour", [1, 2], false) }, + { kind: "bounds", reader: 1, range: [6, 12] }, + { kind: "write", instance: 0, slot: 0, group: 11, frames: 3 }, + { kind: "end", instance: 0, slot: 0 }, + { kind: "ranges", reader: 1, range: undefined }, + { kind: "write", instance: 0, slot: 0, group: undefined, frames: 1 }, + ], + finish: false, + }, + // A forgotten drop reaching a local track's first arrival stays accounted once a lower group + // lands, so no replaced copy is waited on for it. + { + ops: [ + { kind: "join", reader: 0, spec: spec(false, "hour", [10, 12], false) }, + { kind: "giveUp", instance: 0, slot: 0, group: 1 }, + { kind: "expire" }, + { kind: "write", instance: 0, slot: 0, group: 2, frames: 1 }, + { kind: "up", instance: 0, slot: 1 }, + ], + finish: true, + }, + // A replaced copy is waited on only for groups the reader's window names. + { + ops: [ + { kind: "join", reader: 2, spec: spec(false, "hour", undefined, false) }, + { kind: "write", instance: 0, slot: 0, group: 9, frames: 1 }, + { kind: "up", instance: 0, slot: 1 }, + { kind: "down", instance: 0, slot: 0 }, + { kind: "ranges", reader: 2, range: [1, 2] }, + { kind: "write", instance: 0, slot: 0, group: 0, frames: 1 }, + ], + finish: false, + }, + // A read that ends with the track owed the groups its cursor named then, as the Rust model + // judges it. + { + ops: [ + { kind: "up", instance: 1, slot: 1 }, + { kind: "up", instance: 1, slot: 0 }, + { kind: "join", reader: 0, spec: spec(false, "hour", [1, 3], false) }, + { kind: "write", instance: 1, slot: 0, group: undefined, frames: 1 }, + { kind: "write", instance: 1, slot: 1, group: 1, frames: 1 }, + { kind: "write", instance: 1, slot: 0, group: 11, frames: 1 }, + { kind: "down", instance: 1, slot: 1 }, + { kind: "end", instance: 1, slot: 0 }, + { kind: "ranges", reader: 0, range: undefined }, + { kind: "advance", ms: 1 }, + ], + finish: false, + }, + // A time start under the serving copy's resume point is placed where it names, not at the floor + // that raised it, so the read waits on a group the local floor keeps out. Mirrors the Rust case. + { + ops: [ + { kind: "join", reader: 2, spec: spec(false, "hour", undefined, false) }, + { kind: "write", instance: 0, slot: 0, group: 8, frames: 3 }, + { kind: "up", instance: 0, slot: 1 }, + { kind: "down", instance: 0, slot: 0 }, + { kind: "bounds", reader: 2, range: [8, 9] }, + { kind: "ranges", reader: 2, range: [7, 9] }, + { kind: "read", reader: 0 }, + ], + finish: false, + }, + // Ranges widened under the resume point of a copy whose failover cap cut their end short start + // where they name and keep their own end. Mirrors the Rust case. + { + ops: [ + { kind: "up", instance: 1, slot: 0 }, + { kind: "join", reader: 1, spec: spec(false, "hour", [3, 7], false) }, + { kind: "up", instance: 1, slot: 1 }, + { kind: "write", instance: 1, slot: 1, group: 3, frames: 1 }, + { kind: "write", instance: 1, slot: 1, group: 5, frames: 3 }, + { kind: "down", instance: 1, slot: 1 }, + { kind: "ranges", reader: 1, range: [1, 7] }, + { kind: "join", reader: 0, spec: spec(false, "hour", undefined, false) }, + ], + finish: false, + }, ]; const failures: string[] = []; for (const [i, c] of regressions.entries()) { diff --git a/js/net/src/resume.ts b/js/net/src/resume.ts index 0dc1d9d596..614727e519 100644 --- a/js/net/src/resume.ts +++ b/js/net/src/resume.ts @@ -375,6 +375,14 @@ interface Copy { /** * One past the highest group the reader's window dropped from it, which it no longer offers * though a widened window may name it again: a resume point, as {@link Copy.floor} is. + * + * The Rust reader has no counterpart, since it never reaches this shape. Its front keeps a track + * being read on its source until that copy ends, so a copy it replaced has stopped placing the + * window by the time the next one subscribes. That copy subscribes with the window's resolution, + * so its own ranges hold back what the window leaves out, still cached for a widening to offer. + * This front moves a track being read as soon as a better route of its instance answers. A copy + * it replaced, still delivering, can then place the window after the serving copy subscribed with + * nothing resolved, and that copy offers a group the window leaves out: the reader takes it. */ dropped?: bigint; } @@ -406,10 +414,9 @@ function resumePoint(copy: Pick): bigint | undefined /** * Where `range` resolved, as `at`, on a copy whose resume point is `floor`. One above the range's - * time start asked the copy from the floor, so its resolution says nothing of - * which group the range starts at, nor of an end under the floor too. The range is placed at its - * own anchors, which names the groups under the floor that only a backfill reads. Mirrors the - * Rust `unraised`. + * time start asked the copy from the floor, so its resolution says nothing of which group the + * range starts at, nor of an end under the floor too. The range is placed at its own anchors, + * which names the groups under the floor that only a backfill reads. Mirrors the Rust `unraised`. */ function unraised(range: track.Range | undefined, floor: bigint | undefined, at: Resolved): Resolved { const start = range?.start?.time; @@ -708,9 +715,9 @@ class Reader implements ResumeSource { // A failover cap at or below where a range starts empties the copy's range, which then // says nothing of where the reader's own range starts. One at or below where it ends cut // that end short, so it says nothing of where the reader's range ends. - const resolved = own.map((own, index) => { - if (!own) return undefined; - const at = unraised(ranges[index], copy.floor, own); + const resolved = own.map((placed, index) => { + if (!placed) return undefined; + const at = unraised(ranges[index], copy.floor, placed); if (cap !== undefined && at.end !== undefined && at.end <= at.start) return undefined; return cap === undefined || (at.end !== undefined && at.end < cap) ? at : { ...at, end: undefined }; }); diff --git a/js/net/src/track.ts b/js/net/src/track.ts index 2ec4fa800a..46ba39a3ce 100644 --- a/js/net/src/track.ts +++ b/js/net/src/track.ts @@ -1329,8 +1329,8 @@ export class Producer { #wire?: Wire; // The misses its readers asked of a {@link Requests} handle. #fills: FillState; - // The keys the live feed delivered, as a group or a drop, and the stale runs a reclaim - // forgot: what a pending tail is judged by. Eviction never touches it. A gap folds away a + // The keys the live feed delivered as a group, and the drops a reclaim forgot, which `drops` + // no longer holds: what a pending tail is judged by. Eviction never touches it. A gap folds away a // subscription's grace after a later arrival opened it, as the session's tail does, so this // holds only the gaps still worth waiting for. #arrivals = new Ledger(); @@ -1443,12 +1443,9 @@ export class Producer { const declared = feed === "pending" ? this.#wire?.served?.requested : feed; for (const run of forgotten) { const first = this.#arrivals.first(); - if (declared === undefined && first !== undefined && run.start < first && first <= run.end) { - this.#arrive(run.start, run.end); - continue; - } const floor = declared ?? first ?? 0n; - let start = max(run.start, floor); + const reaches = declared === undefined && first !== undefined && run.start < first && first <= run.end; + let start = reaches ? run.start : max(run.start, floor); if (start >= run.end) continue; // The highest run starting at or below the run's end touches it when it ends at or past // its start; otherwise it is the run below. diff --git a/quest/m1/precut-fixes/README.md b/quest/m1/precut-fixes/README.md deleted file mode 100644 index e1274f902a..0000000000 --- a/quest/m1/precut-fixes/README.md +++ /dev/null @@ -1,47 +0,0 @@ -# Pre-cut correctness fixes - -## Goal - -Every defect assigned to this epic by the November 17 and 18 pre-cut audits is fixed on `main` before the `0.22.0` cut, -so the cut publishes none of them. - -## Plan - -The audit read everything that changed from `release` -([ca3b801a6c](https://github.com/moq-dev/moq/commit/ca3b801a6c)) to `main` -([ec5a19540f](https://github.com/moq-dev/moq/commit/ec5a19540f)) for bugs, -hostile input, performance, fragile lifecycles, and unproven claims, with -eighteen read-only reviewers by area. API shape and whether a feature should -exist were out of scope: the 2026-11-16 audit and the -[API shape review](/quest/m3/release/api-review.md) own them. So was code an -open m2 quest replaces (the old lite-07 route rule, YIELDED continuations, -lite-07 sequence addressing, socket endpoints, moq-e2ee). - -Decided 2026-11-17 (maintainer, [moq-dev/moq#9010](https://github.com/moq-dev/moq/pull/9010#issuecomment-6959731587)): ✅ every finding gates the cut, including those `release` already ships, -so they all live in this epic, which the cut requires (rejected: gating only -what `release` lacks, the agent's /quest-afk recommendation; gating none). -The one exception: ✅ ts-step-damage (a lone TS stream's timestamp step) was a -standalone low-priority m1 quest outside the gate, since it was read from -source with no field report (rejected: keeping it in the gate; deleting it). -Deleted 2026-11-19 (maintainer, /quest-complete): with no field report, an -import that ends with the cause, as it has since -[moq-dev/moq#9170](https://github.com/moq-dev/moq/pull/9170), is the right -behavior for an unexplained step. -✅ Every quest the audit added stays in m1 (rejected: only this epic in m1). - -Each child reproduces its finding before fixing it: most were read from -source, not run. The reviewers' reports were scratch and are not kept; each -quest carries what its implementer needs. - -Decided 2026-11-18 (maintainer, release audit interview): ✅ a fresh audit of -[release](https://github.com/moq-dev/moq/commit/c636e03df1) through -[main](https://github.com/moq-dev/moq/commit/d0ce553674), independently of the prior review. -✅ Hold the cut for the seven correctness findings, resolve the DVR retention and scoped discovery -findings, and settle the SDK contracts before publication. The ranged-reader failure reproduced -on the audited head. The empty-token dial and file-pacing defects can ship as patches because their -fixes preserve the published contract (rejected: holding the cut for every reproduced defect). -This policy adds to the November 17 decisions. - -## Related - -- [Feature review](/quest/m3/release/feature-review.md) - the delta pass after m2 judges what m2 lands, which this audit skipped diff --git a/quest/m1/precut-fixes/resume-js-sweep.md b/quest/m1/precut-fixes/resume-js-sweep.md deleted file mode 100644 index d3bd7ff574..0000000000 --- a/quest/m1/precut-fixes/resume-js-sweep.md +++ /dev/null @@ -1,81 +0,0 @@ -# [L] Nightly's JS resume sweep passes - -## Goal - -Every swept seed, 1 to 13, passes `MOQ_RESUME_CASES=50000` on -`js/net/src/resume.model.test.ts`. Each defect behind a failure is fixed at its -root, matching the Rust reader (`rs/moq-net/src/model/resume.rs`) where Rust -passes the same case. - -Nightly's `test/resume-model.sh` draws a fresh random seed each run at its -default 4096 cases, so no fixed set of seeds proves Nightly passes. A clean -sweep of seeds 1 to 13 at 50k cases is this quest's bar; a Nightly failure -after that is a new defect for its own quest. - -## Plan - -The fix for this sweep's `group N outside ranges` failures let it run past -where `main` failed, uncovering the defects below. Both fail the same way on -`main` at [f1df3c3a8e](https://github.com/moq-dev/moq/commit/f1df3c3a8e). -Seeds 3, 10, 11 and 12 pass 50k cases. The rest fail with `missing groups`, -at these case counts: 1 at 11,325; 2 at 14,386; 4 at 2,597; 5 at 12,998; 6 at -16,450; 7 at 1,450; 8 at 29,981; 9 at 43,492; 13 at 2,623. Seeds 4, 7 and 13 -fail within Nightly's 4096 cases. Expect more behind these: each fix so far -exposed the next. - -Replay a counterexample by adding it to the `regressions` test. - -1. **Widened local bounds lose a group.** Rust passes this case. - Seed 1 at 11,325 cases: - - ``` - join r3 ordered [0,1]; bounds r3 [1,2]; write 0/0 next; - bounds r3 none; read r0 - ``` - - This fails with `missing groups 0`. Untraced; the likely cause is that the - ordered cursor passes group 0 while the bounds start at 1, and lowering them - asks no backfill because the serving copy has no resume point (`#backfill` - returns without one). Seeds 2, 4, 5, 8, 9 and 13 fail with - `missing groups` in cases that also move local bounds. Their counterexamples - are in the sweep output; check each against Rust. -2. **A forgotten drop accounts a group never written.** Rust passes this case. - Seed 7 at 1,450 cases: - - ``` - up 1/1; giveUp 1/1 g2; expire; up 1/2; join r0 unbounded; - write 1/1 next; write 1/2 g2; down 1/2; leave r1 - ``` - - This fails with `missing groups 1`. Route 1/1's drop of group 2 expires once - the route's edge passes it, and `#forgot` (Rust `forget_drops`) accounts - `[1, 3)` as arrived, "the gap below it too, given up early as a fold would", - so the backfill copy is let go before group 1 lands. Rust's model never - forgets that drop because its pool tick (`Pool::now`) moves only when the - pool driver polls, while JS's `Pool.now()` reads the clock on demand. Rust in - production polls its pool and may share the defect. Seed 6 fails the same - way at 16,450 cases, also a give-up followed by `expire`. - - Decided 2026-11-19 (coordinator, maintainer away, merge granted): decide by - test. Port this expired-drop counterexample (seeds 6 and 7) to a Rust test - driven by a clock that advances only when polled, the way JS reads it. If - Rust fails, the drop rule is wrong: fix it in both languages. If Rust - passes, fix how JS reads its clock. - -3. **`Copy.dropped` has no Rust counterpart.** A group the JS window drops - raises its copy's resume point (`resumePoint`), so widening backfills it; - Rust's `poll_lowest` drops it and its `backfill`/`backfill_gaps` read only - `copy.floor`. Check whether a Rust serving copy with no floor can offer a - cached group below a window a replaced copy placed. If it can, Rust loses - that group on widening: port the mechanism. If not, write down on - `Copy.dropped` why JS reaches that shape and Rust does not. Raised by - Pullfrog on [moq-dev/moq#9115](https://github.com/moq-dev/moq/pull/9115). - -Nightly's seed 1218508351 (run -[44342367698](https://github.com/moq-dev/moq/actions/runs/44342367698)), which -`quest/m0/nightly/js-resume-window.md` tracked, passes 4096 cases since -[moq-dev/moq#9115](https://github.com/moq-dev/moq/pull/9115). That quest's -partial branch `fix/js-resume-window-wip` (`0f1b73d365`) is superseded by -#9115's window port and holds nothing more; delete it when this quest lands. - -Public API: none. Wire: none. diff --git a/quest/m3/release/cut.md b/quest/m3/release/cut.md index 5d89709874..5c3fe9b367 100644 --- a/quest/m3/release/cut.md +++ b/quest/m3/release/cut.md @@ -250,4 +250,3 @@ check that Release remeasure opened or updated its pin PR, as RELEASE.md describ - [Interop and Video pass on main](/quest/m0/interop-green/README.md) - the cut PR's release gate runs `interop.yml`, which failed on `main` every day through 2026-11-12 - [Nightly passes on main](/quest/m0/nightly/README.md) - the release gate runs `features.yml`, red in the 2026-11-12 Nightly - [Claim new npm names](/quest/m3/release/npm-first-publish.md) - trusted publishing can publish every new `@moq/*` package -- [Pre-cut correctness fixes](/quest/m1/precut-fixes/README.md) - both pre-cut audits' required fixes have landed diff --git a/rs/moq-net/src/model/resume.rs b/rs/moq-net/src/model/resume.rs index 7858b13fff..a8304ac154 100644 --- a/rs/moq-net/src/model/resume.rs +++ b/rs/moq-net/src/model/resume.rs @@ -695,6 +695,25 @@ impl Holdings for Placed { } } +/// Where `range` resolved, as `at`, on a copy whose resume point is `floor`. One above the +/// range's time start asked the copy from the floor, so its resolution says nothing of which +/// group the range starts at, nor of an end under the floor too. The range is placed at its +/// own anchors, which names the groups under the floor that only a backfill reads. Mirrors the +/// JS `unraised`. +fn unraised(range: &track::Range, floor: Option, at: Resolved) -> Resolved { + match (floor, range.start) { + (Some(floor), Anchor::Time(start)) if start < floor => Resolved { + start, + end: match range.end { + Some(Anchor::Time(end)) if end < floor => Some(end + 1), + _ => at.end, + }, + floored: true, + }, + _ => at, + } +} + /// Whether `copy` lost its route, so an error read from it is no verdict on what it carried. /// A terminal track verdict, unlike a delivery failure, still judges its content. fn copy_failed(copy: &track::Consumer) -> bool { @@ -1818,11 +1837,12 @@ impl Reader { if !concluded && copy_failed(©.track) { continue; } - let cap = copy.end(); + let (cap, floor) = (copy.end(), copy.floor); let Sub::Ready(sub) = &mut copy.sub else { continue; }; let keys = self.window.unsettled(); + let mirrored = &self.mirrored; // A failover cap at or below where a range starts empties the copy's range, which // then says nothing of where the reader's own range starts. One at or below where // it ends cut that end short, so it says nothing of where the reader's range ends. @@ -1831,8 +1851,10 @@ impl Reader { .copied() .zip(sub.resolved_ranges(keys.iter().copied())) .filter_map(|(key, resolved)| { - let resolved = resolved - .filter(|resolved| cap.is_none() || resolved.end.is_none_or(|end| end > resolved.start))?; + let resolved = unraised(mirrored.ranges.get(&key)?, floor, resolved?); + if cap.is_some() && resolved.end.is_some_and(|end| end <= resolved.start) { + return None; + } Some(( key, Resolved { diff --git a/rs/moq-net/src/model/resume_model.rs b/rs/moq-net/src/model/resume_model.rs index e941713108..0d037fbacd 100644 --- a/rs/moq-net/src/model/resume_model.rs +++ b/rs/moq-net/src/model/resume_model.rs @@ -1516,6 +1516,68 @@ fn regressions() { ], finish: false, }, + // A time start under the serving copy's resume point is placed where it names, not at + // the floor that raised it, so the read waits on a group the local floor keeps out. + Case { + ops: vec![ + Op::Join { + reader: 2, + spec: spec(false, Budget::Hour, None, false), + }, + Op::Write { + instance: 0, + slot: 0, + group: Some(8), + frames: 3, + }, + Op::Up { instance: 0, slot: 1 }, + Op::Down { instance: 0, slot: 0 }, + Op::Bounds { + reader: 2, + range: Some((8, 9)), + }, + Op::Ranges { + reader: 2, + range: Some((7, 9)), + }, + Op::Read { reader: 0 }, + ], + finish: false, + }, + // Ranges widened under the resume point of a copy whose failover cap cut their end short + // start where they name, and keep their own end. + Case { + ops: vec![ + Op::Up { instance: 1, slot: 0 }, + Op::Join { + reader: 1, + spec: spec(false, Budget::Hour, Some((3, 7)), false), + }, + Op::Up { instance: 1, slot: 1 }, + Op::Write { + instance: 1, + slot: 1, + group: Some(3), + frames: 1, + }, + Op::Write { + instance: 1, + slot: 1, + group: Some(5), + frames: 3, + }, + Op::Down { instance: 1, slot: 1 }, + Op::Ranges { + reader: 1, + range: Some((1, 7)), + }, + Op::Join { + reader: 0, + spec: spec(false, Budget::Hour, None, false), + }, + ], + finish: false, + }, ]; for case in cases { if let Err(err) = run(&case) { diff --git a/rs/moq-net/src/model/track.rs b/rs/moq-net/src/model/track.rs index 1916410c2b..ba06a85ab2 100644 --- a/rs/moq-net/src/model/track.rs +++ b/rs/moq-net/src/model/track.rs @@ -1870,12 +1870,19 @@ impl TrackState { /// A reclaim never adds a run to the arrivals, so forgetting a flood of fragments costs /// nothing there: a run touching no accounted one takes the gap below it too, given up /// early as a fold would. Nothing below the tail's floor is accounted, since nothing waits - /// on it and accounting it would lower the floor onto gaps nobody waited for. + /// on it and accounting it would lower the floor onto gaps nobody waited for. Without a + /// declared start the first arrival stands in for that floor, which a lower arrival still + /// moves down, so a run reaching it extends it down instead: that opens no gap. fn forget_drops(&mut self, run: ops::Range) { self.change_drops(run.clone(), None); self.forgotten.record(run.clone()); let floor = self.tail_floor(); - let start = run.start.max(floor); + let reaches = self.start == Start::Unknown + && self + .arrivals + .first() + .is_some_and(|first| run.start < first && first <= run.end); + let start = if reaches { run.start } else { run.start.max(floor) }; if start >= run.end { return; } @@ -28442,6 +28449,19 @@ mod test { assert!(local.state.read().skipped(5), "a local skip above the edge stays"); } + /// A forgotten run reaching a local track's first arrival extends it down, so a group + /// landing below it later opens no gap over the run for a reader to wait on. + #[test] + #[cfg(feature = "async")] + fn a_forgotten_run_under_the_first_arrival_stays_accounted() { + let producer = track_producer("test", Info::timed()); + producer.give_up(1..2, Hole::drop(StreamError::Cancel)); + write_group(&producer, 2); + producer.forget_drops(1..2); + write_group(&producer, 0); + assert!(producer.state.read().arrivals.covers(0..3), "group 1 is not waited for"); + } + /// A received copy whose end a dropped gap let it reach stays ended once that run expires, /// even for a reader whose budget outlasts the run, which would otherwise wait on the gap. #[test] From b9ead700c1161fceac643b4e20b6479e5a961021 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 19 Nov 2026 22:50:57 -0800 Subject: [PATCH 5/5] chore(quest): follow up a resumed time start below the copy's floor Co-Authored-By: Claude Opus 5.5 --- quest/m1/resume-time-below-floor.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 quest/m1/resume-time-below-floor.md diff --git a/quest/m1/resume-time-below-floor.md b/quest/m1/resume-time-below-floor.md new file mode 100644 index 0000000000..d957f70e43 --- /dev/null +++ b/quest/m1/resume-time-below-floor.md @@ -0,0 +1,19 @@ +# [L] A resumed reader's time start below its copy's resume point starts at the group containing it + +## Goal + +A resume reader (`rs/moq-net/src/model/resume.rs`, `js/net/src/resume.ts`) whose range starts at a time below the serving copy's resume point starts at the group containing that time, as a plain reader of the route would, not at a group key equal to the time. Rust and JS match. + +## Plan + +The serving copy is asked from its floor (`clamped` raises a time start to `max(time, floor)`), so its resolution says nothing of which group the original time names. [moq-dev/moq#9224](https://github.com/moq-dev/moq/pull/9224) stopped placing the window at the floor (`unraised` in both languages). It now places it at the time itself, as a group key. That is still wrong when no group starts exactly there: an arrival reader resumed at group 8 that asks from time 7, on a route holding groups 6 and 8, places the start at 7. `#backfillGaps` (Rust `backfill_gaps`) then backfills from 7, which excludes group 6, the group holding time 7 and possibly the seek's keyframe. Codex raised this on #9224's review. + +- Recommended: a copy whose floor raised a range's time start leaves that start unplaced. The reader then asks the route for a backfill below the resume point that carries the original time anchor unclamped, and the backfill's resolution places the start, as the first copy to place a range does today. Groups the serving copy offers at or above its floor keep flowing while the start waits, since they lie in range wherever it resolves. +- Check that a window waiting on such a start never hands out a group below where it will resolve, from a replaced copy in particular. +- The resume models' oracles (`resume_model.rs`, `resume.model.test.ts`) require only groups at or above a range's start time (`within`), so no sweep catches this. Teach both oracles the group containing a time start, from what the routes wrote, then add the case above as a regression in both. + +Public API: none. Wire: none. + +## Related + +- [moq-dev/moq#9172](https://github.com/moq-dev/moq/pull/9172) - adds `quest/m1/time-start-asks-upstream.md`, the relay copy's version: placing a time start only where it can prove upstream's answer