From d166269e76517e1260be09cf2ac35a6935315d08 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 4 Nov 2026 06:26:26 -0800 Subject: [PATCH 1/3] chore(quest): claim quest/m1/js-resume-model-12345.md Quest-Claim: f0ce184c9c9e3476 From db46253ed6af799f2b8aba9b8ea7b1cff9c9b22f Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 4 Nov 2026 06:34:20 -0800 Subject: [PATCH 2/3] fix(net): apply a resumed reader's ranges and cursor before each read A resumed reader's preferences and group cursor reached its route copies only when their signals notified, a microtask after the change. A read in between judged the copies by the old ones: a fully read range replaced by none read as exhausted and ended the track cleanly, and a narrowed range still handed out a buffered group it left out. Every read now applies both first, as the Rust Reader::sync does. Co-Authored-By: Claude Opus 5.5 --- js/net/src/resume.model.test.ts | 33 +++++++++++++++++++++ js/net/src/resume.ts | 51 +++++++++++++++++++++++---------- 2 files changed, 69 insertions(+), 15 deletions(-) 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. From c3921614d2ced8a47e6aff75b5da6e62e4dbcb39 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 4 Nov 2026 06:37:50 -0800 Subject: [PATCH 3/3] chore(quest): finish quest/m1/js-resume-model-12345.md Co-Authored-By: Claude Opus 5.5 --- quest/m1/README.md | 1 - quest/m1/js-resume-model-12345.md | 30 ------------------------------ 2 files changed, 31 deletions(-) delete mode 100644 quest/m1/js-resume-model-12345.md diff --git a/quest/m1/README.md b/quest/m1/README.md index 9136e7589c9..611f0fa97ab 100644 --- a/quest/m1/README.md +++ b/quest/m1/README.md @@ -180,7 +180,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 - [Prototype-safe rendition names in JS](/quest/m1/proto-safe-names.md) - `js/msf`'s `ext` and `js/publish`'s rendition maps keep `__proto__` and `constructor` names, like Rust - [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 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.