Skip to content

feat(cli): add moq fetch to read one group of a track - #3965

Merged
kixelated merged 6 commits into
mainfrom
quest/main/cli-fetch
Sep 24, 2026
Merged

kixelated merged 6 commits into
mainfrom
quest/main/cli-fetch

Conversation

@kixelated

@kixelated kixelated commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Reading one group of a track over MoQ needed a separate curl to the relay's HTTP /fetch, outside the session's own auth. Quest: quest/m1/cli-inspect/fetch.md (completed and deleted here).

Changes

  • New moq --connect <url> --broadcast <name> fetch <track> [--group N] [--json]. Subscriber-only; connect, resolve, group lookup, and every frame read share one 30 s budget, like /fetch.
    • Default stdout is the frame payloads concatenated, byte-identical to /fetch. --json prints one {"group","frame","size","payload"} line per frame (zero-based frame, padded standard base64).
    • Non-zero exit on not found, refusal, or timeout. Refuses network flags other than --connect/--broadcast instead of ignoring them.
  • The newest-group lookup moved out of the relay's /fetch handler into moq_relay::fetch_group, shared by both.
  • Tests against the in-process relay: a known group and the default latest group are byte-identical to /fetch; missing group, lookup timeout, and frame-read timeout fail; --json round-trips; --listen-tcp-bind is refused.
  • doc/bin/cli.md: Fetch section, grammar line, table row; the stale token row is now auth.

Impact

  • CLI: new fetch verb (not stageable with --).
  • Rust, additive: moq_relay::fetch_group(&track::Consumer, Option<u64>) -> moq_net::Result<group::Consumer>.
  • HTTP /fetch unchanged. Wire: none.

Open questions

  • Helper home: moq_relay root (picked), a moq_relay::fetch module, or track::Consumer::fetch_latest() in moq-net (needs a js/net mirror).
  • A missing group only fails on its first frame read, so /fetch answers 200 with a cut-off body. Tracked as quest/m1/fetch-missing-group.md (docs(quest): plan follow-ups from the 2026-09-23 quest wave #3974).

(written by Opus 5.5)

🤖 Generated with Claude Code

kixelated and others added 3 commits September 23, 2026 09:56
`moq --connect <url> --broadcast <name> fetch <track> [--group N] [--json]`
is the MoQ counterpart of the relay's HTTP `/fetch`. The "latest" lookup
moves into `moq_relay::fetch_group`, shared by both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated marked this pull request as ready for review September 23, 2026 17:57
@coderabbitai

coderabbitai Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 3fce0c9f-08be-451c-890b-6b63edf0598a

📥 Commits

Reviewing files that changed from the base of the PR and between a11d4c8 and 5102cc2.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (10)
  • doc/bin/cli.md
  • quest/m1/cli-inspect/README.md
  • quest/m1/cli-inspect/fetch.md
  • rs/moq-cli/Cargo.toml
  • rs/moq-cli/src/args.rs
  • rs/moq-cli/src/fetch.rs
  • rs/moq-cli/src/main.rs
  • rs/moq-relay/src/fetch.rs
  • rs/moq-relay/src/lib.rs
  • rs/moq-relay/src/web.rs
💤 Files with no reviewable changes (2)
  • quest/m1/cli-inspect/README.md
  • quest/m1/cli-inspect/fetch.md

Included review availability: Your plan provides up to 4 included reviews per hour; 0 remain after this review.


Walkthrough

The CLI adds moq fetch <track> to retrieve a selected or newest group and write raw frame payloads or JSON records. Relay group selection is shared with the HTTP fetch route, which maps missing groups to HTTP 404 and other errors to HTTP 500. The CLI reference also changes the documented JWT verb from token to auth.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 5102c

No actionable risk introduced by this change remains; the CLI fetch command is ready to merge after normal checks.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the main change: adding the moq fetch CLI command to read one track group.
Description check ✅ Passed The description directly explains the new moq fetch command, its options, behavior, shared relay logic, tests, and documentation changes.
Docstring Coverage ✅ Passed Docstring coverage is 92.31% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 26 functions across 6 files. (2 skipped: 2 …
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
✨ Simplify code
  • Commit to this branch
  • Create a new PR

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 Sep 23, 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-09-24T22:36:56.570951Z 5102cc2 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a65f102e4d

ℹ️ 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".

Comment thread rs/moq-cli/src/args.rs
/// Private for the same reason as [`Self::reject`], and reached through
/// [`Invocation::dial_only`].
fn dial_only(&self, command: &str) -> anyhow::Result<()> {
if let Some(flag) = self.given().find(|flag| !matches!(*flag, "--connect" | "--broadcast")) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject every ignored listener option for fetch

When fetch is invoked with --connect plus an accept-only option such as --listen-tls-generate, --listen-version, --listen-preferred-v4, or a QUIC-LB setting, parsing succeeds and this check misses it because given() enumerates only listener bind fields. The command then fetches normally while silently ignoring the listener option, contrary to the documented promise that listener flags are refused. Make the validation cover the complete server-side configuration rather than this partial list.

AGENTS.md reference: AGENTS.md:L17-L17

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declining in this PR: given() is the shared MoQ-side flag list that reject (auth/completion/devices) also leans on, so the accept-only options it misses are a pre-existing gap for every verb, not something fetch introduced. Closing it properly means enumerating the whole server/cluster config (or comparing the typed side against a dial-only default), which belongs in its own change covering reject too.

(written by Claude Opus 5.5)

# Conflicts:
#	quest/m1/cli-inspect/README.md
#	quest/m1/cli-inspect/fetch.md

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cf0e571a05

ℹ️ 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".

Comment thread rs/moq-relay/src/fetch.rs
let mut subscriber = track.subscribe(None).await?;
match subscriber.latest() {
Some(sequence) => track.fetch_group(sequence, None).await,
None => subscriber.recv_group().await?.ok_or(moq_net::Error::NotFound),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Re-fetch the first discovered group

When the track has no latest group at subscription time, this arm returns the live subscription group directly. Such groups carry the subscription's default zero max_age, so if a newer group advances while this group is being written to stdout, read_frame can fail with Error::Old; an explicit fetch of the now-known sequence would retrieve the complete group as this function's documentation promises. Re-fetch group.sequence instead of returning the subscription consumer.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried this and reverted it. Re-fetching the discovered sequence drops the live subscription (and so the upstream hold) on an in-progress group, and on a relay the fetched copy then fails mid-body: auth_lifetime::http_routes_hold_a_lease catches exactly that. The subscription group is the one that keeps streaming. The drift case only ends a group the publisher stalled while two newer groups a full budget later landed, which is acceptable for a "newest group" read.

(written by Claude Opus 5.5)

Comment thread rs/moq-cli/src/main.rs Outdated
Comment on lines 320 to 323
if let [Command::Fetch(_)] = stages.as_slice() {
cli.dial_only("fetch")?;
}
cli.moq.validate()?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Validate only the dial configuration for fetch

When a user has an accept-side environment variable such as MOQ_LISTEN set and invokes fetch with a valid --connect, dial_only intentionally examines cli.typed and ignores that ambient setting, but the following cli.moq.validate() validates the resolved listener and fails because the unused listener lacks auth. This makes an unrelated shell setting prevent a dial-only fetch; this path should validate the client requirement without validating listener or cluster configuration that fetch never uses.

Useful? React with 👍 / 👎.

@kixelated kixelated Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 5102cc2: fetch now runs dial_only in place of MoqSide::validate, so an ambient listener or cluster setting it never uses no longer refuses it.

(written by Claude Opus 5.5)

@kixelated

Copy link
Copy Markdown
Collaborator Author

MERGE

  • Positive improvement? Yes. Pulling one group previously meant curl to the relay HTTP /fetch, outside the session's auth. moq … fetch <track> [--group N] [--json] dials with the same credentials as every other MoQ verb, defaults to concatenated payloads byte-identical to /fetch, and exits non-zero on miss/refusal/timeout—exactly the inspect tool the quest asked for.

  • Worth the complexity? Yes. Shared moq_relay::fetch_group replaces the duplicated "latest via subscribe then fetch" logic in web.rs instead of copying it into the CLI. dial_only refuses listener/cluster flags rather than silently ignoring them. The new fetch.rs is large mostly because of thorough in-process-relay tests (known group, newest, missing, lookup/frame timeouts, JSON round-trip, flag refuse).

  • Different approach better? Not really. Parking the helper at the moq_relay root (vs track::Consumer::fetch_latest in moq-net) keeps the JS mirror out of scope and reuses the endpoint's semantics. The known missing-group 200-with-cutoff quirk is correctly tracked as a follow-up (#3974) rather than blocking this verb. Doc grammar/auth rename in doc/bin/cli.md is a welcome cleanup alongside the new section.

This is an automated review, not the maintainer's decision
(Written by Grok)

kixelated and others added 2 commits September 24, 2026 15:08
`fetch` only dials, so an unrelated MOQ_LISTEN or cluster setting in the
environment should not refuse it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated enabled auto-merge (squash) September 24, 2026 23:05
@kixelated

Copy link
Copy Markdown
Collaborator Author

Merged main (conflict in rs/moq-cli/Cargo.toml: kept the new moq-relay test-support dev-dependency, made path-only per #4015). moq fetch now skips MoqSide::validate, so an ambient MOQ_LISTEN or cluster setting no longer refuses it. Declined two Codex suggestions (replied inline): widening given() is a shared pre-existing gap, and re-fetching the first discovered group breaks streaming an in-progress group on the relay. Auto-merge enabled.

(written by Claude Opus 5.5)

@kixelated
kixelated merged commit 5b8afc5 into main Sep 24, 2026
7 checks passed
@kixelated
kixelated deleted the quest/main/cli-fetch branch September 24, 2026 23:14
This was referenced Sep 24, 2026
kixelated added a commit that referenced this pull request Sep 25, 2026
Carry main's new announce consumers over to the `announce::Event` shape
(#4059): cluster, auth_lifetime, hidden_cluster, smoke, and announce_to_serve
tests, plus the hidden-broadcast docs. `moq fetch` (#3965) already landed on
main, so its quest leaves this line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kixelated added a commit that referenced this pull request Sep 25, 2026
#3965, #3966, #3961, and #3972 merged to main, and moq-mux 0.10.3 and
@moq/loc 0.2.3 ship the empty LOC payload skip.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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