Skip to content

feat(net): metadata subscriptions in Rust, JS, and the bindings - #9793

Merged
kixelated merged 16 commits into
mainfrom
quest/m2/subscribe-meta
Nov 27, 2026
Merged

kixelated merged 16 commits into
mainfrom
quest/m2/subscribe-meta

Conversation

@kixelated

@kixelated kixelated commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Finishes quest/m2/subscribe-meta.md (deleted here), on top of the relay half in moq-dev/moq#9758.

Problem

moq-dev/moq#9758 made every lite-07 publisher and relay serve metadata subscriptions, but nothing outside moq-net could open one: the lookup (track_meta, trackMetaOf) was crate-private or @internal, and reading it meant knowing a metadata copy stores an empty payload with the size beside it. moq-hls live and archive indexing and the route-health standby need it before the lite-07 cut.

Approach

A metadata subscription is a subscription of its own, with types of its own, so a payload read of a header-only frame cannot be written.

  • Rust moq-net: new meta module. broadcast::Consumer::meta(name) returns meta::Consumer, whose subscribe resolves to meta::Subscriber (recv_group, finished, update, control, info). Its meta::Group reads next_header() -> Option<frame::Info>: the timestamp and the declared plain size, read from stored slices so a compressed frame is never inflated or waited on, and without holding the payload in flight.
  • JS @moq/net: Meta namespace mirroring it. broadcast.meta(name) gives Meta.Consumer, Meta.Subscriber (recvGroup, finished, update, info, close), and Meta.Group (nextHeader, index, start, close).
  • Over an older session or hop, which cannot carry the mode, the same call rides the track's one payload subscription and drops the payload. Nothing refuses the mode.
  • To read the payload after all, a reader subscribes to the track from the group it reached and skips to its first missing frame (skip_to / readFrameIndex({ from })). Nothing switches mode in place.
  • moq-ffi: MoqBroadcastConsumer::subscribe_meta returns MoqMetaConsumer (recv_group, info, update, cancel), whose MoqMetaGroup reads next_header() -> MoqFrameHeader { size, timestamp }. Python, Go, Kotlin, Swift, and Dart wrap it as each wraps subscribe_track, and C++ is generated.
  • libmoq: moq_consume_meta, moq_consume_meta_update, and moq_consume_meta_cancel. Its moq_header_callback receives each moq_header (group, frame index, size, and timestamp) borrowed for the call, so libmoq holds nothing per header however slowly the caller drains its copies. This adds to the ABI and leaves moq_subscription unchanged.
  • Interop: a meta tail lane crosses the relay on lite-07, Rust to Rust and both ways with each native JS runtime.
  • Bench: session_delivery_meta sweeps relay depth, viewers, and tracks per viewer, comparing metadata against payload.
  • Docs: doc/concept/moq-lite.md, doc/lib/c, and the libmoq README.
  • Quests: deletes the finished quest and its links. failover.md, hls-server-lifecycle.md, and hls-archive-vod.md lose the Required entry it was.

Decisions

Choices made without asking, for review. The user was away, so the last three were taken on the recommendation, each with the option it rejected:

  • Members dropped until something reads them: largest, subscription, a group's end, and JS closed. Fallow flags unread JS members, and the Rust side mirrors the same set.
  • No metadata ordered(), with_range, or fetch_group yet. The C API delivers headers group by group in arrival order, each naming its group and frame.
  • next_header is named after Rust's next_frame (the header-first read), not read_frame (the whole-frame read). The binding pass suggested read_header. I kept next_header, since nothing behind it is "read whole".
  • A metadata subscription is its own entry (broadcast.meta(name)) and types (meta::Consumer/Subscriber/Group, JS Meta.*, MoqMetaConsumer/MoqMetaGroup, C moq_consume_meta). A payload read of a header-only frame cannot be written, so the bindings need no Unsupported error. The quest recommended this "to confirm when this starts".
    • Rejected: a meta flag on Subscription. That gives one subscribe path, but groups need a runtime "is header-only" check and the C struct changes its ABI.
  • An endpoint whose own session is older than lite-07 serves a metadata subscription from a payload subscription and drops the payload, as a relay does over an older hop. The API never refuses, and AGENTS.md keeps version branches inside moq-net. The quest recommended this "to confirm when this starts".
    • Rejected: refusing with Unsupported on an older session. That makes the cost visible, but every caller then needs a version branch.
  • A chunked DEFLATE frame that a local writer is still writing shows its header when the frame is published at its last chunk, the same moment its payload appears. A writer stalled mid-frame delays the header too. The reviewer held this open for three rounds, so it is accepted on the head (see Review). No producer in either tree streams a compressed frame: every one writes JSON or catalog frames whole, and no metadata consumer reads a compressed track.
    • Rejected: exposing the declaration at frame open. In Rust this is a small port of the parked poll_frame_header (quest/m3/route-health/meta at c00addff48). In JS, though, a compressed createFrame holds nothing in the group until finish(). It would need a new frame-entry state carried through mirrors, takeovers, cut-frame handling, and compression binding, and the parked JS never did this either. I first recommended this option, then changed my recommendation once the JS cost was clear.

Impact

  • Public API (additive, no !):
    • Rust moq-net: broadcast::Consumer::meta, and the meta module with Consumer, Subscribing, Subscriber, and Group.
    • JS @moq/net: Broadcast.Consumer.meta and the Meta namespace.
    • moq-ffi: MoqBroadcastConsumer::subscribe_meta, MoqMetaConsumer, MoqMetaGroup, and MoqFrameHeader, plus the matching names in every wrapper.
    • libmoq C ABI: moq_header, moq_header_callback, and the three moq_consume_meta* functions.
  • Wire: none beyond moq-dev/moq#9758. The draft already describes the metadata subscription, so it needs no edit.
  • Behavior: none for existing callers.

Alternatives

  • A meta flag on Subscription with promotion in place, as moq-dev/moq#8882 built. It was rejected on 2026-11-16 (see Waiting).
  • A metadata fetch_group. A one-shot header read has no consumer yet.

Follow-ups

  • quest/m0/test-flakes-5/finish-go-row-under-load.md (new): under the full interop matrix, one reader of the Go publisher's finished tail sometimes gets nothing, which fails the whole finish go -> row. Seen here (a python reader got 0 of 10 frames) and on moq-dev/moq#9758. It has no open decisions.
  • quest/m3/meta-reuse.md (existing) still owns serving lite-07 metadata readers from the payload copy.

Validation

  • Merged main at ce45c1f3b8. Since main's pacing changes, a publisher records traffic a step after the reader gets the bytes, so one test settles in simulated time before reading traffic, as the file's other traffic checks already do.

  • rs/moq-net: full suite with --features async, 4649 passed.

    • lite::meta_tests, through the public meta API on simulated time, billed per hop:
      • Over lite-07 hops, both hops carry zero payload.
      • Over an older hop, payload crosses only that hop.
      • Over an older hop, mixed readers share one subscription.
      • Once the payload reader leaves, no payload crosses any hop.
      • An end session on lite-06 rides one payload subscription.
      • A payload subscription opened mid-group from a metadata position (group key and frame index) gets the first missing frame while the metadata reader reads on.
      • A history fill with only metadata demand carries no payload.
      • A compressed track reports plain sizes, from a local payload copy and from a lite-07 metadata copy.
      • Dropping the reader closes its subscription on both hops.
    • Pointing broadcast::Consumer::meta at the payload lookup fails the four lite-07 tests.
  • js/net: 3999 passed, 1 skipped. lite/meta.test.ts has 18 tests: the same cases through a session and through a front, plus info, update, and finished.

  • moq-ffi subscribe_meta_reads_headers and libmoq meta_reads_headers check the mapping, an empty frame read as size 0, and a clean end (libmoq's on a NULL header).

  • Wrappers: just go check, just py test and just py check, just kt check, and just dart check each pass with a new local test. Swift was only format-checked, because this Linux host has no toolchain.

  • just ci passes on cb0c30d699. The later commits add only the quest file and trim unread members, with JS meta tests and just fix rerun on them.

  • The interop plan registers the five meta cells, so a run that stops early reports them as not run.

  • just test interop --all: every row passes, including the five new meta lanes, except all nine finish go -> cells.

    • Those failed because the python reader got 0 of 10 frames.
    • Three targeted reruns of --finish --publishers go --subscribers python,rust passed. See Follow-ups.
  • session_delivery_meta (--quick, 16 KiB frames, 4 frames per group, time per round, payload then metadata):

    • 1 relay, 1 viewer, 1 track: 115 µs, 72 µs.
    • 1 relay, 1 viewer, 8 tracks: 800 µs, 377 µs.
    • 1 relay, 64 viewers, 1 track: 15.6 ms, 11.6 ms.
    • 1 relay, 64 viewers, 8 tracks: 59.7 ms, 40.0 ms.
    • 3 relays, 1 viewer, 1 track: 144 µs, 81 µs.

Models

Size: M
Implementer: Claude Code, claude-opus-5-5, unknown (arm A)

🤖 Generated with Claude Code

(Written by Claude Opus 5.5)

Review

Rewritten by quest review after each round.

  • Head: 0ae8076

  • Base: origin/main at ce45c1f

  • Risk: medium, Medium: it adds new public API (Rust `broadcast::Consumer::meta`, JS `meta()`, C `moq_consume_meta*`, and the Go, Python, Kotlin, Swift, and Dart bindings) and new internals, all additive, with no wire or existing-API change, so it is a patch for the next cut and a revert fully undoes it. What could break: a bug in the new header-read path or the new C ABI functions could reach downstream consumers of the next release, which the repo's own tests and the interop lane meet first, and a revert would undo it. The quest plan and test/interop files are low, and nothing touches auth, release scripts, RISK.md, or the merge-gate selection, so none of the High paths apply.

  • Classified: medium by Claude Code, claude-haiku-5-5, low effort, session d0ff7fa7-0b5b-4822-9356-0c56996b688e

  • Risk file: bb7b1c0de60b

  • Accepted by the maintainer: Taken under afk as the agent's recommendation, open to maintainer override (PR body, Decisions): a compressed frame's header appears when the frame is published, with its payload. Exposing it at open needs a new JS frame-entry state through mirrors, takeovers, and compression binding, the parked JS never did it, and no producer streams compressed frames.

  • Reviewer: Codex, gpt-6.2-sol, high effort

  • Session: 01a21f13-f050-79d1-8e8e-aa82abb61fdd, round 4

  • Score: 8/10, The branch is ready to land once metadata readers can see a streamed DEFLATE frame’s declared header while its payload is still being written.

  • Rounds: 4; first round 2 (medium 2); findings 2 (medium 2): fixed 1, refuted 0, open 1

  • Findings, accepted by the maintainer:

    • Medium, rs/moq-net/src/model/meta.rs:157: Expose streamed DEFLATE headers when frames open
  • The last round's findings, at 1f4ad1a:

    • Open: medium, rs/moq-net/src/model/meta.rs:157: Expose streamed DEFLATE headers when frames open; The parked Rust implementation at `c00addff48:rs/moq-net/src/model/group.rs:1170` explicitly returned the declared header from an unfinished DEFLATE frame, and the current Rust metadata path still waits for the frame to finish.

kixelated and others added 13 commits November 27, 2026 12:10
Quest-Claim: 09947984951c4386
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title Metadata-only subscriptions feat(net): metadata subscriptions in Rust, JS, and the bindings Nov 27, 2026
kixelated and others added 3 commits November 27, 2026 14:48
A slab entry per header let a slow C consumer grow native memory without
bound. `moq_header_callback` now passes each `moq_header` by pointer for
the call, which drops `moq_consume_meta_header` and its free. The interop
plan also registers the metadata cells, so an early stop reports them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Since main's pacing changes, a publisher records a group's traffic a
step after its reader gets the bytes, so the check settles in
simulated time first, as the file's other traffic checks do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated marked this pull request as ready for review November 27, 2026 23:29
@kixelated
kixelated added this pull request to the merge queue Nov 27, 2026
Merged via the queue into main with commit d0beaa0 Nov 27, 2026
7 of 8 checks passed
@kixelated
kixelated deleted the quest/m2/subscribe-meta branch November 27, 2026 23:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant