From 1a5c88660c1c58d478690b1cb335397682592476 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Fri, 20 Nov 2026 00:30:28 -0800 Subject: [PATCH 01/11] chore(quest): claim quest/m2/lite07-claim-reach.md Quest-Claim: 0a03b97c215265f2 From 282bc82ad54faf8510cee8f9c4af940b5cfe22ca Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Fri, 20 Nov 2026 01:31:16 -0800 Subject: [PATCH 02/11] fix(moq-net): a lite-07 answer holds SYNCED for what a grant change reads instead A grant change before a prefix's SYNCED counted the mounts read in place of those it dropped, but not the session key's own new reads, so dropping the old mount released SYNCED before their initial set. A claim the answer no longer shows while the node still tells it, as when a change queued before a grant change is judged by the new grant, now ends as lost, not withdrawn. A property test drives the answer through random grant changes, claims, mounts, and edits, interleaved with its output, and checks both promises. Co-Authored-By: Claude Opus 5.5 --- quest/m2/lite07-synced-grant-changes.md | 36 + rs/moq-net/src/lite/publisher/routed.rs | 26 +- rs/moq-net/src/lite/publisher/routed/tests.rs | 675 ++++++++++++++++++ 3 files changed, 729 insertions(+), 8 deletions(-) create mode 100644 quest/m2/lite07-synced-grant-changes.md create mode 100644 rs/moq-net/src/lite/publisher/routed/tests.rs diff --git a/quest/m2/lite07-synced-grant-changes.md b/quest/m2/lite07-synced-grant-changes.md new file mode 100644 index 0000000000..3d1566a89b --- /dev/null +++ b/quest/m2/lite07-synced-grant-changes.md @@ -0,0 +1,36 @@ +# [M] A lite-07 answer's SYNCED holds across grant changes + +## Goal + +A lite-07 publisher (Rust `lite/publisher/routed.rs`, JS `js/net/src/lite/answer.ts`) +sends a prefix's SYNCED only once every claim the grant in effect shows under it has +had its Start, however grant changes (widen, narrow, move, revoke), claims, mounts, and +the peer's edits interleave with the output. A claim that leaves only because of the +permit ends as lost, never as withdrawn. A claim is shown only where its own reach, +the handle's scope, and the permit share a path. A property test in each language +checks these over random sequences and stays fast enough for `just check`. + +## Plan + +Found by CodeRabbit on [moq-dev/moq#9202](https://github.com/moq-dev/moq/pull/9202), +whose answer this fixes: each review round there found another ordering, so this quest +replaces case-by-case fixes with a property test. + +- ✅ Fold [the claim-reach quest](/quest/m2/lite07-claim-reach.md) in (rejected: keep + it separate): the same `shows` the property exercises, and its tests share the + harness. +- The property's oracle is differential: when SYNCED goes out, a fresh answer on the same + origin, under the grant in effect in stream order (the last grant marker the answer + processed), asked for the same prefix and drained, names the claims required. Only those + present since the latest read for the prefix started (its edit or that grant change) + are required, since a claim arriving after its read's initial set is live. +- Rust carries each claim's reach (`origin::RouteEntry::reach`, translated through a + mount) to `Answer::shows`, looked up in the origin when the node tells the claim, and + intersects it with the permit beneath the presented path before the handle check. JS + applies the claim and handle scope intersections with or without a grant. +- Settled on #9202, not reopened: answering region by region (option D); a synced reader + goes unsynced only when a widening can show it more; a claim is shown when the scope + matches some path it covers; replacement mounts hold SYNCED until their initial set + arrives. + +Public API: none. Wire: none. diff --git a/rs/moq-net/src/lite/publisher/routed.rs b/rs/moq-net/src/lite/publisher/routed.rs index 1af956677b..217207cfa1 100644 --- a/rs/moq-net/src/lite/publisher/routed.rs +++ b/rs/moq-net/src/lite/publisher/routed.rs @@ -530,8 +530,8 @@ impl Answer { let holds = std::mem::replace(&mut mount.holds, Holds::Nothing); holds.synced().then_some(mount.prefix) } - // What a grant change reads starts after its prefix's SYNCED, and once all - // of it is in, what the change no longer shows goes. + // What a grant change reads: once all of it is in, what the change no longer + // shows goes. A prefix not yet synced waits for it too. None if !self.answering => { if let Some(left) = self.regranting.as_mut() { *left = left.saturating_sub(1); @@ -540,7 +540,9 @@ impl Answer { self.resync(writer)?; } } - None + (self.prefixes.iter()) + .find(|(_, prefix)| !prefix.synced && prefix.reads.contains(&path)) + .map(|(id, _)| *id) } None => (self.prefixes.iter()) .find(|(_, prefix)| { @@ -680,20 +682,21 @@ impl Answer { .unwrap_or_default(); let dropped: Vec = prefix.reads.difference(&reads).cloned().collect(); let added: Vec = reads.difference(&prefix.reads).cloned().collect(); - // Before its SYNCED, the prefix waits for the mounts read in place of those that go, - // counted before the ones that go release it. + // Before its SYNCED, the prefix waits for what is read in place of what goes, the + // session's key and the mounts beneath each read alike, counted before the mounts + // that go release it. let holds = match prefix.synced { true => Holds::Main, false => Holds::Both, }; - let mut mounted = 0; + let mut waits = added.len(); for read in added { - mounted += self.mount(id, read, holds)?; + waits += self.mount(id, read, holds)?; } let prefix = self.prefixes.get_mut(&id).expect("listed above"); prefix.reads = reads; if !prefix.synced { - prefix.waiting += mounted; + prefix.waiting += waits; } // The mounts beneath a read the grant no longer shows go with it. let sources: Vec = (self.mounts.iter()) @@ -923,6 +926,10 @@ impl Answer { } (Some(_), None) => { let (id, _) = self.live.remove(&key).expect("matched above"); + // Still told, it left because the answer no longer shows it, as when a change + // queued before a grant change is judged by the new grant: its publisher never + // ended it. + let lost = lost || self.told.contains_key(&key); writer.buffer(&Wire::End { id, lost })?; self.encoder.end(id); } @@ -970,3 +977,6 @@ impl Answer { } } } + +#[cfg(test)] +mod tests; diff --git a/rs/moq-net/src/lite/publisher/routed/tests.rs b/rs/moq-net/src/lite/publisher/routed/tests.rs new file mode 100644 index 0000000000..ca0aceeb7a --- /dev/null +++ b/rs/moq-net/src/lite/publisher/routed/tests.rs @@ -0,0 +1,675 @@ +//! The lite-07 answer checked over random grant changes, claims, mounts, and edits, +//! interleaved with the order its node keys' output is sent in. +//! +//! Two promises, each judged as a peer sees the stream: +//! +//! - When a prefix's SYNCED goes out, every claim the grant in effect shows under it has had +//! its Start. The grant in effect is the one whose change the session's key answered last; +//! a change queued behind it may only take claims away. A claim is owed only when it was +//! there before the read that tells it started: the edit adding the prefix, or the grant +//! change in effect. What a fresh answer under that grant tells for the prefix is what the +//! grant shows. +//! - A claim that leaves while its publisher still announces it ends as lost, never as +//! withdrawn. +//! +//! `MOQ_ANSWER_SEED` and `MOQ_ANSWER_CASES` pick the cases. + +use std::collections::{BTreeMap, BTreeSet}; +use std::sync::{Arc, Mutex}; + +use proptest::prelude::*; +use proptest::test_runner::{Config, RngSeed, TestCaseError, TestRunner}; + +use super::Answer; +use crate::coding::Decode; +use crate::lite::{self, AnnounceBroadcast, Version, subscriber::route_stream::Writer, test_transport::*}; +use crate::model::ProduceTest; +use crate::{Hop, Instance, Path, Pattern, Patterns, origin}; + +/// Where claims are announced: some above what grants and prefixes name, one hidden, and +/// some beneath the mount target `s`. +const PATHS: &[&str] = &["a", "a/x", "a/.h", "a/m/x", "b", "b/c", "s", "s/x"]; + +/// The scopes claims are announced through, which bound what each may serve. +const SCOPES: &[&[&str]] = &[&["**"], &["*/x"]]; + +/// The grants the peer gives: widen, narrow, move, and revoke between them. +const GRANTS: &[&[&str]] = &[ + &["**"], + &["a/**"], + &["b/**"], + &["a/x/**"], + &["a/*"], + &["a/m/**"], + &["a/**", "b/**"], + &[], +]; + +/// The prefixes the peer asks for. +const PREFIXES: &[&str] = &["", "a", "a/x", "b", "a/m", "s"]; + +/// The handle's mount, if any: its point and target. +const MOUNTS: &[Option<(&str, &str)>] = &[None, Some(("a", "s")), Some(("a/m", "s"))]; + +/// The handle's own scope. +const HANDLES: &[&[&str]] = &[&["**"], &["a/**", "b/**", "s/**"]]; + +fn path(path: &str) -> Path { + Path::new(path).unwrap() +} + +fn patterns(members: &[&str]) -> Patterns { + members + .iter() + .map(|member| member.parse::().unwrap()) + .collect() +} + +fn grant(index: usize) -> crate::auth::Grant { + crate::auth::Grant { + publish: Patterns::default(), + subscribe: patterns(GRANTS[index]), + expires: None, + } +} + +#[derive(Clone, Debug)] +enum Op { + /// The grant changes and the session notices. + Grant(usize), + /// The grant changes, noticed only by the peer's next edit. + Quiet(usize), + Announce { + path: usize, + scope: usize, + }, + Withdraw(usize), + Reprice { + path: usize, + cost: u64, + }, + /// Removes the prefixes in effect whose bit is set, and adds these. + Edit { + remove: u8, + add: Vec<(usize, bool)>, + }, + /// Send one thing the session's key queued. + Main, + /// Send one thing a mount queued. + Mount(usize), +} + +#[derive(Clone, Debug)] +struct Case { + mount: usize, + handle: usize, + initial: Option, + /// Claims announced before anything else, each a path and a scope. + claims: Vec<(usize, usize)>, + ops: Vec, + /// Whether what is left goes out the mounts' first, rather than the session's key's + /// first as a session sends it. + mounts_first: bool, +} + +/// A prefix to ask for, the root most often: it holds every region a grant moves between. +fn prefix() -> impl Strategy { + prop_oneof![2 => Just(0), 3 => 1..PREFIXES.len()] +} + +fn op() -> impl Strategy { + prop_oneof![ + 6 => (0..GRANTS.len()).prop_map(Op::Grant), + 1 => (0..GRANTS.len()).prop_map(Op::Quiet), + 2 => (0..PATHS.len(), 0..SCOPES.len()).prop_map(|(path, scope)| Op::Announce { path, scope }), + 1 => (0..PATHS.len()).prop_map(Op::Withdraw), + 4 => (0..PATHS.len(), 1..4u64).prop_map(|(path, cost)| Op::Reprice { path, cost }), + 3 => (any::(), proptest::collection::vec((prefix(), any::()), 0..3)) + .prop_map(|(remove, add)| Op::Edit { remove, add }), + 5 => Just(Op::Main), + 3 => (0..4usize).prop_map(Op::Mount), + ] +} + +fn case() -> impl Strategy { + ( + prop_oneof![1 => Just(0), 4 => 1..MOUNTS.len()], + 0..HANDLES.len(), + proptest::option::weighted(0.8, 0..GRANTS.len()), + proptest::collection::vec((0..PATHS.len(), 0..SCOPES.len()), 0..6), + proptest::collection::vec(op(), 1..24), + any::(), + ) + .prop_map(|(mount, handle, initial, claims, ops, mounts_first)| Case { + mount, + handle, + initial, + claims, + ops, + mounts_first, + }) +} + +/// A claim as the peer holds it: its path from the session's root, and its instance. +type Held = (Path, Instance); + +/// The announce stream's bytes, decoded as the peer reads them. +struct Peer { + writes: Arc>>, + cursor: usize, + decoder: lite::AnnounceDecoder, + /// The claims it holds, by Announce ID. + live: BTreeMap, +} + +impl Peer { + fn new(log: &Log) -> Self { + Self { + writes: log.writes.clone(), + cursor: 0, + decoder: lite::AnnounceDecoder::default(), + live: BTreeMap::new(), + } + } + + /// Every message written since the last call. + fn take(&mut self) -> Vec { + let buf = self.writes.lock().unwrap()[self.cursor..].to_vec(); + let mut slice = &buf[..]; + let mut msgs = Vec::new(); + while !slice.is_empty() { + let msg = crate::coding::decode_buf(&mut slice, Version::Lite07, |r, v| AnnounceBroadcast::decode(r, v)); + msgs.push(msg.expect("announce message")); + } + self.cursor += buf.len(); + msgs + } + + fn start(&mut self, suffix: &lite::PathRef, instance: &Instance) -> Held { + let path = self + .decoder + .start(Some(suffix.clone())) + .unwrap() + .expect("a path the peer holds"); + let held = (path, instance.clone()); + self.live.insert(self.decoder.last(), held.clone()); + held + } + + fn end(&mut self, id: u64) -> Held { + self.decoder.end(id).unwrap(); + self.live.remove(&id).expect("ends a live claim") + } + + /// Both ends drop every claim within a prefix the edit removed. + fn drop_within(&mut self, removed: &[Path]) { + let gone: Vec = (self.live.iter()) + .filter(|(_, (path, _))| removed.iter().any(|prefix| path.has_prefix(prefix))) + .map(|(id, _)| *id) + .collect(); + for id in gone { + self.end(id); + } + } + + fn holds(&self) -> BTreeSet { + self.live.values().cloned().collect() + } +} + +/// A writer to a fresh log, and the peer reading it. +fn stream() -> (Writer, Peer) { + let log = Log::default(); + let peer = Peer::new(&log); + let writer = Writer::new( + crate::transport::boxed::SendStream::new(SinkSend::new(log)), + Version::Lite07, + ); + (writer, peer) +} + +fn flush(writer: &mut Writer) { + assert!(writer.poll_flush(&kio::Waiter::noop()).is_ready()); +} + +/// What a fresh answer on `consumer` under `grant` tells for `prefix`, once it is all sent. +fn shown(consumer: &origin::Consumer, grant: Option, prefix: &Path, hidden: bool) -> BTreeSet { + let auth = crate::auth::Link::new(false); + if let Some(index) = grant { + auth.handle().authorize(&self::grant(index)); + } + let mut answer = Answer::alone_on(consumer.clone(), auth); + let (mut writer, mut peer) = stream(); + answer + .request(false, Vec::new(), vec![(prefix.clone(), hidden)]) + .unwrap(); + answer.drain(&mut writer).unwrap(); + flush(&mut writer); + for msg in peer.take() { + match msg { + AnnounceBroadcast::Start { suffix, instance, .. } => { + peer.start(&suffix, &instance); + } + AnnounceBroadcast::End { id, .. } => { + peer.end(id); + } + _ => {} + } + } + peer.holds() +} + +/// A prefix in effect: its path, its Hidden, and the step that asked for it. +struct Asked { + path: Path, + hidden: bool, + at: usize, +} + +/// An edit not answered yet: the Prefix IDs it removes, the prefixes it adds, and its step. +struct Edit { + remove: Vec, + add: Vec<(u64, Path, bool)>, + at: usize, +} + +/// A claim the origin holds: its route, instance, and the step that announced it. +struct Claimed { + route: crate::model::AnnounceProducer, + instance: Instance, + at: usize, +} + +struct Sim { + origin: origin::Producer, + consumer: origin::Consumer, + auth: crate::auth::Link, + answer: Answer, + writer: Writer, + peer: Peer, + /// The step of each op that is no drain, so a claim's age compares with a read's. + step: usize, + claims: BTreeMap, + next_instance: u64, + /// The grant the answer started from, then each change it queued, with its step. + grants: Vec<(usize, Option)>, + /// The grant last given, queued or not. + given: Option, + prefixes: BTreeMap, + next_prefix: u64, + edit: Option, +} + +impl Sim { + fn new(case: &Case) -> Self { + let origin = Hop::new(1).unwrap().produce(); + let handle = patterns(HANDLES[case.handle]); + let consumer = match MOUNTS[case.mount] { + Some((at, target)) => origin.mount(at, target).unwrap().scope("", &handle).unwrap().consume(), + None => origin.consume().scope("", &handle).unwrap(), + }; + let auth = crate::auth::Link::new(false); + if let Some(index) = case.initial { + auth.handle().authorize(&grant(index)); + } + let answer = Answer::alone_on(consumer.clone(), auth.clone()); + let (writer, peer) = stream(); + Self { + origin, + consumer, + auth, + answer, + writer, + peer, + step: 0, + claims: BTreeMap::new(), + next_instance: 0, + grants: vec![(0, case.initial)], + given: case.initial, + prefixes: BTreeMap::new(), + next_prefix: 0, + edit: None, + } + } + + /// How many grant changes the session's key queued and has not answered. + fn unanswered(&self) -> usize { + (self.answer.markers.iter()) + .filter(|marker| matches!(marker, super::Marker::Grant { .. })) + .count() + } + + /// Run `f`, recording a grant change it queued. + fn queues(&mut self, f: impl FnOnce(&mut Self) -> T) -> T { + let before = self.unanswered(); + let out = f(self); + if self.unanswered() > before { + self.grants.push((self.step, self.given)); + } + out + } + + fn apply(&mut self, op: &Op) -> Result<(), TestCaseError> { + if !matches!(op, Op::Main | Op::Mount(_)) { + self.step += 1; + } + match op { + Op::Grant(index) | Op::Quiet(index) => { + self.given = Some(*index); + self.auth.handle().authorize(&grant(*index)); + if matches!(op, Op::Grant(_)) { + self.queues(|sim| sim.answer.poll_permit(&kio::Waiter::noop())) + .map_err(|err| TestCaseError::fail(format!("poll_permit: {err:?}")))?; + } + } + Op::Announce { path: index, scope } => { + if self.claims.contains_key(index) { + return Ok(()); + } + let Ok(producer) = self.origin.scope("", &patterns(SCOPES[*scope])) else { + return Ok(()); + }; + self.next_instance += 1; + let instance: Instance = format!("i{}", self.next_instance).parse().unwrap(); + let info = origin::RouteInfo::new().with_instance(instance.clone(), 0); + if let Ok(route) = producer.announce(PATHS[*index], info) { + let at = self.step; + self.claims.insert(*index, Claimed { route, instance, at }); + } + } + Op::Withdraw(index) => { + self.claims.remove(index); + } + Op::Reprice { path: index, cost } => { + if let Some(held) = self.claims.get(index) { + let info = origin::RouteInfo::new() + .with_instance(held.instance.clone(), 0) + .with_cost(*cost); + held.route.update(info).unwrap(); + } + } + Op::Edit { remove, add } => { + if self.edit.is_some() { + return Ok(()); + } + let remove: Vec = (self.prefixes.keys().enumerate()) + .filter(|(bit, _)| *bit < 8 && remove & (1 << bit) != 0) + .map(|(_, id)| *id) + .collect(); + // Only what a peer may ask for: no prefix twice, or at or below another in the set. + let mut set: Vec = (self.prefixes.iter()) + .filter(|(id, _)| !remove.contains(id)) + .map(|(_, asked)| asked.path.clone()) + .collect(); + let mut adds = Vec::new(); + for (index, hidden) in add { + let prefix = path(PREFIXES[*index]); + if set + .iter() + .all(|other| !other.has_prefix(&prefix) && !prefix.has_prefix(other)) + { + set.push(prefix.clone()); + adds.push((prefix, *hidden)); + } + } + let add = adds; + let asked = self.queues(|sim| sim.answer.request(false, remove.clone(), add.clone())); + prop_assert!(asked.is_ok(), "a valid edit is refused: {asked:?}"); + { + let mut next = self.next_prefix; + let add = (add.into_iter()) + .map(|(path, hidden)| { + next += 1; + (next - 1, path, hidden) + }) + .collect(); + self.next_prefix = next; + self.edit = Some(Edit { + remove, + add, + at: self.step, + }); + } + } + Op::Main | Op::Mount(_) => { + self.send(op)?; + return Ok(()); + } + } + // The origin feeds its node what changed, as its driver would. + self.origin.route_node(); + flush(&mut self.writer); + self.read() + } + + /// Send one thing the session's key, or the `nth` mount, queued, returning whether there + /// was one. The key waits while it is held. + fn send(&mut self, op: &Op) -> Result { + let waiter = kio::Waiter::noop(); + self.answer.main.flush(); + let (source, msg) = match op { + Op::Main if self.answer.holding() => return Ok(false), + Op::Main => match self.answer.main.try_wire() { + Some(msg) => (super::MAIN, msg), + None => return Ok(false), + }, + Op::Mount(nth) => { + let Some(source) = (self.answer.mounts.keys()) + .nth(nth % self.answer.mounts.len().max(1)) + .copied() + else { + return Ok(false); + }; + match self.answer.mounts[&source].stream.poll_wire(&waiter) { + std::task::Poll::Ready(msg) => (source, msg), + std::task::Poll::Pending => return Ok(false), + } + } + _ => unreachable!("only a drain sends"), + }; + (self.answer.sourced(&mut self.writer, source, msg)) + .map_err(|err| TestCaseError::fail(format!("output: {err:?}")))?; + self.origin.route_node(); + flush(&mut self.writer); + self.read()?; + Ok(true) + } + + /// Read what the answer sent, checking each promise as the peer meets it. + fn read(&mut self) -> Result<(), TestCaseError> { + for msg in self.peer.take() { + match msg { + AnnounceBroadcast::Start { suffix, instance, .. } => { + self.peer.start(&suffix, &instance); + } + AnnounceBroadcast::Change { id, .. } => { + prop_assert!(self.peer.live.contains_key(&id), "a change to {id}, which is not live"); + } + AnnounceBroadcast::End { id, lost } => { + let (path, instance) = self.peer.end(id); + let announced = self.claims.values().any(|held| held.instance == instance); + prop_assert!( + lost || !announced, + "{path} ({instance}) ended as withdrawn while its publisher still announces it" + ); + } + AnnounceBroadcast::Ok => { + let edit = self.edit.take().expect("an ANNOUNCE_OK answers an edit"); + let removed: Vec = (edit.remove.iter()) + .filter_map(|id| self.prefixes.remove(id)) + .map(|asked| asked.path) + .collect(); + self.peer.drop_within(&removed); + for (id, path, hidden) in edit.add { + self.prefixes.insert( + id, + Asked { + path, + hidden, + at: edit.at, + }, + ); + } + } + AnnounceBroadcast::Synced { prefix } => self.synced(prefix)?, + msg => prop_assert!(false, "a claims-only peer is sent {msg:?}"), + } + } + Ok(()) + } + + /// SYNCED for `id` went out: every claim the grant in effect shows under it, there before + /// the read that tells it started, has had its Start. That read started with the edit + /// adding the prefix, or with the latest grant change in effect that showed the claim + /// there when the one before did not. + fn synced(&self, id: u64) -> Result<(), TestCaseError> { + let asked = self.prefixes.get(&id).expect("SYNCED names a prefix in effect"); + let effect = self.grants.len() - 1 - self.unanswered(); + // The grant the edit was read under, then each change answered or queued since. + let first = (self.grants.iter().rposition(|(step, _)| *step <= asked.at)) + .unwrap_or(0) + .min(effect); + let views: Vec> = (self.grants[first..].iter()) + .map(|(_, grant)| shown(&self.consumer, *grant, &asked.path, asked.hidden)) + .collect(); + let view = |index: usize| &views[index - first]; + let held = self.peer.holds(); + for claim in view(effect) { + // A change queued behind the one in effect may only take claims away. + if (effect + 1..self.grants.len()).any(|later| !view(later).contains(claim)) { + continue; + } + let since = (first + 1..=effect) + .rev() + .find(|index| !view(index - 1).contains(claim)) + .map_or(asked.at, |index| self.grants[index].0); + let (path, instance) = claim; + let old = (self.claims.values()).any(|held| held.instance == *instance && held.at < since); + prop_assert!( + !old || held.contains(claim), + "SYNCED for {:?} went out before {path} ({instance}) under grant {:?}", + asked.path, + self.grants[effect].1.map(|index| GRANTS[index]), + ); + } + Ok(()) + } +} + +fn run(case: &Case) -> Result<(), TestCaseError> { + let mut sim = Sim::new(case); + for (path, scope) in &case.claims { + sim.apply(&Op::Announce { + path: *path, + scope: *scope, + })?; + } + for op in &case.ops { + sim.apply(op)?; + } + // Then everything queued goes out, one side drained before the other. + loop { + let mut sent = false; + if !case.mounts_first { + while sim.send(&Op::Main)? { + sent = true; + } + } + for nth in 0..sim.answer.mounts.len() { + while sim.send(&Op::Mount(nth))? { + sent = true; + } + } + if !sent && !sim.send(&Op::Main)? { + return Ok(()); + } + } +} + +/// Runs the cases `MOQ_ANSWER_SEED` and `MOQ_ANSWER_CASES` pick. +#[test] +fn synced_follows_what_the_grant_shows() { + let setting = |name: &str, fallback: u64| std::env::var(name).map_or(fallback, |value| value.parse().expect(name)); + let seed = setting("MOQ_ANSWER_SEED", 0x616e73); + let count = setting("MOQ_ANSWER_CASES", 1024) as u32; + let mut runner = TestRunner::new(Config { + cases: count, + rng_seed: RngSeed::Fixed(seed), + failure_persistence: None, + ..Default::default() + }); + runner.run(&case(), |case| run(&case)).unwrap(); +} + +/// Each message `answer` sends once everything queued goes out, the session's key first. +fn sent(answer: &mut Answer, writer: &mut Writer, peer: &mut Peer) -> Vec { + answer.drain(writer).unwrap(); + flush(writer); + peer.take() +} + +/// A root request under `a/**` still waiting on the mount at `a` when the grant moves to +/// `b/**` holds its SYNCED for the initial set of `b`, read in place of `a`. +#[test] +fn a_grant_change_before_synced_holds_it_for_what_is_read_instead() { + let origin = Hop::new(1).unwrap().produce(); + let _bc = origin.announce("b/c", origin::RouteInfo::new()).unwrap(); + let _cam = origin.announce("s/cam", origin::RouteInfo::new()).unwrap(); + let consumer = origin + .mount("a", "s") + .unwrap() + .scope("", &patterns(&["**"])) + .unwrap() + .consume(); + let auth = crate::auth::Link::new(false); + auth.handle().authorize(&grant(1)); + let mut answer = Answer::alone_on(consumer, auth.clone()); + let (mut writer, mut peer) = stream(); + answer.request(false, Vec::new(), vec![(path(""), false)]).unwrap(); + // The session's key answers the edit and sends what it reads of `a` before the mount at + // `a` sends its initial set; the grant moves meanwhile. + let mut msgs = Vec::new(); + while let Some(msg) = answer.main.try_wire() { + answer.output(&mut writer, msg).unwrap(); + } + auth.handle().authorize(&grant(2)); + answer.poll_permit(&kio::Waiter::noop()).unwrap(); + msgs.extend(sent(&mut answer, &mut writer, &mut peer)); + let start = msgs + .iter() + .position(|msg| matches!(msg, AnnounceBroadcast::Start { .. })); + let synced = msgs + .iter() + .position(|msg| *msg == AnnounceBroadcast::Synced { prefix: 0 }); + assert!(start.is_some() && start < synced, "{msgs:?}"); +} + +/// A re-price queued before the grant revokes the claim is judged by the new grant, and +/// the claim it hides ends as lost, since its publisher never withdrew it. +#[test] +fn a_change_queued_before_a_revocation_ends_its_claim_as_lost() { + let origin = Hop::new(1).unwrap().produce(); + let ac = origin.announce("a/c", origin::RouteInfo::new()).unwrap(); + let auth = crate::auth::Link::new(false); + auth.handle().authorize(&grant(1)); + let mut answer = Answer::alone_on(origin.consume(), auth.clone()); + let (mut writer, mut peer) = stream(); + answer.request(false, Vec::new(), vec![(path(""), false)]).unwrap(); + let first = sent(&mut answer, &mut writer, &mut peer); + let AnnounceBroadcast::Start { instance, .. } = first[1].clone() else { + panic!("{first:?}"); + }; + ac.update(origin::RouteInfo::new().with_instance(instance, 0).with_cost(5)) + .unwrap(); + origin.route_node(); + auth.handle().authorize(&grant(2)); + answer.poll_permit(&kio::Waiter::noop()).unwrap(); + let revoked = sent(&mut answer, &mut writer, &mut peer); + let ends: Vec = (revoked.iter()) + .filter_map(|msg| match msg { + AnnounceBroadcast::End { lost, .. } => Some(*lost), + _ => None, + }) + .collect(); + assert_eq!(ends, [true], "{revoked:?}"); +} From d2a90c5724037e044935e03482b5a117f943bd79 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Fri, 20 Nov 2026 01:36:55 -0800 Subject: [PATCH 03/11] fix(moq-net): a lite-07 answer shows a claim only where its route can serve The answer judged the permit against the handle's scope but never the claim's own reach, so a route scoped to a/*/x at a was shown under a/q/y, or under a grant it shares no path with. The node tells claims without their reach, so the answer looks it up in the origin when told, names it through the mount, and intersects it with the permit beneath the path. Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/lite/publisher/routed.rs | 54 ++++++++++++++----- rs/moq-net/src/lite/publisher/routed/tests.rs | 51 ++++++++++++++++++ rs/moq-net/src/model/origin.rs | 21 ++++++++ 3 files changed, 112 insertions(+), 14 deletions(-) diff --git a/rs/moq-net/src/lite/publisher/routed.rs b/rs/moq-net/src/lite/publisher/routed.rs index 217207cfa1..832c736e51 100644 --- a/rs/moq-net/src/lite/publisher/routed.rs +++ b/rs/moq-net/src/lite/publisher/routed.rs @@ -132,6 +132,14 @@ struct Parts { add: Vec<(Path, bool)>, } +/// A claim the node told: the key that told it, the claim, and what its route may serve, as +/// the handle names it, or `None` when the origin holds no route for it to judge. +struct Told { + source: Source, + claim: Claim, + reach: Option, +} + /// A route the peer holds: its Route ID, and the Announce ID of each claim under it. struct Sent { id: u64, @@ -177,7 +185,7 @@ pub(in crate::lite) struct Answer { next_route: u64, /// Every claim the node told for any other peer, as the handle names it, before /// filtering, with the key that told it. - told: BTreeMap, + told: BTreeMap, /// The claims such a peer holds: their Announce ID, and what it was sent. live: HashMap, /// The session is leaving: nothing more is sent. @@ -671,7 +679,7 @@ impl Answer { regions: Option<&[Path]>, ) -> Result<(), Error> { let mut gone: Vec = (self.told.iter()) - .filter(|(key, (source, _))| *source == MAIN && removed.iter().any(|read| route::within(&key.0, read))) + .filter(|(key, told)| told.source == MAIN && removed.iter().any(|read| route::within(&key.0, read))) .map(|(key, _)| key.clone()) .collect(); let ids: Vec = self.prefixes.keys().copied().collect(); @@ -711,7 +719,7 @@ impl Answer { } gone.extend( (self.told.iter()) - .filter(|(_, (told, _))| *told == source) + .filter(|(_, told)| told.source == source) .map(|(key, _)| key.clone()), ); } @@ -832,13 +840,24 @@ impl Answer { (path, instance): node::Broadcast, change: Change, ) -> Result<(), Error> { + // What its route may serve, looked up where the claim's own prefix is, above the path + // it is told at, and named as the handle names it. + let reach = match &change { + Change::Live(claim) => { + let above = usize::try_from(claim.item.above).unwrap_or(usize::MAX); + let prefix = path.head(path.depth().saturating_sub(above)).unwrap_or_default(); + self.origin.reach(&prefix, &instance) + } + _ => None, + }; // Named as the handle names it: beneath the mount point for a mount, and never a // claim the origin holds beneath a mount for the session's own. - let (named, change) = match self.mounts.get(&source).map(|mount| &mount.mount) { + let (named, change, reach) = match self.mounts.get(&source).map(|mount| &mount.mount) { Some(mount) => { let Some(named) = mount.name(&path) else { return Ok(()); }; + let reach = reach.map(|reach| mount.name_patterns(&reach)); // A claim above the target covers all of the mount, so as the handle names // it, it is no more above the path than the mount point is. let beneath = mount.beneath(&named); @@ -849,20 +868,20 @@ impl Answer { } change => change, }; - (named, change) + (named, change, reach) } None if self.origin.shadows(&path) => return Ok(()), - None => (path, change), + None => (path, change, reach), }; let key = (named, instance); let lost = match change { Change::Live(claim) => { - self.told.insert(key.clone(), (source, claim)); + self.told.insert(key.clone(), Told { source, claim, reach }); false } change => { // Another key may show it now, as when a mount took its place. - if self.told.get(&key).is_some_and(|(told, _)| *told == source) { + if self.told.get(&key).is_some_and(|told| told.source == source) { self.told.remove(&key); } change == Change::Lost @@ -878,9 +897,10 @@ impl Answer { path.parts().count().saturating_sub(self.origin.root().parts().count()) as u64 } - /// Whether the peer is shown the claim at the absolute `path`: the permit and this - /// handle allow some path it covers, the same one. - fn shows(&self, path: &Path) -> bool { + /// Whether the peer is shown the claim at the absolute `path`, whose route may serve + /// `reach`: the permit, this handle, and the route all allow some path it covers, the + /// same one. An intersection too large to spell allows nothing, never more. + fn shows(&self, path: &Path, reach: Option<&crate::Patterns>) -> bool { let Some((_, prefix)) = self.region(path) else { return false; }; @@ -888,15 +908,21 @@ impl Answer { let (Some(suffix), Some(relative)) = (within, path.strip_prefix(self.origin.root())) else { return false; }; - (prefix.hidden || !suffix.is_hidden()) && self.origin.reaches_any(path, &self.permit.beneath(relative.as_str())) + let mut allowed = self.permit.beneath(relative.as_str()); + if let Some(reach) = reach { + let reach = reach.rebase(self.origin.root().as_str()); + allowed = allowed.intersect(&reach).unwrap_or_default(); + } + (prefix.hidden || !suffix.is_hidden()) && self.origin.reaches_any(path, &allowed) } /// Bring the peer's claim `key` in line with what the node told and the answer /// shows. A claim that goes is `lost`, or else ended. fn sync(&mut self, writer: &mut Writer, key: Named, lost: bool) -> Result<(), Error> { let depth = self.depth(&key.0); - let wanted = (self.told.get(&key)).filter(|_| self.shows(&key.0)).map(|(_, claim)| { - let mut claim = claim.clone(); + let told = self.told.get(&key); + let wanted = (told.filter(|told| self.shows(&key.0, told.reach.as_ref()))).map(|told| { + let mut claim = told.claim.clone(); claim.item.above = claim.item.above.min(depth); claim }); diff --git a/rs/moq-net/src/lite/publisher/routed/tests.rs b/rs/moq-net/src/lite/publisher/routed/tests.rs index ca0aceeb7a..f5f6b4cc34 100644 --- a/rs/moq-net/src/lite/publisher/routed/tests.rs +++ b/rs/moq-net/src/lite/publisher/routed/tests.rs @@ -673,3 +673,54 @@ fn a_change_queued_before_a_revocation_ends_its_claim_as_lost() { .collect(); assert_eq!(ends, [true], "{revoked:?}"); } + +/// A claim is shown only where its own route, the handle, and the grant share a path it +/// covers: a route scoped to `a/*/x` at `a` serves neither `a/q/y` nor anything under the +/// grant `a/*` or `a/q/y/**`, and one scoped to `a/private/**` serves nothing under +/// `a/public/**`. Through a mount, the route's reach is named as the handle names it. +#[test] +fn a_claim_is_shown_only_where_its_route_can_serve() { + let origin = Hop::new(1).unwrap().produce(); + let scoped = |scope: &[&str], at: &str| { + let producer = origin.scope("", &patterns(scope)).unwrap(); + producer.announce(at, origin::RouteInfo::new()).unwrap() + }; + let _x = scoped(&["a/*/x"], "a"); + let _private = scoped(&["c/private/**"], "c"); + let _target = scoped(&["s/*/x"], "s"); + let consumer = origin + .mount("m", "s") + .unwrap() + .scope("", &patterns(&["**"])) + .unwrap() + .consume(); + let told = |grant: Option<&[&str]>, prefix: &str| -> Vec { + let auth = crate::auth::Link::new(false); + if let Some(grant) = grant { + auth.handle().authorize(&crate::auth::Grant { + publish: Patterns::default(), + subscribe: patterns(grant), + expires: None, + }); + } + let mut answer = Answer::alone_on(consumer.clone(), auth); + let (mut writer, mut peer) = stream(); + answer.request(false, Vec::new(), vec![(path(prefix), false)]).unwrap(); + let mut told = Vec::new(); + for msg in sent(&mut answer, &mut writer, &mut peer) { + if let AnnounceBroadcast::Start { suffix, instance, .. } = msg { + told.push(peer.start(&suffix, &instance).0.to_string()); + } + } + told + }; + assert!(told(None, "a/q/y").is_empty()); + assert_eq!(told(None, "a/q/x"), ["a/q/x"]); + assert!(told(Some(&["a/*"]), "").is_empty()); + assert!(told(Some(&["a/q/y/**"]), "").is_empty()); + assert_eq!(told(Some(&["a/q/x/**"]), ""), ["a/q/x"]); + assert!(told(Some(&["c/public/**"]), "").is_empty()); + assert_eq!(told(Some(&["c/private/**"]), ""), ["c/private"]); + assert!(told(None, "m/q/y").is_empty()); + assert_eq!(told(None, "m/q/x"), ["m/q/x"]); +} diff --git a/rs/moq-net/src/model/origin.rs b/rs/moq-net/src/model/origin.rs index 4ff2ddf103..d5fb3f453c 100644 --- a/rs/moq-net/src/model/origin.rs +++ b/rs/moq-net/src/model/origin.rs @@ -2018,6 +2018,14 @@ impl Mounted { self.mount.name(path) } + /// The absolute, origin-side `patterns` as the handle names what they match at or + /// beneath the target: beneath the mount point. A name past the wire limits matches nothing. + pub fn name_patterns(&self, patterns: &Patterns) -> Patterns { + (patterns.rebase(self.mount.target.as_str())) + .rooted(self.mount.at.as_str()) + .unwrap_or_default() + } + /// How many segments the handle-side `path` lies beneath the mount point: the most a /// claim read through the mount can be above it. A claim covering the whole target, which /// is broader than the mount point as the handle sees it, covers no more than that. @@ -7845,6 +7853,19 @@ impl Consumer { allowed.iter().any(|pattern| ours.overlaps(pattern)) } + /// What the live routes announced exactly at the absolute `prefix` serving `instance` may + /// serve, absolute: each route's [`RouteEntry::reach`]. `None` when the table holds none, + /// as for a neighbour's claim no session serves here yet. + #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] + pub(crate) fn reach(&self, prefix: &Path, instance: &Instance) -> Option { + let state = self.shared.lock(); + let mut entries = (state.routes.at(prefix)) + .filter(|entry| entry.instance == *instance && entry.live()) + .peekable(); + entries.peek()?; + Some(entries.flat_map(|entry| entry.reach.iter().cloned()).collect()) + } + /// Whether the absolute `path` lies beneath one of this handle's mounts, where the /// origin's own claims at that path are hidden from it. #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] From ad3e821989c46d6812392aaab075fb989bd5293a Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Fri, 20 Nov 2026 01:40:47 -0800 Subject: [PATCH 04/11] fix(net): a lite-07 answer intersects the claim and handle scopes without a grant With no grant set, the JS answer skipped both scope intersections, so a claim reached a request under a prefix where its own scope and the handle's share no path. A property test mirrors the Rust one: random grant changes, claims, and edits, interleaved with the stream's sends. Co-Authored-By: Claude Opus 5.5 --- js/net/src/lite/answer.test.ts | 398 ++++++++++++++++++ js/net/src/lite/answer.ts | 10 +- rs/moq-net/src/lite/publisher/routed/tests.rs | 4 +- 3 files changed, 406 insertions(+), 6 deletions(-) create mode 100644 js/net/src/lite/answer.test.ts diff --git a/js/net/src/lite/answer.test.ts b/js/net/src/lite/answer.test.ts new file mode 100644 index 0000000000..e9f268225d --- /dev/null +++ b/js/net/src/lite/answer.test.ts @@ -0,0 +1,398 @@ +/** + * The lite-07 answer checked over random grant changes, claims, and edits, interleaved with its + * stream's sends, mirroring the Rust `lite::publisher::routed::tests`. + * + * Two promises, each judged as the peer reads the stream: + * + * - When a prefix's SYNCED goes out, every claim the grant shows under it has had its Start. The + * grant and the claims are those the answer last read; a fresh answer under them tells what + * the grant shows. + * - A claim that leaves while the origin still advertises it ends as lost, never as withdrawn. + * + * `MOQ_ANSWER_SEED` and `MOQ_ANSWER_CASES` pick the cases. + */ + +import { afterAll, beforeAll, expect, spyOn, test } from "bun:test"; +import { type Getter, Once, Signal } from "@moq/signals"; +import fc from "fast-check"; +import type { Grant } from "../auth.ts"; +import { WireRoute } from "../hop.ts"; +import * as Instance from "../instance.ts"; +import * as Path from "../path.ts"; +import type { Advertised, Advertisements } from "../wire.ts"; +import type { AnnounceBroadcast } from "./announce.ts"; +import type { AnnounceStream } from "./announce_stream.ts"; +import { Answer } from "./answer.ts"; +import { Version } from "./version.ts"; + +/** Where claims are advertised: some above what grants and prefixes name, and one hidden. */ +const PATHS = ["a", "a/x", "a/q/x", "a/.h", "b", "b/c"].map((path) => Path.from(path)); +/** The scopes claims are advertised with, which bound what each may serve. */ +const SCOPES: (string[] | undefined)[] = [undefined, ["a/*/x"], ["*/c/**"]]; +/** The grants: widen, narrow, move, and revoke between them. */ +const GRANTS: (string[] | undefined)[] = [undefined, ["**"], ["a/**"], ["b/**"], ["a/*"], ["a/x/**"], []]; +/** The prefixes the peer asks for. */ +const PREFIXES = ["", "a", "a/x", "a/q", "b"].map((path) => Path.from(path)); +/** The handle's own scope. */ +const HANDLES: (string[] | undefined)[] = [undefined, ["a/**", "b/**"], ["*/q/**", "b/**"]]; + +function patterns(members: string[]): Path.Patterns { + return new Path.Patterns(members.map((member) => Path.Pattern.parse(member))); +} + +function grant(index: number): Grant | undefined { + const members = GRANTS[index]; + return members && { publish: patterns(members), subscribe: patterns([]) }; +} + +type Op = + | { kind: "grant"; index: number } + | { kind: "advertise"; path: number; scope: number } + | { kind: "withdraw"; path: number } + | { kind: "reprice"; path: number; cost: number } + | { kind: "edit"; remove: number; add: [number, boolean][] } + /** The oldest send in flight completes. */ + | { kind: "send" } + /** The answer runs as far as it can without a send completing. */ + | { kind: "run" }; + +interface Case { + handle: number; + initial: number; + claims: [number, number][]; + ops: Op[]; +} + +const op: fc.Arbitrary = fc.oneof( + { weight: 4, arbitrary: fc.nat(GRANTS.length - 1).map((index) => ({ kind: "grant", index }) as const) }, + { + weight: 2, + arbitrary: fc + .tuple(fc.nat(PATHS.length - 1), fc.nat(SCOPES.length - 1)) + .map(([path, scope]) => ({ kind: "advertise", path, scope }) as const), + }, + { weight: 1, arbitrary: fc.nat(PATHS.length - 1).map((path) => ({ kind: "withdraw", path }) as const) }, + { + weight: 3, + arbitrary: fc + .tuple(fc.nat(PATHS.length - 1), fc.integer({ min: 1, max: 3 })) + .map(([path, cost]) => ({ kind: "reprice", path, cost }) as const), + }, + { + weight: 3, + arbitrary: fc + .tuple(fc.nat(255), fc.array(fc.tuple(fc.nat(PREFIXES.length - 1), fc.boolean()), { maxLength: 2 })) + .map(([remove, add]) => ({ kind: "edit", remove, add }) as const), + }, + { weight: 5, arbitrary: fc.constant({ kind: "send" } as const) }, + { weight: 3, arbitrary: fc.constant({ kind: "run" } as const) }, +); + +const cases: fc.Arbitrary = fc.record({ + handle: fc.nat(HANDLES.length - 1), + initial: fc.nat(GRANTS.length - 1), + claims: fc.array(fc.tuple(fc.nat(PATHS.length - 1), fc.nat(SCOPES.length - 1)), { maxLength: 5 }), + ops: fc.array(op, { minLength: 1, maxLength: 32 }), +}); + +/** Let the answer's loop run until it waits on something outside it. */ +async function settle() { + for (let i = 0; i < 64; i++) await Promise.resolve(); +} + +/** A getter that remembers the value its reader last read. */ +class Watched { + signal: Signal; + read: T; + getter: Getter; + + constructor(value: T) { + this.signal = new Signal(value); + this.read = value; + const signal = this.signal; + this.getter = { + peek: () => { + this.read = signal.peek(); + return this.read; + }, + changed: signal.changed.bind(signal), + subscribe: signal.subscribe.bind(signal), + }; + } +} + +/** The claims the peer holds, by Announce ID: each its path and instance. */ +class Peer { + live = new Map(); + #next = 0n; + + start(path: Path.Valid, instance: Instance.Valid) { + this.live.set(this.#next++, [path, instance]); + } + + end(id: bigint): [Path.Valid, Instance.Valid] { + const held = this.live.get(id); + if (!held) throw new Error(`ends ${id}, which is not live`); + this.live.delete(id); + return held; + } + + /** Both ends drop every claim within a prefix the edit removed. */ + dropWithin(removed: Path.Valid[]) { + for (const [id, [path]] of [...this.live]) { + if (removed.some((prefix) => Path.hasPrefix(prefix, path))) this.live.delete(id); + } + } + + holds(): Set { + return new Set([...this.live.values()].map(([path, instance]) => `${path} ${instance}`)); + } +} + +/** A stream whose sends complete only when the test says, recording each as it is made. */ +function stream(onSend: (msgs: AnnounceBroadcast[]) => void, gated: boolean) { + const pending: (() => void)[] = []; + const fake = { + send: (...msgs: AnnounceBroadcast[]) => { + onSend(msgs); + if (!gated) return Promise.resolve(); + return new Promise((resolve) => pending.push(resolve)); + }, + } as unknown as AnnounceStream; + return { stream: fake, pending }; +} + +function answer( + advertised: Getter, + grant: Getter, + allowed: Path.Patterns | undefined, + stream: AnnounceStream, +) { + return new Answer({ + version: Version.DRAFT_07, + advertised, + origin: { covers: () => true, allowed }, + grant, + ready: Promise.resolve(), + closing: new Once(), + stream, + }); +} + +/** What a fresh answer under `grant` tells for `prefix` from `table`, once it settles. */ +async function shown( + table: Advertisements, + grant: Grant | undefined, + allowed: Path.Patterns | undefined, + prefix: Path.Valid, + hidden: boolean, +): Promise> { + const peer = new Peer(); + let synced = false; + const { stream: fake } = stream((msgs) => { + for (const msg of msgs) { + if (msg.status === "start") peer.start(msg.suffix, msg.instance); + else if (msg.status === "endedId") peer.end(msg.id); + else if (msg.status === "synced") synced = true; + } + }, false); + const granted = new Signal(grant); + const fresh = answer(new Signal(table), granted, allowed, fake); + void fresh.request(false, [], [{ prefix, hidden }]); + await settle(); + expect(synced).toBe(true); + // What it settles to, judged again from scratch, so its own SYNCED proves nothing. + granted.set(grant, true); + await settle(); + fresh.close(); + return peer.holds(); +} + +async function run(c: Case) { + const members = HANDLES[c.handle]; + const allowed = members && patterns(members); + const table = new Watched(new Map()); + const granted = new Watched(grant(c.initial)); + const claims = new Map(); + let nextInstance = 0; + const peer = new Peer(); + const prefixes = new Map(); + let nextPrefix = 0n; + let edit: { remove: bigint[]; add: [bigint, Path.Valid, boolean][] } | undefined; + // Each send's SYNCED checks, run once the send is recorded, outside the answer's call. + const checks: Promise[] = []; + + const publish = () => { + const out = new Map(); + for (const [index, snap] of claims) out.set(PATHS[index], [snap]); + table.signal.set(out); + }; + const advertise = (path: number, scope: number) => { + if (claims.has(path)) return; + const members = SCOPES[scope]; + const instance = Instance.parse(`i${++nextInstance}`); + claims.set(path, { + identity: {}, + route: WireRoute.normalize({ instance, epoch: 0n }), + claim: members && patterns(members), + }); + publish(); + }; + + const { stream: fake, pending } = stream((msgs) => { + const advertised = new Set([...claims.values()].map((snap) => snap.route.instance)); + for (const msg of msgs) { + switch (msg.status) { + case "start": + peer.start(msg.suffix, msg.instance); + break; + case "change": + break; + case "endedId": { + const [path, instance] = peer.end(msg.id); + if (!msg.lost && advertised.has(instance)) + throw new Error(`${path} (${instance}) ended as withdrawn while still advertised`); + break; + } + case "ok": { + if (!edit) throw new Error("an ANNOUNCE_OK answers no edit"); + const removed = edit.remove.flatMap((id) => { + const asked = prefixes.get(id); + prefixes.delete(id); + return asked ? [asked.path] : []; + }); + peer.dropWithin(removed); + for (const [id, path, hidden] of edit.add) prefixes.set(id, { path, hidden }); + edit = undefined; + break; + } + case "synced": { + const asked = prefixes.get(msg.prefix); + if (!asked) throw new Error(`SYNCED for ${msg.prefix}, which is not in effect`); + const read = table.read ?? new Map(); + const grant = granted.read; + const held = peer.holds(); + checks.push( + shown(read, grant, allowed, asked.path, asked.hidden).then((owed) => { + for (const claim of owed) { + if (!held.has(claim)) + throw new Error(`SYNCED for "${asked.path}" went out before ${claim}`); + } + }), + ); + break; + } + default: + throw new Error(`a claims-only peer is sent ${msg.status}`); + } + } + }, true); + + for (const [path, scope] of c.claims) advertise(path, scope); + const subject = answer(table.getter, granted.getter, allowed, fake); + let running: Promise | undefined; + try { + for (const step of c.ops) { + switch (step.kind) { + case "grant": + granted.signal.set(grant(step.index)); + break; + case "advertise": + advertise(step.path, step.scope); + break; + case "withdraw": + if (claims.delete(step.path)) publish(); + break; + case "reprice": { + const snap = claims.get(step.path); + if (!snap) break; + claims.set(step.path, { ...snap, route: { ...snap.route, cost: BigInt(step.cost) } }); + publish(); + break; + } + case "edit": { + if (edit) break; + const remove = [...prefixes.keys()].filter((_, bit) => step.remove & (1 << bit)); + // Only what a peer may ask for: no prefix twice, or at or below another in the set. + const set = [...prefixes].filter(([id]) => !remove.includes(id)).map(([, asked]) => asked.path); + const add: { prefix: Path.Valid; hidden: boolean }[] = []; + for (const [index, hidden] of step.add) { + const prefix = PREFIXES[index]; + if (set.some((other) => Path.hasPrefix(other, prefix) || Path.hasPrefix(prefix, other))) continue; + set.push(prefix); + add.push({ prefix, hidden }); + } + running = subject.request(false, remove, add); + edit = { remove, add: add.map(({ prefix, hidden }) => [nextPrefix++, prefix, hidden]) }; + break; + } + case "send": + pending.shift()?.(); + break; + case "run": + break; + } + await settle(); + } + // Then everything queued goes out. + while (pending.length > 0) { + pending.shift()?.(); + await settle(); + } + await Promise.all(checks); + } finally { + subject.close(); + for (const release of pending) release(); + await running; + } +} + +function setting(name: string, fallback: number, min: number): number { + const raw = process.env[name]; + if (raw !== undefined && !/^\d+$/.test(raw)) throw new Error(`${name} must be an integer`); + const value = Number(raw ?? fallback); + if (!Number.isInteger(value) || value < min || value > 0x7fffffff) { + throw new Error(`${name} must be an integer between ${min} and 2147483647`); + } + return value; +} + +// The answer logs every claim it tells. +let quiet: ReturnType | undefined; +beforeAll(() => { + quiet = spyOn(console, "debug").mockImplementation(() => {}); +}); +afterAll(() => quiet?.mockRestore()); + +test( + "synced follows what the grant shows", + async () => { + const seed = setting("MOQ_ANSWER_SEED", 0x616e73, 0); + const numRuns = setting("MOQ_ANSWER_CASES", 1024, 1); + await fc.assert(fc.asyncProperty(cases, run), { seed, numRuns }); + }, + { timeout: 3_600_000 }, +); + +// A claim is shown only where its own scope and the handle's share a path it covers, granted or +// not: one at `a` serving `a/q/x` and `a/r/y`, through a handle admitting `a/q/y` and `a/r/y`, +// serves nothing under `a/q`. +test("a claim is shown only where its scope and the handle's share a path", async () => { + const table: Advertisements = new Map([ + [ + Path.from("a"), + [ + { + identity: {}, + route: WireRoute.normalize({ instance: Instance.parse("i1"), epoch: 0n }), + claim: patterns(["a/q/x", "a/r/y"]), + }, + ], + ], + ]); + const allowed = patterns(["a/q/y", "a/r/y"]); + for (const grant of [undefined, { publish: patterns(["**"]), subscribe: patterns([]) }]) { + expect(await shown(table, grant, allowed, Path.from("a/q"), false)).toEqual(new Set()); + expect(await shown(table, grant, allowed, Path.from("a/r"), false)).toEqual(new Set(["a/r i1"])); + } +}); diff --git a/js/net/src/lite/answer.ts b/js/net/src/lite/answer.ts index bc8e9b9191..e8dfdedfa6 100644 --- a/js/net/src/lite/answer.ts +++ b/js/net/src/lite/answer.ts @@ -227,18 +227,18 @@ export class Answer { // 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. const latest = new Map(); - // 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. + // A claim is shown where some path it covers is served by the claim's own scope and the + // handle's, and our grant, if any, lets us publish it, 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; 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)); + const paths = [...beneath]; + return grant ? paths.some((pattern) => grant.publish.overlaps(pattern)) : paths.length > 0; }; // 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 diff --git a/rs/moq-net/src/lite/publisher/routed/tests.rs b/rs/moq-net/src/lite/publisher/routed/tests.rs index f5f6b4cc34..819b814183 100644 --- a/rs/moq-net/src/lite/publisher/routed/tests.rs +++ b/rs/moq-net/src/lite/publisher/routed/tests.rs @@ -232,7 +232,7 @@ fn flush(writer: &mut Writer) { assert!(writer.poll_flush(&kio::Waiter::noop()).is_ready()); } -/// What a fresh answer on `consumer` under `grant` tells for `prefix`, once it is all sent. +/// What a fresh answer on `consumer` under `grant` tells for `prefix`, once it settles. fn shown(consumer: &origin::Consumer, grant: Option, prefix: &Path, hidden: bool) -> BTreeSet { let auth = crate::auth::Link::new(false); if let Some(index) = grant { @@ -244,6 +244,8 @@ fn shown(consumer: &origin::Consumer, grant: Option, prefix: &Path, hidde .request(false, Vec::new(), vec![(prefix.clone(), hidden)]) .unwrap(); answer.drain(&mut writer).unwrap(); + // What it settles to, judged again from scratch, so its own SYNCED proves nothing. + answer.resync(&mut writer).unwrap(); flush(&mut writer); for msg in peer.take() { match msg { From 3f5e297ff3725dd35bbca5a21256dd0fa2a0e803 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Fri, 20 Nov 2026 01:55:07 -0800 Subject: [PATCH 05/11] style(net): format the answer property test Co-Authored-By: Claude Opus 5.5 --- js/net/src/lite/answer.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/js/net/src/lite/answer.test.ts b/js/net/src/lite/answer.test.ts index e9f268225d..2b151c8543 100644 --- a/js/net/src/lite/answer.test.ts +++ b/js/net/src/lite/answer.test.ts @@ -318,7 +318,8 @@ async function run(c: Case) { const add: { prefix: Path.Valid; hidden: boolean }[] = []; for (const [index, hidden] of step.add) { const prefix = PREFIXES[index]; - if (set.some((other) => Path.hasPrefix(other, prefix) || Path.hasPrefix(prefix, other))) continue; + if (set.some((other) => Path.hasPrefix(other, prefix) || Path.hasPrefix(prefix, other))) + continue; set.push(prefix); add.push({ prefix, hidden }); } From 847fdb05719eddc2880b7e469aa34774112760e6 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Fri, 20 Nov 2026 02:11:39 -0800 Subject: [PATCH 06/11] quest: the answer's SYNCED and claim reach are done; a neighbour's claim reach follows Co-Authored-By: Claude Opus 5.5 --- quest/m2/lite07-claim-reach.md | 23 --------------- quest/m2/lite07-neighbour-claim-reach.md | 26 +++++++++++++++++ quest/m2/lite07-synced-grant-changes.md | 36 ------------------------ 3 files changed, 26 insertions(+), 59 deletions(-) delete mode 100644 quest/m2/lite07-claim-reach.md create mode 100644 quest/m2/lite07-neighbour-claim-reach.md delete mode 100644 quest/m2/lite07-synced-grant-changes.md diff --git a/quest/m2/lite07-claim-reach.md b/quest/m2/lite07-claim-reach.md deleted file mode 100644 index 472156600e..0000000000 --- a/quest/m2/lite07-claim-reach.md +++ /dev/null @@ -1,23 +0,0 @@ -# [S] A Rust lite-07 answer shows a claim only where its route can serve - -## Goal - -A Rust lite-07 publisher shows a peer a claim only where the claim's own route can -serve some path the peer may ask for, as the JS answer already does. Today a route -announced through a producer scoped to `a/*/x` at the prefix `a` is shown at `a/q/y` -(Above 2) to a peer that asks for `a/q/y`, and at `a` to a peer confined to `a/*`, -though the route serves neither: a request there fails. - -## Plan - -- `origin::RouteEntry::reach` already holds what a route may serve (its producer's - scope intersected with its prefix). The answer (`lite/publisher/routed.rs` - `Answer::shows`) judges the handle's scope and the permit together - (`Consumer::reaches_any`, `Permit::beneath`) but never the route's reach, since the - node tells a claim without it. Carry the reach, or a predicate over it, to the - answer, and intersect it with what `shows` already judges. -- JS selects among candidates with the same predicate (`presented`'s `shows`), so a - narrower cheap route gives way to one the peer can use; the Rust node presents one - claim per instance, so check whether it needs the same. -- The test: a producer scoped to `a/*/x` announcing at `a`, asked for `a/q/y` with no - grant and for the root under `a/*`, shows nothing; asked for `a/q/x`, shows it. diff --git a/quest/m2/lite07-neighbour-claim-reach.md b/quest/m2/lite07-neighbour-claim-reach.md new file mode 100644 index 0000000000..e67dfba8e4 --- /dev/null +++ b/quest/m2/lite07-neighbour-claim-reach.md @@ -0,0 +1,26 @@ +# [S] A lite-07 answer judges a neighbour's claim by its reach + +## Goal + +A Rust lite-07 answer shows a claim a scoped neighbour gave only where that claim's route +can serve some path the peer may ask for, as it already does for the origin's own claims. +Today the answer looks a claim's reach up in the origin when the node tells it +(`Answer::announce` in `rs/moq-net/src/lite/publisher/routed.rs`), and a neighbour's claim +can be told before the session that gave it serves it into the origin, so the answer finds +no route and shows it as before: under a grant it shares no path with, where a request fails. + +## Plan + +Found by [moq-dev/moq#9229](https://github.com/moq-dev/moq/pull/9229), which carried the +reach to `Answer::shows` for claims the origin holds when told. + +- Recommended: the giving session already knows the reach when it files the claim + (`lite/subscriber/routed.rs`, `admits`: its producer's scope intersected with the claim's + prefix). Carry it with the claim inside the node, never on the wire, so every answer the + node tells judges it at once, and drop the origin lookup. +- Rejected: looking the reach up again later, since nothing tells the answer when the + serving session catches up. +- The test: a scoped neighbour whose grant is `a/*/x` gives a claim at `a`; another peer + under the grant `a/q/y/**` is not shown it, even before the giving session serves it. + +Public API: none. Wire: none. diff --git a/quest/m2/lite07-synced-grant-changes.md b/quest/m2/lite07-synced-grant-changes.md deleted file mode 100644 index 3d1566a89b..0000000000 --- a/quest/m2/lite07-synced-grant-changes.md +++ /dev/null @@ -1,36 +0,0 @@ -# [M] A lite-07 answer's SYNCED holds across grant changes - -## Goal - -A lite-07 publisher (Rust `lite/publisher/routed.rs`, JS `js/net/src/lite/answer.ts`) -sends a prefix's SYNCED only once every claim the grant in effect shows under it has -had its Start, however grant changes (widen, narrow, move, revoke), claims, mounts, and -the peer's edits interleave with the output. A claim that leaves only because of the -permit ends as lost, never as withdrawn. A claim is shown only where its own reach, -the handle's scope, and the permit share a path. A property test in each language -checks these over random sequences and stays fast enough for `just check`. - -## Plan - -Found by CodeRabbit on [moq-dev/moq#9202](https://github.com/moq-dev/moq/pull/9202), -whose answer this fixes: each review round there found another ordering, so this quest -replaces case-by-case fixes with a property test. - -- ✅ Fold [the claim-reach quest](/quest/m2/lite07-claim-reach.md) in (rejected: keep - it separate): the same `shows` the property exercises, and its tests share the - harness. -- The property's oracle is differential: when SYNCED goes out, a fresh answer on the same - origin, under the grant in effect in stream order (the last grant marker the answer - processed), asked for the same prefix and drained, names the claims required. Only those - present since the latest read for the prefix started (its edit or that grant change) - are required, since a claim arriving after its read's initial set is live. -- Rust carries each claim's reach (`origin::RouteEntry::reach`, translated through a - mount) to `Answer::shows`, looked up in the origin when the node tells the claim, and - intersects it with the permit beneath the presented path before the handle check. JS - applies the claim and handle scope intersections with or without a grant. -- Settled on #9202, not reopened: answering region by region (option D); a synced reader - goes unsynced only when a widening can show it more; a claim is shown when the scope - matches some path it covers; replacement mounts hold SYNCED until their initial set - arrives. - -Public API: none. Wire: none. From 8bfb4fa9ea698985bc4f3593e579a463a40af169 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Fri, 20 Nov 2026 02:26:31 -0800 Subject: [PATCH 07/11] fix(moq-net): a lite-07 answer judges a claim's reach by the routes as they stand Looked up once when the node told the claim, the reach went stale when another route of its instance changed without the claim changing. Each judgment now looks it up, so a grant change or an edit judges the claim by the routes as they stand; what the node never tells is a follow-up. Co-Authored-By: Claude Opus 5.5 --- quest/m2/lite07-claim-reach-routes.md | 37 +++++++++++++++++ quest/m2/lite07-neighbour-claim-reach.md | 26 ------------ rs/moq-net/src/lite/publisher/routed.rs | 40 +++++++++++------- rs/moq-net/src/lite/publisher/routed/tests.rs | 41 +++++++++++++++++++ 4 files changed, 103 insertions(+), 41 deletions(-) create mode 100644 quest/m2/lite07-claim-reach-routes.md delete mode 100644 quest/m2/lite07-neighbour-claim-reach.md diff --git a/quest/m2/lite07-claim-reach-routes.md b/quest/m2/lite07-claim-reach-routes.md new file mode 100644 index 0000000000..403aad4e87 --- /dev/null +++ b/quest/m2/lite07-claim-reach-routes.md @@ -0,0 +1,37 @@ +# [M] A lite-07 claim's reach follows every route that serves it + +## Goal + +A Rust lite-07 answer re-judges a claim the moment what its routes may serve changes, so a +peer is never left without a claim some route can serve, or shown one none can. Today the +answer looks the claim's reach up in the origin each time it judges the claim +(`Answer::reach` in `rs/moq-net/src/lite/publisher/routed.rs`), and two changes reach it +only at the claim's next change, grant change, or edit: + +- A route of the same instance at the same prefix that does not win the prefix appears, + leaves, or changes scope: the origin's cursors report only the winning route, so the + node tells nothing. +- A scoped neighbour's claim is told before the session that gave it serves it into the + origin, so the lookup finds no route and the claim is shown as before the check. + +## Plan + +Found by the local review of [moq-dev/moq#9229](https://github.com/moq-dev/moq/pull/9229), +which carried the reach to `Answer::shows`. + +- Recommended: carry the reach with the claim inside the node (on its `Attr`, never on the + wire), so the node tells every answer when it changes and the origin lookup goes. The + origin's own claims take it from the feeder cursor (`OwnClaims` in + `rs/moq-net/src/model/origin.rs`), which then reports the union reach of the winner's + instance at each prefix (`sync_route`, `TableCursor::update`); a neighbour's claims take + it from the session that gives them (`lite/subscriber/routed.rs`, `admits`: its producer's + scope intersected with the claim's prefix). +- Only the feeder's cursors compute the union, since every cursor touching a prefix visits + `TableCursor::update`; bench that over routes per prefix and cursors, both swept. +- Rejected: a watch per claim the reach hides, which costs origin state per claim. +- The tests: a route of the claim's instance serving `c/public/**` announced beside a winner + serving only `c/private/**` shows the claim to a peer granted `c/public/**` at once; a + scoped neighbour granted `a/*/x` gives a claim at `a`, and a peer granted `a/q/y/**` is + never shown it. + +Public API: none. Wire: none. diff --git a/quest/m2/lite07-neighbour-claim-reach.md b/quest/m2/lite07-neighbour-claim-reach.md deleted file mode 100644 index e67dfba8e4..0000000000 --- a/quest/m2/lite07-neighbour-claim-reach.md +++ /dev/null @@ -1,26 +0,0 @@ -# [S] A lite-07 answer judges a neighbour's claim by its reach - -## Goal - -A Rust lite-07 answer shows a claim a scoped neighbour gave only where that claim's route -can serve some path the peer may ask for, as it already does for the origin's own claims. -Today the answer looks a claim's reach up in the origin when the node tells it -(`Answer::announce` in `rs/moq-net/src/lite/publisher/routed.rs`), and a neighbour's claim -can be told before the session that gave it serves it into the origin, so the answer finds -no route and shows it as before: under a grant it shares no path with, where a request fails. - -## Plan - -Found by [moq-dev/moq#9229](https://github.com/moq-dev/moq/pull/9229), which carried the -reach to `Answer::shows` for claims the origin holds when told. - -- Recommended: the giving session already knows the reach when it files the claim - (`lite/subscriber/routed.rs`, `admits`: its producer's scope intersected with the claim's - prefix). Carry it with the claim inside the node, never on the wire, so every answer the - node tells judges it at once, and drop the origin lookup. -- Rejected: looking the reach up again later, since nothing tells the answer when the - serving session catches up. -- The test: a scoped neighbour whose grant is `a/*/x` gives a claim at `a`; another peer - under the grant `a/q/y/**` is not shown it, even before the giving session serves it. - -Public API: none. Wire: none. diff --git a/rs/moq-net/src/lite/publisher/routed.rs b/rs/moq-net/src/lite/publisher/routed.rs index 832c736e51..e34da7c9c8 100644 --- a/rs/moq-net/src/lite/publisher/routed.rs +++ b/rs/moq-net/src/lite/publisher/routed.rs @@ -132,12 +132,12 @@ struct Parts { add: Vec<(Path, bool)>, } -/// A claim the node told: the key that told it, the claim, and what its route may serve, as -/// the handle names it, or `None` when the origin holds no route for it to judge. +/// A claim the node told: the key that told it, the claim, and the absolute, origin-side +/// prefix it claims, above the path it is told at, where its routes are announced. struct Told { source: Source, claim: Claim, - reach: Option, + prefix: Path, } /// A route the peer holds: its Route ID, and the Announce ID of each claim under it. @@ -840,24 +840,21 @@ impl Answer { (path, instance): node::Broadcast, change: Change, ) -> Result<(), Error> { - // What its route may serve, looked up where the claim's own prefix is, above the path - // it is told at, and named as the handle names it. - let reach = match &change { + // Where its routes are announced: its own prefix, above the path it is told at. + let prefix = match &change { Change::Live(claim) => { let above = usize::try_from(claim.item.above).unwrap_or(usize::MAX); - let prefix = path.head(path.depth().saturating_sub(above)).unwrap_or_default(); - self.origin.reach(&prefix, &instance) + path.head(path.depth().saturating_sub(above)).unwrap_or_default() } - _ => None, + _ => Path::default(), }; // Named as the handle names it: beneath the mount point for a mount, and never a // claim the origin holds beneath a mount for the session's own. - let (named, change, reach) = match self.mounts.get(&source).map(|mount| &mount.mount) { + let (named, change) = match self.mounts.get(&source).map(|mount| &mount.mount) { Some(mount) => { let Some(named) = mount.name(&path) else { return Ok(()); }; - let reach = reach.map(|reach| mount.name_patterns(&reach)); // A claim above the target covers all of the mount, so as the handle names // it, it is no more above the path than the mount point is. let beneath = mount.beneath(&named); @@ -868,15 +865,15 @@ impl Answer { } change => change, }; - (named, change, reach) + (named, change) } None if self.origin.shadows(&path) => return Ok(()), - None => (path, change, reach), + None => (path, change), }; let key = (named, instance); let lost = match change { Change::Live(claim) => { - self.told.insert(key.clone(), Told { source, claim, reach }); + self.told.insert(key.clone(), Told { source, claim, prefix }); false } change => { @@ -916,12 +913,25 @@ impl Answer { (prefix.hidden || !suffix.is_hidden()) && self.origin.reaches_any(path, &allowed) } + /// What the routes of the told claim serving `instance` may serve now, as the handle names + /// it, or `None` when the origin holds none to judge it by, as for a neighbour's claim no + /// session serves here yet. Looked up at each judgment, so any change to the claim, the + /// grant, or the peer's prefixes judges it by the routes as they stand. + fn reach(&self, instance: &Instance, told: &Told) -> Option { + let reach = self.origin.reach(&told.prefix, instance)?; + match self.mounts.get(&told.source) { + Some(mount) => Some(mount.mount.name_patterns(&reach)), + None => Some(reach), + } + } + /// Bring the peer's claim `key` in line with what the node told and the answer /// shows. A claim that goes is `lost`, or else ended. fn sync(&mut self, writer: &mut Writer, key: Named, lost: bool) -> Result<(), Error> { let depth = self.depth(&key.0); let told = self.told.get(&key); - let wanted = (told.filter(|told| self.shows(&key.0, told.reach.as_ref()))).map(|told| { + let shown = |told: &&Told| self.shows(&key.0, self.reach(&key.1, told).as_ref()); + let wanted = told.filter(shown).map(|told| { let mut claim = told.claim.clone(); claim.item.above = claim.item.above.min(depth); claim diff --git a/rs/moq-net/src/lite/publisher/routed/tests.rs b/rs/moq-net/src/lite/publisher/routed/tests.rs index 819b814183..e37e9bf521 100644 --- a/rs/moq-net/src/lite/publisher/routed/tests.rs +++ b/rs/moq-net/src/lite/publisher/routed/tests.rs @@ -726,3 +726,44 @@ fn a_claim_is_shown_only_where_its_route_can_serve() { assert!(told(None, "m/q/y").is_empty()); assert_eq!(told(None, "m/q/x"), ["m/q/x"]); } + +/// A claim is judged by the routes as they stand: one hidden because its route serves only +/// `c/private/**` is shown once another route of its instance serves `c/public/**`, at the +/// next grant change, which judges it again. +#[test] +fn a_claim_is_judged_by_the_routes_as_they_stand() { + let origin = Hop::new(1).unwrap().produce(); + let instance: Instance = "cam".parse().unwrap(); + let route = |scope: &[&str], cost: u64| { + let producer = origin.scope("", &patterns(scope)).unwrap(); + let info = origin::RouteInfo::new() + .with_instance(instance.clone(), 0) + .with_cost(cost); + producer.announce("c", info).unwrap() + }; + let _private = route(&["c/private/**"], 1); + let auth = crate::auth::Link::new(false); + let public = |extra: &[&str]| crate::auth::Grant { + publish: Patterns::default(), + subscribe: patterns(&[&["c/public/**"], extra].concat()), + expires: None, + }; + auth.handle().authorize(&public(&[])); + let mut answer = Answer::alone_on(origin.consume(), auth.clone()); + let (mut writer, mut peer) = stream(); + answer.request(false, Vec::new(), vec![(path(""), false)]).unwrap(); + let starts = |msgs: &[AnnounceBroadcast]| { + msgs.iter() + .filter(|msg| matches!(msg, AnnounceBroadcast::Start { .. })) + .count() + }; + let first = sent(&mut answer, &mut writer, &mut peer); + assert_eq!(starts(&first), 0, "{first:?}"); + + let _public = route(&["c/public/**"], 5); + origin.route_node(); + auth.handle().authorize(&public(&["x/**"])); + answer.poll_permit(&kio::Waiter::noop()).unwrap(); + let regranted = sent(&mut answer, &mut writer, &mut peer); + assert_eq!(starts(®ranted), 1, "{regranted:?}"); +} From d4ee5e568b35c9117b2bbad43193bea6e8cb940c Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Fri, 20 Nov 2026 10:03:31 -0800 Subject: [PATCH 08/11] quest: the lite-07 cut waits on a claim's reach following every route Decided by the maintainer on #9229: the PR lands as is, and the cut waits on lite07-claim-reach-routes, since #9229 can leave hidden a claim a costlier route of its instance could serve. Co-Authored-By: Claude Opus 5.5 --- quest/m2/lite07-claim-reach-routes.md | 5 +++++ quest/m2/lite07-finalize.md | 1 + 2 files changed, 6 insertions(+) diff --git a/quest/m2/lite07-claim-reach-routes.md b/quest/m2/lite07-claim-reach-routes.md index 403aad4e87..67eb129c7a 100644 --- a/quest/m2/lite07-claim-reach-routes.md +++ b/quest/m2/lite07-claim-reach-routes.md @@ -19,6 +19,11 @@ only at the claim's next change, grant change, or edit: Found by the local review of [moq-dev/moq#9229](https://github.com/moq-dev/moq/pull/9229), which carried the reach to `Answer::shows`. +Decided 2026-11-20 (maintainer, on #9229): ✅ the lite-07 cut waits on this +quest, and #9229 lands without it (rejected: fixing it after the cut; holding +#9229 until it is fixed). #9229 can leave hidden a claim a costlier route of +its instance could serve, which main showed. + - Recommended: carry the reach with the claim inside the node (on its `Attr`, never on the wire), so the node tells every answer when it changes and the origin lookup goes. The origin's own claims take it from the feeder cursor (`OwnClaims` in diff --git a/quest/m2/lite07-finalize.md b/quest/m2/lite07-finalize.md index 430e9bc508..410740dfa1 100644 --- a/quest/m2/lite07-finalize.md +++ b/quest/m2/lite07-finalize.md @@ -214,6 +214,7 @@ the version that ships them. ## Required - [Cache-aware multicast](/quest/m2/multicast/README.md) - lite-07 carries the redesigned route layer: routes to forwarding nodes, no holds or doubt, claims crossing trust boundaries by a chain, and no Route Key +- [A lite-07 claim's reach follows every route that serves it](/quest/m2/lite07-claim-reach-routes.md) - a peer is never left without a claim some route can serve, nor shown one none can (maintainer, 2026-11-20) ## Related From 738960d06d73d61a3f6250de3ef6955e284f0478 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Fri, 20 Nov 2026 10:52:49 -0800 Subject: [PATCH 09/11] fix(moq-net): a lite-07 answer holds SYNCED until a grant change's resync; the reach check moves to its quest Drop the per-judgment origin lookup of a claim's reach (Consumer::reach, Mounted::name_patterns) and its tests: quest/m2/lite07-claim-reach-routes.md carries the reach in the node's claims instead. Every prefix's SYNCED now waits for a pending grant change to settle, so a claim the change shows in a read it keeps starts first. The property test requires SYNCED for every prefix once drained, owes a claim only from the read that tells it, and can now generate a hidden claim in a kept read. Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/lite/publisher/routed.rs | 98 ++++----- rs/moq-net/src/lite/publisher/routed/tests.rs | 205 +++++++++--------- rs/moq-net/src/model/origin.rs | 21 -- 3 files changed, 144 insertions(+), 180 deletions(-) diff --git a/rs/moq-net/src/lite/publisher/routed.rs b/rs/moq-net/src/lite/publisher/routed.rs index e34da7c9c8..c58a46b774 100644 --- a/rs/moq-net/src/lite/publisher/routed.rs +++ b/rs/moq-net/src/lite/publisher/routed.rs @@ -132,14 +132,6 @@ struct Parts { add: Vec<(Path, bool)>, } -/// A claim the node told: the key that told it, the claim, and the absolute, origin-side -/// prefix it claims, above the path it is told at, where its routes are announced. -struct Told { - source: Source, - claim: Claim, - prefix: Path, -} - /// A route the peer holds: its Route ID, and the Announce ID of each claim under it. struct Sent { id: u64, @@ -175,7 +167,8 @@ pub(in crate::lite) struct Answer { /// The latest marker answered the peer's edit, so the SYNCED after it count. answering: bool, /// How many reads a grant change added have yet to send their initial set, before - /// what it no longer shows goes: a claim a wider read tells again is kept. + /// what it no longer shows goes and what it now shows starts: a claim a wider read tells + /// again is kept. Every prefix's SYNCED waits for that too. regranting: Option, /// The ANNOUNCE_REQUESTs of an edit that continues. parts: Option, @@ -185,7 +178,7 @@ pub(in crate::lite) struct Answer { next_route: u64, /// Every claim the node told for any other peer, as the handle names it, before /// filtering, with the key that told it. - told: BTreeMap, + told: BTreeMap, /// The claims such a peer holds: their Announce ID, and what it was sent. live: HashMap, /// The session is leaving: nothing more is sent. @@ -538,14 +531,13 @@ impl Answer { let holds = std::mem::replace(&mut mount.holds, Holds::Nothing); holds.synced().then_some(mount.prefix) } - // What a grant change reads: once all of it is in, what the change no longer - // shows goes. A prefix not yet synced waits for it too. + // What a grant change reads: once all of it is in, the claims and the SYNCED + // held back for it settle. A prefix not yet synced waits for its own reads too. None if !self.answering => { if let Some(left) = self.regranting.as_mut() { *left = left.saturating_sub(1); if *left == 0 { - self.regranting = None; - self.resync(writer)?; + self.settle(writer)?; } } (self.prefixes.iter()) @@ -678,8 +670,11 @@ impl Answer { added: usize, regions: Option<&[Path]>, ) -> Result<(), Error> { + // The mounts that go below may release a prefix, whose SYNCED waits for the claims + // this change shows in the reads it keeps. + self.regranting = Some(added); let mut gone: Vec = (self.told.iter()) - .filter(|(key, told)| told.source == MAIN && removed.iter().any(|read| route::within(&key.0, read))) + .filter(|(key, (source, _))| *source == MAIN && removed.iter().any(|read| route::within(&key.0, read))) .map(|(key, _)| key.clone()) .collect(); let ids: Vec = self.prefixes.keys().copied().collect(); @@ -719,7 +714,7 @@ impl Answer { } gone.extend( (self.told.iter()) - .filter(|(_, told)| told.source == source) + .filter(|(_, (told, _))| *told == source) .map(|(key, _)| key.clone()), ); } @@ -730,12 +725,24 @@ impl Answer { } self.main.flush(); match added { - 0 => self.resync(writer), - added => { - self.regranting = Some(added); - Ok(()) - } + 0 => self.settle(writer), + _ => Ok(()), + } + } + + /// All a grant change reads is in: bring every claim in line with it, then send each + /// SYNCED held back for it. + fn settle(&mut self, writer: &mut Writer) -> Result<(), Error> { + self.regranting = None; + self.resync(writer)?; + let ready: Vec = (self.prefixes.iter()) + .filter(|(_, prefix)| !prefix.synced && prefix.waiting == 0) + .map(|(id, _)| *id) + .collect(); + for id in ready { + self.synced(writer, id, 0)?; } + Ok(()) } /// Bring every claim the peer holds or the node told in line with the grant. @@ -750,13 +757,14 @@ impl Answer { } /// `keys` of those answering the prefix with Prefix ID `id` sent their initial set: - /// SYNCED goes out once every one has. + /// SYNCED goes out once every one has, and no grant change is still reading. fn synced(&mut self, writer: &mut Writer, id: u64, keys: usize) -> Result<(), Error> { + let regranting = self.regranting.is_some(); let Some(prefix) = self.prefixes.get_mut(&id).filter(|prefix| !prefix.synced) else { return Ok(()); }; prefix.waiting = prefix.waiting.saturating_sub(keys); - if prefix.waiting > 0 { + if prefix.waiting > 0 || regranting { return Ok(()); } prefix.synced = true; @@ -840,14 +848,6 @@ impl Answer { (path, instance): node::Broadcast, change: Change, ) -> Result<(), Error> { - // Where its routes are announced: its own prefix, above the path it is told at. - let prefix = match &change { - Change::Live(claim) => { - let above = usize::try_from(claim.item.above).unwrap_or(usize::MAX); - path.head(path.depth().saturating_sub(above)).unwrap_or_default() - } - _ => Path::default(), - }; // Named as the handle names it: beneath the mount point for a mount, and never a // claim the origin holds beneath a mount for the session's own. let (named, change) = match self.mounts.get(&source).map(|mount| &mount.mount) { @@ -873,12 +873,12 @@ impl Answer { let key = (named, instance); let lost = match change { Change::Live(claim) => { - self.told.insert(key.clone(), Told { source, claim, prefix }); + self.told.insert(key.clone(), (source, claim)); false } change => { // Another key may show it now, as when a mount took its place. - if self.told.get(&key).is_some_and(|told| told.source == source) { + if self.told.get(&key).is_some_and(|(told, _)| *told == source) { self.told.remove(&key); } change == Change::Lost @@ -894,10 +894,9 @@ impl Answer { path.parts().count().saturating_sub(self.origin.root().parts().count()) as u64 } - /// Whether the peer is shown the claim at the absolute `path`, whose route may serve - /// `reach`: the permit, this handle, and the route all allow some path it covers, the - /// same one. An intersection too large to spell allows nothing, never more. - fn shows(&self, path: &Path, reach: Option<&crate::Patterns>) -> bool { + /// Whether the peer is shown the claim at the absolute `path`: the permit and this + /// handle allow some path it covers, the same one. + fn shows(&self, path: &Path) -> bool { let Some((_, prefix)) = self.region(path) else { return false; }; @@ -905,34 +904,15 @@ impl Answer { let (Some(suffix), Some(relative)) = (within, path.strip_prefix(self.origin.root())) else { return false; }; - let mut allowed = self.permit.beneath(relative.as_str()); - if let Some(reach) = reach { - let reach = reach.rebase(self.origin.root().as_str()); - allowed = allowed.intersect(&reach).unwrap_or_default(); - } - (prefix.hidden || !suffix.is_hidden()) && self.origin.reaches_any(path, &allowed) - } - - /// What the routes of the told claim serving `instance` may serve now, as the handle names - /// it, or `None` when the origin holds none to judge it by, as for a neighbour's claim no - /// session serves here yet. Looked up at each judgment, so any change to the claim, the - /// grant, or the peer's prefixes judges it by the routes as they stand. - fn reach(&self, instance: &Instance, told: &Told) -> Option { - let reach = self.origin.reach(&told.prefix, instance)?; - match self.mounts.get(&told.source) { - Some(mount) => Some(mount.mount.name_patterns(&reach)), - None => Some(reach), - } + (prefix.hidden || !suffix.is_hidden()) && self.origin.reaches_any(path, &self.permit.beneath(relative.as_str())) } /// Bring the peer's claim `key` in line with what the node told and the answer /// shows. A claim that goes is `lost`, or else ended. fn sync(&mut self, writer: &mut Writer, key: Named, lost: bool) -> Result<(), Error> { let depth = self.depth(&key.0); - let told = self.told.get(&key); - let shown = |told: &&Told| self.shows(&key.0, self.reach(&key.1, told).as_ref()); - let wanted = told.filter(shown).map(|told| { - let mut claim = told.claim.clone(); + let wanted = (self.told.get(&key)).filter(|_| self.shows(&key.0)).map(|(_, claim)| { + let mut claim = claim.clone(); claim.item.above = claim.item.above.min(depth); claim }); diff --git a/rs/moq-net/src/lite/publisher/routed/tests.rs b/rs/moq-net/src/lite/publisher/routed/tests.rs index e37e9bf521..8fe5a262f5 100644 --- a/rs/moq-net/src/lite/publisher/routed/tests.rs +++ b/rs/moq-net/src/lite/publisher/routed/tests.rs @@ -26,9 +26,9 @@ use crate::lite::{self, AnnounceBroadcast, Version, subscriber::route_stream::Wr use crate::model::ProduceTest; use crate::{Hop, Instance, Path, Pattern, Patterns, origin}; -/// Where claims are announced: some above what grants and prefixes name, one hidden, and -/// some beneath the mount target `s`. -const PATHS: &[&str] = &["a", "a/x", "a/.h", "a/m/x", "b", "b/c", "s", "s/x"]; +/// Where claims are announced: some above what grants and prefixes name, some deeper than a +/// grant's `*` shows, one hidden, and some beneath the mount target `s`. +const PATHS: &[&str] = &["a", "a/x", "a/x/y", "a/.h", "a/m/x", "b", "b/c", "b/c/d", "s", "s/x"]; /// The scopes claims are announced through, which bound what each may serve. const SCOPES: &[&[&str]] = &[&["**"], &["*/x"]]; @@ -42,6 +42,7 @@ const GRANTS: &[&[&str]] = &[ &["a/*"], &["a/m/**"], &["a/**", "b/**"], + &["a/**", "b/*"], &[], ]; @@ -95,6 +96,8 @@ enum Op { }, /// Send one thing the session's key queued. Main, + /// Send everything the session's key queued. + Drain, /// Send one thing a mount queued. Mount(usize), } @@ -127,6 +130,7 @@ fn op() -> impl Strategy { 3 => (any::(), proptest::collection::vec((prefix(), any::()), 0..3)) .prop_map(|(remove, add)| Op::Edit { remove, add }), 5 => Just(Op::Main), + 2 => Just(Op::Drain), 3 => (0..4usize).prop_map(Op::Mount), ] } @@ -232,8 +236,14 @@ fn flush(writer: &mut Writer) { assert!(writer.poll_flush(&kio::Waiter::noop()).is_ready()); } -/// What a fresh answer on `consumer` under `grant` tells for `prefix`, once it settles. -fn shown(consumer: &origin::Consumer, grant: Option, prefix: &Path, hidden: bool) -> BTreeSet { +/// What a fresh answer on `consumer` under `grant` reads and tells for `prefix`, once it settles. +struct View { + reads: BTreeSet, + shown: BTreeSet, +} + +/// What a fresh answer on `consumer` under `grant` reads and tells for `prefix`, once it settles. +fn shown(consumer: &origin::Consumer, grant: Option, prefix: &Path, hidden: bool) -> View { let auth = crate::auth::Link::new(false); if let Some(index) = grant { auth.handle().authorize(&self::grant(index)); @@ -258,7 +268,13 @@ fn shown(consumer: &origin::Consumer, grant: Option, prefix: &Path, hidde _ => {} } } - peer.holds() + let reads = (answer.prefixes.values().next()) + .map(|prefix| prefix.reads.clone()) + .unwrap_or_default(); + View { + reads, + shown: peer.holds(), + } } /// A prefix in effect: its path, its Hidden, and the step that asked for it. @@ -300,6 +316,8 @@ struct Sim { prefixes: BTreeMap, next_prefix: u64, edit: Option, + /// The prefixes in effect whose SYNCED went out. + synced: BTreeSet, } impl Sim { @@ -331,6 +349,7 @@ impl Sim { prefixes: BTreeMap::new(), next_prefix: 0, edit: None, + synced: BTreeSet::new(), } } @@ -352,7 +371,7 @@ impl Sim { } fn apply(&mut self, op: &Op) -> Result<(), TestCaseError> { - if !matches!(op, Op::Main | Op::Mount(_)) { + if !matches!(op, Op::Main | Op::Drain | Op::Mount(_)) { self.step += 1; } match op { @@ -437,6 +456,10 @@ impl Sim { self.send(op)?; return Ok(()); } + Op::Drain => { + while self.send(&Op::Main)? {} + return Ok(()); + } } // The origin feeds its node what changed, as its driver would. self.origin.route_node(); @@ -497,6 +520,9 @@ impl Sim { } AnnounceBroadcast::Ok => { let edit = self.edit.take().expect("an ANNOUNCE_OK answers an edit"); + for id in &edit.remove { + self.synced.remove(id); + } let removed: Vec = (edit.remove.iter()) .filter_map(|id| self.prefixes.remove(id)) .map(|asked| asked.path) @@ -513,7 +539,10 @@ impl Sim { ); } } - AnnounceBroadcast::Synced { prefix } => self.synced(prefix)?, + AnnounceBroadcast::Synced { prefix } => { + prop_assert!(self.synced.insert(prefix), "a second SYNCED for {prefix}"); + self.synced(prefix)?; + } msg => prop_assert!(false, "a claims-only peer is sent {msg:?}"), } } @@ -522,8 +551,9 @@ impl Sim { /// SYNCED for `id` went out: every claim the grant in effect shows under it, there before /// the read that tells it started, has had its Start. That read started with the edit - /// adding the prefix, or with the latest grant change in effect that showed the claim - /// there when the one before did not. + /// adding the prefix, or with the latest grant change in effect that read it when the one + /// before did not. A change that keeps the read only judges again what it told, so a claim + /// announced after the read started is a live change, whenever it comes. fn synced(&self, id: u64) -> Result<(), TestCaseError> { let asked = self.prefixes.get(&id).expect("SYNCED names a prefix in effect"); let effect = self.grants.len() - 1 - self.unanswered(); @@ -531,21 +561,24 @@ impl Sim { let first = (self.grants.iter().rposition(|(step, _)| *step <= asked.at)) .unwrap_or(0) .min(effect); - let views: Vec> = (self.grants[first..].iter()) + let views: Vec = (self.grants[first..].iter()) .map(|(_, grant)| shown(&self.consumer, *grant, &asked.path, asked.hidden)) .collect(); let view = |index: usize| &views[index - first]; let held = self.peer.holds(); - for claim in view(effect) { + for claim in &view(effect).shown { // A change queued behind the one in effect may only take claims away. - if (effect + 1..self.grants.len()).any(|later| !view(later).contains(claim)) { + if (effect + 1..self.grants.len()).any(|later| !view(later).shown.contains(claim)) { continue; } + let (path, instance) = claim; + // The read that tells it: the one it lies in, or the one it is presented at. + let read = + |index: usize| (view(index).reads.iter()).find(|read| path.has_prefix(read) || read.has_prefix(path)); let since = (first + 1..=effect) .rev() - .find(|index| !view(index - 1).contains(claim)) + .find(|index| read(*index).is_none_or(|read| !view(index - 1).reads.contains(read))) .map_or(asked.at, |index| self.grants[index].0); - let (path, instance) = claim; let old = (self.claims.values()).any(|held| held.instance == *instance && held.at < since); prop_assert!( !old || held.contains(claim), @@ -583,9 +616,14 @@ fn run(case: &Case) -> Result<(), TestCaseError> { } } if !sent && !sim.send(&Op::Main)? { - return Ok(()); + break; } } + // Once everything is out, every prefix in effect has had its SYNCED. + for (id, asked) in &sim.prefixes { + prop_assert!(sim.synced.contains(id), "no SYNCED for {:?} once drained", asked.path); + } + Ok(()) } /// Runs the cases `MOQ_ANSWER_SEED` and `MOQ_ANSWER_CASES` pick. @@ -637,13 +675,25 @@ fn a_grant_change_before_synced_holds_it_for_what_is_read_instead() { auth.handle().authorize(&grant(2)); answer.poll_permit(&kio::Waiter::noop()).unwrap(); msgs.extend(sent(&mut answer, &mut writer, &mut peer)); - let start = msgs - .iter() - .position(|msg| matches!(msg, AnnounceBroadcast::Start { .. })); - let synced = msgs - .iter() - .position(|msg| *msg == AnnounceBroadcast::Synced { prefix: 0 }); - assert!(start.is_some() && start < synced, "{msgs:?}"); + assert_eq!(events(&mut peer, &msgs), ["b/c", "SYNCED 0"], "{msgs:?}"); +} + +/// What the peer reads in `msgs`, in order: the path of each Start, and each SYNCED. +fn events(peer: &mut Peer, msgs: &[AnnounceBroadcast]) -> Vec { + let mut events = Vec::new(); + for msg in msgs { + match msg { + AnnounceBroadcast::Start { suffix, instance, .. } => { + events.push(peer.start(suffix, instance).0.to_string()); + } + AnnounceBroadcast::End { id, .. } => { + peer.end(*id); + } + AnnounceBroadcast::Synced { prefix } => events.push(format!("SYNCED {prefix}")), + _ => {} + } + } + events } /// A re-price queued before the grant revokes the claim is judged by the new grant, and @@ -676,94 +726,49 @@ fn a_change_queued_before_a_revocation_ends_its_claim_as_lost() { assert_eq!(ends, [true], "{revoked:?}"); } -/// A claim is shown only where its own route, the handle, and the grant share a path it -/// covers: a route scoped to `a/*/x` at `a` serves neither `a/q/y` nor anything under the -/// grant `a/*` or `a/q/y/**`, and one scoped to `a/private/**` serves nothing under -/// `a/public/**`. Through a mount, the route's reach is named as the handle names it. +/// A claim the old grant hid inside a read the new grant keeps is started before the SYNCED +/// of a prefix that another read of the change releases first: `a` waits on the mount at +/// `a/drop` when the grant moves from `a/u/*/old` to `a/u/*/new`, and SYNCED for `a` follows +/// `a/u/z/new`, though the read of `a/v` finishes before that of `b`. #[test] -fn a_claim_is_shown_only_where_its_route_can_serve() { +fn a_grant_change_shows_what_it_keeps_before_synced() { let origin = Hop::new(1).unwrap().produce(); - let scoped = |scope: &[&str], at: &str| { - let producer = origin.scope("", &patterns(scope)).unwrap(); - producer.announce(at, origin::RouteInfo::new()).unwrap() - }; - let _x = scoped(&["a/*/x"], "a"); - let _private = scoped(&["c/private/**"], "c"); - let _target = scoped(&["s/*/x"], "s"); + let _new = origin.announce("a/u/z/new", origin::RouteInfo::new()).unwrap(); let consumer = origin - .mount("m", "s") + .mount("a/drop", "s") .unwrap() .scope("", &patterns(&["**"])) .unwrap() .consume(); - let told = |grant: Option<&[&str]>, prefix: &str| -> Vec { - let auth = crate::auth::Link::new(false); - if let Some(grant) = grant { - auth.handle().authorize(&crate::auth::Grant { - publish: Patterns::default(), - subscribe: patterns(grant), - expires: None, - }); - } - let mut answer = Answer::alone_on(consumer.clone(), auth); - let (mut writer, mut peer) = stream(); - answer.request(false, Vec::new(), vec![(path(prefix), false)]).unwrap(); - let mut told = Vec::new(); - for msg in sent(&mut answer, &mut writer, &mut peer) { - if let AnnounceBroadcast::Start { suffix, instance, .. } = msg { - told.push(peer.start(&suffix, &instance).0.to_string()); - } - } - told - }; - assert!(told(None, "a/q/y").is_empty()); - assert_eq!(told(None, "a/q/x"), ["a/q/x"]); - assert!(told(Some(&["a/*"]), "").is_empty()); - assert!(told(Some(&["a/q/y/**"]), "").is_empty()); - assert_eq!(told(Some(&["a/q/x/**"]), ""), ["a/q/x"]); - assert!(told(Some(&["c/public/**"]), "").is_empty()); - assert_eq!(told(Some(&["c/private/**"]), ""), ["c/private"]); - assert!(told(None, "m/q/y").is_empty()); - assert_eq!(told(None, "m/q/x"), ["m/q/x"]); -} - -/// A claim is judged by the routes as they stand: one hidden because its route serves only -/// `c/private/**` is shown once another route of its instance serves `c/public/**`, at the -/// next grant change, which judges it again. -#[test] -fn a_claim_is_judged_by_the_routes_as_they_stand() { - let origin = Hop::new(1).unwrap().produce(); - let instance: Instance = "cam".parse().unwrap(); - let route = |scope: &[&str], cost: u64| { - let producer = origin.scope("", &patterns(scope)).unwrap(); - let info = origin::RouteInfo::new() - .with_instance(instance.clone(), 0) - .with_cost(cost); - producer.announce("c", info).unwrap() - }; - let _private = route(&["c/private/**"], 1); let auth = crate::auth::Link::new(false); - let public = |extra: &[&str]| crate::auth::Grant { - publish: Patterns::default(), - subscribe: patterns(&[&["c/public/**"], extra].concat()), - expires: None, + let authorize = |subscribe: &[&str]| { + auth.handle().authorize(&crate::auth::Grant { + publish: Patterns::default(), + subscribe: patterns(subscribe), + expires: None, + }) }; - auth.handle().authorize(&public(&[])); - let mut answer = Answer::alone_on(origin.consume(), auth.clone()); + authorize(&["a/u/*/old", "a/drop/**"]); + let mut answer = Answer::alone_on(consumer, auth.clone()); let (mut writer, mut peer) = stream(); - answer.request(false, Vec::new(), vec![(path(""), false)]).unwrap(); - let starts = |msgs: &[AnnounceBroadcast]| { - msgs.iter() - .filter(|msg| matches!(msg, AnnounceBroadcast::Start { .. })) - .count() - }; - let first = sent(&mut answer, &mut writer, &mut peer); - assert_eq!(starts(&first), 0, "{first:?}"); + answer + .request(false, Vec::new(), vec![(path("a"), false), (path("b"), false)]) + .unwrap(); + // The session's key answers the edit; the mount at `a/drop` has yet to send its initial set. + answer.main.flush(); + while let Some(msg) = answer.main.try_wire() { + answer.output(&mut writer, msg).unwrap(); + } + flush(&mut writer); + let first = peer.take(); + assert_eq!(events(&mut peer, &first), ["SYNCED 1"], "{first:?}"); - let _public = route(&["c/public/**"], 5); - origin.route_node(); - auth.handle().authorize(&public(&["x/**"])); + authorize(&["a/u/*/new", "a/v/**", "b/**"]); answer.poll_permit(&kio::Waiter::noop()).unwrap(); let regranted = sent(&mut answer, &mut writer, &mut peer); - assert_eq!(starts(®ranted), 1, "{regranted:?}"); + assert_eq!( + events(&mut peer, ®ranted), + ["a/u/z/new", "SYNCED 0"], + "{regranted:?}" + ); } diff --git a/rs/moq-net/src/model/origin.rs b/rs/moq-net/src/model/origin.rs index d5fb3f453c..4ff2ddf103 100644 --- a/rs/moq-net/src/model/origin.rs +++ b/rs/moq-net/src/model/origin.rs @@ -2018,14 +2018,6 @@ impl Mounted { self.mount.name(path) } - /// The absolute, origin-side `patterns` as the handle names what they match at or - /// beneath the target: beneath the mount point. A name past the wire limits matches nothing. - pub fn name_patterns(&self, patterns: &Patterns) -> Patterns { - (patterns.rebase(self.mount.target.as_str())) - .rooted(self.mount.at.as_str()) - .unwrap_or_default() - } - /// How many segments the handle-side `path` lies beneath the mount point: the most a /// claim read through the mount can be above it. A claim covering the whole target, which /// is broader than the mount point as the handle sees it, covers no more than that. @@ -7853,19 +7845,6 @@ impl Consumer { allowed.iter().any(|pattern| ours.overlaps(pattern)) } - /// What the live routes announced exactly at the absolute `prefix` serving `instance` may - /// serve, absolute: each route's [`RouteEntry::reach`]. `None` when the table holds none, - /// as for a neighbour's claim no session serves here yet. - #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] - pub(crate) fn reach(&self, prefix: &Path, instance: &Instance) -> Option { - let state = self.shared.lock(); - let mut entries = (state.routes.at(prefix)) - .filter(|entry| entry.instance == *instance && entry.live()) - .peekable(); - entries.peek()?; - Some(entries.flat_map(|entry| entry.reach.iter().cloned()).collect()) - } - /// Whether the absolute `path` lies beneath one of this handle's mounts, where the /// origin's own claims at that path are hidden from it. #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] From 949041e4889b52879bd10d010433d5f92dc0275c Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Fri, 20 Nov 2026 10:52:49 -0800 Subject: [PATCH 10/11] quest: the Rust lite-07 claim reach check moves whole to lite07-claim-reach-routes Co-Authored-By: Claude Opus 5.5 --- quest/m2/lite07-claim-reach-routes.md | 82 +++++++++++++++++---------- quest/m2/lite07-finalize.md | 2 +- 2 files changed, 53 insertions(+), 31 deletions(-) diff --git a/quest/m2/lite07-claim-reach-routes.md b/quest/m2/lite07-claim-reach-routes.md index 67eb129c7a..8b921fdaea 100644 --- a/quest/m2/lite07-claim-reach-routes.md +++ b/quest/m2/lite07-claim-reach-routes.md @@ -1,42 +1,64 @@ -# [M] A lite-07 claim's reach follows every route that serves it +# [L] A Rust lite-07 answer shows a claim only where a route of it can serve ## Goal -A Rust lite-07 answer re-judges a claim the moment what its routes may serve changes, so a -peer is never left without a claim some route can serve, or shown one none can. Today the -answer looks the claim's reach up in the origin each time it judges the claim -(`Answer::reach` in `rs/moq-net/src/lite/publisher/routed.rs`), and two changes reach it -only at the claim's next change, grant change, or edit: +A Rust lite-07 publisher shows a peer a claim only where some route of the claim's instance +can serve a path the peer may ask for, as the JS answer already does, and re-judges the claim +the moment what those routes may serve changes. So a peer is never shown a claim no route can +serve, nor left without one some route can. -- A route of the same instance at the same prefix that does not win the prefix appears, - leaves, or changes scope: the origin's cursors report only the winning route, so the - node tells nothing. -- A scoped neighbour's claim is told before the session that gave it serves it into the - origin, so the lookup finds no route and the claim is shown as before the check. +Today `Answer::shows` (`rs/moq-net/src/lite/publisher/routed.rs`) judges the handle's scope and +the permit (`Consumer::reaches_any`, `Permit::beneath`) but never the route's reach, since the +node tells a claim without it. A route announced through a producer scoped to `a/*/x` at the +prefix `a` is shown at `a/q/y` (Above 2) to a peer that asks for `a/q/y`, and at `a` to a peer +confined to `a/*`, though the route serves neither: a request there fails. ## Plan -Found by the local review of [moq-dev/moq#9229](https://github.com/moq-dev/moq/pull/9229), -which carried the reach to `Answer::shows`. - -Decided 2026-11-20 (maintainer, on #9229): ✅ the lite-07 cut waits on this -quest, and #9229 lands without it (rejected: fixing it after the cut; holding -#9229 until it is fixed). #9229 can leave hidden a claim a costlier route of -its instance could serve, which main showed. +Decided 2026-11-20 (maintainer, on [moq-dev/moq#9229](https://github.com/moq-dev/moq/pull/9229)): +✅ the lite-07 cut waits on this quest, and #9229 lands without it (rejected: fixing it after the +cut; holding #9229 until it is fixed). #9229 first carried an origin lookup of the reach and +then dropped it here (see below), so until this lands Rust shows claims as before. - Recommended: carry the reach with the claim inside the node (on its `Attr`, never on the - wire), so the node tells every answer when it changes and the origin lookup goes. The - origin's own claims take it from the feeder cursor (`OwnClaims` in - `rs/moq-net/src/model/origin.rs`), which then reports the union reach of the winner's - instance at each prefix (`sync_route`, `TableCursor::update`); a neighbour's claims take - it from the session that gives them (`lite/subscriber/routed.rs`, `admits`: its producer's - scope intersected with the claim's prefix). -- Only the feeder's cursors compute the union, since every cursor touching a prefix visits - `TableCursor::update`; bench that over routes per prefix and cursors, both swept. + wire), so the node tells every answer when it changes and `shows` intersects it with the + permit beneath the path, lock-free. + - The origin's own claims take it from the feeder cursor (`OwnClaims` in + `rs/moq-net/src/model/origin.rs`), which then reports the union reach of the winner's + instance at each prefix (`sync_route`, `TableCursor::update`). The origin's cursors report + only the winning route, so without this a route of the same instance at the same prefix + that does not win (appears, leaves, or changes scope) reaches no answer. + - A neighbour's claims take it from the session that gives them (`lite/subscriber/routed.rs`, + `admits`: its producer's scope intersected with the claim's prefix). That session files the + route at the path the claim entered (`serve`, with `Lane::above` from the claim), not at the + claim's own prefix, and may tell the claim before it serves it into the origin. Carrying the + reach from the giver covers both. + - Each route's reach keeps its producer's exclusions (`RouteEntry::excluded`, which + `RouteEntry::authorizes` applies but `RouteEntry::reach` omits), applied before routes are + combined, so an exclusion on one route never hides what another serves. + - Through a mount, the answer names the reach as the handle names it member by member, + dropping only a member with no path within the wire limits: `Patterns::rooted` fails a + whole union when one member is too deep. + - Only the feeder's cursors compute the union, since every cursor touching a prefix visits + `TableCursor::update`; bench that over routes per prefix and cursors, both swept, and the + answer's judgment over sessions and claim churn. +- Rejected, tried in #9229: looking the reach up in the origin at each judgment + (`Consumer::reach` over `routes.at`). It took the origin's whole-table lock and allocated per + claim per session on the announce fan-out; it looked up the claim's own prefix (its path less + `above`) while a neighbour's route is filed where the claim entered, so a relayed claim missed + and the check failed open; it ignored exclusions; and a mount translation failed whole. - Rejected: a watch per claim the reach hides, which costs origin state per claim. -- The tests: a route of the claim's instance serving `c/public/**` announced beside a winner - serving only `c/private/**` shows the claim to a peer granted `c/public/**` at once; a - scoped neighbour granted `a/*/x` gives a claim at `a`, and a peer granted `a/q/y/**` is - never shown it. +- Any judgment change between a grant change and its SYNCED goes through `Answer::sync`, and + #9229 holds every prefix's SYNCED until a grant change's resync, so a reach change that + arrives through the node needs nothing more for SYNCED. +- The tests: a producer scoped to `a/*/x` announcing at `a`, asked for `a/q/y` with no grant and + for the root under `a/*` or `a/q/y/**`, shows nothing; asked for `a/q/x`, shows it; a mount + names the reach beneath its point. A route of the claim's instance serving `c/public/**` + announced beside a winner serving only `c/private/**` shows the claim to a peer granted + `c/public/**` at once. A scoped neighbour granted `a/*/x` gives a claim at `a` presented at + `a/q` (Above 1), and a peer granted `a/q/y/**` is never shown it. A producer scoped to + `t/x/live` and `t/y/chat` that excludes `t/x` is never shown under `t/*/live`. The property + test in `lite/publisher/routed/tests.rs` (`synced_follows_what_the_grant_shows`) already + announces through scoped producers: its oracle then covers reach as well. Public API: none. Wire: none. diff --git a/quest/m2/lite07-finalize.md b/quest/m2/lite07-finalize.md index 410740dfa1..6294a945a3 100644 --- a/quest/m2/lite07-finalize.md +++ b/quest/m2/lite07-finalize.md @@ -214,7 +214,7 @@ the version that ships them. ## Required - [Cache-aware multicast](/quest/m2/multicast/README.md) - lite-07 carries the redesigned route layer: routes to forwarding nodes, no holds or doubt, claims crossing trust boundaries by a chain, and no Route Key -- [A lite-07 claim's reach follows every route that serves it](/quest/m2/lite07-claim-reach-routes.md) - a peer is never left without a claim some route can serve, nor shown one none can (maintainer, 2026-11-20) +- [A Rust lite-07 answer shows a claim only where a route of it can serve](/quest/m2/lite07-claim-reach-routes.md) - a peer is never shown a claim no route can serve, nor left without one some route can (maintainer, 2026-11-20) ## Related From 9907493cf17a7d3bd57dcd309e756707bf7807ad Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Fri, 20 Nov 2026 11:50:50 -0800 Subject: [PATCH 11/11] quest: claim reach rides prefix grants instead of a reach check A relay cannot judge a neighbour claim's reach: lite-07 carries none, so a relay that takes a claim over a session granted everything shows it where the upstream route cannot serve. The maintainer chose to revert grants to prefixes, so a route serves whole subtrees and a claim's reach is where it is filed and presented, exact at every hop with no new wire field. prefix-grants owns the revert; claim-reach-routes now files and presents claims no broader than their grants, and requires it. Co-Authored-By: Claude Opus 5.5 --- quest/m2/lite07-claim-reach-routes.md | 108 +++++++++++++------------- quest/m2/lite07-finalize.md | 2 +- quest/m2/prefix-grants.md | 46 +++++++++++ 3 files changed, 102 insertions(+), 54 deletions(-) create mode 100644 quest/m2/prefix-grants.md diff --git a/quest/m2/lite07-claim-reach-routes.md b/quest/m2/lite07-claim-reach-routes.md index 8b921fdaea..17c91f18b9 100644 --- a/quest/m2/lite07-claim-reach-routes.md +++ b/quest/m2/lite07-claim-reach-routes.md @@ -1,64 +1,66 @@ -# [L] A Rust lite-07 answer shows a claim only where a route of it can serve +# [L] A lite-07 claim is shown no broader than the grants it crossed ## Goal -A Rust lite-07 publisher shows a peer a claim only where some route of the claim's instance -can serve a path the peer may ask for, as the JS answer already does, and re-judges the claim -the moment what those routes may serve changes. So a peer is never shown a claim no route can -serve, nor left without one some route can. +Every lite-07 node files and presents a claim no broader than its route can serve under the +grants that route crossed, at every hop. So a peer is never shown a claim at a path no route of +it can serve, through any number of relays. Nothing about it is local-only: the path a claim is +presented at, with its Above, carries its reach on the wire. -Today `Answer::shows` (`rs/moq-net/src/lite/publisher/routed.rs`) judges the handle's scope and -the permit (`Consumer::reaches_any`, `Permit::beneath`) but never the route's reach, since the -node tells a claim without it. A route announced through a producer scoped to `a/*/x` at the -prefix `a` is shown at `a/q/y` (Above 2) to a peer that asks for `a/q/y`, and at `a` to a peer -confined to `a/*`, though the route serves neither: a request there fails. +Today the Rust answer (`Answer::shows`, `rs/moq-net/src/lite/publisher/routed.rs`) judges the +handle's scope and the permit but never the route's reach. A producer granted `a/b` that +announces at `a` is shown to a peer asking for `a/q`, though a request there fails Unroutable. +The JS answer judges reach in-process, but no node can judge it through a relay. A relay that +takes the claim over a session granted everything files it at `a`, and shows it at `a/q` to its +own peers. The request is refused Unroutable upstream while the claim stays shown, which strands +the reader as the splice-stall did. ## Plan Decided 2026-11-20 (maintainer, on [moq-dev/moq#9229](https://github.com/moq-dev/moq/pull/9229)): ✅ the lite-07 cut waits on this quest, and #9229 lands without it (rejected: fixing it after the -cut; holding #9229 until it is fixed). #9229 first carried an origin lookup of the reach and -then dropped it here (see below), so until this lands Rust shows claims as before. +cut; holding #9229 until it is fixed). ✅ Grants become prefixes +([prefix grants](/quest/m2/prefix-grants.md)), so a route serves whole subtrees and a claim's +reach is where it is filed and presented (rejected: carrying the reach as patterns on +ANNOUNCE_START and ANNOUNCE_UPDATE, a wire field and its machinery that only wildcard grants +needed; judging reach from the routes a node knows, which a relay cannot do, so in-process and +relayed answers differ; never judging reach, which shows claims a request then fails Unroutable +on). -- Recommended: carry the reach with the claim inside the node (on its `Attr`, never on the - wire), so the node tells every answer when it changes and `shows` intersects it with the - permit beneath the path, lock-free. - - The origin's own claims take it from the feeder cursor (`OwnClaims` in - `rs/moq-net/src/model/origin.rs`), which then reports the union reach of the winner's - instance at each prefix (`sync_route`, `TableCursor::update`). The origin's cursors report - only the winning route, so without this a route of the same instance at the same prefix - that does not win (appears, leaves, or changes scope) reaches no answer. - - A neighbour's claims take it from the session that gives them (`lite/subscriber/routed.rs`, - `admits`: its producer's scope intersected with the claim's prefix). That session files the - route at the path the claim entered (`serve`, with `Lane::above` from the claim), not at the - claim's own prefix, and may tell the claim before it serves it into the origin. Carrying the - reach from the giver covers both. - - Each route's reach keeps its producer's exclusions (`RouteEntry::excluded`, which - `RouteEntry::authorizes` applies but `RouteEntry::reach` omits), applied before routes are - combined, so an exclusion on one route never hides what another serves. - - Through a mount, the answer names the reach as the handle names it member by member, - dropping only a member with no path within the wire limits: `Patterns::rooted` fails a - whole union when one member is too deep. - - Only the feeder's cursors compute the union, since every cursor touching a prefix visits - `TableCursor::update`; bench that over routes per prefix and cursors, both swept, and the - answer's judgment over sessions and claim churn. -- Rejected, tried in #9229: looking the reach up in the origin at each judgment - (`Consumer::reach` over `routes.at`). It took the origin's whole-table lock and allocated per - claim per session on the announce fan-out; it looked up the claim's own prefix (its path less - `above`) while a neighbour's route is filed where the claim entered, so a relayed claim missed - and the check failed open; it ignored exclusions; and a mount translation failed whole. -- Rejected: a watch per claim the reach hides, which costs origin state per claim. -- Any judgment change between a grant change and its SYNCED goes through `Answer::sync`, and - #9229 holds every prefix's SYNCED until a grant change's resync, so a reach change that - arrives through the node needs nothing more for SYNCED. -- The tests: a producer scoped to `a/*/x` announcing at `a`, asked for `a/q/y` with no grant and - for the root under `a/*` or `a/q/y/**`, shows nothing; asked for `a/q/x`, shows it; a mount - names the reach beneath its point. A route of the claim's instance serving `c/public/**` - announced beside a winner serving only `c/private/**` shows the claim to a peer granted - `c/public/**` at once. A scoped neighbour granted `a/*/x` gives a claim at `a` presented at - `a/q` (Above 1), and a peer granted `a/q/y/**` is never shown it. A producer scoped to - `t/x/live` and `t/y/chat` that excludes `t/x` is never shown under `t/*/live`. The property - test in `lite/publisher/routed/tests.rs` (`synced_follows_what_the_grant_shows`) already - announces through scoped producers: its oracle then covers reach as well. +- A route serves the claim's subtree within its producer's grant prefixes. So: + - The origin files a producer's claim at each of its grant's prefixes beneath the claim's own + prefix, with Above, and as now when a grant prefix lies at or above it + (`rs/moq-net/src/model/origin.rs`, `RouteEntry`, `sync_route`). + - A session files a neighbour's claim where the session's grant meets the path the claim + entered at, the same way (`lite/subscriber/routed.rs`, `admits` and `serve`). + - An answer presents a claim no higher than where it is filed, as the draft's region rule + already presents a claim above a region at that region. The draft says so in Claims, so a + relay passes on what it was shown. + - `Answer::shows` then judges only the handle's scope and the permit, and the JS answer's reach + check becomes the same rule. Delete the reach code the filing replaces, in Rust and JS. +- One claim filed at several grant prefixes is one claim: one Announce ID per presented path, + one Instance, and the specificity of its own prefix (`RouteEntry::specificity`). A grant + change re-files it under #9229's SYNCED hold (`Answer::sync`). +- Exclusions (`Producer::exclude`): the relay's one caller keeps publishers out of its stats + prefix, which the relay's own more specific claim owns, so that claim wins its paths. Test it. + Recommended: refuse announcing a claim over an exclusion no more specific claim can own, + rather than show a hole. +- The tests: + - A producer granted `a/b` that announces at `a` is shown at `a/b` with Above 1. A peer + asking for `a/q` is shown nothing, and a peer asking for `a/b/c` is shown it. + - The same claim relayed over a session granted everything is shown the same way one and two + hops on (the multi-hop case). + - A neighbour granted `customer` gives a claim at the root, and it is presented onward at + `customer` with Above 1. + - A mount names the claim beneath its point. + - The property test in `lite/publisher/routed/tests.rs` (`synced_follows_what_the_grant_shows`) + announces through granted producers, so its oracle covers reach. +- Bench filing over grant prefixes per claim and claims per prefix, both swept, and the answer's + judgment over sessions and claim churn. -Public API: none. Wire: none. +Public API: none. Wire: the draft's Claims rule for where a claim is presented. + +## Required + +- [Prefix grants](/quest/m2/prefix-grants.md) - a grant is a set of prefixes, so a route serves + whole subtrees diff --git a/quest/m2/lite07-finalize.md b/quest/m2/lite07-finalize.md index 6294a945a3..71afcac469 100644 --- a/quest/m2/lite07-finalize.md +++ b/quest/m2/lite07-finalize.md @@ -214,7 +214,7 @@ the version that ships them. ## Required - [Cache-aware multicast](/quest/m2/multicast/README.md) - lite-07 carries the redesigned route layer: routes to forwarding nodes, no holds or doubt, claims crossing trust boundaries by a chain, and no Route Key -- [A Rust lite-07 answer shows a claim only where a route of it can serve](/quest/m2/lite07-claim-reach-routes.md) - a peer is never shown a claim no route can serve, nor left without one some route can (maintainer, 2026-11-20) +- [A lite-07 claim is shown no broader than the grants it crossed](/quest/m2/lite07-claim-reach-routes.md) - a peer is never shown a claim at a path no route of it can serve, through any number of relays (maintainer, 2026-11-20) ## Related diff --git a/quest/m2/prefix-grants.md b/quest/m2/prefix-grants.md new file mode 100644 index 0000000000..f1b1518a05 --- /dev/null +++ b/quest/m2/prefix-grants.md @@ -0,0 +1,46 @@ +# [L] A grant is a set of path prefixes again + +## Goal + +Every grant is a set of path prefixes, each covering its whole subtree, as before +[moq-dev/moq#3746](https://github.com/moq-dev/moq/pull/3746). That covers a token's publish +and subscribe lists, `moq auth serve` rules, the relay's public rules, an origin handle's +scope, and lite-07's AUTH_OK. A wildcard grant (`live/*`, `*/chat`, `cam-*.hang`) is refused +where it is made. So a route a grant admits always serves whole subtrees, and a claim's reach +is the path it is shown at ([claim reach](/quest/m2/lite07-claim-reach-routes.md)). + +## Plan + +Decided 2026-11-20 (maintainer, on [moq-dev/moq#9229](https://github.com/moq-dev/moq/pull/9229)): +✅ revert to prefix grants before the lite-07 cut. No use case needed a wildcard grant, and one +makes a claim's reach inexpressible through a relay (rejected: keeping wildcard grants and +carrying a claim's reach as patterns on ANNOUNCE_START and ANNOUNCE_UPDATE). + +- Back out the grant half of #3746 and the pattern-valued scopes of + [moq-dev/moq#3672](https://github.com/moq-dev/moq/pull/3672): + - `Producer::scope`, `Consumer::scope`, and their `allowed` take and return prefixes, in + Rust (`rs/moq-net/src/model/origin.rs`, `OriginScope`) and JS (`js/net`). + - `Permit` (`rs/moq-net/src/auth.rs`) holds prefixes. + - moq-auth and @moq/auth tokens, `moq auth serve` rules, the relay's `public*` config, + moq-ffi, and the bindings carry prefixes. + - Anything that only existed to intersect wildcard grants goes with it, such as + `Consumer::reaches_any` where a prefix test now does. + - Discovery filters, which choose the claims a reader looks at (announcement captures), keep + their patterns: reach does not concern them. +- Wire: lite-07's AUTH_OK carries Publish and Subscribe Prefixes, and the region rule's regions + (`drafts/draft-lcurley-moq-lite.md`, Announce Request) are the scope's prefixes. The Path + Pattern section goes, with any other use the draft keeps. lite-07 is unpublished, so nothing + stays compatible with the pattern form. +- Syntax, recommended: a member `foo` covers `foo` and its subtree, and the empty member covers + everything. A trailing `/**` (and a bare `**`) parses as the same prefix, since it names exactly + that set, so deployed `anon/**` tokens and configs keep their meaning. Every other wildcard is + refused where it is parsed. The migration note warns that a bare member minted since #3746 + widens from one broadcast to its subtree. +- Align the quests that assume wildcard members: `quest/m4/regrant-route-recheck.md` (a member's + literal prefix before its first wildcard) and `quest/m5/peer-grant-bound.md` (the Orthogonal + Vectors bound, which prefixes remove). +- Docs: `doc/bin/relay/auth.md` (Path matching and the rule tables), and each library page that + shows a wildcard grant. + +Public API: breaking (grant types and token contents, in Rust, JS, and the bindings). Wire: +lite-07 AUTH_OK.