Skip to content

feat(auth): a grant prices its session's link - #9696

Closed
kixelated wants to merge 3 commits into
mainfrom
quest/m1/grant-cost
Closed

kixelated wants to merge 3 commits into
mainfrom
quest/m1/grant-cost

Conversation

@kixelated

@kixelated kixelated commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Implements quest/m1/grant-cost.md and deletes it.

Problem

A relay accepting a session cannot price its link. Only the dialer can (Client::with_cost), and only once, at connect. A mesh coordinator that prices links by measured quality needs to set an accepted session's cost through its auth answer, and reprice it as quality changes without a reconnect.

Approach

  • moq_auth::Grant gains cost: Option<NonZeroU64>. @moq/auth's GrantSchema takes the same field (a positive int), and the shared corpus covers it. Zero, negative, fractional, string, and null values are refused, as is any unknown field.
  • moq-net gains session::Price: a cloneable handle for this side's link price, from Session::price() and server::Handshake::price(). It defaults to the dialed with_cost and can be set before the session learns a route. None falls back to the peer's SETUP price, then 1. Setting it reprices in place. Nothing goes on the wire, so other relays learn the new cost from the route adverts they already get.
    • lite-05/06: every route the announce stream holds (attached or withheld) is recharged and updated in its origin claim.
    • lite-07: new route::node::Stream::reprice / Router::reprice changes the port's cost. Routes heard from a routing neighbour reselect, claims an endpoint or scoped neighbour gave are recharged and restated, and the node re-advertises them.
    • lite-01..04 carry no route cost, so a price does nothing there, the same as with_cost today.
    • moq-transport charges each route as it arrives, so it reads the price once at start. A later set returns Error::Unsupported.
  • moq-relay: Refresh (the in-band auth supervisor) prices the link from the connection credential's grant only. The newest one is used if the credential was presented again. A request token's grant never prices the link. When the connection credential ends while another credential keeps the session alive, the price falls back to None. The price is set in Lease::preparing, before SETUP OK. If a re-check changes cost and the session can't apply it (moq-transport), the session ends with link cost changed: … and reconnects at the new price.
  • moq-tokio::server::Request::price() and the relay's sealed Incoming::price() expose the handshake's handle.
  • test/drill/mutations/subscriber-leaks-broadcasts.patch is retargeted onto the edited PrefixRun. It applies again and its mutation is unchanged.

Choices made without asking (listed for review):

  • cost is typed NonZeroU64, so zero can't be represented and is refused when the grant is parsed. That's stricter than the quest's "refused at validation", with the same effect.
  • Leases without in-band auth (gateways, and Lease::new callers) ignore cost, since they learn no routes.
  • A moq-transport server never declares its price in SETUP, matching lite, where only the dialer declares one.

Impact

  • moq-auth: Grant::cost (new public field; Grant is #[non_exhaustive]). Wire: the auth endpoint's grant JSON gains an optional cost. A relay that predates it refuses such a grant, which fails closed. An auth server must send cost only to relays that read it (branch on Request::relay), as doc/bin/relay/auth.md now says.
  • @moq/auth: GrantSchema / Grant gain optional cost.
  • moq-net: new session::Price (set, get), Session::price(), server::Handshake::price(). All additive. No moq-lite or moq-transport wire change.
  • moq-tokio: new server::Request::price().
  • Behavior: a relay re-check that changes cost reprices a lite session in place and ends a moq-transport one.

No breaking change, so no ! and no migration note.

Alternatives

  • A wire message pushing a session's cost to the peer. Rejected in the quest's plan: it needs versioning and nothing would use it.
  • Live repricing on moq-transport: store each advert's raw cost and recharge it under the subscriber's state lock. Not built, because moq-transport is the low-effort compatibility layer; see Waiting.

Compatibility with related PRs

  • moq-dev/moq#9630 (a subscriber's credential rides SUBSCRIBE and renews in place): those are request-scoped credentials, and this PR never prices from a request token, so a renewed one cannot reprice the link.
  • moq-dev/moq#9640 (a request grant admits only the request kinds it names): it adds a separate field to Grant and doesn't overlap. Whichever lands second rebases.
  • quest/m1/js-session-cost.md (running in parallel) adds Server::with_cost. That fits here: it can seed Handshake::price from the builder. This PR deletes only its link to this quest.

Validation

  • rs/moq-net/tests/integration/link_price.rs: over real mock sessions, a subscriber accepts links from two relays and prices them through Session::price() on the server side. Repricing the cheap link above the other moves the route on lite-06 and lite-07. Setting None returns it to the default 1. moq-transport refuses with Unsupported and keeps no price. Mutation check: with the lite-06 and lite-07 reprice calls removed, both lite tests fail.
  • route::relay::tests::a_repriced_link_reranks_what_it_gave: an endpoint's claims recharge (a claim at the ceiling stays there), and the best route moves off a routing neighbour whose link got dearer.
  • moq-relay auth::refresh::tests::the_connection_credential_prices_the_link: the price is set before SETUP OK, a re-check reprices in place, a request token's cost is ignored, and the price falls back to None once the connection credential expires.
  • moq-auth grant round-trip, cross-language vector, unknown/invalid field refusals, and corpus. js/auth bun test (290 pass) with the updated Rust vector.
  • just check on the branch: 11888 Rust tests pass and every module passes except drill, which was then fixed (just test drill-sensitivity --apply-only: 11 of 11 mutations apply).

Follow-ups

None.

Waiting

  • Maintainer: When a re-check changes a moq-transport session's cost, should the relay end the session (it reconnects at the new price) or should moq-transport reprice live?
    • End the session (Recommended) - shipped here; moq-transport is the low-effort compatibility layer, and the mesh coordinator this serves speaks moq-lite
    • Reprice live - store each advert's raw cost in the moq-transport subscriber and recharge it under the state lock; more code in a layer we keep minimal
  • Maintainer: Should @moq/net mirror Session.price / the accept-side price handle now?
    • Not until a JS consumer exists (Recommended) - JS never accepts relay sessions that carry grants, and the parallel js-session-cost quest already gives JS a fixed cost on connect and accept
    • Mirror it now - keeps Rust and JS API names in step, with nothing using the JS side yet

Models

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

🤖 Generated with Claude Code

(Written by Claude Opus 5.5)

kixelated and others added 3 commits November 26, 2026 09:26
Quest-Claim: f551eaa9b5db85fa
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 A grant prices its session feat(auth): a grant prices its session's link Nov 26, 2026
@kixelated

Copy link
Copy Markdown
Collaborator Author

Maintainer decision (relayed from the maintainer's /quest-run round, 2026-11-26):

  • A changed cost on a moq-transport session: ✅ reprice live (rejected: end the session; keep the old price until reconnect; graceful GOAWAY). Ending the session is too heavy-handed, and it makes the relay behave differently per protocol version, which moq-net should hide. Store each advert's uncharged cost in the moq-transport subscriber and recharge it under the state lock, so both versions re-rank in place.
  • Mirror Session::price() / the accept-side price handle in @moq/net: ✅ Rust only for now (rejected: mirror it now). JS never accepts relay sessions that carry grants; add it once a JS accept-side consumer exists.

(Written by Claude Opus 5.5)

@kixelated

Copy link
Copy Markdown
Collaborator Author

Superseded by the 2026-11-26 maintainer /quest-plan decision:

  • Dropping Grant::cost and Lease::update live repricing (quest/m1/grant-cost.md) in favor of automatic reversible draining route demotion on Stale sessions in moq-net (tracked in the new quest/m1/stale-route-demotion.md), plus public RouteInfo::draining(), keep_alive (soft, hard) config on moq_tokio::quic::Config and moq-relay's [limits.peer.quic], and documenting the moq-auth::Grant boundary in rs/moq-auth/AGENTS.md.
  • Offer.draining (DRAINING = 0x2) already propagates across multi-hop lite-07 meshes, is verified convergent, recovers cleanly on Live, outranks all priorities and costs without a sentinel, and needs zero wire or moq-auth changes.

Closing this PR as superseded.

(Written by Gemini 4 Neon with high)

@kixelated

Copy link
Copy Markdown
Collaborator Author

Superseding the 2026-11-25 decision (maintainer, /quest-plan on 2026-11-26): closing this PR and dropping Grant::cost (quest/m1/grant-cost.md).

  • Decision: ✅ moq-net will automatically demote Stale sessions (from keep-alive) using the existing reversible draining rank (Peer.stale: bool, never sending Msg::Drain, with Offer.draining already propagating across lite-07 hops and RouteInfo::draining(&self) -> bool exposed for consumers). Rejected: keeping Grant::cost + Lease::update live repricing here; adding a local Session::price() handle.
  • Why: Routing cost and transport liveness do not belong in moq-auth::Grant. Auto-demoting Stale via the existing draining rank avoids wire/auth changes, avoids raw-cost storage in moq-transport, avoids arbitrary STALE_COST sentinels, and gives CDNs generic stalled-link failover too.
  • Replacement: Planned in moq-dev/moq (quest/m1/stale-route-demotion.md, requiring quest/m1/keep-alive.md) along with documenting the moq-auth boundary rule in rs/moq-auth/AGENTS.md.

(Written by Gemini 4 Neon with high)

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