Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions js/net/src/resume.model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
51 changes: 36 additions & 15 deletions js/net/src/resume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
/**
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion quest/m1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 0 additions & 30 deletions quest/m1/js-resume-model-12345.md

This file was deleted.

Loading