From 3a865dafc5a0cfca692d1fbd6968c2cb8f931361 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 6 Nov 2026 11:59:06 -0800 Subject: [PATCH 1/4] quest: container export ends cleanly when its broadcast closes Co-Authored-By: Claude Opus 5.5 --- quest/m3/README.md | 1 + quest/m3/export-close.md | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 quest/m3/export-close.md diff --git a/quest/m3/README.md b/quest/m3/README.md index e176efdea7e..29c11527c57 100644 --- a/quest/m3/README.md +++ b/quest/m3/README.md @@ -181,6 +181,7 @@ federation) land. - [Bandwidth reservations ignore in-process readers](/quest/m3/reservation-local-readers.md) - a local recorder no longer counts as uplink demand - [Container export starts apart from its skip budget](/quest/m3/export-live-start.md) - fMP4 and MP4 export start at the live edge and report sample counts - [MP4 export trims exactly at both ends](/quest/m3/mp4-export-window.md) - a presentation window with no lead-in and no presented tail +- [Container export ends cleanly when its broadcast closes](/quest/m3/export-close.md) - fMP4 and MP4 export return `None` when the instance closes, not the dropped track's error - [Audio capture opens a format the mix accepts](/quest/m3/audio-capture-negotiate.md) - multichannel and odd-rate devices capture, with discrete input selection - [A mix-minus removes several sources](/quest/m3/bus-minus-several.md) - a guest's return feed drops every copy of their own sound - [Bus writes land at a bus position](/quest/m3/bus-positioned-write.md) - callers sync audio to video without copying the bus's private latency diff --git a/quest/m3/export-close.md b/quest/m3/export-close.md new file mode 100644 index 00000000000..92f892dcb61 --- /dev/null +++ b/quest/m3/export-close.md @@ -0,0 +1,25 @@ +# [S] Container export ends cleanly when its broadcast closes + +## Goal + +An fMP4 or MP4 export whose broadcast instance closes returns `None` from +`poll_next`, as its docs promise ("`None` once the broadcast ends"), after +the media it already read, instead of failing with the dropped track's error. +A broadcast that fails while it stays live still fails the export. + +## Plan + +Decided 2026-11-06 (maintainer, on moq-dev/studio's /quest-plan): m3, since +the studio is a named consumer that is not urgent. + +`mp4::Export` (`rs/moq-mux/src/container/mp4.rs`) ends when the fMP4 export +under it (`container/fmp4/export.rs`) does, so fix it there, for both. +Tell a closing instance apart from a failure by what the broadcast reports, +not by a timeout or by matching an error string. + +Consumer: the studio's per-guest recorder +([moq-dev/studio#65](https://github.com/moq-dev/studio/pull/65)) treats an +export error as the guest leaving only if the broadcast already reads as +closed (`is_closed` in `rs/moq-studio/src/record.rs`). A departure whose +track error arrives before the close then marks the recording failed. The +studio drops that check when it next bumps `moq`. From cf33eb2d84e5acf2679f797f7e3174d807900853 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 6 Nov 2026 13:42:56 -0800 Subject: [PATCH 2/4] quest: export-close fixes ExportSource for every container, and both orders Pullfrog noted that reading the broadcast's state at error time is the check that misses the error-first order, and that the close decision lives in ExportSource, which every container export shares. Co-Authored-By: Claude Opus 5.5 --- quest/m3/README.md | 2 +- quest/m3/export-close.md | 39 +++++++++++++++++++++++++++------------ 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/quest/m3/README.md b/quest/m3/README.md index 29c11527c57..eaf34e03760 100644 --- a/quest/m3/README.md +++ b/quest/m3/README.md @@ -181,7 +181,7 @@ federation) land. - [Bandwidth reservations ignore in-process readers](/quest/m3/reservation-local-readers.md) - a local recorder no longer counts as uplink demand - [Container export starts apart from its skip budget](/quest/m3/export-live-start.md) - fMP4 and MP4 export start at the live edge and report sample counts - [MP4 export trims exactly at both ends](/quest/m3/mp4-export-window.md) - a presentation window with no lead-in and no presented tail -- [Container export ends cleanly when its broadcast closes](/quest/m3/export-close.md) - fMP4 and MP4 export return `None` when the instance closes, not the dropped track's error +- [Container export ends cleanly when its broadcast closes](/quest/m3/export-close.md) - every container export returns `None` when its instance closes, whichever signal arrives first - [Audio capture opens a format the mix accepts](/quest/m3/audio-capture-negotiate.md) - multichannel and odd-rate devices capture, with discrete input selection - [A mix-minus removes several sources](/quest/m3/bus-minus-several.md) - a guest's return feed drops every copy of their own sound - [Bus writes land at a bus position](/quest/m3/bus-positioned-write.md) - callers sync audio to video without copying the bus's private latency diff --git a/quest/m3/export-close.md b/quest/m3/export-close.md index 92f892dcb61..c3f953ca63b 100644 --- a/quest/m3/export-close.md +++ b/quest/m3/export-close.md @@ -1,25 +1,40 @@ -# [S] Container export ends cleanly when its broadcast closes +# [M] Container export ends cleanly when its broadcast closes ## Goal -An fMP4 or MP4 export whose broadcast instance closes returns `None` from -`poll_next`, as its docs promise ("`None` once the broadcast ends"), after -the media it already read, instead of failing with the dropped track's error. -A broadcast that fails while it stays live still fails the export. +A container export (FLV, MKV, TS, fMP4, or MP4) whose broadcast instance +closes in an orderly way returns `None`, as each one's docs promise ("`None` +when the broadcast ends"), after the media it already read, whichever of the +track's shutdown error and the instance's close arrives first. A failure that +is no orderly shutdown, such as malformed media or a failed transport, still +fails the export. ## Plan Decided 2026-11-06 (maintainer, on moq-dev/studio's /quest-plan): m3, since the studio is a named consumer that is not urgent. -`mp4::Export` (`rs/moq-mux/src/container/mp4.rs`) ends when the fMP4 export -under it (`container/fmp4/export.rs`) does, so fix it there, for both. -Tell a closing instance apart from a failure by what the broadcast reports, -not by a timeout or by matching an error string. +`ExportSource::poll_track` (`rs/moq-mux/src/container/source.rs`), which +every container exporter shares, already ends a track on a shutdown-class +error (`Cancel`, `Closed`, `GoingAway`, a session cancel), but only if +`instance.poll_closed` is ready at that moment. When the error arrives first, +it fails the export. Fix it there, so every exporter gets it; `mp4::Export` +ends when the fMP4 export under it does. + +Open: how the error-first order resolves. Holding a shutdown-class error +until the instance closes cannot be the whole answer: nothing bounds that +wait if the instance stays live, and no timeout may decide it. Prefer fixing +the order at its source, so an instance's end is visible before its tracks +report shutdown, locally and over the wire, if moq-net can promise that; +otherwise find what else tells the two apart. Reproduce both orders first. +A failure that is no orderly shutdown (malformed media, a protocol violation, +producers that went away unfinished) still fails the export even once the +instance has gone, as `a_sibling_failure_outlives_its_instance` pins, and +`a_remote_sibling_ends_with_its_instance` covers the remote case. Consumer: the studio's per-guest recorder ([moq-dev/studio#65](https://github.com/moq-dev/studio/pull/65)) treats an export error as the guest leaving only if the broadcast already reads as -closed (`is_closed` in `rs/moq-studio/src/record.rs`). A departure whose -track error arrives before the close then marks the recording failed. The -studio drops that check when it next bumps `moq`. +closed (`is_closed` in `rs/moq-studio/src/record.rs`), so a departure whose +track error arrives first marks the recording failed. The studio drops that +check when it next bumps `moq`. From b829b7cb1acf8a0261fffb476ed602dc14830b50 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 6 Nov 2026 15:41:39 -0800 Subject: [PATCH 3/4] quest: export-close covers the source's own broadcast and the catalog track The OpenAI review and Pullfrog noted that ExportSource consults the instance only for sibling renditions, so the studio's own-broadcast case never reaches that check, and that every exporter polls the catalog track first, which fails the export on its own shutdown error. Co-Authored-By: Claude Opus 5.5 --- quest/m3/export-close.md | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/quest/m3/export-close.md b/quest/m3/export-close.md index c3f953ca63b..22081a32457 100644 --- a/quest/m3/export-close.md +++ b/quest/m3/export-close.md @@ -14,19 +14,37 @@ fails the export. Decided 2026-11-06 (maintainer, on moq-dev/studio's /quest-plan): m3, since the studio is a named consumer that is not urgent. -`ExportSource::poll_track` (`rs/moq-mux/src/container/source.rs`), which -every container exporter shares, already ends a track on a shutdown-class -error (`Cancel`, `Closed`, `GoingAway`, a session cancel), but only if -`instance.poll_closed` is ready at that moment. When the error arrives first, -it fails the export. Fix it there, so every exporter gets it; `mp4::Export` -ends when the fMP4 export under it does. +A broadcast's orderly end reaches an export by three paths, and each must +end it cleanly whichever signal comes first: + +- **Renditions on the source's own broadcast**, the studio's case. + `ExportSource::poll_track` (`rs/moq-mux/src/container/source.rs`) sets + `instance` only for a sibling (`sibling: *path != self.path` in + `rs/moq-mux/src/source.rs`), so these never consult `poll_closed` and any + shutdown-class error fails the export. +- **Sibling renditions.** `poll_track` ends one on a shutdown-class error + (`Cancel`, `Closed`, `GoingAway`, a session cancel) only if + `instance.poll_closed` is already ready. +- **The catalog track**, which every exporter polls before its media (for + fMP4, `catalog.poll_next(waiter)?` in `container/fmp4/export.rs`). The + catalog consumer returns `Cancel` when its track is lost + (`a_lost_track_is_a_transport_error` in `catalog/hang/consumer.rs`), so an + orderly leave can fail the export there before any media is read. + +Fix them in the shared source and the catalog consumer, so every exporter +gets it; `mp4::Export` ends when the fMP4 export under it does. Buffered +media still drains before `None`. Prove it through whole exports, where the +catalog's and the media's shutdown arrive in both orders against the +instance's close. Open: how the error-first order resolves. Holding a shutdown-class error until the instance closes cannot be the whole answer: nothing bounds that wait if the instance stays live, and no timeout may decide it. Prefer fixing the order at its source, so an instance's end is visible before its tracks -report shutdown, locally and over the wire, if moq-net can promise that; -otherwise find what else tells the two apart. Reproduce both orders first. +(catalog included) report shutdown, locally and over the wire, if moq-net can +promise that; otherwise find what else tells the two apart. Reproduce both +orders first. + A failure that is no orderly shutdown (malformed media, a protocol violation, producers that went away unfinished) still fails the export even once the instance has gone, as `a_sibling_failure_outlives_its_instance` pins, and From 88769608f599ecc02b01dc864467abfc9f79a944 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 6 Nov 2026 16:01:19 -0800 Subject: [PATCH 4/4] quest: export-close ends at the catalog broadcast's end, and covers pending siblings From CodeRabbit on b829b7c. Co-Authored-By: Claude Opus 5.5 --- quest/m3/export-close.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/quest/m3/export-close.md b/quest/m3/export-close.md index 22081a32457..7d169c6c404 100644 --- a/quest/m3/export-close.md +++ b/quest/m3/export-close.md @@ -32,8 +32,10 @@ end it cleanly whichever signal comes first: orderly leave can fail the export there before any media is read. Fix them in the shared source and the catalog consumer, so every exporter -gets it; `mp4::Export` ends when the fMP4 export under it does. Buffered -media still drains before `None`. Prove it through whole exports, where the +gets it; `mp4::Export` ends when the fMP4 export under it does. The +catalog-owning broadcast's end is the export's end: a sibling still +publishing stops being read then, rather than keeping the export open. +Buffered media still drains before `None`. Prove it through whole exports, where the catalog's and the media's shutdown arrive in both orders against the instance's close. @@ -47,8 +49,10 @@ orders first. A failure that is no orderly shutdown (malformed media, a protocol violation, producers that went away unfinished) still fails the export even once the -instance has gone, as `a_sibling_failure_outlives_its_instance` pins, and -`a_remote_sibling_ends_with_its_instance` covers the remote case. +instance has gone, whether the sibling's subscription had resolved +(`a_sibling_failure_outlives_its_instance` pins this) or was still pending, +which no test covers yet. `a_remote_sibling_ends_with_its_instance` covers +the remote case. Consumer: the studio's per-guest recorder ([moq-dev/studio#65](https://github.com/moq-dev/studio/pull/65)) treats an