Skip to content

fix(net): open JS SUBSCRIBE_TRACKS PUBLISHes only as stream credit admits - #6663

Merged
kixelated merged 4 commits into
mainfrom
quest/m1/js-listing-credit
Oct 25, 2026
Merged

kixelated merged 4 commits into
mainfrom
quest/m1/js-listing-credit

Conversation

@kixelated

@kixelated kixelated commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

A @moq/net draft-18+ SUBSCRIBE_TRACKS listing started a PUBLISH for every listed track up to the Limits.requests cap, skipping the rest, and queued every FORWARD=1 skip at once. What a peer could make us hold grew with the catalog, not with what it read. moq-dev/moq#6641 fixed this in moq-net. moq-dev/moq#6644 made @moq/qmux hold stream credit until both halves of a bidi stream end, so credit now bounds open streams in JS too.

Approach

#listBroadcast in js/net/src/ietf/publisher.ts mirrors Rust's run_listed_broadcast:

  • One track per broadcast is staged. Its PUBLISH stream opens only as the peer's credit admits it, and #runPublish receives the opened stream.
  • The listing is read while the open waits, since an unlisted track's PUBLISH_DONE is what returns credit. Tracks read but not yet PUBLISHed wait in pending. A removed staged track gives its stream to the next pending one.
  • On draft 18, a track's one-subscription claim is held from staging, and a claimed track is skipped before any stream opens.
  • A FORWARD=1 listing reads its next track only once the request stream has taken the last skip. The skip writer now signals changed whenever it takes one.
  • The listing no longer uses Limits.requests. Since nothing else reads it, Limits.requests, the publisher's subscription counter, and Slots.hold are removed.

The new tests also exposed a gap: untilAborted threw on an already-aborted signal without observing the promise it dropped. A peer resetting a PUBLISH while its write was in flight then left request.next()'s rejection unhandled. It now observes that promise.

Tests (js/net/src/ietf/subscribe_tracks.test.ts), each swept over catalogs of 4, 64 and 512 tracks. Both fail on the old code:

  • a listing publishes only as credit admits, on every draft: a real @moq/qmux pair over an in-memory socket, where the client grants 2 bidi streams and reads nothing. At most one stream open waits beyond the granted credit, and every track is PUBLISHed exactly once as refusals return credit. The old code had every remaining track waiting, which fails on the first catalog.
  • a forwarding listing reads only as skips go out, on drafts 19 and 22: each skip's write is held. The listing reads at most the skips taken plus three: the one being written, the one queued, and SYNCED or the next read. The old code read the whole catalog up front.

Impact

  • Wire: none.
  • Public API: none. Limits, Slots and Publisher are @internal and not exported from @moq/net. Listing PUBLISHes are no longer skipped (PUBLISH_BLOCKED on draft 18) past a request cap. They wait on stream credit instead, as in Rust. doc/concept/standard.md now states this for both languages.

Decisions made without asking

  • Testing used a real qmux pair rather than adding credit to the mock transport. That exercises the actual credit return from fix(qmux)!: return stream credit once both halves of a bidi stream end #6644 and keeps the mock simple.
  • The FORWARD=1 test gates Message.write for PUBLISH_SKIPPED with a spy, which stands for a peer that stops reading.
  • Three tests that asserted the removed cap or slot accounting were deleted: the cap half of "track listing skips beyond the cap", "paused updates keep one slot", and "a failed PUBLISH stream open returns its subscription slot". The overlap check and the FORWARD=1 suffix check were kept.
  • A failed PUBLISH stream open ends that broadcast's listing, as in Rust.
  • A pending createBidirectionalStream can't be cancelled, so a stream that opens after its staged track went (and no pending track can take it) is reset at once. This is bounded to one per broadcast listing.
  • The untilAborted fix is in this PR because the new test reaches it, and any real transport can reach it the same way.

Checks

  • just check: passed.
  • just ci: passed.
  • just test interop --all: passed, except the known flake in quest/m1/test-flakes-2/interop-timestamp-gap.md: rust -> js-native-node failed once with an audio timestamp gap and passed on rerun, and the rerun then hit the same gap on rust-swapped -> js-native-node. Both are moq-lite paths, which don't touch the changed listing code.
  • Each new test was run against the pre-PR publisher.ts and limits.ts and failed at its bound.

Alternatives

  • Extending createMockTransportPair to model stream credit. A second credit implementation could drift from qmux's real behavior.

Follow-ups

  • The in-memory qmuxPair helper could move to js/net/src/mock.ts for other tests that need a peer withholding credit, such as quest/m1/ietf-request-cancel.md.

(Written by Claude Opus 5.5)

🤖 Generated with Claude Code

kixelated and others added 3 commits October 24, 2026 10:45
…mits

Mirror moq-net's run_listed_broadcast in @moq/net's #listBroadcast: stage
one track per broadcast and open its PUBLISH stream only as the peer's
credit admits, keep reading the listing for removals meanwhile, and have a
FORWARD=1 listing read its next track only once the request stream took
the last skip. The listing no longer uses the Limits request cap, so
Limits.requests and Slots.hold are gone.

untilAborted now observes the promise it drops when its signal is already
aborted, which a peer resetting a PUBLISH during its write surfaced as an
unhandled rejection.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title JS SUBSCRIBE_TRACKS listings follow stream credit fix(net): open JS SUBSCRIBE_TRACKS PUBLISHes only as stream credit admits Oct 24, 2026
@kixelated
kixelated marked this pull request as ready for review October 24, 2026 18:46
@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 20 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4f489f2d-ea8e-4023-8b2d-cfb36aaa943d
Commits

Reviewing files that changed from the base of the PR and between 1092357 and 7c17130.

Files selected for processing: 10
  • doc/concept/standard.md
  • js/net/src/ietf/publisher.ts
  • js/net/src/ietf/subscribe_tracks.test.ts
  • js/net/src/lite/tracks.test.ts
  • js/net/src/session-limits.test.ts
  • js/net/src/util/abort.ts
  • js/net/src/util/limits.test.ts
  • js/net/src/util/limits.ts
  • quest/m1/README.md
  • quest/m1/js-listing-credit.md
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-25T00:13:05.174497Z 7c17130 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@kixelated

Copy link
Copy Markdown
Collaborator Author

Merging e3f4ae9 with the maintainer's approval. The non-Grok review of this head is clean, every finding is fixed or answered, and the pre-land quest check passes against origin/main.

(Written by Claude Opus 5.5)

@kixelated
kixelated added this pull request to the merge queue Oct 24, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 24, 2026
@kixelated

Copy link
Copy Markdown
Collaborator Author

Re-landing after the queue dropped it for a conflict with main. Merged origin/main (no rebase), resolving two conflicts:

  • js/net/src/ietf/publisher.ts: kept main's new untilGivenUp import and dropped the LIMITS/Slots import this PR already removes.
  • doc/concept/standard.md: took main's rewritten Pull bullet (watched-prefix requests) and this PR's SUBSCRIBE_TRACKS bullet (credit-gated PUBLISHes in both languages).

The PR's own diff against main is unchanged by the merge. just check and the pre-land quest check pass on 7c17130.

(Written by Claude Opus 5.5)

@kixelated
kixelated added this pull request to the merge queue Oct 25, 2026
Merged via the queue into main with commit 2b4692c Oct 25, 2026
10 checks passed
@kixelated
kixelated deleted the quest/m1/js-listing-credit branch October 25, 2026 00:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant