Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3d43d6a
chore(quest): claim quest/m2/cluster-routes/acceptance.md
kixelated Nov 19, 2026
eb22e25
wip: lite-07 answers a prefix wider than the grant region by region
kixelated Nov 19, 2026
0a6c444
wip
kixelated Nov 19, 2026
f54eef4
wip
kixelated Nov 19, 2026
4c8ae61
wip
kixelated Nov 19, 2026
9de74e4
wip
kixelated Nov 19, 2026
1ca221e
wip
kixelated Nov 19, 2026
c795007
wip
kixelated Nov 19, 2026
74cffe2
wip
kixelated Nov 19, 2026
1be2923
fix(moq-net): lite-07 answers a prefix wider than the grant region by…
kixelated Nov 19, 2026
b8ad39a
wip review fixes
kixelated Nov 19, 2026
c992f20
fix(moq-net): a grant change keeps what a wider read tells again, and…
kixelated Nov 19, 2026
ff203d6
Merge origin/main into quest/m2/cluster-routes/acceptance
kixelated Nov 19, 2026
c6b136f
fix(moq-net): a grant change unsyncs only the readers it can show mor…
kixelated Nov 19, 2026
eb6f8a6
style: format
kixelated Nov 20, 2026
164756c
fix(moq-net): a grant change within a coarsened ask still orders the …
kixelated Nov 20, 2026
b698d67
Merge origin/main into quest/m2/cluster-routes/acceptance
kixelated Nov 20, 2026
7af8b24
fix(moq-net): a grant change holds one prefix per want, skips what li…
kixelated Nov 20, 2026
38133d0
fix(moq-net): a grant change holds what each pattern shows, until the…
kixelated Nov 20, 2026
0b80585
fix(moq-net): a grant change holds what the grant shows beyond what t…
kixelated Nov 20, 2026
6f67b10
fix(js/net): a grant head past the path limits holds no region, and a…
kixelated Nov 20, 2026
33a1cd1
test(js/net): type the expected suffix as a path
kixelated Nov 20, 2026
5c1eab2
Merge origin/main into quest/m2/cluster-routes/acceptance
kixelated Nov 20, 2026
b7a8c5c
fix(moq-net): lite-07 shows a claim above what the scope matches, and…
kixelated Nov 20, 2026
c2fdaf7
style(js/net): format the claim-above-scope test
kixelated Nov 20, 2026
8ba977c
Merge remote-tracking branch 'origin/main' into iterate-9202
kixelated Nov 20, 2026
335a2c5
fix(moq-net): lite-07 shows a claim only where the scope and what ser…
kixelated Nov 20, 2026
3557cb3
fix(js/net): type the scoped-claim test's cases
kixelated Nov 20, 2026
819e223
style(js/net): format the scoped-claim test
kixelated Nov 20, 2026
e9d1393
fix(js/net): a lite-07 claim is shown only where the handle and the g…
kixelated Nov 20, 2026
0845587
Merge remote-tracking branch 'origin/main' into iterate-9202
kixelated Nov 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion drafts/draft-lcurley-moq-lite.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,10 @@ The initial set is relative to this hop: a relay answers with what it holds with
The publisher MAY coalesce changes to a claim it has not yet sent, and sends no more claims before SYNCED than the initial set holds.
A retraction of a claim or route already sent MAY precede SYNCED.
A prefix outside the subscriber's [scope](#auth-stream) lists nothing and is SYNCED at once.
A prefix wider than the scope is answered as if each of the scope's regions inside it were requested, a region being the leading literal segments of one of the scope's [patterns](#path-pattern), and none lying within another: a claim above a region is presented at that region, sent only within the scope as any presented claim is (below), and the prefix's SYNCED follows every region's initial set.
So a subscriber whose scope's regions do not fit one ANNOUNCE_REQUEST asks for a prefix they share, the empty prefix at the widest, and still learns every region.
A change to the scope takes effect on the publisher's stream before the ANNOUNCE_OK answering any edit the publisher reads after it sends or reads the AUTH_OK, AUTH_ERROR, or stream end making the change.
An edit MAY change nothing, so a subscriber whose scope widens under a prefix it already asked for can send an empty edit and treat the region as synced at its ANNOUNCE_OK.

Each Add of an ANNOUNCE_REQUEST implicitly assigns the next Prefix ID on its sender's stream, each ROUTE to a routing node the stream has no live route to the next Route ID, and each ANNOUNCE_START the next Announce ID: three counters per stream starting at 0 that increment by 1 per assignment.
No id appears on the wire where it is assigned; both endpoints derive it from the message order on the (reliable, ordered) stream, and other messages reference it instead of repeating the prefix, the routing node, or the claim's path.
Expand All @@ -426,7 +430,8 @@ When the session closes, an endpoint MUST assume that every route and claim on t

A broadcast path has at most 32 segments and at most 4,096 bytes; a receiver MUST close the session with a PROTOCOL_VIOLATION on a longer one, except one resolved by [Compression](#announce-compression) or joined beneath a root of the receiver's own, whose claim it drops: the ANNOUNCE_START still assigns its Announce ID, the messages naming it stay valid, and the receiver SHOULD log and count it.
A claim covers a path when its prefix is a leading run of the path's segments; matching is per path segment, so a prefix never matches half a segment, and equality is byte-by-byte within each segment.
A publisher presents each claim inside a requested prefix and only the most specific claim at or above it, at that prefix itself, which is exactly the covered set the subscriber may see.
A publisher presents each claim inside a requested prefix and only the most specific claim at or above it, at that prefix itself, or at each region answering it, and sends those within the subscriber's scope, which is exactly the covered set the subscriber may see.
A presented claim is within the scope when the scope matches a path it covers, as a claim at `a` is under the scope `a/*`, which does not match `a` itself: a prefix answered with no claim has none covering a path the scope matches.
A claim presented above its own prefix carries how many segments broader it is than the path it is presented at, its Above, so the subscriber can tell it from a claim exactly at that path.
Every path on the stream is relative to the session, whichever requested prefix it lies in.

Expand Down Expand Up @@ -2309,6 +2314,7 @@ A stream that FINs without a GROUP_END carries a closed Group, which may have he
- A node closes a session whose peer leaves its Announce Stream undrained for 10 seconds.
- A publisher presents only the most specific claim covering the requested prefix.
- A subscriber whose scope confines it to some prefixes SHOULD request those, and edit its set when they change.
- A prefix wider than the subscriber's scope is answered region by region, a claim above a region presented at the region, so a subscriber whose regions do not fit one request asks for a prefix they share. A claim is within the scope when the scope matches a path it covers. A scope change takes effect before the ANNOUNCE_OK of any edit read after it, and an edit may change nothing.
- Added `Node` to TRACK, TRACKS, SUBSCRIBE, FETCH, and DATAGRAMS: the routing node announcing the claim the first hop selected, which every later hop follows.
- Replaced Warm and Cold Route Cost with one cost, which each link adds to.
- The Cost parameter must be at least 1.
Expand Down
8 changes: 5 additions & 3 deletions js/net/src/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,16 @@ export function hiddenBelow(prefix: Path.Valid, path: Path.Valid): boolean {
/**
* Where each carried route lands under the requested prefix: its suffix beneath the
* prefix, or the empty suffix for a route above it, where the most specific such route
* wins the way a request through the prefix would resolve.
* wins the way a request through the prefix would resolve. Only a candidate `shows` admits
* at the path it lands on competes.
*/
export function presented(
prefix: Path.Valid,
table: Advertisements,
carries: (covered: Path.Valid) => boolean,
// Lite-07: a route above the prefix keeps how many segments broader than the prefix it is.
keepAbove = false,
shows: (candidate: Advertised, at: Path.Valid) => boolean = () => true,
): Map<Path.Valid, Advertised> {
const out = new Map<Path.Valid, Advertised>();
let rootLen = -1;
Expand All @@ -134,7 +136,7 @@ export function presented(
// A scoped route covers only what it claims, so the best one that can serve the prefix wins.
const snap = firstEligible(
candidates,
(candidate) => !candidate.claim || candidate.claim.overlaps(requested),
(candidate) => (!candidate.claim || candidate.claim.overlaps(requested)) && shows(candidate, prefix),
);
if (!snap) continue;
rootLen = covered.length;
Expand All @@ -148,7 +150,7 @@ export function presented(
continue;
}
const suffix = Path.stripPrefix(prefix, covered);
const best = suffix !== null ? firstEligible(candidates) : undefined;
const best = suffix !== null ? firstEligible(candidates, (candidate) => shows(candidate, covered)) : undefined;
if (suffix !== null && best) out.set(suffix, best);
}
return out;
Expand Down
81 changes: 70 additions & 11 deletions js/net/src/lite/answer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@
// per broadcast the peer is shown, at no cost. The peer edits its prefixes in place: each edit
// takes effect at the ANNOUNCE_OK answering it, where both ends drop every claim within a prefix
// it removed, and the answer then tells what the added prefixes cover.
//
// A prefix wider than our grant is answered region by region, as if the peer had asked for each
// granted region inside it: a claim above a region is presented at the region. A claim is shown
// where the grant covers some path beneath it. A grant change is answered before the ANNOUNCE_OK of
// the next edit.

import { type GetPromise, type Getter, race } from "@moq/signals";
import type { Grant } from "../auth.ts";
import { ProtocolViolation } from "../error.ts";
import { coveringPrefixes, hiddenBelow, presented } from "../internal.ts";
import type * as Instance from "../instance.ts";
import { coveringPrefixes, hiddenBelow, presented, scopeHead } from "../internal.ts";
import * as Path from "../path.ts";
import { type Advertised, type Advertisements, type OriginConsumer, sameInstance } from "../wire.ts";
import { type Add, type AnnounceBroadcast, type Claim, claimsEqual, ownClaim, requestFits } from "./announce.ts";
Expand All @@ -22,7 +28,7 @@ export interface Publish {
/** The origin's claims, or undefined once it closed. */
advertised: Getter<Advertisements | undefined>;
/** The origin's scope, when the session publishes one. */
origin?: Pick<OriginConsumer, "covers">;
origin?: Pick<OriginConsumer, "covers" | "allowed">;
/** Our grant: only what it lets us publish is announced. */
grant?: Getter<Grant | undefined>;
/** Resolves once the tokens this session presented at setup are answered, so nothing is
Expand Down Expand Up @@ -185,6 +191,8 @@ export class Answer {
// Put the peer's request in effect: answer it, drop what the removed prefixes covered, tell
// what the added ones cover, and close each added prefix's initial set.
async #edit(request: { remove: bigint[]; add: [bigint, Prefix][] }) {
// A grant change the peer may have seen before this edit is answered before it.
if (this.#dirty) await this.#sync();
const removed: Path.Valid[] = [];
for (const id of request.remove) {
const prefix = this.#prefixes.get(id);
Expand Down Expand Up @@ -215,21 +223,51 @@ export class Answer {
const { advertised, origin } = this.#publish;
const table = origin ? advertised.peek() : undefined;
const grant = this.#publish.grant?.peek();
const granted = grant && regions(grant.publish);
// The claims the peer is shown, by their path from the session's root: the table under each
// prefix, less the hidden ones it did not ask for and whatever our grant does not let us
// publish, which is kept apart to tell a claim it no longer covers from one that ended.
// prefix, less the hidden ones it did not ask for and whatever our grant does not let us publish.
const latest = new Map<Path.Valid, Advertised>();
const ungranted = new Set<Path.Valid>();
// A claim is shown where the grant lets us publish some path it covers that the claim's own
// scope and the handle's both serve, as one at `a` serves `a/*` though `a` itself is not
// granted. An intersection too large to spell covers nothing, never more.
const shows = (snap: Advertised, path: Path.Valid) => {
if (!grant) return true;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
let beneath = new Path.Patterns([Path.Pattern.subtree(path)]);
try {
for (const scope of [snap.claim, origin?.allowed]) if (scope) beneath = scope.intersect(beneath);
} catch {
return false;
}
return [...beneath].some((pattern) => grant.publish.overlaps(pattern));
};
// Whether the advertisement a claim the peer holds came from is still in the table, as when
// its presentation moved: the claim is lost to the peer rather than ended, since its publisher
// never withdrew it. Another path's advertisement of the same instance proves nothing.
// Indexed once per diff, and only when a claim leaves.
let advertisements: Map<object, Set<Instance.Valid | undefined>> | undefined;
const stillAdvertised = (sent: Sent) => {
if (!advertisements) {
advertisements = new Map();
for (const candidates of table?.values() ?? []) {
for (const snap of candidates) {
const instances = advertisements.get(snap.identity) ?? new Set();
instances.add(snap.route.instance);
advertisements.set(snap.identity, instances);
}
}
}
return advertisements.get(sent.snap.identity)?.has(sent.snap.route.instance) ?? false;
};
const ids = [...this.#prefixes.keys()].sort((a, b) => (a < b ? -1 : 1));
for (const id of table ? ids : []) {
const prefix = this.#prefixes.get(id);
if (!prefix || !table) continue;
const carries = (covered: Path.Valid) => prefix.hidden || !hiddenBelow(prefix.path, covered);
// A claim covering the prefix from above keeps how many segments broader than it it is.
for (const [suffix, snap] of presented(prefix.path, table, carries, true)) {
const path = Path.join(prefix.path, suffix);
if (!grant || grant.publish.matches(path)) latest.set(path, snap);
else ungranted.add(path);
for (const read of reads(prefix.path, granted)) {
// A claim covering what is read from above keeps how many segments broader than it it is.
for (const [suffix, snap] of presented(read, table, carries, true, shows)) {
latest.set(Path.join(read, suffix), snap);
}
}
}

Expand All @@ -241,7 +279,7 @@ export class Answer {
};
for (const [path, sent] of [...this.#live]) {
// No longer granted, it is lost to the peer: its publisher never ended it.
if (!latest.has(path)) end(path, sent, ungranted.has(path));
if (!latest.has(path)) end(path, sent, !shows(sent.snap, path) || stillAdvertised(sent));
}
for (const [path, snap] of latest) {
const { instance, epoch, cost } = snap.route;
Expand All @@ -266,3 +304,24 @@ export class Answer {
return msgs;
}
}

// The regions `patterns` confine the peer to, none within another, or undefined when they allow
// every path. A head too long or deep to be a path holds none. Mirrors rs/moq-net's
// `interest_prefixes`.
function regions(patterns: Path.Patterns): Path.Valid[] | undefined {
if (patterns.contains(Path.Pattern.all())) return undefined;
const heads = new Set(
patterns
.toArray()
.map(scopeHead)
.filter((head) => Path.check(head) === undefined),
);
return [...heads].filter((head) => ![...heads].some((other) => other !== head && Path.hasPrefix(other, head)));
}

// What answers the requested `prefix`: the prefix itself when a region holds it or nothing confines
// the peer, and otherwise each region inside it.
function reads(prefix: Path.Valid, granted: Path.Valid[] | undefined): Path.Valid[] {
if (!granted || granted.some((region) => Path.hasPrefix(region, prefix))) return [prefix];
return granted.filter((region) => Path.hasPrefix(prefix, region));
}
Loading