diff --git a/js/net/src/resume.model.test.ts b/js/net/src/resume.model.test.ts index b40633d5c17..919dee85a19 100644 --- a/js/net/src/resume.model.test.ts +++ b/js/net/src/resume.model.test.ts @@ -1016,6 +1016,39 @@ test("regressions", async () => { ], finish: false, }, + // A read right after a fully read range is replaced by none follows live, not the old range's end. + { + ops: [ + { kind: "up", instance: 1, slot: 1 }, + { kind: "join", reader: 0, spec: spec(false, "hour", [0, 1], false) }, + { kind: "write", instance: 1, slot: 1, group: undefined, frames: 1 }, + { kind: "ranges", reader: 0, range: undefined }, + ], + finish: false, + }, + // A read right after the ranges narrow hands out no buffered group they left out. + { + ops: [ + { kind: "up", instance: 0, slot: 1 }, + { kind: "join", reader: 1, spec: spec(false, "hour", [0, 1], false) }, + { kind: "write", instance: 0, slot: 1, group: 1, frames: 1 }, + { kind: "write", instance: 0, slot: 1, group: 0, frames: 1 }, + { kind: "down", instance: 0, slot: 1 }, + { kind: "ranges", reader: 1, range: [1, 2] }, + ], + finish: false, + }, + // A read right after the ranges widen below a group the copy passed waits for it. + { + ops: [ + { kind: "up", instance: 1, slot: 0 }, + { kind: "join", reader: 0, spec: spec(true, "hour", undefined, false) }, + { kind: "ranges", reader: 0, range: [1, 2] }, + { kind: "write", instance: 1, slot: 0, group: 0, frames: 1 }, + { kind: "ranges", reader: 0, range: [0, 1] }, + ], + 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 5eeb0f98130..cfe675582b1 100644 --- a/js/net/src/resume.ts +++ b/js/net/src/resume.ts @@ -300,13 +300,15 @@ class Reader implements ResumeSource { #shell: ResumeShell; /** The route generation last read. */ #generation?: number; + /** The reader's preferences as last mirrored into its copies; see {@link #follow}. */ + #mirrored?: track.Subscription; /** * Oldest first, except that a backfill goes before the copy of the route it backfills: the last * one is the serving route's own, when it is subscribed. */ #copies: Copy[] = []; - /** The cursor start the copies were last bounded at: a lower one asks for a backfill. */ - #start: bigint; + /** The reader's cursor the copies were last bounded at: a lower start asks for a backfill. */ + #bounded: { start: bigint; end?: bigint }; /** The newest group handed out: where a new copy is asked to start. */ #newest?: bigint; /** @@ -358,19 +360,12 @@ class Reader implements ResumeSource { this.route = route; this.#shell = shell; this.#record = record; - this.#start = shell.cursor.peek().start; + this.#mirrored = shell.subscription.peek(); + this.#bounded = shell.cursor.peek(); route.readers.add(this); this.#dispose.push( - shell.subscription.subscribe(() => { - for (const copy of this.#copies) this.#update(copy); - }), - shell.cursor.subscribe(() => { - for (const copy of this.#copies) this.#bound(copy); - const passed = this.#start; - this.#start = shell.cursor.peek().start; - if (this.#start < passed) this.#backfill(this.#start, passed); - if (this.#ended) this.#letGo(this.#delivered); - }), + shell.subscription.subscribe(() => this.#follow()), + shell.cursor.subscribe(() => this.#follow()), ); // A fork starts on its parent's newest copy, at that copy's generation: the copy keeps its // retained groups even where no route serves the track, between routes or once the front @@ -390,9 +385,14 @@ class Reader implements ResumeSource { this.sync(); } - /** Follow the route: subscribe to a new copy and mark the ones it replaced. */ + /** + * Follow the route: apply the reader's preferences and cursor to its copies, subscribe to a + * new copy, and mark the ones it replaced. + */ sync(): void { - if (this.#closed || this.#ended) return; + if (this.#closed) return; + this.#follow(); + if (this.#ended) return; const route = this.route; if (this.#generation === route.generation) return; this.#generation = route.generation; @@ -497,6 +497,27 @@ class Reader implements ResumeSource { if (copy.sub.closed.peek() === undefined) copy.sub.update(this.#wire(copy)); } + /** + * Apply the reader's preferences and cursor to every copy once they changed. Their signals + * notify a microtask after a change, so every read applies them first too: a copy then picks + * and judges its groups by what the reader holds now, such as a just-lowered `delay.max` or + * replaced ranges, not its last ones. Mirrors the Rust `Reader::sync`. + */ + #follow(): void { + const subscription = this.#shell.subscription.peek(); + if (subscription !== this.#mirrored) { + this.#mirrored = subscription; + for (const copy of this.#copies) this.#update(copy); + } + const cursor = this.#shell.cursor.peek(); + if (cursor === this.#bounded) return; + const passed = this.#bounded.start; + this.#bounded = cursor; + for (const copy of this.#copies) this.#bound(copy); + if (cursor.start < passed) this.#backfill(cursor.start, passed); + if (this.#ended) this.#letGo(this.#delivered); + } + /** * Apply the reader's group cursor to `copy`, never below the copy's own resume point: groups * under it were handed out by an earlier route, or never owed. diff --git a/quest/m1/README.md b/quest/m1/README.md index d19dae6e0dd..033852b6604 100644 --- a/quest/m1/README.md +++ b/quest/m1/README.md @@ -179,7 +179,6 @@ their end report, so an embedder's drain alert pages on real cuts. - [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 - [The relay reports native sessions it force-closes at the drain deadline](/quest/m1/relay-drain-cuts.md) - the drain's public outcome and live tally separate sessions cut while open from sessions only finishing their end report, so an embedder's drain alert pages on real cuts - [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 -- [The JS resume model passes seed 12345](/quest/m1/js-resume-model-12345.md) - a reader updated to no ranges keeps reading instead of ending cleanly - [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 diff --git a/quest/m1/js-resume-model-12345.md b/quest/m1/js-resume-model-12345.md deleted file mode 100644 index 9a2d3a94a16..00000000000 --- a/quest/m1/js-resume-model-12345.md +++ /dev/null @@ -1,30 +0,0 @@ -# [S] The JS resume model passes seed 12345 - -## Goal - -`@moq/net`'s resume model passes -`MOQ_RESUME_SEED=12345 MOQ_RESUME_CASES=400 bun test src/resume.model.test.ts` -(in `js/net`), fixed at the cause: a reader whose range was fully read and -then updated to no ranges keeps reading instead of reporting the track ended -cleanly. The minimal case is a fixed regression test. - -## Plan - -Decided 2026-11-03 (maintainer, follow-up planning after the 2026-11-03 /quest-afk and /quest-complete runs), milestone: - -- m0 -- ✅ m1 -- m2 - -Found by [moq-dev/moq#7681](https://github.com/moq-dev/moq/pull/7681), which -reproduced it at its merge base `8121cf68`: "the track ended cleanly though no -route declared an end". A reader whose `[0,1)` range was read, then updated -to `ranges: undefined`, reports done. - -- An update to no ranges means "follow live" again, not "every range is - covered"; find where the reader's completion check reads the emptied range - list as exhausted. -- Sibling of [moq-dev/moq#7705](https://github.com/moq-dev/moq/pull/7705) on - the Rust side; compare the two fixes so the languages agree. - -Public API: none. Wire: none.