Repository navigation
fix(spf): end published tracks with PUBLISH_DONE track ended - #62
Conversation
moq-relay 0.17.0 reports a bare FIN on an upstream subscription as PUBLISH_DONE "internal error" to every viewer, so an intentional unpublish looked like a failed track. Send PUBLISH_DONE (TRACK_ENDED) with the exact Stream Count before the FIN, as §10.12 and MSF §11.3 intend; the relay then forwards "track ended". Track publishers count the data streams each subscription received at the subgroup-header commit, and the session adds its fill streams. A track without a counter reports the 2^64-1 unknown sentinel. A superseded subscription still ends with a bare FIN, since it is not a track end. Older moq-relay builds abort a track on any byte after SUBSCRIBE_OK and are no longer supported.
📦 Bundle Size Report🎨 @videojs/html — 2 small size changes
Presets (7)
Media (20)
Players (6)
Skins (32)
UI Components (73)
⚛️ @videojs/react — 1 small size change
Presets (7)
Media (23)
Extensions (2)
Players (5)
Skins (20)
UI Components (50)
🧩 @videojs/core — no changesEntries (77)
🏷️ @videojs/element — no changesEntries (2)
📦 @videojs/store — no changesEntries (3)
🔧 @videojs/utils — no changesEntries (13)
📦 @videojs/cdn — no changes📦 @videojs/cloudflare-video — no changes📦 @videojs/dash-video — no changes📦 @videojs/google-cast — no changes📦 @videojs/hlsjs-video — no changes📦 @videojs/media — no changesEntries (3)
📦 @videojs/mux — no changes📦 @videojs/mux-audio — no changesEntries (2)
📦 @videojs/mux-data — no changes📦 @videojs/mux-video — no changesEntries (2)
📦 @videojs/native-hls-video — no changes📦 @videojs/shaka-video — no changes📦 @videojs/spf — 3 small size changes
Entries (10)
📦 @videojs/spotify-audio — no changes📦 @videojs/tiktok-video — no changes📦 @videojs/twitch-video — no changes📦 @videojs/other — 1 small size change
Entries (3)
📦 @videojs/vimeo-video — no changes📦 @videojs/wistia-video — no changesEntries (2)
📦 @videojs/youtube-video — no changesℹ️ How to interpretEach entry is independently bundled, minified, and brotli-compressed. Initial size includes its static import graph; lazy dynamic chunks are reported separately. Entries are not additive because their dependency graphs overlap. Preset rows represent realistic combined bundles. Changes of 300 B or less across initial, lazy, and total size are collapsed, not discarded. Run |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1e1c860b01
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
All reported issues were addressed across 15 files
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
Draft-20 §10.12: a sender MUST NOT send PUBLISH_DONE until it has closed every stream for the subscription. Media teardown wrote PUBLISH_DONE while the open group's FIN was still queued, and the catalog path raced destroy() against it on a flush timeout. Every track now ends the same way: end, a bounded flush (half the close drain, so PUBLISH_DONE still fits), destroy() to FIN or reset what is left, then PUBLISH_DONE and FIN. Also prune superseded aliases from the per-subscription stream counts on each new bind, keeping the current alias across a Forward State toggle.
The loopback relay reduced the publisher's PUBLISH_DONE to a FIN toward its players, which the SPF subscriber ignores, so a viewer only noticed the track end through its stall watchdog. Forward the upstream status with a per-subscription Stream Count, like moq-relay 0.17.0, and end viewers with INTERNAL_ERROR when the upstream subscription stream carries anything else, including a malformed frame.
There was a problem hiding this comment.
1 issue found across 6 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/sandbox/templates/moq-publisher/loopback-relay.ts">
<violation number="1" location="apps/sandbox/templates/moq-publisher/loopback-relay.ts:801">
P2: A malformed PUBLISH_DONE body can leave every attached player waiting indefinitely: an empty body makes `Reader.varint()` throw, and the outer catch cleans up the upstream without ending subscribers. Validate the complete body here and end subscribers with INTERNAL_ERROR when it is malformed.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
| return; | ||
| } | ||
|
|
||
| publishDoneStatus = new Reader(message.body).varint(); |
There was a problem hiding this comment.
P2: A malformed PUBLISH_DONE body can leave every attached player waiting indefinitely: an empty body makes Reader.varint() throw, and the outer catch cleans up the upstream without ending subscribers. Validate the complete body here and end subscribers with INTERNAL_ERROR when it is malformed.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At apps/sandbox/templates/moq-publisher/loopback-relay.ts, line 801:
<comment>A malformed PUBLISH_DONE body can leave every attached player waiting indefinitely: an empty body makes `Reader.varint()` throw, and the outer catch cleans up the upstream without ending subscribers. Validate the complete body here and end subscribers with INTERNAL_ERROR when it is malformed.</comment>
<file context>
@@ -771,29 +780,32 @@ export function createPublisherLoopbackRelay({ onLog }: PublisherLoopbackRelayOp
return;
}
+
+ publishDoneStatus = new Reader(message.body).varint();
}
</file context>
| publishDoneStatus = new Reader(message.body).varint(); | |
| try { | |
| const fields = new Reader(message.body); | |
| publishDoneStatus = fields.varint(); | |
| fields.varint(); // stream count | |
| const reasonLength = fields.varint(); | |
| if (fields.offset + reasonLength !== message.body.length) throw new Error('malformed PUBLISH_DONE body'); | |
| fields.slice(reasonLength); | |
| } catch { | |
| log(`upstream ${track.name}: malformed PUBLISH_DONE after SUBSCRIBE_OK — aborting the track`); | |
| for (const subscriber of [...track.subscribers]) subscriber.end(PUBLISH_DONE_INTERNAL_ERROR); | |
| return; | |
| } |
Moq-relay (0.14.17 through 0.17.0) subscribes upstream with Next Object plus FILL_PARAMETERS for the current group. Once a track has content that fill range is nonempty, and the publish session refused the whole SUBSCRIBE with NOT_SUPPORTED when the transport's writers lack WebTransport's commit() (RESET_STREAM_AT). Chromium 147 has no commit(), so in the browser a relay's second pull of a live track always failed: the real subscribe after a cross-relay TRACK_INFO probe, or any re-subscribe after the last viewer left. Players on another relay never got a catalog. Serve the subscription, and fail the fill as before: write the FETCH_HEADER, commit it where the writer can, and reset. Without commit() the reset may discard the header, and the subscriber sees no fill, which leaves its join at the next group boundary, as a failed fill does. REQUEST_UPDATE fills get the same treatment instead of ending the subscription. Stacked on #62, which ends tracks with PUBLISH_DONE and an exact Stream Count. There the fill counted only past the commit() gate this change removes. It now counts wherever the session opens one, whether or not its header survives the reset: §10.12 counts the streams the publisher opened, fill fetch streams included. A subscriber waits out a timeout for a stream reset before its header, but one that receives more streams than the count may close the session. moq-relay 0.17.0 never closes on either: it ends the track once the counted streams and the fill have arrived, or after a 1 s grace. A lost fill header leaves its fill outstanding, so that track end waits out the grace whatever the count says. The relay hub can now model a transport without commit(). The session tests cover the relay's probe-then-subscribe sequence, and the Stream Count of a fill reset without commit(), with its header delivered and lost. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ts6nhCDi2pBF9h5ooBNbss
… end Review (cubic, #63) read the fill counter's comment as "count every stream this side opens" and flagged a fill whose stream is still opening when the track ends: PUBLISH_DONE goes out without it. That is the intended rule, the one the track publisher applies to subgroup streams (#62): a stream counts in the step that commits it to its header, so a stream reset before its header, which the subscriber cannot attribute to the subscription, is left out. The late fill is reset with no header, so the count can never fall short of the streams the subscriber can tie to the subscription. Reword the comment to say so, including the over-count side (a counted fill whose reset discards its header, or whose write rejects), which §10.12 covers with the subscriber's timeout. Add a test that ends the track while the fill's open is pending, with and without reliable reset: Stream Count 3, the fill stream gets no write and is aborted.
Review (cubic, #63) suspected the probe's unbind could land after pull 237's bind and leave the binding undefined. It cannot: a subscription's end reports the newest live binding, not an unbind, and pull 237 is already accepted. Run the relay test both ways, with the probe cancelled before and after the second pull, and check the binding is still 237 once the probe's end has been handled. Reporting an unbind there fails the new case.
fix(spf): serve relay pulls whose fill cannot be reset reliably
Summary
moq-relay 0.17.0 (sjc.relay.mux.global) reports a publisher's bare FIN on an upstream subscription as
PUBLISH_DONEstatus 0 "internal error" to every viewer. Since this branch ended tracks with a bare FIN, every intentional unpublish looked like a failed track. The publisher now sendsPUBLISH_DONE(TRACK_ENDED) with an exact Stream Count before the FIN, as draft-20 §10.12 and MSF §11.3 intend. The relay then forwards "track ended".Changes
PUBLISH_DONEwith status TRACK_ENDED and its Stream Count, then FINs it.encodePublishDonecan now write.trackEndsrecord now carries the status. The sandbox loopback relay acceptsPUBLISH_DONEthen FIN as a clean end.internal/design/spf/features/moq-publish.mddrop the old "a track ends by FIN alone" rule.Compatibility
Older moq-relay builds abort a track on any byte after
SUBSCRIBE_OK. relay.mux.dev still runs one: with this change, its viewers lose every track on the firstPUBLISH_DONE, including the §11.3 end-of-broadcast catalog. Those builds are no longer supported.encodePublishDonelives innetwork/moqt(the playback branch's wire layer). The change only widensstreamCounttonumber | undefined, so base syncs should merge cleanly.Testing
pnpm -F @videojs/spf test: new coverage for per-alias stream counts, fill streams counted in the Stream Count, the unknown-count encoding, and the teardown paths assertingPUBLISH_DONETRACK_ENDED with exact counts. 2722 tests passed in three consecutive runs. One earlier run had a single failure that didn't reproduce (test name not captured), so treat it as a possible flake.pnpm lintandpnpm typecheckpass after a cleanpnpm build:packages.PUBLISH_DONEstatus 2 "track ended" on both catalog and audio (previously status 0 "internal error"). After TRACK_ENDED, the relay also appends its ownend-of-trackstatus object, which the SPF player already skips.🤖 Generated with Claude Code
Summary by cubic
Ends published tracks with
PUBLISH_DONE(TRACK_ENDED) and an exact Stream Count before each FIN, so intentional unpublishes no longer reach viewers as status 0 "internal error" on moq-relay 0.17.0. Previously a bare FIN ended tracks, which the relay reported as a failed track. Relay pulls whose fill cannot be reset reliably are also served now, instead of refusing the whole SUBSCRIBE with NOT_SUPPORTED.PUBLISH_DONEper §10.12: the open group gets a FIN, then a bounded flush (half the close drain window), thendestroy()on the publisher.INTERNAL_ERRORon any malformed post-SUBSCRIBE_OKframe.commit(): the session serves the subscribe, writes the FETCH_HEADER where it can, and resets the fill as before. A reset may discard the header, which leaves the subscriber's join at the next group boundary.SUBSCRIBE_OK; with this change, they are no longer supported.encodePublishDone's stream count widens fromnumbertonumber | undefined, so base syncs should merge cleanly.Written for commit 685c9c9. Summary will update on new commits.