Skip to content

fix!: a failed group is a gap every reader reads past - #9847

Open
kixelated wants to merge 3 commits into
mainfrom
group-failure-gap
Open

kixelated wants to merge 3 commits into
mainfrom
group-failure-gap

Conversation

@kixelated

@kixelated kixelated commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Supersedes moq-dev/moq#9808. Finishes and deletes quest/m2/typed-superseded-group-end.md, whose goal it rewrites to the maintainer's rule: a failure that belongs to one group is that group's error, and the subscription and track read on. A track read's Err means only "the track ended"; a failed group is a gap the reader continues past. No reader matches on error variants.

Problem

Readers ended a whole track on one group's failure unless the error matched an allowlist. libmoq's C raw reader and moq-ffi's ordered read_frame passed only Old, so over moq-transport, where a group an on-demand producer's drop left open arrives as a cancelled stream that recovers to NotFound, the C raw reader ended the track with -2 instead of reading on (reproduced by raw_track_reads_past_a_group_a_drop_left_open). JS Ordered.readFrame rethrew TooFarBehind, GroupTooLarge, and Evicted, and the moq-json snapshot and window consumers (Rust and JS) ended on anything outside their GAPS allowlists. Every one of these matched on error variants, which AGENTS.md forbids.

Approach

  • Rust moq-net: already reads this way (Item::Gap, and poll_next_group passes gaps). The rule is now written on group::Consumer and in doc/lib/rs/moq-net.md.
  • JS @moq/net: Ordered.readFrame passes any failed group and resyncs from the next; only the track's own error throws. Callers who need the reason use nextItem() and the group's readFrame(). Rule added to doc/lib/js/net.md.
  • moq-ffi: MoqTrackConsumer.read_frame passes any failed group without matching. The Python, Kotlin, Swift, and Go wrappers forward that call unchanged, so none ends a stream on a group failure; their docs say so. Dart uses the generated binding directly.
  • libmoq: raw reads are typed like moq_media_read: moq_raw_read { kind: FRAME|GAP, frame, gap: { start, end, code, reason, protocol, has_protocol } }. run_raw reads with poll_next_item, so a skipped group and a group that failed partway both arrive as MOQ_RAW_READ_GAP; code is the failure's negative libmoq code reason stays valid until the read is freed, and protocol carries the stream reset or session close behind it, as moq_error_protocol reports one. The metadata callback gets a moq_meta_read the same way, with a gap for a group that failed partway. A callback <= 0 stays terminal and means only that the track ended.
  • moq-json (Rust and JS): the snapshot and window consumers resync from the next group on any group failure, and end only with the track. The GAPS allowlists are gone.
  • moq-cli publish.rs test: any group error is "move on".
  • Tests: ported fix(net): a superseded group reads as one over moq-transport too #9808's superseded_group.rs as rs/moq-net/tests/integration/failed_group.rs (a group a drop left open, and one its publisher aborted, both read past on moq-lite-03/06/07-wip and moq-transport-18/22/23) and libmoq's raw_track_reads_past_a_group_a_drop_left_open (now expecting a gap, then the next producer's frame, on moq-lite-06 and moq-transport-22).

Impact

  • libmoq C API (breaking):
    • moq_consume_track_frame(frame, moq_frame *) and moq_consume_track_frame_free are replaced by moq_consume_track_read(read, moq_raw_read *) and moq_consume_track_read_free.
    • New moq_raw_read, moq_raw_read_kind (MOQ_RAW_READ_FRAME, MOQ_RAW_READ_GAP), and moq_raw_gap.
    • moq_consume_meta takes a moq_meta_callback (void *user_data, const moq_meta_read *read, int32_t code) in place of moq_header_callback, and moq_meta_read wraps the moq_header.
    • Migration: call moq_consume_track_read, branch on kind, read the payload from read.frame (same fields as before), and treat MOQ_RAW_READ_GAP as groups [gap.start, gap.end) lost, with gap.code, gap.reason, and (when gap.has_protocol) gap.protocol saying why; then keep reading. Free with moq_consume_track_read_free. For metadata, take read->header where header was, and handle MOQ_RAW_READ_GAP. A terminal callback (<= 0) still ends the track. Recompile against the regenerated moq.h.
  • Behavior (no API change):
    • libmoq raw and metadata readers, moq-ffi MoqTrackConsumer.read_frame (and every wrapper over it), JS Ordered.readFrame, and the moq-json snapshot and window consumers read past a group that failed for any reason, a publisher's group abort included, where they used to end the track with that error.
    • A libmoq raw reader now reports the groups it skipped as gaps, which it used to pass silently.
  • Wire: none. No moq-transport code remap, and no superseded() API.

Decisions

Taken while the maintainer was away, each with the option I recommended:

  • libmoq metadata reads keep arrival order. The brief had run_meta switch to poll_next_item, but a metadata subscription has no ordered reader in moq-net (meta::Subscriber offers only recv_group, in Rust and JS). It now reports a group that failed partway as a gap and reads on; groups it never received are not reported, as arrival order never did.
    • Rejected: add meta::Subscriber::ordered() and its item type to moq-net in Rust and JS. New public API in two languages, and a change from arrival to key order for every C metadata reader, for skipped-group reports no caller asked for.
  • test/stream-credit keeps its Old check. The brief had it treat any group error as "move on", but the harness exists to check that a group the relay reset to make room (TOO_FAR_BEHIND) comes back whole when fetched. Skipping every errored group drops that check (the driver then fails "no group stopped early"), and fetching every one adds a fetch per stale live-edge group, thousands per run. It asserts the relay's wire behavior rather than reading a track, so it stays as it is.
    • Rejected: return on any error without fetching; fetch on any error.
  • moq-json stream mode is unchanged. Its log rides one group, so there is no next group to resync from; a failure there is the log's end, as before.
  • The quest is deleted rather than rewritten. This PR finishes the rewritten goal. The fetch-path matches the brief leaves alone move to quest/m3/error-matches.md.

Alternatives

  • moq-dev/moq#9808: classify a superseded group with Error::superseded() and remap moq-transport DELIVERY_TIMEOUT to carry it. Superseded by the maintainer's rule: a group's failure stays with that group, so no reader needs to tell kinds apart and no wire code changes.

Caused by

  • moq-dev/moq#9550 - had libmoq and moq-ffi read past a dropped producer's open group by matching Error::Old | StreamError::Old, which a moq-transport reader never sees, so the C raw reader ended the track there (found by person).

Follow-ups

  • quest/m3/error-matches.md (edited): moq-hls's export (unservable, 404 versus 500) and moq-relay's HTTP fetch (web.rs) still tell a single-group miss from a failure by matching NotFound, Old, and Evicted. Left as they are per the brief; the quest now lists them, and drops the libmoq and moq-ffi Old matches this PR removed.

Validation

  • Fail first, on origin/main:
    • libmoq raw_track_reads_past_a_group_a_drop_left_open: moq-transport-22 ended the track with -2.
    • JS a read skips a group whose front was shed, as it does any failed group: threw Evicted.
    • JS json snapshot consumer reads past any failed group and ends only with the track and consumer resumes at a checkpoint after losing a group (now with Internal and a plain Error): both rethrew.
    • Rust moq-json a_lost_group_waits_for_its_replacement (now with App(7)) and consumer_resumes_at_a_checkpoint_after_losing_a_group (now with Internal and App(7)): both failed.
    • moq-ffi track_read_frame_passes_an_aborted_group: read_frame returned the abort. It replaces raw_read_frame_drops_aborted_pending_group, which asserted the old behavior.
    • libmoq raw_track_reads_past_an_aborted_group and meta_reads_past_an_aborted_group replace raw_track_ends_on_an_aborted_group, which asserted the old behavior.
  • rs/moq-net/tests/integration/failed_group.rs passes on origin/main too: moq-net already reads this way, so it guards the rule rather than reproducing a bug.
  • quest gate just check: passed.
  • quest gate just ci: passed.
  • quest gate just test interop --all: all checks passed, including the C client over libmoq.
  • just rs c-tests: the C fixtures (on-demand-free.c, timestamps.c) pass against the new header.

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: 964b6b5

  • Base: origin/main at e1dd5f6

  • Risk: high, It breaks published consumers: libmoq's C API removes `moq_consume_track_frame` and `moq_consume_track_frame_free` in favor of `moq_consume_track_read` and `moq_consume_track_read_free`, changes the `moq_consume_track` and `moq_consume_meta` callback types, and the CHANGELOG marks it Breaking. A failed group that used to end a track now reads on, a behavior change for Rust, JS, Python, Go, Swift, and Kotlin readers. Reverting is a code revert, but a C caller built against the new header, or a release that ships it, is already affected.

  • Classified: high by Claude Code, claude-haiku-5-5, low effort, session ec74125a-6b32-470d-b14d-ac2f28c303fb

  • Risk file: bb7b1c0de60b

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

  • Session: 01a2218f-6a19-7ef3-bf59-dac03bcb97a3, round 3

  • Score: 10/10, The failure handlers now release their group handles before advancing, and the new changes introduce no findings.

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

  • Findings: none

  • The last round's findings, at 8ff718a:

    • Fixed: medium, js/json/src/snapshot/consumer.ts:148: Close the failed group before discarding its handle; Both snapshot failure handlers (`js/json/src/snapshot/consumer.ts:128` and `:149`) and the window failure handler (`js/json/src/window/consumer.ts:73`) close the failed group before clearing its handle.
  • Reviewer: Claude Code, claude-opus-5-5, high effort, second

  • Session: 362a8e5b-08eb-49a1-82b9-07c6855cc4a2, round 3

  • Score: 9/10, The only change since the last round has the JSON snapshot and window consumers close a failed group's reader before moving on to the next group. `close()` just releases that reader and doesn't touch the producer, so the change frees resources and adds no new bug, and no findings are open.

  • Rounds: 3; first round 0; findings 0: fixed 0, refuted 0, open 0

  • Findings: none

kixelated and others added 3 commits November 28, 2026 01:15
A failure that belongs to one group is that group's error: readers of a
track read on past it, and a track read's error means only that the
track ended. libmoq's raw and metadata reads become typed (frame or gap).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tocol error

Also recover from a failed group while the JS snapshot reader drains its
backlog, and correct the gap docs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated marked this pull request as ready for review November 28, 2026 10:27
@coderabbitai

coderabbitai Bot commented Nov 28, 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 4 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: 8ac74ffe-b296-4bd9-8bb7-cf61d2e98427
Commits

Reviewing files that changed from the base of the PR and between 47dda97 and 964b6b5.

Files selected for processing: 35

  • doc/lib/c/index.md
  • doc/lib/js/net.md
  • doc/lib/rs/moq-net.md
  • go/wrapper/subscribe.go
  • js/json/src/snapshot/consumer.ts
  • js/json/src/snapshot/snapshot.test.ts
  • js/json/src/window/consumer.ts
  • js/json/src/window/window.test.ts
  • js/net/src/broadcast.test.ts
  • js/net/src/track.ts
  • kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Flows.kt
  • py/moq-rs/README.md
  • py/moq-rs/moq/subscribe.py
  • quest/m2/typed-superseded-group-end.md
  • quest/m3/error-matches.md
  • rs/libmoq/CHANGELOG.md
  • rs/libmoq/README.md
  • rs/libmoq/c-tests/on-demand-free.c
  • rs/libmoq/c-tests/timestamps.c
  • rs/libmoq/src/api.rs
  • rs/libmoq/src/consume.rs
  • rs/libmoq/src/ffi.rs
  • rs/libmoq/src/test.rs
  • rs/moq-cli/src/publish.rs
  • rs/moq-ffi/src/consumer.rs
  • rs/moq-ffi/src/test.rs
  • rs/moq-json/src/snapshot/consumer.rs
  • rs/moq-json/src/snapshot/mod.rs
  • rs/moq-json/src/window/consumer.rs
  • rs/moq-json/src/window/mod.rs
  • rs/moq-net/src/model/group.rs
  • rs/moq-net/tests/integration/failed_group.rs
  • rs/moq-net/tests/integration/main.rs
  • swift/Sources/Moq/Track.swift
  • test/interop/clients/c/subscribe.c
  • 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

This branch has not been deployed

No deployments
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