From 215a088682d364dea7af049f5aebcb663f6d819f Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 18 Nov 2026 14:04:04 -0800 Subject: [PATCH 1/3] chore(quest): claim quest/m1/precut-fixes/window-finished-abort.md Quest-Claim: 4279edac52714dca From 23af8a4bc5470ec1861a26fcb1337c0307009310 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 18 Nov 2026 14:13:45 -0800 Subject: [PATCH 2/3] docs: a finished track's abort leaves draining readers a clean end The Finished::abort docs in moq-json, moq-mux, moq-audio, moq-video, and their JS counterparts said readers that have not drained the track get the error. Both moq-net implementations deliberately end those readers cleanly once every group below the declared end finished, which finish guarantees. The docs now say so, and a window test in each language pins the behavior. Co-Authored-By: Claude Opus 5.5 --- js/hang/src/container/legacy.ts | 10 ++++++++-- js/json/src/window/producer.ts | 10 ++++++++-- js/json/src/window/window.test.ts | 15 ++++++++++++++ .../m1/precut-fixes/window-finished-abort.md | 9 --------- rs/moq-audio/src/encode/producer.rs | 4 ++-- rs/moq-json/src/snapshot/producer.rs | 3 ++- rs/moq-json/src/stream/producer.rs | 3 ++- rs/moq-json/src/window/mod.rs | 20 +++++++++++++++++++ rs/moq-json/src/window/producer.rs | 3 ++- rs/moq-mux/src/container/flv/import.rs | 4 ++-- rs/moq-mux/src/container/fmp4/import.rs | 4 ++-- rs/moq-mux/src/container/mkv/import.rs | 4 ++-- rs/moq-mux/src/container/producer.rs | 4 ++-- rs/moq-mux/src/container/ts/import.rs | 4 ++-- rs/moq-mux/src/container/ts/passthrough.rs | 4 ++-- rs/moq-mux/src/container/ts/republish.rs | 3 ++- rs/moq-mux/src/import/container.rs | 3 ++- rs/moq-mux/src/import/track.rs | 4 ++-- rs/moq-video/src/encode/publisher.rs | 3 ++- 19 files changed, 79 insertions(+), 35 deletions(-) delete mode 100644 quest/m1/precut-fixes/window-finished-abort.md diff --git a/js/hang/src/container/legacy.ts b/js/hang/src/container/legacy.ts index c4aea1ce7d8..638a828c6f0 100644 --- a/js/hang/src/container/legacy.ts +++ b/js/hang/src/container/legacy.ts @@ -120,7 +120,10 @@ function micros(timestamp: Duration): number { * still refuses a frame after the finish. */ export interface Finished { - /** Abort the track with an error; see {@link Producer.abort}. */ + /** + * Mirrors the Rust `container::Finished::abort`, and like it changes nothing a reader sees: every + * group finished, so readers still draining get the rest of the track and its clean end, not `err`. + */ abort(err: Error): void; } @@ -282,7 +285,10 @@ export class Producer { return this; } - /** Abort the current group and the track with `err`, which readers see in place of a clean end. */ + /** + * Abort the current group and the track with `err`, which readers see in place of a clean end. A + * no-op after {@link finish}: the track is already complete. + */ abort(err: Error) { this.#group?.abort(err); this.#group = undefined; diff --git a/js/json/src/window/producer.ts b/js/json/src/window/producer.ts index 4d9a25e04b8..b2beb2e4da1 100644 --- a/js/json/src/window/producer.ts +++ b/js/json/src/window/producer.ts @@ -16,7 +16,10 @@ export interface Finished { readonly window: T[]; /** Absolute index of the oldest retained record; see {@link Producer.offset}. */ readonly offset: number; - /** Abort the track with an error; see {@link Producer.abort}. */ + /** + * Mirrors the Rust `window::Finished::abort`, and like it changes nothing a reader sees: every group + * finished, so readers still draining get the rest of the window and its clean end, not `err`. + */ abort(err: Error): void; } @@ -192,7 +195,10 @@ export class Producer { return this; } - /** Abort the track with `err`, so readers see the cause rather than a complete window. Idempotent. */ + /** + * Abort the track with `err`, so readers see the cause rather than a complete window. Idempotent, + * and a no-op after {@link finish}: the window is already complete. + */ abort(err: Error): void { this.#close(err); } diff --git a/js/json/src/window/window.test.ts b/js/json/src/window/window.test.ts index b6a594bc1d4..7c428fe4f75 100644 --- a/js/json/src/window/window.test.ts +++ b/js/json/src/window/window.test.ts @@ -644,3 +644,18 @@ test("finishing returns a window that reads but takes no edit", () => { // @ts-expect-error a finished window takes no record expect(() => finished.push({ n: 2 }, key())).toThrow("track is closed"); }); + +// Mirrors the Rust `aborting_a_finished_window_still_drains`: an abort after finish changes nothing a +// reader sees, since every group finished, so one still draining gets the rest and the clean end. +test("aborting a finished window still drains", async () => { + const track = new Track.Producer("test"); + const consumer = new Consumer({ track: track.subscribe() }); + const producer = new Producer({ track }); + producer.push({ n: 0 }, key()); + producer.push({ n: 1 }, key()); + expect((await consumer.next())?.value).toEqual({ push: { index: 0, value: { n: 0 } } }); + + producer.finish().abort(new NetError.Stream(StreamCode.Cancel)); + expect((await consumer.next())?.value).toEqual({ push: { index: 1, value: { n: 1 } } }); + expect(await consumer.next()).toBeUndefined(); +}); diff --git a/quest/m1/precut-fixes/window-finished-abort.md b/quest/m1/precut-fixes/window-finished-abort.md deleted file mode 100644 index 7864e2f5f30..00000000000 --- a/quest/m1/precut-fixes/window-finished-abort.md +++ /dev/null @@ -1,9 +0,0 @@ -# [S] An abort on a finished JS window reaches undrained readers - -## Goal - -Window.Finished.abort(error) releases the finished window and reports the error to readers still draining it, matching Rust. - -## Plan - -The handle from [moq-dev/moq#8395](https://github.com/moq-dev/moq/pull/8395) returns its producer after finish sets the terminal guard. Publishing two records, consuming one, then calling finish().abort(error) delivered the second and clean EOF. Exercise an undrained reader and normal finish through the public API. diff --git a/rs/moq-audio/src/encode/producer.rs b/rs/moq-audio/src/encode/producer.rs index 3aaa7274253..476ec5d5749 100644 --- a/rs/moq-audio/src/encode/producer.rs +++ b/rs/moq-audio/src/encode/producer.rs @@ -944,8 +944,8 @@ impl Finished { self.track.demand() } - /// Abort the track with `err`, so subscribers that have not drained it see the real cause; see - /// [`Producer::abort`]. + /// Abort the track with `err`; see [`Producer::abort`]. Readers still draining get the clean end + /// instead once every group below the end finished. pub fn abort(self, err: moq_net::Error) { self.track.abort(err); } diff --git a/rs/moq-json/src/snapshot/producer.rs b/rs/moq-json/src/snapshot/producer.rs index 58a3b9e5bd0..4709ad5f1ce 100644 --- a/rs/moq-json/src/snapshot/producer.rs +++ b/rs/moq-json/src/snapshot/producer.rs @@ -266,7 +266,8 @@ impl Finished { take(&self.inner).track.inner.demand() } - /// Release the track's cache, reporting `err` to readers that have not drained it. + /// Abort the track with `err`; see [`moq_net::track::Finished::abort`]. Readers still draining + /// get the clean end instead once every group below the end finished. pub fn abort(self, err: moq_net::Error) -> Result<()> { take(&self.inner).abort(err.into()); Ok(()) diff --git a/rs/moq-json/src/stream/producer.rs b/rs/moq-json/src/stream/producer.rs index 21cd84b7116..ae972fff556 100644 --- a/rs/moq-json/src/stream/producer.rs +++ b/rs/moq-json/src/stream/producer.rs @@ -149,7 +149,8 @@ impl Finished { self.inner.lock().unwrap().track.inner.demand() } - /// Release the track's cache, reporting `err` to readers that have not drained it. + /// Abort the track with `err`; see [`moq_net::track::Finished::abort`]. Readers still draining + /// get the clean end instead once every group below the end finished. pub fn abort(self, err: moq_net::Error) -> Result<()> { self.inner.lock().unwrap().track.abort(err); Ok(()) diff --git a/rs/moq-json/src/window/mod.rs b/rs/moq-json/src/window/mod.rs index 0360e0fc205..b601fa715d3 100644 --- a/rs/moq-json/src/window/mod.rs +++ b/rs/moq-json/src/window/mod.rs @@ -285,6 +285,26 @@ mod test { let _ = Encoder::::new(config); } + /// An abort after finish changes nothing a reader sees: every group finished, so one still + /// draining gets the rest of the window and the clean end, not the error. + #[test] + fn aborting_a_finished_window_still_drains() { + let (mut producer, track) = producer(Config::default()); + let mut consumer = consumer(track); + producer.push(&rec(0), key()).unwrap(); + producer.push(&rec(1), key()).unwrap(); + let waiter = kio::Waiter::noop(); + let mut next = || match consumer.poll_next(&waiter) { + Poll::Ready(next) => next.unwrap().map(|event| event.value), + Poll::Pending => panic!("expected a window event or its end"), + }; + assert!(matches!(next(), Some(Event::Push { index: 0, .. }))); + + producer.finish().unwrap().abort(moq_net::Error::Cancel).unwrap(); + assert!(matches!(next(), Some(Event::Push { index: 1, .. }))); + assert!(next().is_none()); + } + fn consumer(track: moq_net::track::Subscriber) -> Consumer { Consumer::new(track, consumer::Config::default()) } diff --git a/rs/moq-json/src/window/producer.rs b/rs/moq-json/src/window/producer.rs index 2bd3dcbfb97..29e0e03ee4a 100644 --- a/rs/moq-json/src/window/producer.rs +++ b/rs/moq-json/src/window/producer.rs @@ -191,7 +191,8 @@ impl Finished { self.inner.lock().unwrap().encoder.range() } - /// Release the track's cache, reporting `err` to readers that have not drained it. + /// Abort the track with `err`; see [`moq_net::track::Finished::abort`]. Readers still draining + /// get the clean end instead once every group below the end finished. pub fn abort(self, err: moq_net::Error) -> Result<()> { self.inner.lock().unwrap().abort(err.into()); Ok(()) diff --git a/rs/moq-mux/src/container/flv/import.rs b/rs/moq-mux/src/container/flv/import.rs index 99f9fa8049d..cbf923e9ca4 100644 --- a/rs/moq-mux/src/container/flv/import.rs +++ b/rs/moq-mux/src/container/flv/import.rs @@ -833,8 +833,8 @@ pub struct Finished { } impl Finished { - /// Release every track's cache, reporting `err` to readers that have not drained it; see - /// [`Import::abort`]. + /// Abort every track with `err`; see [`Import::abort`]. Readers still draining a track get its + /// clean end instead once every group below its end finished. pub fn abort(self, err: moq_net::Error) { self.import.abort(err); } diff --git a/rs/moq-mux/src/container/fmp4/import.rs b/rs/moq-mux/src/container/fmp4/import.rs index 33a9070163d..adee5f6f85b 100644 --- a/rs/moq-mux/src/container/fmp4/import.rs +++ b/rs/moq-mux/src/container/fmp4/import.rs @@ -1921,8 +1921,8 @@ pub struct Finished { } impl Finished { - /// Release every track's cache, reporting `err` to readers that have not drained it; see - /// [`Import::abort`]. + /// Abort every track with `err`; see [`Import::abort`]. Readers still draining a track get its + /// clean end instead once every group below its end finished. pub fn abort(self, err: moq_net::Error) { self.import.abort(err); } diff --git a/rs/moq-mux/src/container/mkv/import.rs b/rs/moq-mux/src/container/mkv/import.rs index ee3431f58a8..ed5052ff84c 100644 --- a/rs/moq-mux/src/container/mkv/import.rs +++ b/rs/moq-mux/src/container/mkv/import.rs @@ -1033,8 +1033,8 @@ pub struct Finished { } impl Finished { - /// Release every track's cache, reporting `err` to readers that have not drained it; see - /// [`Import::abort`]. + /// Abort every track with `err`; see [`Import::abort`]. Readers still draining a track get its + /// clean end instead once every group below its end finished. pub fn abort(self, err: moq_net::Error) { self.import.abort(err); } diff --git a/rs/moq-mux/src/container/producer.rs b/rs/moq-mux/src/container/producer.rs index ea869644cfb..4c4165e4d88 100644 --- a/rs/moq-mux/src/container/producer.rs +++ b/rs/moq-mux/src/container/producer.rs @@ -1179,8 +1179,8 @@ where self.producer.estimate() } - /// Release the track's cache, reporting `err` to readers that have not drained it; see - /// [`moq_net::track::Finished::abort`]. + /// Abort the track with `err`; see [`moq_net::track::Finished::abort`]. Readers still draining get the clean end + /// instead once every group below the end finished. pub fn abort(self, err: moq_net::Error) { self.producer.abort(err); } diff --git a/rs/moq-mux/src/container/ts/import.rs b/rs/moq-mux/src/container/ts/import.rs index 9b449237324..3cd3040fb46 100644 --- a/rs/moq-mux/src/container/ts/import.rs +++ b/rs/moq-mux/src/container/ts/import.rs @@ -2056,8 +2056,8 @@ impl Finished { self.import.stats() } - /// Release every track's cache, reporting `err` to readers that have not drained it; see - /// [`Import::abort`]. + /// Abort every track with `err`; see [`Import::abort`]. Readers still draining a track get its + /// clean end instead once every group below its end finished. pub fn abort(self, err: moq_net::Error) { self.import.abort(err); } diff --git a/rs/moq-mux/src/container/ts/passthrough.rs b/rs/moq-mux/src/container/ts/passthrough.rs index 04a03d37898..43f00a7f369 100644 --- a/rs/moq-mux/src/container/ts/passthrough.rs +++ b/rs/moq-mux/src/container/ts/passthrough.rs @@ -197,8 +197,8 @@ impl Finished { self.passthrough.track() } - /// Release the track's cache, reporting `err` to readers that have not drained it; see - /// [`Passthrough::abort`]. + /// Abort the track with `err`; see [`Passthrough::abort`]. Readers still draining get the clean end + /// instead once every group below the end finished. pub fn abort(self, err: moq_net::Error) { self.passthrough.abort(err); } diff --git a/rs/moq-mux/src/container/ts/republish.rs b/rs/moq-mux/src/container/ts/republish.rs index bbcaa29f9d3..52b1592f1e4 100644 --- a/rs/moq-mux/src/container/ts/republish.rs +++ b/rs/moq-mux/src/container/ts/republish.rs @@ -306,7 +306,8 @@ impl Finished { self.import.stats() } - /// Release every track's cache, reporting `err` to readers that have not drained it. + /// Abort every track with `err`. Readers still draining a track get its clean end instead once + /// every group below its end finished. pub fn abort(self, err: moq_net::Error) { self.import.abort(err); } diff --git a/rs/moq-mux/src/import/container.rs b/rs/moq-mux/src/import/container.rs index 3bcc382c9dd..8dd6d7f092d 100644 --- a/rs/moq-mux/src/import/container.rs +++ b/rs/moq-mux/src/import/container.rs @@ -175,7 +175,8 @@ pub struct Finished { } impl Finished { - /// Release every track's cache, reporting `err` to readers that have not drained it. + /// Abort every track with `err`. Readers still draining a track get its clean end instead once + /// every group below its end finished. pub fn abort(self, err: moq_net::Error) { match self.inner { FinishedImpl::Fmp4(finished) => finished.abort(err), diff --git a/rs/moq-mux/src/import/track.rs b/rs/moq-mux/src/import/track.rs index f1c87b14f5d..3b5650ae7ac 100644 --- a/rs/moq-mux/src/import/track.rs +++ b/rs/moq-mux/src/import/track.rs @@ -933,8 +933,8 @@ impl Finished { } } - /// Release the track's cache, reporting `err` to readers that have not drained it; see - /// [`moq_net::track::Finished::abort`]. + /// Abort the track with `err`; see [`moq_net::track::Finished::abort`]. Readers still draining get the clean end + /// instead once every group below the end finished. pub fn abort(self, err: moq_net::Error) { match self.inner { FinishedKind::Video(track) => track.abort(err), diff --git a/rs/moq-video/src/encode/publisher.rs b/rs/moq-video/src/encode/publisher.rs index de1c3139fa9..985c39e22fa 100644 --- a/rs/moq-video/src/encode/publisher.rs +++ b/rs/moq-video/src/encode/publisher.rs @@ -254,7 +254,8 @@ impl Finished { self.track.demand() } - /// Abort the track with `err`, so subscribers that have not drained it see the real cause. + /// Abort the track with `err`; see [`moq_net::track::Finished::abort`]. Readers still draining + /// get the clean end instead once every group below the end finished. pub fn abort(self, err: moq_net::Error) { self.track.abort(err); } From 29142a836525c48e9885318cde9da7e9e4e47141 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 18 Nov 2026 14:35:42 -0800 Subject: [PATCH 3/3] docs: a failed track's abort leaves draining readers its error Finished::abort after fail keeps the fail error for readers still draining, not a clean end. Say so on moq-net's, moq-mux container's, and moq-audio's Finished::abort, the three that a fail can produce. Co-Authored-By: Claude Opus 5.5 --- rs/moq-audio/src/encode/producer.rs | 5 +++-- rs/moq-mux/src/container/producer.rs | 5 +++-- rs/moq-net/src/model/track.rs | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/rs/moq-audio/src/encode/producer.rs b/rs/moq-audio/src/encode/producer.rs index 476ec5d5749..a1913f851ed 100644 --- a/rs/moq-audio/src/encode/producer.rs +++ b/rs/moq-audio/src/encode/producer.rs @@ -944,8 +944,9 @@ impl Finished { self.track.demand() } - /// Abort the track with `err`; see [`Producer::abort`]. Readers still draining get the clean end - /// instead once every group below the end finished. + /// Abort the track with `err`; see [`Producer::abort`]. Readers still draining get the end the + /// track declared instead once every group below it finished: the clean end after + /// [`Producer::finish`], or the capture's error when the source failed. pub fn abort(self, err: moq_net::Error) { self.track.abort(err); } diff --git a/rs/moq-mux/src/container/producer.rs b/rs/moq-mux/src/container/producer.rs index 4c4165e4d88..dd077aeee83 100644 --- a/rs/moq-mux/src/container/producer.rs +++ b/rs/moq-mux/src/container/producer.rs @@ -1179,8 +1179,9 @@ where self.producer.estimate() } - /// Abort the track with `err`; see [`moq_net::track::Finished::abort`]. Readers still draining get the clean end - /// instead once every group below the end finished. + /// Abort the track with `err`; see [`moq_net::track::Finished::abort`]. Readers still draining get the end + /// the track declared instead once every group below it finished: the clean end after [`Producer::finish`], + /// or the error [`Producer::fail`] gave. pub fn abort(self, err: moq_net::Error) { self.producer.abort(err); } diff --git a/rs/moq-net/src/model/track.rs b/rs/moq-net/src/model/track.rs index 01b416416d9..d30b32c485c 100644 --- a/rs/moq-net/src/model/track.rs +++ b/rs/moq-net/src/model/track.rs @@ -5460,7 +5460,8 @@ impl Finished { /// Abort the track with the given error; see [`Producer::abort`]. /// - /// Once every group below the end finished, readers still get the clean end. + /// Once every group below the end finished, readers still get the end the track declared: the + /// clean end after [`Producer::finish`], or the error [`Producer::fail`] gave. pub fn abort(self, err: Error) -> Result<()> { self.producer.abort(err) }