Repository navigation
Key session stats by a grant label instead of the auth root - #5731
Conversation
Co-Authored-By: OpenAI Codex <noreply@openai.com>
Co-Authored-By: OpenAI Codex <noreply@openai.com>
Retagging a session from A to B and back counted its live bytes twice on A, and a readout could dip while a session retagged or dropped, which stats readers treat as a counter reset. Each label row now holds its live sessions and folded total under one lock, and a retag cuts the session's counters with a single load under the old row's lock. Also counts datagram payload toward the label, skips excluded paths, keeps a row open while a meter outlives its session, keys moq-cli session stats by label, and updates stale "auth root" wording. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
c348b56 to
14f7a2e
Compare
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. |
|
Warning Review limit reachedYou'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 30 minutes. View limit details
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. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 14f7a2ee49
ℹ️ 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".
An embedder's lease update skipped Grant::validate, so a malformed stats label (or any other contract violation) could retag a live session. Both the lease and refresh paths now validate a changed grant first; one that admits nothing ends as Narrowed and one already past its expiry as Expired. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ba22e46563
ℹ️ 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".
A retag searched the row's live sessions linearly under its lock, so moving N co-labeled sessions cost O(N^2). Key them by session identity instead, and add a retag benchmark swept over labels and sessions per label: each move stays near 150 ns from 1 to 10,000 sessions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d39917116b
ℹ️ 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".
Presence::regressed skipped sent_bytes and received_bytes, so a source whose byte counters restarted while its other presence counters had caught up replaced its earlier contribution instead of starting a new segment, and merged byte totals could go backward. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Session stats rows are keyed by (tier, root, label). `root` stays the auth root and `SessionEntry::label` carries the optional grant label, with no fallback to the root. A new per-tier `labels.json` track sums labeled rows by label; `sessions.json` and `presence.json` stay keyed by root and sum across labels. The producer folds an ended row into its key's sum while the key lives on, so a sum never dips. `Handle::session` and `Handle::request` take `label: Option<PathOwned>`, and `Session::retag` moves tier and label without touching the root. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 17fe326086
ℹ️ 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".
`Auth::admit` validated one snapshot of the decider's grant and then re-read it for the token, so an embedder update in between could install an unchecked label. Admission now builds the token from the snapshot it checked; a later update still arrives as a change and is re-checked. `Refresh::new` likewise holds the grant it reads at protocol setup to `Grant::validate`, not only the rate check. Also notes in the stats docs that a label spanning groups appears on each group's track. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The auth root is for auth only. Session stats rows, `sessions.json`, presence tracks, and `--stats-depth` groups are keyed by the grant's stats label, and `SessionEntry::root` is renamed `label`. A grant without a label, and the relay's own refusals, record under the empty label; there is no fallback to the root. This drops the parallel `labels.json` track and the per-root sums. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolves #5811's prefix tracks against label-keyed presence: presence tracks and requests take the stats label, prefix tracks keep the broadcast path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Wire counters from #5773 follow the session's label and tier on retag. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Merging at 591be53: main merged, all checks green (TS validation and io_uring included), Codex reviewed this head with no findings. The earlier TS validation and acme failures were main-side flakes, unrelated to this PR. Decision taken while merging main: #5773's wire counters follow the label too ( (Written by Claude Opus 5.5) |
Problem
Authorization roots currently do two jobs: scope what a session may access and key its session statistics. Most sessions share a broad root (often
/), so per-root stats say little, and a narrowly scoped credential splits one project's usage across credential roots. Per-credential bytes only reach an auth decider throughLease::close, once a session ends.Approach
labelto Rust and JavaScript auth grants.Grant::validateandGrantSchemarefuse a label that is not a literal path.Tokencarries the label (PathOwned, empty when the grant names none) and hands it to session and HTTP request stats (cluster.rs,web.rs,moq-cli).[<tier>/]sessions.jsonis keyed by label,<label>/presence.jsonreplaces<root>/presence.json, and--stats-depthgroups sessions by the label's leading segments, the same way it grouped by root. Presence requests and their group check follow the label path.sent_bytesandreceived_bytes(payload this node sent to and received from those sessions) beside presence.(tier, label)row holds its live sessions (keyed by identity) and their counters at arrival under one lock, plus a folded total for sessions that left. A read sums them under that lock and folds in sessions no handle can write through anymore, so a readout never goes down. A retag cuts the session's counters with a single load under the old row's lock, then joins the new row from that cut, so a concurrent write counts exactly once.Session::set_tier(tier)becomesSession::retag(tier, label), called fromLease::endedandRefreshwhen a re-checked grant changes tier or label. Earlier bytes stay under the old label; later ones, including through meters handed out before the retag, go to the new one.Registry::reportonly once no session holds it and no meter outliving its session can still write to it.doc/concept/stats.md,doc/bin/relay/auth.md,doc/bin/relay/config.md,doc/bin/inspect.md,doc/lib/rs/moq-auth.md,doc/lib/js/auth.md, themoq-statscrate docs,rs/moq-net/MIGRATE.md, and the demo stats dashboard (demo/web/src/stats.{ts,html}). Retiresquest/m2/grant-label.md.Impact
[<tier>/]sessions.jsonentries are keyed by stats label rather than auth root, and presence tracks are requested as<label>/presence.jsonrather than<root>/presence.json. At--stats-depth1 or more, sessions group under their label's leading segments rather than their root's. Unlabeled sessions and the relay's own refusals appear under the empty label ("", andpresence.json), as unscoped refusals did under the empty root. Presence JSON (sessions.json,presence.json,totals.json) also gains additivesent_bytesandreceived_bytes. The traffic, totals, and requested prefix (<path>/traffic.json) tracks stay keyed by broadcast path and are unchanged apart from those byte fields.labelon the grant. Old grants remain valid. An older relay ignores the field; access is unchanged.stats::Handle::session(label),stats::Handle::request(label),stats::Handle::refuse(label, reason), andstats::Handle::wire(label, counters)take the stats label where they took the auth root.stats::Session::set_tier(tier)is replaced bystats::Session::retag(tier, label).stats::SessionEntry::rootis renamedlabel.moq_statspresence helpers and readers (presence_track,consume::Consumer::presence,aggregate::Consumer::presence) take a label; the signatures are unchanged.moq_auth::Grant::label,moq_auth::Error::InvalidLabel,moq_net::stats::Presence::{sent_bytes, received_bytes},moq_relay::auth::Token::label.GrantSchemagains optionallabel. The demo dashboard's sessions table now lists labels.Decisions
From the maintainer:
[<tier>/]sessions.jsonis keyed by label and a per-label presence track replaces<root>/presence.json. No separatelabels.jsonand no per-root sums.--stats-depthgroups and presence requests follow the label path the way they followed the root path. Labels are literal paths, so they fit that model unchanged.Settled by the quest plan:
labeland sits besidetier.set_tiergeneralizes into one(tier, label)retag rather than a second method.sent_bytes/received_bytes.Made during iteration (by the agent, unattended; challenge any of them):
Token::labelis aPathOwned, empty when the grant names none, rather than anOption: the empty path is already the stats key for "no label", like the default tier.moq-statsaggregation treats a drop insent_bytesorreceived_bytesas a reset, like the other presence counters, so merged byte totals never go backward. (From the Codex review.)lease::Producer::update) or a refreshed credential is held toGrant::validate, like the admitting grant, so a malformed label cannot retag a live session. An update that admits nothing ends asNarrowed; one past its expiry ends asExpired. (From the Codex review.)wire_tx/wire_rx, from feat(stats): collect owned transport wire counters #5773) follow the session's label like its other presence fields: a retag flushes the old(tier, label)row before the session moves, andstats::Handle::wiretakes a label. (Merge with main.)Grant::validate, so an update racing either step cannot install an unchecked label (an_invalid_label_added_before_protocol_setup_is_refused). (From the Codex review.)Verification
just fixjust checkcargo test -p moq-net --lib stats(wire_deltas_follow_label_and_tier_changesretags tier and label together; new:retag_back_counts_bytes_once,retag_moves_presence_between_labels_on_one_tier,session_bytes_outlive_the_session,excluded_paths_skip_session_bytes)cargo test -p moq-stats(new:byte_only_regression_begins_another_segment)cargo test -p moq-relay --lib auth(new:an_invalid_label_at_revalidation_ends_the_lease,an_invalid_label_added_before_protocol_setup_is_refused; the token test asserts an absent label is the empty label, not the root)cargo test -p moq-relay --test integration(a_moved_tier_retags_the_live_sessionmoves tier and label and asserts per-label presence and bytes end to end; refusals and HTTP requests without a label land under the empty label)cargo bench -p moq-net --features fuzz --bench stats -- stats/ --sample-size 10 --warm-up-time 1 --measurement-time 1on a shared, loaded machine: write path 3.7 ns path-only vs 7.5 ns with session bytes; retag about 300 ns per move, flat from 1 to 10,000 sessions per label and 1 to 100 labels; session report 69 ns (1 label x 1 session), 4.1 us (100x1), 9.0 us (100x10), 41 us (1000x1), 96 us (1000x10)CI notes for the latest head:
TS validationfails the same way on main's nightly (8bcbc7dfd, an mp2 audio hole in the TS round trip), and io_uring'sacme::tests::failed_validations_stop_short_of_the_rate_limithung once at its 30s bound where it normally passes in about 6s. That test points validations at a port it bound and released, so a concurrently running test can reuse the port and the mock's TLS dial waits forever; it is untouched here and tracked as a follow-up.(Written by Claude Opus 5.5)
🤖 Generated with Claude Code