diff --git a/js/net/src/fill.test.ts b/js/net/src/fill.test.ts index dce591424e1..bde1ffc93a3 100644 --- a/js/net/src/fill.test.ts +++ b/js/net/src/fill.test.ts @@ -283,6 +283,35 @@ async function failedAnswerHoldsTheEnd(error: Error) { broadcast.close(); } +// A reader whose range lowers the copy's floor asks the live feed for those groups, as the update +// it sends does, so none is asked of a fill too, even before the session declares the new floor: +// the START answered the old floor, so it no longer bounds what the feed owes. +test("fill: a group a lowered floor asks the feed for is not asked of a fill", async () => { + const broadcast = new BroadcastProducer(); + const track = broadcast.createTrack("video", { maxAge: null }); + hooks.receiveTrack(track); + const live = track.subscribe({ ranges: [{ start: { relative: 0n } }], delay: { max: null } }); + hooks.startTrack(track, { start: 1n }); + hooks.receiveGroup(track, { sequence: 1n, start: 0 }).finish(); + expect((await live.recvGroup())?.sequence).toBe(1n); + const requests = track.requests(); + const asked = requests.requestedFill(); + + const history = track.subscribe({ + ranges: [{ start: { absolute: 0n }, end: { absolute: 1n } }], + delay: { max: null }, + }); + const next = history.recvGroup(); + expect(await Promise.race([asked.then(() => "asked"), yieldNow().then(() => "waiting")])).toBe("waiting"); + hooks.receiveGroup(track, { sequence: 0n, start: 0 }).finish(); + expect((await next)?.sequence).toBe(0n); + + live.close(); + history.close(); + requests.close(); + broadcast.close(); +}); + // Withheld as it fails, so a read in the same turn cannot take it either. test("fill: a failed answer is withheld from a subscribed reader that reads at once", async () => { for (const dispositions of [false, true]) { diff --git a/js/net/src/lite/copy_fill.test.ts b/js/net/src/lite/copy_fill.test.ts index 556534937d3..65961b64c6b 100644 --- a/js/net/src/lite/copy_fill.test.ts +++ b/js/net/src/lite/copy_fill.test.ts @@ -397,7 +397,11 @@ test("copy fill: a yielded group the fill's drop names ends", async () => { const remote = wireOf(client).consume(Path.from("room")); try { const reader = remote.track("video").subscribe({ ranges: [{ start: { relative: 0n } }] }); - expect((await reader.ordered().nextGroup())?.sequence).toBe(1n); + const live = await reader.ordered().nextGroup(); + expect(live?.sequence).toBe(1n); + expect(dec.decode((await live?.readFrame())?.payload)).toBe("live 1"); + expect(await live?.readFrame()).toBeUndefined(); + live?.close(); const history = remote .track("video") .subscribe({ ...WIDE, ranges: [{ start: { absolute: 0n }, end: { absolute: 1n } }] }); diff --git a/js/net/src/track.ts b/js/net/src/track.ts index 66d3341ecfa..bbd8dffec78 100644 --- a/js/net/src/track.ts +++ b/js/net/src/track.ts @@ -1470,7 +1470,10 @@ export class Producer { if (first === undefined) return; start = max(start, first); } - start = max(start, this.#wire?.served?.start ?? 0n); + // A START bounds the feed only while the demand keeps the floor it answered: a lowered floor + // asks the feed for the groups below it, which a fill must not duplicate. + const feed = this.#feedStart(); + if (typeof feed === "bigint") start = max(start, feed); const declared = this.#state.end.peek()?.at; const end = declared === undefined ? land.end : min(land.end, finalSequence(declared)); const at = now();