From 300e47bd7836db19c710dc21077b232eaab9cac4 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 22 Oct 2026 19:11:02 -0700 Subject: [PATCH 1/4] chore(quest): claim quest/m1/api-audit/resolve.md Quest-Claim: 12931269bf9f0263 From ea7f86037a4c9cb818d426e40021c791f5ac1497 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 22 Oct 2026 20:52:37 -0700 Subject: [PATCH 2/4] feat(net): own broadcast discovery during resolution Keep one-instance requests scoped to synchronized discovery, follow pinned instances through gaps, and preserve explicit refusal provenance. Use the shared native resolver for mux references and stats while recording the remaining public API rollout. Co-Authored-By: GPT-6 --- cpp/moq/MIGRATE.md | 4 +- dart/moq/MIGRATE.md | 4 +- dart/moq_ffi/MIGRATE.md | 4 +- dart/moq_ffi/lib/src/moq.dart | 4 +- doc/lib/rs/moq-net.md | 2 +- go/ffi/MIGRATE.md | 4 +- go/wrapper/MIGRATE.md | 4 +- js/net/MIGRATE.md | 7 + js/net/bench/requests.ts | 25 +++ js/net/src/connection/forward.test.ts | 63 ++++-- js/net/src/connection/forward.ts | 6 +- js/net/src/integration.test.ts | 25 +-- js/net/src/origin-request.test.ts | 179 ++++++++++++++++-- js/net/src/origin.test.ts | 6 +- js/net/src/origin.ts | 111 +++++------ kt/moq-ffi/MIGRATE.md | 4 +- kt/moq/MIGRATE.md | 4 +- py/moq-ffi/MIGRATE.md | 4 +- py/moq-rs/MIGRATE.md | 4 +- py/moq-rs/README.md | 2 +- quest/m1/api-audit/resolve.md | 102 +++++----- rs/moq-c/MIGRATE.md | 4 +- rs/moq-c/src/api.rs | 10 +- rs/moq-ffi/MIGRATE.md | 4 +- rs/moq-ffi/src/origin.rs | 17 +- rs/moq-ffi/src/test.rs | 9 +- rs/moq-mux/src/source.rs | 76 ++------ rs/moq-net/MIGRATE.md | 12 +- rs/moq-net/benches/origin.rs | 56 +++--- rs/moq-net/src/lite/publisher.rs | 2 +- rs/moq-net/src/model/follow.rs | 35 +++- rs/moq-net/src/model/mod.rs | 5 +- rs/moq-net/src/model/origin.rs | 169 +++++++++++------ .../tests/integration/lazy_discovery.rs | 72 ++++++- rs/moq-net/tests/integration/model.rs | 2 +- rs/moq-stats/src/aggregate.rs | 28 +-- swift/MIGRATE.md | 4 +- swift/ffi/MIGRATE.md | 4 +- 38 files changed, 696 insertions(+), 381 deletions(-) diff --git a/cpp/moq/MIGRATE.md b/cpp/moq/MIGRATE.md index e128eb16e37..f81a55a3221 100644 --- a/cpp/moq/MIGRATE.md +++ b/cpp/moq/MIGRATE.md @@ -13,8 +13,8 @@ To keep a value's moq-lite byte, subtract 128 from it, widening first (`static_c ### A client asks only about what it watches (#6165) On moq-lite, a client session asks its relay for announcements only under paths something watches, through `announced` or `announced_broadcast`, instead of under its whole scope at connect. -`OriginConsumer::request_broadcast` watches nothing, so on a client it fails with an unroutable error for a path nothing watches, even when the relay announces it. -Resolve the path with `announced_broadcast`, or hold `announced` over its prefix while requesting. +`OriginConsumer::request_broadcast` owns discovery of its path while resolving and reports an unroutable path only once discovery has synced without a covering route. +Request the path directly; no separate announcement stream is needed for resolution. An explicit selected-handler refusal is returned directly, including while following announcements. Handle that error before explicitly trying a later resolution. moq-transport and moq-lite-03/04 sessions are unchanged. ### `moq::ContainerFormat::kFmp4` unwraps to Legacy (#6250) diff --git a/dart/moq/MIGRATE.md b/dart/moq/MIGRATE.md index d466a24a91f..345cdf72946 100644 --- a/dart/moq/MIGRATE.md +++ b/dart/moq/MIGRATE.md @@ -19,8 +19,8 @@ To keep a value's moq-lite byte, subtract 128 from it: 255 becomes 127, 128 beco ### A client asks only about what it watches (#6165) On moq-lite, a client session asks its relay for announcements only under paths something watches, through `announced()` or `announcedBroadcast()`, instead of under its whole scope at connect. -`requestBroadcast()` watches nothing, so on a client it fails with an unroutable error for a path nothing watches, even when the relay announces it. -Resolve the path with `announcedBroadcast()`, or hold `announced()` over its prefix while requesting. +`requestBroadcast()` owns discovery of its path while resolving and reports an unroutable path only once discovery has synced without a covering route. +Request the path directly; no separate announcement stream is needed for resolution. An explicit selected-handler refusal is returned directly, including while following announcements. Handle that error before explicitly trying a later resolution. moq-transport and moq-lite-03/04 sessions are unchanged. ### `ContainerFormat.fmp4` unwraps to Legacy (#6250) diff --git a/dart/moq_ffi/MIGRATE.md b/dart/moq_ffi/MIGRATE.md index 8df537cb61c..6c1aeb57d39 100644 --- a/dart/moq_ffi/MIGRATE.md +++ b/dart/moq_ffi/MIGRATE.md @@ -14,8 +14,8 @@ Regenerate the bindings for the changed checksums. ### A client asks only about what it watches (#6165) On moq-lite, a client session asks its relay for announcements only under paths something watches, through `announced()` or `announcedBroadcast()`, instead of under its whole scope at connect. -`MoqOriginConsumer.requestBroadcast()` watches nothing, so on a client it fails with an unroutable error for a path nothing watches, even when the relay announces it. -Resolve the path with `announcedBroadcast()`, or hold `announced()` over its prefix while requesting. +`MoqOriginConsumer.requestBroadcast()` owns discovery of its path while resolving and reports an unroutable path only once discovery has synced without a covering route. +Request the path directly; no separate announcement stream is needed for resolution. An explicit selected-handler refusal is returned directly, including while following announcements. Handle that error before explicitly trying a later resolution. moq-transport and moq-lite-03/04 sessions are unchanged. Regenerate the bindings for the changed `request_broadcast` checksum. diff --git a/dart/moq_ffi/lib/src/moq.dart b/dart/moq_ffi/lib/src/moq.dart index f530ade4eea..a1da55f0ce0 100644 --- a/dart/moq_ffi/lib/src/moq.dart +++ b/dart/moq_ffi/lib/src/moq.dart @@ -19605,11 +19605,11 @@ void _checkApiChecksums() { throw UniffiInternalError.panicked("UniFFI API checksum mismatch"); } if (uniffi_moq_ffi_checksum_method_moqoriginconsumer_announced_broadcast() != - 56171) { + 40619) { throw UniffiInternalError.panicked("UniFFI API checksum mismatch"); } if (uniffi_moq_ffi_checksum_method_moqoriginconsumer_request_broadcast() != - 65225) { + 36974) { throw UniffiInternalError.panicked("UniFFI API checksum mismatch"); } if (uniffi_moq_ffi_checksum_method_moqorigindynamic_cancel() != 47453) { diff --git a/doc/lib/rs/moq-net.md b/doc/lib/rs/moq-net.md index d9295f9ad4a..290bf6e4df7 100644 --- a/doc/lib/rs/moq-net.md +++ b/doc/lib/rs/moq-net.md @@ -19,7 +19,7 @@ What you use it for, beyond what the concept page already describes: - **Requests can pin an epoch.** `consumer.request_broadcast(path, Some(epoch))` resolves only through a route announcing that [publisher epoch](/concept/moq-lite#publisher-epochs); `None` takes whichever route wins. The resolved consumer names its epoch in `info().epoch`, pinned or not. - **Rank several CDNs.** Dial each with its own subscribe handle, `origin.clone().with_preference(origin::Preference::new(rank))` (higher wins; 0 is neutral and a negative rank demotes), all on one origin. Requests use the preferred link that has a route and fail over to the next; see [multiple CDNs](/concept/moq-lite#multiple-cdns). - **Follow restarts.** `consumer.announced_broadcast(path, None)` hands out each publisher instance serving a path from `available()`: the first once announced, then each one that takes over or returns after an end, like JS `request(path, { announced: true })`. A broadcast already resolved stays on the old instance until dropped or its route goes. `consumer.follow(path)` yields the underlying start, update, restart, and end of the route a request resolves. -- **Discovery follows what you watch.** On moq-lite, a client session asks the relay for announcements only under the prefixes its subscribe origin's readers watch, with `announced()`, `routed_broadcast`, or `announced_broadcast`, stops asking about a prefix 2s after nothing at or beneath it is watched, and asks again on reconnect. A broadcast resolved through a discovered route keeps its path watched until dropped. `request_broadcast` watches nothing, so a path nobody watches is unroutable. A server session, or a client fed into a `peer()` or `upstream()` origin handle, asks for everything it may, so a relay discovers everything. An HTTP gateway (the moq-hls `Server`, the moq-rtc WHEP router) watches its whole scope while it lives, so the paths its callers name never open a request each. moq-transport sessions, and moq-lite-03/04 sessions (whose announcements mark no initial set), still ask for everything. +- **Discovery follows what you watch.** On moq-lite, a client session asks the relay for announcements only under the prefixes its subscribe origin's readers watch, with `announced()`, `routed_broadcast`, or `announced_broadcast`, stops asking about a prefix 2s after nothing at or beneath it is watched, and asks again on reconnect. A broadcast resolved through a discovered route keeps its path watched until dropped. `request_broadcast` owns discovery of its path and reports absence only once discovery has synced; no separate watch is needed. A server session, or a client fed into a `peer()` or `upstream()` origin handle, asks for everything it may, so a relay discovers everything. An HTTP gateway (the moq-hls `Server`, the moq-rtc WHEP router) watches its whole scope while it lives, so the paths its callers name never open a request each. moq-transport sessions, and moq-lite-03/04 sessions (whose announcements mark no initial set), still ask for everything. - **One track per name.** Concurrent subscriptions share one request and producer. The application owns sequence numbers: a producer that replaces an ended one gets `Error::Duplicate` from an append that would reuse a sequence the name already wrote, so it starts with `create_group` at an explicit sequence. Only a new broadcast starts over. Readers of an aborted track resume onto the replacement only when the broadcast announces an epoch; otherwise their subscription ends with the error. - **End a broadcast with `finish()`.** When the input ends, finish the tracks, then call `broadcast.finish()`. The returned handle keeps the broadcast announced and serving its finished tracks for `linger()`, their longest max-age, so a subscriber still catching up can drain them. Await `wait()` on a runtime, or drop the handle once your own clock passes `linger()`. Dropping it early is the interrupt, and `close()` on another handle ends it at once. - **Publish only while someone is watching.** `demand()` on a track, group, or broadcast says whether a subscriber is attached, which is how capture and transcode skip work nobody asked for. Holding a broadcast or track consumer is not demand: a track consumer requests nothing until it queries, subscribes, or fetches, and those count until dropped. A shared fetch stays up until its last reader leaves. diff --git a/go/ffi/MIGRATE.md b/go/ffi/MIGRATE.md index 5319a4adb04..93a16df25aa 100644 --- a/go/ffi/MIGRATE.md +++ b/go/ffi/MIGRATE.md @@ -14,8 +14,8 @@ Regenerate the bindings for the changed checksums. ### A client asks only about what it watches (#6165) On moq-lite, a client session asks its relay for announcements only under paths something watches, through `Announced()` or `AnnouncedBroadcast()`, instead of under its whole scope at connect. -`MoqOriginConsumer.RequestBroadcast()` watches nothing, so on a client it fails with an unroutable error for a path nothing watches, even when the relay announces it. -Resolve the path with `AnnouncedBroadcast()`, or hold `Announced()` over its prefix while requesting. +`MoqOriginConsumer.RequestBroadcast()` owns discovery of its path while resolving and reports an unroutable path only once discovery has synced without a covering route. +Request the path directly; no separate announcement stream is needed for resolution. An explicit selected-handler refusal is returned directly, including while following announcements. Handle that error before explicitly trying a later resolution. moq-transport and moq-lite-03/04 sessions are unchanged. Regenerate the bindings for the changed `request_broadcast` checksum. diff --git a/go/wrapper/MIGRATE.md b/go/wrapper/MIGRATE.md index 765675dbae7..52bfef5ad15 100644 --- a/go/wrapper/MIGRATE.md +++ b/go/wrapper/MIGRATE.md @@ -19,8 +19,8 @@ To keep a value's moq-lite byte, subtract 128 from it: 255 becomes 127, 128 beco ### A client asks only about what it watches (#6165) On moq-lite, a client session asks its relay for announcements only under paths something watches, through `Announced()` or `AnnouncedBroadcast()`, instead of under its whole scope at connect. -`OriginConsumer.RequestBroadcast()` watches nothing, so on a client it fails with an unroutable error for a path nothing watches, even when the relay announces it. -Resolve the path with `AnnouncedBroadcast()`, or hold `Announced()` over its prefix while requesting. +`OriginConsumer.RequestBroadcast()` owns discovery of its path while resolving and reports an unroutable path only once discovery has synced without a covering route. +Request the path directly; no separate announcement stream is needed for resolution. An explicit selected-handler refusal is returned directly, including while following announcements. Handle that error before explicitly trying a later resolution. moq-transport and moq-lite-03/04 sessions are unchanged. ### `media.ContainerFormatFmp4` unwraps to Legacy (#6250) diff --git a/js/net/MIGRATE.md b/js/net/MIGRATE.md index 85a6485f847..290c2992957 100644 --- a/js/net/MIGRATE.md +++ b/js/net/MIGRATE.md @@ -4,6 +4,13 @@ How to update your code for each breaking change, newest first. ## Unreleased +### Broadcast requests own discovery + +`Origin.Consumer.request` watches its path from creation until close and reports absence once scoped discovery has synced. +Paths containing wildcard characters are refused before registering a request because discovery cannot name them. +`{ announced: true, epoch }` follows that instance through gaps and returns it when announced again. +Announcement-following requests no longer fall back to blind requests on a session without discovery; use a plain request for that session. + ### Stage a requested track before subscribers see it (#6111) `Track.Request.stage(info)` returns a `Track.Staged` whose `producer` writes while subscribers waiting on the request stay pending; `commit()` publishes it with everything written so far and returns the `Producer`. diff --git a/js/net/bench/requests.ts b/js/net/bench/requests.ts index 32aa2666a3f..e61037734e8 100644 --- a/js/net/bench/requests.ts +++ b/js/net/bench/requests.ts @@ -343,3 +343,28 @@ for (const [version, alpn] of [ origin.close(); } } + +// Missing-path classification examines only ancestor prefixes, even with unrelated snapshots. +console.log("unrelated_snapshots,requests,lookup_us"); +for (const unrelated of [8, 128, 2048]) + for (const requesters of [1, 8, 32]) { + const origin = new Producer(); + const wire = wireOf(origin); + const detach = wire.attach(true); + const pending = Array.from({ length: unrelated }, (_, i) => wire.snapshot(Path.from(`other/${i}`))); + const requests = Array.from({ length: requesters }, (_, i) => origin.request(Path.from(`missing/${i}`))); + const samples: number[] = []; + for (let round = 0; round < 7; round++) { + const start = performance.now(); + for (let iteration = 0; iteration < 128; iteration++) + for (const request of requests) + if (!request.unroutable.peek()) throw new Error("unrelated snapshot delayed absence"); + if (round > 0) samples.push(((performance.now() - start) * 1000) / 128); + } + samples.sort((a, b) => a - b); + console.log(`${unrelated},${requesters},${samples[3].toFixed(2)}`); + for (const request of requests) request.close(); + for (const land of pending) land(); + detach(); + origin.close(); + } diff --git a/js/net/src/connection/forward.test.ts b/js/net/src/connection/forward.test.ts index ed3350c345a..5ed4b2737c0 100644 --- a/js/net/src/connection/forward.test.ts +++ b/js/net/src/connection/forward.test.ts @@ -113,17 +113,22 @@ function record(stream: Announce.Consumer): string[] { return events; } -test("no watcher opens no announce request, and a plain request answers blind", async () => { +test("a plain request discovers an unwatched path and waits for its initial set", async () => { const origin = new OriginProducer(); const session = new FakeSession(); forwardAnnounced(session.session, origin); - + expect(session.requests).toEqual([]); const request = origin.request(Path.from("room")); await settle(); - expect(session.requests).toEqual([]); + expect(session.open()).toEqual(["room/**"]); + expect(request.active.peek()).toBeUndefined(); + expect(request.unroutable.peek()).toBe(false); + expect(session.consumes(Path.from("room"))).toBe(0); + start(session.stream("room/**"), "room"); + session.stream("room/**").synced(); + await settle(); expect(request.active.peek()).toBeDefined(); expect(session.consumes(Path.from("room"))).toBe(1); - request.close(); session.die(); origin.close(); @@ -413,8 +418,12 @@ test("a refused announce request downgrades the session once, and later watches session.stream("room/**").close(new Error("namespace rejected")); await settle(); expect(origin.discovery.peek()).toBe(false); - // The gated request falls back to a blind answer on the live session. - expect(watched.active.peek()).toBeDefined(); + // Following cannot use a peer that no longer announces; a plain request can. + expect(watched.active.peek()).toBeUndefined(); + expect(session.consumes(path)).toBe(0); + const plain = origin.request(path); + await settle(); + expect(plain.active.peek()).toBeDefined(); expect(session.consumes(path)).toBe(1); const later = origin.announced(Path.Pattern.subtree(Path.from("other"))); @@ -422,6 +431,7 @@ test("a refused announce request downgrades the session once, and later watches expect(session.requests.length).toBe(1); later.close(); + plain.close(); watched.close(); session.die(); origin.close(); @@ -450,13 +460,17 @@ test("a discovery failure under a live session retracts what it fed and answers expect(wireOf(origin).routes(path)).toBe(false); expect(origin.discovery.peek()).toBe(false); - // The same request falls back to a blind answer on the live session. + // The follower stays offline; a separate plain request can use the blind peer. expect(watched.closed.peek()).toBeUndefined(); - expect(watched.active.peek()).toBeDefined(); + expect(watched.active.peek()).toBeUndefined(); + const plain = origin.request(path); + await settle(); + expect(plain.active.peek()).toBeDefined(); // The announcement's own consume, plus the blind answer standing in for it now. expect(session.consumes(path)).toBe(2); watched.close(); + plain.close(); session.die(); origin.close(); }); @@ -491,6 +505,11 @@ test("a request replaced across one coalesced wakeup still gets answered", async const path = Path.from("wanted"); forwardAnnounced(session.session, origin); + const listing = origin.announced(Path.Pattern.subtree(path)); + await settle(); + start(session.stream("wanted/**"), "wanted"); + session.stream("wanted/**").synced(); + await settle(); const first = origin.request(path); await settle(); @@ -510,6 +529,7 @@ test("a request replaced across one coalesced wakeup still gets answered", async expect(session.consumes(path)).toBe(2); second.close(); + listing.close(); session.die(); origin.close(); }); @@ -553,7 +573,7 @@ test("a scoped origin narrows a root watch to its disjoint literal heads", async origin.close(); }); -test("a scoped session filters announcements and blind requests under its root", async () => { +test("a scoped session filters discovered routes and requests under its root", async () => { const origin = new OriginProducer(); const scoped = origin.scope(Path.from("tenant"), new Path.Patterns([Path.Pattern.parse("room/*/chat")])); const session = new FakeSession(); @@ -564,12 +584,13 @@ test("a scoped session filters announcements and blind requests under its root", await settle(); // Session-relative: the scope's root is the session's. expect(session.open()).toEqual(["room/**"]); - for (const prefix of ["room/alice/video", "room/alice/chat"]) start(session.stream("room/**"), prefix); + for (const prefix of ["room/alice/video", "room/alice/chat", "room/bob/chat"]) + start(session.stream("room/**"), prefix); const allowed = origin.request(Path.from("tenant/room/bob/chat")); const denied = origin.request(Path.from("tenant/room/bob/video")); await settle(); - expect(events).toEqual(["start tenant/room/alice/chat"]); + expect(events).toEqual(["start tenant/room/alice/chat", "start tenant/room/bob/chat"]); expect(session.consumes(Path.from("room/bob/chat"))).toBe(1); expect(session.consumes(Path.from("room/bob/video"))).toBe(0); @@ -675,3 +696,23 @@ test("a request synced as it opens releases the watcher", async () => { session.die(); origin.close(); }); + +test("a scoped session refuses blind requests outside its allowed paths", async () => { + const origin = new OriginProducer(); + const scoped = origin.scope(Path.from("tenant"), new Path.Patterns([Path.Pattern.parse("room/*/chat")])); + const session = new FakeSession(); + forwardAnnounced(session.session, scoped); + const allowed = origin.request(Path.from("tenant/room/bob/chat")); + const denied = origin.request(Path.from("tenant/room/bob/video")); + await settle(); + for (const request of session.requests) request.stream.close(new Error("no discovery")); + await settle(); + expect(allowed.active.peek()).toBeDefined(); + expect(session.consumes(Path.from("room/bob/chat"))).toBe(1); + expect(denied.active.peek()).toBeUndefined(); + expect(session.consumes(Path.from("room/bob/video"))).toBe(0); + allowed.close(); + denied.close(); + session.die(); + origin.close(); +}); diff --git a/js/net/src/connection/forward.ts b/js/net/src/connection/forward.ts index 684482c7977..40bad5d2637 100644 --- a/js/net/src/connection/forward.ts +++ b/js/net/src/connection/forward.ts @@ -50,7 +50,7 @@ interface Reported { * requests with blind subscriptions. * * Discovery is lazy. One announce request opens per prefix in the origin's covering set of - * watches (`announced(scope)` and `request(path, { announced: true })`) that no open request + * watches (`announced(scope)` and every `request(path)`) that no open request * already covers, and closes {@link LINGER} after nothing at or beneath its prefix is watched. * A narrower watch rides an open broader request, and a narrower request already open stays * open until the broader one covering it goes, so neither takes the other's routes over @@ -147,8 +147,8 @@ export function forwardAnnounced(conn: Established, origin: OriginProducer): voi const downgrade = (failure: unknown) => { if (blind) return; blind = true; - // Announcement-gated consumers would wait forever on a table this session cannot fill, - // so they fall back to blind answers, which this session still provides. + // Plain requests can still use this session's blind answers. Announcement followers + // keep waiting for a source that can discover their path. console.warn("broadcast discovery failed; broadcasts resolve on request only.", failure); detach(); detach = originWire.attach(false); diff --git a/js/net/src/integration.test.ts b/js/net/src/integration.test.ts index 76cf549637e..1765c0186a5 100644 --- a/js/net/src/integration.test.ts +++ b/js/net/src/integration.test.ts @@ -1872,7 +1872,7 @@ test("integration: an announced request waits for a late publisher", async () => clientOrigin.close(); }); -test("integration: an announced request consumes blind without discovery", async () => { +test("integration: only a plain request consumes blind without discovery", async () => { withoutDiscovery(); const pair = createMockTransportPair(Lite.ALPN_06); const origin = new OriginProducer(); @@ -1891,13 +1891,16 @@ test("integration: an announced request consumes blind without discovery", async } })(); - // No announcement ever arrives, so waiting for one would hang. Subscribe anyway. - const watched = clientOrigin.request(Path.from("test"), { announced: true }); + const followed = clientOrigin.request(Path.from("test"), { announced: true }); + await until(() => clientOrigin.discovery.peek() === false); + expect(followed.active.peek()).toBeUndefined(); + const watched = clientOrigin.request(Path.from("test")); const active = await waitFor(watched.active, (b) => b !== undefined); if (!active) throw new Error("expected an active broadcast"); expect(await active.track("video").subscribe().ordered().readString()).toBe("blind"); watched.close(); + followed.close(); broadcast.close(); await serving; client.abort(); @@ -2052,7 +2055,7 @@ test("integration: a blind handle picks up a publisher that arrives late", async ]); // Without discovery there is no announcement to wait for, so the handle consumes blind. - const watched = clientOrigin.request(Path.from("later"), { announced: true }); + const watched = clientOrigin.request(Path.from("later")); const blind = await waitFor(watched.active, (b) => b !== undefined); if (!blind) throw new Error("expected a blind consumer"); @@ -2091,7 +2094,7 @@ test("integration: a blind handle goes offline when the session dies", async () accept(pair.server, url, { publish: origin.consume() }), ]); - const watched = clientOrigin.request(Path.from("whatever"), { announced: true }); + const watched = clientOrigin.request(Path.from("whatever")); await waitFor(watched.active, (b) => b !== undefined); // The gated path goes offline when the announcement stream ends with the session. There is @@ -2116,7 +2119,7 @@ test("integration: ietf blind handle picks up a publisher that arrives late", as accept(pair.server, url, { version: Ietf.Version.DRAFT_14, publish: origin.consume() }), ]); - const watched = clientOrigin.request(Path.from("later"), { announced: true }); + const watched = clientOrigin.request(Path.from("later")); const blind = await waitFor(watched.active, (b) => b !== undefined); if (!blind) throw new Error("expected a blind consumer"); @@ -2304,7 +2307,7 @@ test("origin: one origin on both directions consumes locally and never echoes", serverSees.close(); }); -test("origin: a plain request resolves blind without opening discovery", async () => { +test("origin: a plain request discovers the peer cannot announce before resolving blind", async () => { const refused = withoutDiscovery(); const pair = createMockTransportPair(Lite.ALPN_05); const serverOrigin = new OriginProducer(); @@ -2325,8 +2328,7 @@ test("origin: a plain request resolves blind without opening discovery", async ( })(); const reader = clientOrigin.consume(); - // Nothing watches, so the session never asks about announcements and never learns the - // relay would refuse: the table stays empty and a plain request answers blind. + // A request owns discovery, so it learns that this peer needs a blind request. expect(wireOf(reader).routes(Path.from("blind"))).toBe(false); const request = reader.request(Path.from("blind")); @@ -2336,8 +2338,8 @@ test("origin: a plain request resolves blind without opening discovery", async ( const track = front?.track("chat").subscribe().ordered(); if (!track) throw new Error("expected a track"); expect(await track.readString()).toBe("found you"); - expect(refused()).toBe(0); - expect(reader.discovery.peek()).toBe(true); + expect(refused()).toBe(1); + expect(reader.discovery.peek()).toBe(false); track.close(); request.close(); @@ -2508,6 +2510,7 @@ test.each([Ietf.ALPN.DRAFT_16, Ietf.ALPN.DRAFT_17, Ietf.ALPN.DRAFT_18])( ); test("origin: a blind request ends with its session, and the next session answers a fresh one", async () => { + withoutDiscovery(); const original = globalThis.WebTransport; const reconnectUrl = new URL("https://example.com/re-request"); diff --git a/js/net/src/origin-request.test.ts b/js/net/src/origin-request.test.ts index 4a92d9b7113..97da261785b 100644 --- a/js/net/src/origin-request.test.ts +++ b/js/net/src/origin-request.test.ts @@ -1,6 +1,7 @@ import { expect, test } from "bun:test"; import { Producer as BroadcastProducer } from "./broadcast"; import * as Epoch from "./epoch"; +import { StreamCode, StreamError } from "./error"; import { Route } from "./hop"; import { Producer } from "./origin"; import * as Path from "./path"; @@ -82,13 +83,17 @@ test("a closed announced request never acquires another publisher", async () => origin.close(); }); -test("announced requests refuse paths that cannot be watched or are outside scope", () => { - const origin = new Producer(); - expect(() => origin.request(Path.from("camera*main"), { announced: true })).toThrow(); - const scoped = origin.scope(Path.empty(), new Path.Patterns([Path.Pattern.subtree(Path.from("pool/job/cam"))])); - expect(() => scoped.request(Path.from("pool/job"), { announced: true })).toThrow(); - origin.close(); -}); +test.each([false, true])( + "requests refuse unwatchable paths and scope violations before registering (announced: %s)", + (announced) => { + const origin = new Producer(); + expect(() => origin.request(Path.from("camera*main"), { announced })).toThrow(); + const scoped = origin.scope(Path.empty(), new Path.Patterns([Path.Pattern.subtree(Path.from("pool/job/cam"))])); + expect(() => scoped.request(Path.from("pool/job"), { announced })).toThrow(); + expect(wireOf(origin).requests.peek()?.size).toBe(0); + origin.close(); + }, +); test("unrelated routes never notify announced request followers", async () => { const origin = new Producer(); @@ -119,20 +124,22 @@ test("an origin closing settles pending announced requests", async () => { request.close(); }); -test("an announced request keeps its fallback blind answer", async () => { +test("only a plain request can use a session without discovery", async () => { const origin = new Producer(); const wire = wireOf(origin); const detach = wire.attach(false); const path = Path.from("blind"); - const request = origin.request(path, { announced: true }); - const broadcast = new BroadcastProducer(); - const withdraw = wire.answer(path, broadcast.consume()); - await settle(); - expect(request.active.peek()?.closed).toBe(broadcast.closed); - request.close(); - withdraw?.(); + const followed = origin.request(path, { announced: true }); + const slot = wire.requests.peek()?.get(path); + if (!slot) throw new Error("request did not register"); + expect(wire.blind(slot)).toBe(false); + const requested = origin.request(path); + expect(wire.blind(slot)).toBe(true); + requested.close(); + await settle(); + expect(wire.blind(slot)).toBe(false); + followed.close(); detach(); - broadcast.close(); origin.close(); }); @@ -268,7 +275,7 @@ test("an announced request keeps a refusal that lands with a re-price", async () }); for (const received of [false, true]) { - test(`a plain request watches its path only through a received route (received: ${received})`, async () => { + test(`a plain request owns discovery through both local and received routes (received: ${received})`, async () => { const origin = new Producer(); const path = Path.from("room"); const events: string[] = []; @@ -282,12 +289,12 @@ for (const received of [false, true]) { const request = origin.request(path); await settle(); expect(request.active.peek()).toBeDefined(); - // A local route needs no discovery; one a session received stays discovered while held. - expect(events).toEqual(received ? ["room true"] : []); + // Every request owns discovery, independent of the route that currently serves it. + expect(events).toEqual(["room true"]); request.close(); await settle(); - expect(events).toEqual(received ? ["room true", "room false"] : []); + expect(events).toEqual(["room true", "room false"]); stop(); route.close(); source.close(); @@ -404,3 +411,135 @@ test("an answer prepared for an abandoned claim is never announced", async () => request.close(); origin.close(); }); + +test("an epoch-pinned follower resumes when its instance returns after a gap", async () => { + const origin = new Producer(); + const path = Path.from("room/audio"); + const epoch = Epoch.mint(); + const source = new BroadcastProducer(); + const keeper = source.consume(); + const serve = (instance: Epoch.Valid, broadcast: BroadcastProducer) => { + const route = origin.dynamicRoute(path, { epoch: instance }); + void (async () => { + for await (const request of route.requested()) request.accept(broadcast.consume()); + })(); + return route; + }; + const first = serve(epoch, source); + const request = origin.request(path, { announced: true, epoch }); + await settle(); + expect(request.active.peek()?.epoch).toBe(epoch); + first.close(); + await settle(); + expect(request.active.peek()).toBeUndefined(); + expect(request.closed.peek()).toBeUndefined(); + const otherSource = new BroadcastProducer(); + const other = serve(Epoch.mint(), otherSource); + await settle(); + expect(request.active.peek()).toBeUndefined(); + other.close(); + await settle(); + expect(request.closed.peek()).toBeUndefined(); + const back = serve(epoch, source); + await settle(); + expect(request.active.peek()?.epoch).toBe(epoch); + request.close(); + back.close(); + keeper.close(); + source.close(); + otherSource.close(); + origin.close(); +}); + +test("a request waits for its scoped discovery boundary before reporting absence", async () => { + const origin = new Producer(); + const wire = wireOf(origin); + const detach = wire.attach(true); + const path = Path.from("room/audio"); + const interests: string[] = []; + let synced: (() => void) | undefined; + const stop = wire.interests((prefix, wanted) => { + interests.push(`${prefix} ${wanted}`); + if (wanted) synced = wire.snapshot(prefix); + }); + const request = origin.request(path); + expect(interests).toEqual(["room/audio true"]); + expect(request.unroutable.peek()).toBe(false); + const unrelated = wire.snapshot(Path.from("other")); + synced?.(); + expect(request.unroutable.peek()).toBe(true); + unrelated(); + request.close(); + expect(interests).toEqual(["room/audio true", "room/audio false"]); + stop(); + detach(); + origin.close(); +}); + +test("an announced request retains a selected handler's explicit unroutable refusal", async () => { + const origin = new Producer(); + const path = Path.from("room/audio"); + const route = origin.dynamicRoute(path); + const pending = route.requested(); + const requested = origin.request(path, { announced: true }); + const request = (await pending.next()).value; + if (!request) throw new Error("request did not reach its handler"); + const refused = new StreamError(StreamCode.Unroutable); + request.reject(refused); + await settle(); + expect(requested.closed.peek()).toBe(refused); + requested.close(); + route.close(); + origin.close(); +}); + +test("a pending plain request retries a route gap and never retargets after resolving", async () => { + const origin = new Producer(); + const path = Path.from("room/audio"); + const first = origin.dynamicRoute(path); + const requested = origin.request(path); + const before = await first.requested().next(); + expect(before.value).toBeDefined(); + first.close(); + await settle(); + expect(requested.closed.peek()).toBeUndefined(); + const second = origin.dynamicRoute(path); + const pending = (await second.requested().next()).value; + if (!pending) throw new Error("replacement route was not requested"); + const source = new BroadcastProducer(); + const keeper = source.consume(); + pending.accept(source.consume()); + await settle(); + expect(requested.active.peek()?.closed).toBe(source.closed); + const replacement = origin.createBroadcast(path); + replacement.announce(); + await settle(); + expect(requested.active.peek()?.closed).toBe(source.closed); + second.close(); + await settle(); + expect(requested.closed.peek()).toBeInstanceOf(StreamError); + expect(requested.active.peek()).toBeUndefined(); + requested.close(); + replacement.close(); + keeper.close(); + source.close(); + origin.close(); +}); + +test("a plain epoch pin waits for an answer and refuses one without that epoch", () => { + const origin = new Producer(); + const wire = wireOf(origin); + const detach = wire.attach(false); + const path = Path.from("room/audio"); + const requested = origin.request(path, { epoch: Epoch.mint() }); + expect(requested.unroutable.peek()).toBe(false); + const source = new BroadcastProducer(); + const withdraw = wire.answer(path, source.consume()); + expect(requested.active.peek()).toBeUndefined(); + expect(requested.unroutable.peek()).toBe(true); + requested.close(); + withdraw?.(); + source.close(); + detach(); + origin.close(); +}); diff --git a/js/net/src/origin.test.ts b/js/net/src/origin.test.ts index 23ffd232ab3..31720651481 100644 --- a/js/net/src/origin.test.ts +++ b/js/net/src/origin.test.ts @@ -767,12 +767,12 @@ test("announced requests share no subscription and follow discovery", () => { const slots = [...(wire.requests.peek()?.values() ?? [])]; expect(slots.length).toBe(200); - // Gated with no session attached and with full discovery; blind once one session cannot announce. + // Following remains gated even when a session cannot announce. expect(slots.some((slot) => wire.blind(slot))).toBe(false); const seeing = wire.attach(true); expect(slots.some((slot) => wire.blind(slot))).toBe(false); const silent = wire.attach(false); - expect(slots.every((slot) => wire.blind(slot))).toBe(true); + expect(slots.some((slot) => wire.blind(slot))).toBe(false); silent(); expect(slots.some((slot) => wire.blind(slot))).toBe(false); @@ -1041,6 +1041,7 @@ test("closing the origin makes an existing request unroutable", async () => { const path = Path.from("doomed"); const detach = wireOf(origin).attach(true); + const synced = wireOf(origin).snapshot(path); const request = origin.consume().request(path); expect(request.unroutable.peek()).toBe(false); @@ -1056,6 +1057,7 @@ test("closing the origin makes an existing request unroutable", async () => { expect(request.unroutable.peek()).toBe(true); request.close(); + synced(); }); test("createBroadcast is invisible to everyone until announce", async () => { diff --git a/js/net/src/origin.ts b/js/net/src/origin.ts index c42bbc876bb..30f2b40a38f 100644 --- a/js/net/src/origin.ts +++ b/js/net/src/origin.ts @@ -265,10 +265,8 @@ class CoveringRoot { * @internal */ export interface RequestSlot { - /** Open handles that always take a blind answer. */ + /** Open plain handles that can use a peer without discovery. */ blind: number; - /** Open announcement-gated handles, which take a blind answer only while discovery is incomplete. */ - announced: number; answer?: broadcast.Consumer; readonly handles: Set>; readonly route: Signal; @@ -373,6 +371,9 @@ function unroutable(): StreamError { return new StreamError(StreamCode.Unroutable, { message: "unroutable" }); } +// A selected handler refused these requests; a coalesced route gap can have the same error. +const refusedRequests = new WeakSet>(); + /** A served route from {@link Producer.dynamic}: the queue a handler drains. */ class ServeState { readonly root: Path.Valid; @@ -903,14 +904,9 @@ class OriginState { } } - /** - * Whether sessions should answer `slot` with a blind subscription. An announcement-gated - * handle falls back to one only while at least one attached session cannot announce, and - * stays gated with no session attached. - */ + /** Whether a plain request needs the non-discovery session's blind answer. */ blind(slot: RequestSlot): boolean { - if (slot.blind > 0) return true; - if (slot.announced === 0) return false; + if (slot.blind === 0) return false; const { total, discovery } = this.sessions.peek(); return discovery < total; } @@ -923,13 +919,17 @@ class OriginState { refuse(path: Path.Valid, entry: RouteEntry, err: Error): void { // A detached slot failing over to this route ends with its answer. for (const other of [...(this.detached.get(path) ?? [])]) { - if (other.failover === entry) this.drop(path, other, err); + if (other.failover === entry) { + for (const closed of other.handles) refusedRequests.add(closed); + this.drop(path, other, err); + } } const slot = this.requests.peek()?.get(path); if (!slot) return; // Only the route the request is waiting on speaks for it; one superseded by another // route or a local broadcast has a moot answer. if (this.bestEntry(path) !== entry || this.localWins(path, entry)) return; + for (const closed of slot.handles) refusedRequests.add(closed); this.drop(path, slot, err); } @@ -1118,8 +1118,8 @@ export interface Table { /** Options for resolving a broadcast path. */ export interface RequestOptions { /** - * Follow announced instances unless an epoch is pinned; resolve blindly when discovery is - * unavailable. Watches the path, so a `consume` session asks its peer about it. + * Follow announced instances, pinned to one epoch when provided. Requires discovery; + * never falls back to a blind request when discovery is unavailable. */ announced?: boolean; /** Refuse a different publisher instance, including an asynchronous answer or a retry. */ @@ -1594,8 +1594,8 @@ export class Requesting { /** * The current broadcast, or undefined while nothing provides the path. - * Announced requests without an epoch follow publisher restarts. Blind and epoch-pinned - * requests retain their accepted instance. Another route of the same epoch taking over keeps + * Announced requests follow publisher instances, pinned to one when requested. + * Plain requests retain their accepted instance. Another route of the same epoch taking over keeps * this handle: its tracks resume on that route from the first group each reader lacks. * Closing this handle affects only this request. */ @@ -1608,14 +1608,15 @@ export class Requesting { * attached and no connection reconnecting toward one. False whenever {@link active} is * set, and false while a connection is still coming up, so the ordinary page-load window * before the first handshake reads as pending rather than as a missing broadcast. + * A plain request also reports absence once its scoped discovery has synced. * An announced request can still resolve on a later announcement. True once refused or closed. */ readonly unroutable: Getter; /** * Settles on refusal, origin shutdown, or explicit close. - * A pinned or blind request also ends when its accepted instance stops serving; - * an unpinned announced request waits for a later start instead. + * A plain request also ends when its accepted instance stops serving; + * an announced request waits for a later start, even when pinned. */ readonly closed: GetPromise; @@ -1726,16 +1727,13 @@ export class Consumer { } /** - * Resolve a path, following publisher restarts when `announced` is true and no epoch is pinned. - * Announced requests clear `active` on an end and resolve again on the next start. A refusal - * is terminal. An epoch-pinned request never changes instance; a plain request keeps its - * accepted instance and may resolve blindly when discovery has no answer. Either one, - * once resolved through a discovered route, watches its path until closed. - * Announcement gating falls back to blind resolution when discovery is unavailable. - * Close the request to release its handle and announcement watch. + * Resolve one publisher instance, or follow announcements when `announced` is true. + * Every request owns discovery of its path until closed. A plain request reports absence + * only after discovery syncs and can use a session without discovery. A follower requires + * discovery and waits for its pinned instance to return instead of closing on a gap. */ request(path: Path.Valid, options: RequestOptions = {}): Requesting { - if (options.announced && options.epoch === undefined) return this.#following(path, options); + if (options.announced) return this.#following(path, options); return this.#resolve(path, options); } @@ -1758,8 +1756,6 @@ export class Consumer { (value, answerers, error) => error !== undefined || (!value && answerers === 0), ); let current: Requesting | undefined; - // Whether `current` ever resolved, so losing it reads as an end rather than a refusal. - let resolved = false; let subscriptions: Dispose[] = []; let disposed = false; const release = () => { @@ -1777,10 +1773,15 @@ export class Consumer { active.set(undefined); closed.set(error); }; - const ended = (error: Error | null | undefined) => { + const ended = (error: Error | null | undefined, request: Requesting | undefined = current) => { if (!error) return; - // Losing an accepted instance waits for its next announcement; a refusal is final. - if (resolved && error instanceof StreamError && error.code === StreamCode.Unroutable) { + // Provenance survives a coalesced end/start, even when both routes serve one epoch. + if ( + error instanceof StreamError && + error.code === StreamCode.Unroutable && + request && + !refusedRequests.has(request.closed) + ) { active.set(undefined); return; } @@ -1806,15 +1807,13 @@ export class Consumer { current = next; active.set(value); if (!next) return; - resolved = value !== undefined; subscriptions.push( next.active.subscribe((value) => { - if (value) resolved = true; active.set(value); }), ); - subscriptions.push(next.closed.subscribe(ended)); - ended(next.closed.peek()); + subscriptions.push(next.closed.subscribe((error) => ended(error, next))); + ended(next.closed.peek(), next); }; try { replace(this.#resolve(path, options)); @@ -1848,6 +1847,7 @@ export class Consumer { } #resolve(path: Path.Valid, options: RequestOptions): Requesting { + Path.Pattern.literal(path); const epoch = options.epoch; const relative = path; path = this.#scope.path(path); @@ -1873,7 +1873,6 @@ export class Consumer { // notify nobody. const created: RequestSlot = { blind: 0, - announced: 0, handles: new Set(), route: new Signal(this.#state.route(path, {})), }; @@ -1886,10 +1885,9 @@ export class Consumer { slot.handles.add(closed); // Counted, not subscribed: serving sessions decide blindness from the live discovery state. const announced = options.announced === true; - if (announced) slot.announced += 1; - else slot.blind += 1; - // An announced request is a watch: sessions ask their peer about this path while it lives. - let unwatch = announced ? this.#state.watch([path]) : undefined; + if (!announced) slot.blind += 1; + // Resolution owns discovery from the first ask, not just after a route arrives. + const unwatch = this.#state.watch([path]); this.#state.requests.mutate(() => {}); // Hand out a handle of the request's own rather than the table's. Closing a consumer @@ -1940,30 +1938,22 @@ export class Consumer { // holder that only ever peeked would then pin a route that has already been retracted // until it happened to read again. Following the route as well retires it promptly, // and the memo makes the two paths agree: whichever runs first does the swap. - // Any other request watches its path once it resolves through a discovered route, so that - // route stays discovered after whatever watch found it, such as a listing, is gone. - const discovered = (resolution: Resolution | undefined) => { - if (unwatch || !resolution?.front) return; - // Only a route a session received; a local broadcast or dynamic route needs no discovery. - const entry = this.#state.materialized.get(path)?.entry; - if (!entry || entry.identity !== resolution.source || !received(entry)) return; - unwatch = this.#state.watch([path]); - }; - discovered(route.peek()); - const unsubscribe = route.subscribe((resolution) => { - own(resolution); - discovered(resolution); - }); + const unsubscribe = route.subscribe(own); // Only meaningful while nothing is routed, so it reads the route rather than `active`: // the two cannot disagree, since a routed path always has an answerer-independent // answer. const unroutable = new Derived( - [route, this.#state.answerers, closed], - (resolution, answerers, ended) => - ended !== undefined || - (epoch !== undefined && resolution?.epoch !== epoch) || - (!own(resolution) && answerers === 0), + [route, this.#state.answerers, this.#state.sessions, this.#state.snapshots, closed, this.#state.closed], + (resolution, answerers, sessions, snapshots, ended, shutdown) => { + if (ended !== undefined || shutdown !== undefined) return true; + if (own(resolution)) return false; + if (resolution?.front && epoch !== undefined && resolution.epoch !== epoch) return true; + for (const prefix of coveringPrefixes(path)) { + if (snapshots.has(prefix)) return false; + } + return answerers === 0 || (sessions.total > 0 && sessions.discovery === sessions.total); + }, ); return makeRequesting(relative, active, unroutable, closed, () => { @@ -1976,11 +1966,10 @@ export class Consumer { handle = undefined; source = undefined; - unwatch?.(); + unwatch(); taken.handles.delete(closed); if (closed.peek() === undefined) closed.set(null); - if (announced) taken.announced -= 1; - else taken.blind -= 1; + if (!announced) taken.blind -= 1; this.#state.requests.mutate(() => {}); if (taken.handles.size > 0) return; diff --git a/kt/moq-ffi/MIGRATE.md b/kt/moq-ffi/MIGRATE.md index a87e06daea2..6a29d61de39 100644 --- a/kt/moq-ffi/MIGRATE.md +++ b/kt/moq-ffi/MIGRATE.md @@ -7,8 +7,8 @@ How to update your code for each breaking change, newest first. ### A client asks only about what it watches (#6165) On moq-lite, a client session asks its relay for announcements only under paths something watches, through `announced()` or `announcedBroadcast()`, instead of under its whole scope at connect. -`MoqOriginConsumer.requestBroadcast()` watches nothing, so on a client it fails with an unroutable error for a path nothing watches, even when the relay announces it. -Resolve the path with `announcedBroadcast()`, or hold `announced()` over its prefix while requesting. +`MoqOriginConsumer.requestBroadcast()` owns discovery of its path while resolving and reports an unroutable path only once discovery has synced without a covering route. +Request the path directly; no separate announcement stream is needed for resolution. An explicit selected-handler refusal is returned directly, including while following announcements. Handle that error before explicitly trying a later resolution. moq-transport and moq-lite-03/04 sessions are unchanged. Regenerate the bindings for the changed `request_broadcast` checksum. diff --git a/kt/moq/MIGRATE.md b/kt/moq/MIGRATE.md index 6e1db97c770..979fa35d1ea 100644 --- a/kt/moq/MIGRATE.md +++ b/kt/moq/MIGRATE.md @@ -19,8 +19,8 @@ To keep a value's moq-lite byte, subtract 128 from it: 255 becomes 127, 128 beco ### A client asks only about what it watches (#6165) On moq-lite, a client session asks its relay for announcements only under paths something watches, through `announced()` or `announcedBroadcast()`, instead of under its whole scope at connect. -`requestBroadcast()` watches nothing, so on a client it fails with an unroutable error for a path nothing watches, even when the relay announces it. -Resolve the path with `announcedBroadcast()`, or hold `announced()` over its prefix while requesting. +`requestBroadcast()` owns discovery of its path while resolving and reports an unroutable path only once discovery has synced without a covering route. +Request the path directly; no separate announcement stream is needed for resolution. An explicit selected-handler refusal is returned directly, including while following announcements. Handle that error before explicitly trying a later resolution. moq-transport and moq-lite-03/04 sessions are unchanged. ### `ContainerFormat.FMP4` unwraps to Legacy (#6250) diff --git a/py/moq-ffi/MIGRATE.md b/py/moq-ffi/MIGRATE.md index 3390d71fffd..892ac1bd67d 100644 --- a/py/moq-ffi/MIGRATE.md +++ b/py/moq-ffi/MIGRATE.md @@ -7,8 +7,8 @@ How to update your code for each breaking change, newest first. ### A client asks only about what it watches (#6165) On moq-lite, a client session asks its relay for announcements only under paths something watches, through `announced()` or `announced_broadcast()`, instead of under its whole scope at connect. -`MoqOriginConsumer.request_broadcast()` watches nothing, so on a client it fails with an unroutable error for a path nothing watches, even when the relay announces it. -Resolve the path with `announced_broadcast()`, or hold `announced()` over its prefix while requesting. +`MoqOriginConsumer.request_broadcast()` owns discovery of its path while resolving and reports an unroutable path only once discovery has synced without a covering route. +Request the path directly; no separate announcement stream is needed for resolution. An explicit selected-handler refusal is returned directly, including while following announcements. Handle that error before explicitly trying a later resolution. moq-transport and moq-lite-03/04 sessions are unchanged. Regenerate the bindings for the changed `request_broadcast` checksum. diff --git a/py/moq-rs/MIGRATE.md b/py/moq-rs/MIGRATE.md index b9a85594a45..f1fc20c496c 100644 --- a/py/moq-rs/MIGRATE.md +++ b/py/moq-rs/MIGRATE.md @@ -19,8 +19,8 @@ To keep a value's moq-lite byte, subtract 128 from it: 255 becomes 127, 128 beco ### A client asks only about what it watches (#6165) On moq-lite, a client session asks its relay for announcements only under paths something watches, through `announced()` or `announced_broadcast()`, instead of under its whole scope at connect. -`OriginConsumer.request_broadcast()` watches nothing, so on a client it fails with an unroutable error for a path nothing watches, even when the relay announces it. -Resolve the path with `announced_broadcast()`, or hold `announced()` over its prefix while requesting. +`OriginConsumer.request_broadcast()` owns discovery of its path while resolving and reports an unroutable path only once discovery has synced without a covering route. +Request the path directly; no separate announcement stream is needed for resolution. An explicit selected-handler refusal is returned directly, including while following announcements. Handle that error before explicitly trying a later resolution. moq-transport and moq-lite-03/04 sessions are unchanged. ### `ContainerFormat.FMP4` unwraps to Legacy (#6250) diff --git a/py/moq-rs/README.md b/py/moq-rs/README.md index 1b37695547c..6260c7b725a 100644 --- a/py/moq-rs/README.md +++ b/py/moq-rs/README.md @@ -247,7 +247,7 @@ Every handle whose cleanup is `cancel()` is an async context manager, so exiting - **`OriginConsumer`**. Discover broadcasts. - `.announced(prefix, filter=None) → AnnounceConsumer` (async iterator of `AnnounceEvent`: `AnnounceEventStart`, `AnnounceEventUpdate`, `AnnounceEventEnd`, or `AnnounceEventRestart`, each carrying an `Announce` whose `.route.epoch` names the publisher run; on a restart, request the path again); `filter` is a pattern relative to the literal prefix, while each `Announce.prefix` stays origin-relative and `.captures` reports wildcard matches - `.announced_broadcast(path) → AnnouncedBroadcast` (awaitable, waits until something serves the path) - - `.request_broadcast(path) → BroadcastConsumer` (awaitable; announced now or a dynamic fallback, else raises) + - `.request_broadcast(path) → BroadcastConsumer` (awaitable; owns discovery and resolves one instance, or raises once synced without a route) ### Types diff --git a/quest/m1/api-audit/resolve.md b/quest/m1/api-audit/resolve.md index 9bf6fc9f706..b9db189a9e8 100644 --- a/quest/m1/api-audit/resolve.md +++ b/quest/m1/api-audit/resolve.md @@ -20,58 +20,68 @@ No caller can assemble a racy two-step resolve, and no crate hand-rolls Decided 2026-10-22 (API audit, maintainer approved the recommendation). -Rust `origin::Consumer` today has five overlapping operations -(`rs/moq-net/src/model/origin.rs`): `routed(path) -> Option` (swallows -errors), `follow(path) -> Follow` (route level), `routed_broadcast(path)` (no -epoch), `announced_broadcast(path, epoch)`, and `request_broadcast(path, -epoch)`. Per `rs/moq-net/MIGRATE.md`, `request_broadcast` on a client fails -`Unroutable` for a path no reader watches, even when the peer announces it, -and the bindings promote it as a top-level convenience. +The behavioral checkpoint makes `request_broadcast` own scoped discovery and +retry route churn. It reports table absence only after sync; a selected handler's +explicit refusal stays terminal, including a dropped Prepared answer. The front +records that refusal privately at its existing standing-route decision, rather +than guessing from unrelated mutations of the table. The old immediate lookup +is private to sessions. `Requesting::is_queued` and the public `Routing` task are +gone; `Requesting` is the owned task. The mux sibling resolver and stats reader +use it instead of their own sync/retry helpers. A binding retains its first +verdict and releases the completed request, so an errored reference never +silently retargets to a later publisher. Rust and JS have same-epoch +follow-return coverage, and every JS request owns its discovery watch from +creation. JS announcement-following no longer silently uses a blind peer. +The existing `routed_broadcast` helper privately retains its route-change retry +policy for active CLI, gateway, and relay HTTP consumers. Its removal belongs +to the remaining rollout, after their replacement is settled. -- Rust: `request(path, epoch) -> Pending` takes - `routed_broadcast`'s semantics plus the epoch pin and the synced - `Unroutable` answer, with no wall clock (relays never block on peers). - `follow(path, epoch)` is today's `announced_broadcast`. Delete `routed`, - `routed_broadcast`, and `Requesting::is_queued`. The immediate table lookup - (today's `request_broadcast`) and the route-level `Follow` become - `pub(crate)` for the sessions; route inspection stays where a consumer - needs it (the `routed()` callers in moq-cli reporting move to whatever - route observation remains public, or drop the report). -- JS (`js/net/src/origin.ts` `Consumer.request(path, {announced, epoch})`): - two methods, `request(path, {epoch})` and `follow(path, {epoch})`. Fix the - mismatch where `{announced: true, epoch}` closes when the instance ends - while Rust's pinned follow hands back the same instance if it returns. Drop - the silent fallback that turns `announced: true` into a blind request when - discovery is unavailable. `Producer.request`/`announced` pass-throughs stay - only if `Table` needs them. moq.pro's five `{announced: true}` sites move - to `follow`. -- Bindings: `request_broadcast(path, epoch)` and `announced_broadcast(path, - epoch)` map onto the two operations under the same names as Rust, and the - Kotlin, Dart, Go, and Python top-level shortcuts follow. -- Callers to fix: `rs/moq-wasm/src/lib.rs` (`routed()` then - `request_broadcast()`, error hidden by `.ok()`), `rs/moq-srt/src/ts.rs` - `Subscriber::new` (production), `rs/moq-cli/src/subscribe.rs` and - `report.rs`, `rs/moq-transcode/examples/transcode.rs`, - `rs/moq-bench/src/connection.rs`, the hand-rolled resolvers in - `rs/moq-mux/src/source.rs`, `rs/moq-hls/src/server/mod.rs` (wall-clock - `RESOLVE_TIMEOUT`) and `rs/moq-stats/src/aggregate.rs`, the - `rs/moq-relay/src/web.rs` fetch deadline, the `rs/moq-e2ee/MIGRATE.md` - advice to read the epoch via `routed()`, and - `demo/carla/sim/moq_carla_sim/publish.py`, which reads the epoch from an - announce and then requests unpinned. +The approved public method names have not rolled out. What remains: -The prior audit's race claim is narrower than stated: discovery lingers 2 s -after `routed()` drops its follower, so the window is a route retraction or -failover between the two calls. +- Rust: name the owned operation `request(path, epoch)` and today's + `announced_broadcast` operation `follow(path, epoch)`. Keep the immediate + table lookup private. Delete `routed` and `routed_broadcast` and fix their + callers. Preserve terminal selected-handler refusals, private deferred + validity checks, and instance identity across route churn. +- Move the active route-level `Follow` consumers before making it private. + `moq play`, `moqsrc`, and the mux TS follower still consume its Start, End, + and Restart events. Their replacement belongs to the existing + `Source::follow` work below, whose shape is explicitly open. Do not add a + new public route API or compatibility shim to make the privatization pass. +- JS: expose `request(path, {epoch})` and `follow(path, {epoch})` instead of the + `announced` option and migrate actual callers. Make a one-instance request's + synced-absence verdict terminal, matching Rust and the bindings, while a + follower remains open. The current JS handle exposes it through `unroutable`. + The checkpoint covers pending + one-instance retry through a route gap without retargeting an already resolved + instance. Retain synchronous request peeks and path-local wakeups. + `Producer` pass-throughs stay only where `Table` needs them. +- Bindings: mirror `request` and `follow`, including the optional epoch, in + the FFI and every actual wrapper/consumer. Regenerate from source, update + package migrations, and run all-language interop. Existing binding names + currently inherit the owned-discovery behavior, not the final naming. +- Callers: remove the racy two-step lookup and hidden error in moq-wasm, + route waits in moq-cli subscribe/report, and the HLS hand-rolled discovery + and `RESOLVE_TIMEOUT`. Review SRT, transcode, benchmark connections, relay + HTTP fetch deadlines, the e2ee epoch advice, and the demo's announce-derived + epoch pin. No caller should hand-roll synced resolution or rely on a wall + clock to decide table absence. -Tests: a lite client resolves an announced but unwatched path; a pinned -`follow` hands back the same instance when its route returns, in Rust and JS. +Tests cover an announced but unwatched path over lite-05/06/07-wip, synced +absence, discovery retention and release, pinned follow return, no follower +fallback on a blind peer, and unchanged explicit refusal. Finish the API and +caller rollout with the same lifecycle and churn checks, then the required +Nix gate and all-language interop. -Public API: breaking in moq-net, `@moq/net`, moq-ffi, and every wrapper. +Public API: breaking task shape in moq-net; behavior changes in `@moq/net` and +the bindings. Final method/epoch naming remains breaking across every wrapper. Wire: none. +## Required + +- [Reference announcements](/quest/m0/broadcast-epoch/reference-announcements.md) - settles `Source::follow`, the existing owner of the active route-level consumers' replacement + ## Related -- [Readers follow restarts](/quest/m1/sink-restart-follow.md) - moves readers to `follow`; whichever lands second adopts the other's names -- [Reference announcements](/quest/m0/broadcast-epoch/reference-announcements.md) - `moq_mux::Source::follow` builds on the follow operation +- [Readers follow restarts](/quest/m1/sink-restart-follow.md) - moves CLI and GStreamer readers to the shared follow operation after reference following - [Origin fronts park](/quest/m2/origin-front-parks.md) - touches the same retry diff --git a/rs/moq-c/MIGRATE.md b/rs/moq-c/MIGRATE.md index 2a7b6e6571d..a76ccebe2e2 100644 --- a/rs/moq-c/MIGRATE.md +++ b/rs/moq-c/MIGRATE.md @@ -19,8 +19,8 @@ To keep a value's moq-lite byte, subtract 128 from it: 255 becomes 127, 128 beco ### A client asks only about what it watches (#6165) On moq-lite, a client session asks its relay for announcements only under paths something watches, through `moq_origin_announced` or `moq_origin_announced_broadcast`, instead of under its whole scope at connect. -`moq_origin_request` watches nothing, so on a client it fails with a negative code for a path nothing watches, even when the relay announces it. -Resolve the path with `moq_origin_announced_broadcast`, or hold `moq_origin_announced` over its prefix while requesting. +`moq_origin_request` owns discovery of its path while resolving and reports an unroutable path only once discovery has synced without a covering route. +Request the path directly; no separate announcement stream is needed for resolution. An explicit selected-handler refusal is returned directly, including while following announcements. Handle that error before explicitly trying a later resolution. moq-transport and moq-lite-03/04 sessions are unchanged. ### `MOQ_CONTAINER_FORMAT_FMP4` unwraps to Legacy (#6250) diff --git a/rs/moq-c/src/api.rs b/rs/moq-c/src/api.rs index aa7170afaa1..7badc157898 100644 --- a/rs/moq-c/src/api.rs +++ b/rs/moq-c/src/api.rs @@ -2098,12 +2098,10 @@ pub extern "C" fn moq_origin_announced_broadcast_cancel(task: u32) -> i32 { /// Request a broadcast from an origin by path, resolving as soon as it can be served. /// -/// Resolves against what is announced *now*, where [moq_origin_announced_broadcast] waits -/// indefinitely: it returns an announced broadcast at once, and fails when none is reachable, -/// including a broadcast created but not announced. It does NOT wait for a later -/// announcement. Serve on-demand paths with [moq_origin_dynamic]. A moq-lite client session -/// only asks its peer about paths something watches, through [moq_origin_announced] or -/// [moq_origin_announced_broadcast], so a path nothing watches is unreachable on it. +/// Owns discovery of the path and retries route churn while resolving one publisher instance. +/// It fails as unroutable once discovery has synced without a covering route, including a +/// broadcast created but not announced. No separate announcement stream is needed. +/// Serve on-demand paths with [moq_origin_dynamic]. /// /// `on_broadcast` is invoked with a positive broadcast handle once served, then exactly once more /// with a terminal code: `0` (finished, including after [moq_origin_request_cancel]) or a negative diff --git a/rs/moq-ffi/MIGRATE.md b/rs/moq-ffi/MIGRATE.md index 8ed40b7a0a6..9b70ddeae0e 100644 --- a/rs/moq-ffi/MIGRATE.md +++ b/rs/moq-ffi/MIGRATE.md @@ -20,8 +20,8 @@ To keep a value's moq-lite byte, subtract 128 from it: 255 becomes 127, 128 beco ### A client asks only about what it watches (#6165) On moq-lite, a client session asks its relay for announcements only under paths something watches, through `announced` or `announced_broadcast`, instead of under its whole scope at connect. -`MoqOriginConsumer::request_broadcast` watches nothing, so on a client it fails with `MoqError::Unroutable` for a path nothing watches, even when the relay announces it. -Resolve the path with `announced_broadcast`, or hold `announced` over its prefix while requesting. +`MoqOriginConsumer::request_broadcast` owns discovery of its path while resolving and reports an unroutable path only once discovery has synced without a covering route. +Request the path directly; no separate announcement stream is needed for resolution. An explicit selected-handler refusal is returned directly, including while following announcements. Handle that error before explicitly trying a later resolution. moq-transport and moq-lite-03/04 sessions are unchanged. ### `MoqContainerFormat::Fmp4` unwraps to Legacy (#6250) diff --git a/rs/moq-ffi/src/origin.rs b/rs/moq-ffi/src/origin.rs index 6bbc6af4af4..23bf2e3e6d3 100644 --- a/rs/moq-ffi/src/origin.rs +++ b/rs/moq-ffi/src/origin.rs @@ -467,10 +467,8 @@ impl MoqOriginConsumer { /// Follow the broadcast at `path`, resolving each publisher instance that serves it. /// - /// This is how you resolve a path right after connecting: announcements arrive over the - /// session after it opens, so `request_broadcast` on its own races them. A - /// broadcast created on this origin resolves once it is announced, like a - /// remote one. + /// Unlike `request_broadcast`, this waits for future announcements and keeps following + /// publisher instances. A local broadcast resolves once announced, like a remote one. pub fn announced_broadcast(&self, path: String) -> Result, MoqError> { let _guard = crate::ffi::enter(); self.driver.check()?; @@ -492,14 +490,9 @@ impl MoqOriginConsumer { /// Resolves through the best announced route covering the path: an announced broadcast /// on this origin, a route a session announced (served on demand by that session), or a /// dynamic handler on the origin. The most specific prefix wins, then the cheapest. An - /// unannounced broadcast is unroutable. Unlike `announced_broadcast`, this answers for what is - /// reachable *now* and errors if nothing can serve the path. Drop the returned future to - /// cancel. - /// - /// Calling this straight after connecting therefore races the session's announcements - /// and can report a live broadcast as unroutable. Await `announced_broadcast` first. A - /// moq-lite client only asks the relay about paths something watches, through `announced` - /// or `announced_broadcast`, so a path nothing watches stays unroutable. + /// unannounced broadcast is unroutable once discovery has synced without a covering route. + /// The request owns discovery of its path and retries route churn until then; no separate + /// announcement stream is needed. Drop the returned future to cancel. pub async fn request_broadcast(&self, path: String) -> Result, MoqError> { let broadcast = self .driver diff --git a/rs/moq-ffi/src/test.rs b/rs/moq-ffi/src/test.rs index 67c72461817..6181b69daf6 100644 --- a/rs/moq-ffi/src/test.rs +++ b/rs/moq-ffi/src/test.rs @@ -219,9 +219,8 @@ fn video_init(format: MoqVideoFormat, data: Vec) -> MoqVideoInit { /// Wait for `path` to be announced on `origin` and return its consumer. /// -/// A created broadcast becomes routable asynchronously, and resolving a reference goes through -/// `request_broadcast`, which reports a not-yet-announced path as unroutable rather than waiting. -/// So every broadcast a test resolves has to be awaited, not just the one it starts from. +/// A local reference published asynchronously may appear after discovery has synced empty. +/// These tests wait for that future announcement before resolving the reference. async fn await_announced(consumer: &MoqOriginConsumer, path: &str) -> Arc { let announced = consumer.announced_broadcast(path.into()).unwrap(); tokio::time::timeout(TIMEOUT, announced.available()) @@ -3980,7 +3979,7 @@ async fn cancel_retracts_the_route_synchronously() { let dynamic = serve(&origin, ""); let inner = origin.inner().consume(); - let queued = inner.request_broadcast("x", None).into_inner(); + let mut queued = inner.request_broadcast("x", None).into_inner(); assert!( queued.poll_ok(&kio::Waiter::noop()).is_pending(), "the route must serve while the handler lives" @@ -3988,7 +3987,7 @@ async fn cancel_retracts_the_route_synchronously() { drop(queued); dynamic.cancel(); - let verdict = inner.request_broadcast("y", None).into_inner(); + let mut verdict = inner.request_broadcast("y", None).into_inner(); match verdict.poll_ok(&kio::Waiter::noop()) { std::task::Poll::Ready(Err(moq_net::Error::Unroutable)) => {} std::task::Poll::Ready(Err(err)) => panic!("unexpected error: {err}"), diff --git a/rs/moq-mux/src/source.rs b/rs/moq-mux/src/source.rs index c64a28c44d0..8e1e1dddaf3 100644 --- a/rs/moq-mux/src/source.rs +++ b/rs/moq-mux/src/source.rs @@ -363,73 +363,35 @@ impl Binding { } } -/// One request for a path, made once the origin has heard whether anything serves it. -/// -/// A client session only asks its peer about paths something watches, so a sibling no -/// listing covers would be unroutable when asked at once. Following the path first and -/// asking once a route serves it, or once every session has synced without one, answers -/// from what the peers announce. An origin that already knows its routes answers at once, -/// so the request still goes out on binding. +/// One sibling resolution, retaining its first verdict for every read of the binding. struct Lookup { - origin: moq_net::origin::Consumer, - path: moq_net::PathOwned, - /// Dropped once the request settles: a broadcast resolved through a discovered route - /// keeps its own path watched. - watch: Option, request: Option, + result: Option>, } impl Lookup { fn new(origin: &moq_net::origin::Consumer, path: &moq_net::PathOwned) -> Self { - // A path no pattern can spell, or one outside the scope, fails on the request instead. - let watch = origin.follow(path).ok(); - let mut lookup = Self { - origin: origin.clone(), - path: path.clone(), - watch, - request: None, - }; - // Ask now when the origin already knows, so a dynamic handler hears it on binding. - let _ = lookup.poll(&kio::Waiter::noop()); - lookup + Self { + request: Some(origin.request_broadcast(path, None).into_inner()), + result: None, + } } fn poll(&mut self, waiter: &kio::Waiter) -> Poll> { - loop { - if self.request.is_none() { - if let Some(watch) = &mut self.watch { - // The follower reduces the covering routes to the one serving the path, so its - // latest event is whether a route serves it now. Ask as soon as one does: - // waiting for every session to sync would let one that never answers hold the - // lookup up. Without a route, only sync concludes that none will. - let mut routed = false; - loop { - match watch.poll_next(waiter) { - Poll::Ready(Some(moq_net::announce::Event::End(_))) => routed = false, - Poll::Ready(Some(_)) => routed = true, - Poll::Ready(None) | Poll::Pending => break, - } - } - if !routed { - ready!(watch.poll_synced(waiter)); - } - } - self.request = Some(self.origin.request_broadcast(&self.path, None).into_inner()); - } - let result = ready!(self.request.as_ref().expect("requested above").poll_ok(waiter)); - // The route can retract between the follower reporting it and the request reading - // the table. Until every session has synced, keep following for another. - let unsynced = self - .watch - .as_ref() - .is_some_and(|watch| watch.poll_synced(&kio::Waiter::noop()).is_pending()); - if matches!(result, Err(moq_net::Error::Unroutable)) && unsynced { - self.request = None; - continue; - } - self.watch = None; - return Poll::Ready(result); + if let Some(result) = &self.result { + return Poll::Ready(result.clone()); } + let result = ready!( + self.request + .as_mut() + .expect("unresolved lookup holds its request") + .poll_ok(waiter) + ); + // A binding never retargets after its first verdict. Releasing the completed + // request also releases its discovery interest; a resolved front owns its own. + self.request = None; + self.result = Some(result.clone()); + Poll::Ready(result) } } diff --git a/rs/moq-net/MIGRATE.md b/rs/moq-net/MIGRATE.md index e16d361e179..ba309a6f3f0 100644 --- a/rs/moq-net/MIGRATE.md +++ b/rs/moq-net/MIGRATE.md @@ -4,6 +4,14 @@ How to update your code for each breaking change, newest first. ## Unreleased +### Broadcast requests own discovery + +`Consumer::request_broadcast` now owns discovery of its path and retries across route churn until discovery has synced without a route for its requested instance. +It returns `Pending`; `routed_broadcast` uses that task too, replacing `origin::Routing`. +When polling directly, keep the task mutable for `poll_ok`; awaiting it is unchanged. +Remove manual `Requesting::is_queued` retries: the resolver now watches route changes itself. +A selected handler's explicit refusal is returned directly by `request_broadcast` and `announced_broadcast`; they do not wait for other discovery. The existing `routed_broadcast` helper retains its policy of retrying refusals only after the covering routes change. Paths discovery cannot name fail with `InvalidPath`. + ### IETF whole-group FETCH answers name the requested group ([#6199](https://github.com/moq-dev/moq/issues/6199)) On moq-transport drafts 14 through 19, a whole-group `FETCH_OK` now names `{g, 0}` instead of `{g+1, 0}`. @@ -96,8 +104,8 @@ On the wire, moq-lite carries `priority + 128` and moq-transport `127 - priority On moq-lite, a client session no longer asks its peer for announcements under its whole subscribe scope at connect. It asks only under the prefixes its subscribe origin's readers watch, with `announced()`, `follow`, `routed`, `routed_broadcast`, or `announced_broadcast`, and stops asking 2s after nothing at or beneath a prefix is watched. -`request_broadcast` watches nothing, so on a client it fails with `Error::Unroutable` for a path no reader watches, even when the peer announces it. -Resolve a path with `routed_broadcast` or `announced_broadcast`, or hold an `announced()` stream over its prefix while requesting, the way `routed` already did after connecting. +`request_broadcast` owns discovery of its path while resolving and reports an unroutable path only once discovery has synced without a covering route. +Request the path directly; no separate announcement stream is needed for resolution. An explicit selected-handler refusal is returned directly, including while following announcements. Handle that error before explicitly trying a later resolution. A broadcast resolved through a discovered route keeps its path watched until dropped. A server session, and a client fed into a `Producer::peer` or `Producer::upstream` handle, still asks for everything it may, so a relay discovers as before. Serving another session's request is not a watch, so a client that relays what it discovers to its own sessions should feed its client session `origin.upstream()` (or `peer()`) instead of a plain handle. diff --git a/rs/moq-net/benches/origin.rs b/rs/moq-net/benches/origin.rs index 5decd12b2fd..ffef579da07 100644 --- a/rs/moq-net/benches/origin.rs +++ b/rs/moq-net/benches/origin.rs @@ -500,34 +500,40 @@ fn bench_subscribe(c: &mut Criterion) { /// depend on `publishers`. fn bench_request(c: &mut Criterion) { let mut group = c.benchmark_group("origin/request"); - // A request costs nothing per subscriber, so this sweeps the publisher counts - // in `SHAPES` rather than its shapes, whose last two share one. for publishers in [100, 1_000] { - let mut fleet = fanout(publishers, 0); - // A broadcast above the misses covers them without serving them. - let _covering = fleet.producer.publish("room", origin::Route::default()).unwrap(); - let waiter = kio::Waiter::noop(); - group.bench_function(BenchmarkId::new("local", publishers), |b| { - b.iter(|| { - let pending = fleet.consumer.request_broadcast("room/0", None); - // The front's driver resolves the first request; later ones join it. - fleet.driver.poll(moq_net::time::Instant::now(), &waiter).unwrap(); - pending - .now_or_never() - .expect("resolves once driven") - .expect("local broadcast"); + for requesters in [1, 8, 32] { + let mut fleet = fanout(publishers, 0); + let _covering = fleet.producer.publish("room", origin::Route::default()).unwrap(); + let waiter = kio::Waiter::noop(); + let shape = format!("{publishers}p_{requesters}r"); + group.throughput(Throughput::Elements(requesters)); + group.bench_function(BenchmarkId::new("local", &shape), |b| { + b.iter(|| { + let pending: Vec<_> = (0..requesters) + .map(|_| fleet.consumer.request_broadcast("room/0", None)) + .collect(); + fleet.driver.poll(moq_net::time::Instant::now(), &waiter).unwrap(); + for pending in pending { + pending + .now_or_never() + .expect("resolves once driven") + .expect("local broadcast"); + } + }); }); - }); - group.bench_function(BenchmarkId::new("unroutable", publishers), |b| { - b.iter(|| { - let result = fleet - .consumer - .request_broadcast("room/missing", None) - .now_or_never() - .expect("fails synchronously"); - assert!(matches!(result, Err(moq_net::Error::Unroutable))); + group.bench_function(BenchmarkId::new("unroutable", &shape), |b| { + b.iter(|| { + for _ in 0..requesters { + let result = fleet + .consumer + .request_broadcast("room/missing", None) + .now_or_never() + .expect("fails synchronously"); + assert!(matches!(result, Err(moq_net::Error::Unroutable))); + } + }); }); - }); + } } group.finish(); } diff --git a/rs/moq-net/src/lite/publisher.rs b/rs/moq-net/src/lite/publisher.rs index 0b4a3aa7909..4dba01b5dd1 100644 --- a/rs/moq-net/src/lite/publisher.rs +++ b/rs/moq-net/src/lite/publisher.rs @@ -1562,7 +1562,7 @@ enum RequestState { /// broadcast (may wait on a dynamic handler). Resolve { msg: M, - requesting: Option, + requesting: Option, }, Serve(R), /// FIN the reply, and keep the request until the requester closes its side. diff --git a/rs/moq-net/src/model/follow.rs b/rs/moq-net/src/model/follow.rs index d1c69270da0..1d855f77550 100644 --- a/rs/moq-net/src/model/follow.rs +++ b/rs/moq-net/src/model/follow.rs @@ -1,7 +1,7 @@ use std::task::{Poll, ready}; use super::WeakEntry; -use super::origin_impl::{Announce, AnnounceConsumer, AnnounceEvent, Consumer, Routing}; +use super::origin_impl::{Announce, AnnounceConsumer, AnnounceEvent, Consumer, Requesting}; use crate::{Epoch, Error, PathOwned, broadcast}; /// The announcements covering one path, as one broadcast coming online, being replaced, and @@ -202,7 +202,7 @@ pub struct AnnouncedBroadcast { /// An instance serves the path that was not handed out yet. unseen: bool, /// The resolution in flight, kept across a dropped wait so a retry picks it up. - resolving: Option, + resolving: Option, /// The broadcast handed out last, until the path goes offline. Weak, so it never keeps an /// instance the caller let go of from retiring. last: Option, @@ -589,6 +589,37 @@ mod tests { assert_ne!(current.info().epoch.as_ref(), Some(&epoch)); } + #[moq_clock::test] + async fn announced_pinned_hands_out_its_instance_after_a_gap() { + let origin = Hop::new(1).unwrap().produce(); + let epoch = Epoch::mint(); + let first = origin.publish("live", route(&epoch)).unwrap(); + let mut announced = origin.consume().announced_broadcast("live", epoch.clone()).unwrap(); + assert_eq!(available(&mut announced).await.info().epoch.as_ref(), Some(&epoch)); + first.unannounce(); + none(&mut announced).await; + first.announce(route(&epoch)).unwrap(); + assert_eq!(available(&mut announced).await.info().epoch.as_ref(), Some(&epoch)); + } + + #[moq_clock::test] + async fn announced_reports_a_dropped_prepared_answer() { + let origin = Hop::new(1).unwrap().produce(); + let claim = origin.dynamic("live").unwrap(); + let mut announced = origin.consume().announced_broadcast("live", None).unwrap(); + let (result, ()) = futures::join!( + moq_clock::timeout(Duration::from_secs(1), announced.available()), + async { + let prepared = requested(&claim).await.prepare(Epoch::mint()).unwrap(); + drop(prepared); + } + ); + assert!(matches!( + result.expect("the selected refusal must answer"), + Err(Error::Unroutable) + )); + } + /// A path no pattern can spell is refused rather than followed through the whole scope, /// where a route that never serves it could win its prefix. #[test] diff --git a/rs/moq-net/src/model/mod.rs b/rs/moq-net/src/model/mod.rs index 3c443bc5c77..b1135c132cf 100644 --- a/rs/moq-net/src/model/mod.rs +++ b/rs/moq-net/src/model/mod.rs @@ -52,9 +52,12 @@ pub use timed::Timed; /// Publishing broadcasts, announcing routes, and consuming both through an origin. pub mod origin { pub use super::follow::AnnouncedBroadcast; + #[cfg(feature = "async")] + // private: capability gap + pub(crate) use super::origin_impl::Lookup; pub use super::origin_impl::{ Config, Consumer, Cost, DEFAULT_UPDATE_HOLD, Driver, Dynamic, Preference, Prepared, Producer, Request, - Requesting, Route, Routing, Source, + Requesting, Route, Source, }; } diff --git a/rs/moq-net/src/model/origin.rs b/rs/moq-net/src/model/origin.rs index d59a83a9456..49b80eb4601 100644 --- a/rs/moq-net/src/model/origin.rs +++ b/rs/moq-net/src/model/origin.rs @@ -3147,6 +3147,13 @@ async fn serve_front(task: FrontTask) -> Vec { loop { while let Some(event) = events.pop_front() { + let refused = matches!( + &event, + Event::Resolved { + result: Err(Refusal { standing: true, .. }), + .. + } + ); let answered = match &event { Event::TrackInfo { track, source, .. } => Some((track.clone(), *source)), _ => None, @@ -3408,6 +3415,7 @@ async fn serve_front(task: FrontTask) -> Vec { .fronts .remove_if(&(path.clone(), horizon), |front| front.request.same_channel(&request)); if let Ok(mut pending) = request.write() { + pending.refused = refused; pending.resolved.get_or_insert(Err(err.clone())); } // Ending the broadcast only retracts it: no new requesters or @@ -5107,6 +5115,8 @@ struct PendingBroadcast { #[derive(Default)] struct PendingFront { resolved: Option>, + // The selected serving handler refused, rather than the route disappearing. + refused: bool, } /// What a front resolved: the instance its first source serves, and the route that @@ -5537,13 +5547,9 @@ impl Drop for Request { } } -/// The pollable result of [`Consumer::request_broadcast`]. -/// -/// Awaited via the [`kio::Pending`] wrapper; resolves to the [`broadcast::Consumer`] -/// immediately when the broadcast was already announced, or once an [`Dynamic`] -/// handler serves the request. Resolves to an error if the request is rejected or every -/// handler drops before serving it. -pub struct Requesting { +/// The immediate table lookup serving a peer without initiating application discovery. +// private: capability gap +pub(crate) struct Lookup { inner: RequestState, // The path the requester asked for, relative to its cursor's root. Stamped on the // resolved broadcast (see [`broadcast::Info::path`]) because a handler is free to @@ -5569,7 +5575,7 @@ enum RequestState { }, } -impl Requesting { +impl Lookup { fn failed(error: Error) -> Self { Self::new(RequestState::Failed(error)) } @@ -5578,18 +5584,6 @@ impl Requesting { Self::new(RequestState::Pending { front, broadcast }) } - /// Whether the request was handed to a serving route, rather than decided on - /// the spot. - /// - /// Fixed at request time, so it distinguishes the two ways - /// [`Error::Unroutable`] arises: a queued request that fails was killed by - /// its serving route retracting, and the table may already hold a - /// replacement worth retrying against (`Consumer::routed_broadcast` does), - /// while an unqueued failure means nothing could serve the path at all. - pub fn is_queued(&self) -> bool { - matches!(self.inner, RequestState::Pending { .. }) - } - fn new(inner: RequestState) -> Self { Self { inner, @@ -5648,7 +5642,7 @@ impl Requesting { } } -impl kio::Task for Requesting { +impl kio::Task for Lookup { type Output = Result; fn poll(&mut self, waiter: &kio::Waiter) -> Poll { @@ -5656,8 +5650,8 @@ impl kio::Task for Requesting { } } -/// The pollable result of [`Consumer::routed_broadcast`]. -pub struct Routing { +/// An owned broadcast resolution, driven by polling or awaiting it. +pub struct Requesting { consumer: Consumer, path: PathOwned, // Asks sessions to discover the path for as long as this waits on it. @@ -5665,20 +5659,61 @@ pub struct Routing { // The covering routes, watched since the generation the last ask saw. watch: Option<(Watch, u64)>, // The ask in flight, dropped once it fails `Unroutable` until the routes move. - request: Option, + request: Option, // The publisher instance every ask is pinned to, if any. epoch: Option, + // A finite request owns discovery and can conclude absence once its initial set lands. + discovery: Option, + routed: bool, + // Legacy route-wait callers retry refusals only after the covering routes move. + terminal_refusal: bool, } -impl kio::Task for Routing { - type Output = Result; - - fn poll(&mut self, waiter: &kio::Waiter) -> Poll { +impl Requesting { + /// Poll for the requested instance, retrying only after its covering routes change. + pub fn poll_ok(&mut self, waiter: &kio::Waiter) -> Poll> { loop { + if let Some(discovery) = &mut self.discovery { + loop { + match discovery.poll_next(waiter) { + Poll::Ready(Some(AnnounceEvent::End(_))) => self.routed = false, + Poll::Ready(Some( + AnnounceEvent::Start(announce) + | AnnounceEvent::Restart(announce) + | AnnounceEvent::Update(announce), + )) => { + self.routed = self.epoch.is_none() || announce.route.epoch == self.epoch; + } + Poll::Ready(None) => return Poll::Ready(Err(Error::Closed)), + Poll::Pending => break, + } + } + // Sync is an event, not a deadline: sessions hold it from the moment the + // interest is created until the initial announcement set is delivered. + let synced = discovery.poll_synced(waiter).is_ready(); + if self.request.is_none() + && synced && (!self.routed || self.watch.as_ref().is_some_and(|(watch, seen)| watch.seen() == *seen)) + { + return Poll::Ready(Err(Error::Unroutable)); + } + } + match (&self.watch, &self.request) { (_, Some(request)) => match ready!(request.poll_ok(waiter)) { Ok(broadcast) => return Poll::Ready(Ok(broadcast)), - Err(Error::Unroutable) => self.request = None, + Err(Error::Unroutable) => { + // The front already distinguishes a selected handler's refusal + // from route churn; retain that verdict rather than infer it from + // unrelated changes a prepared answer makes to the table. + let refused = match &request.inner { + RequestState::Pending { front, .. } => front.read().refused, + RequestState::Failed(_) => false, + }; + if self.terminal_refusal && refused { + return Poll::Ready(Err(Error::Unroutable)); + } + self.request = None; + } Err(err) => return Poll::Ready(Err(err)), }, (Some((watch, seen)), None) => { @@ -5704,7 +5739,7 @@ impl kio::Task for Routing { }; let watch = table.watch(&self.consumer.shared, &resolved); let seen = watch.seen(); - if self.interest.is_none() && self.consumer.interested { + if self.interest.is_none() && self.discovery.is_none() && self.consumer.interested { let resolved = resolved.to_owned(); self.interest = Some(Interest::new(&mut table, &self.consumer.shared, resolved)); } @@ -5721,6 +5756,14 @@ impl kio::Task for Routing { } } +impl kio::Task for Requesting { + type Output = Result; + + fn poll(&mut self, waiter: &kio::Waiter) -> Poll { + self.poll_ok(waiter) + } +} + /// Derive a read view from a handle. /// /// Lets APIs accept either a producer or a consumer (e.g. @@ -6173,22 +6216,27 @@ impl Consumer { /// [`Error::Unauthorized`] for a path outside this consumer's scope, /// [`Error::Closed`] once the origin closes, and any other resolution /// failure as-is. Await it, or poll it through [`kio::Task`]. - pub fn routed_broadcast(&self, path: impl AsPath) -> kio::Pending { - kio::Pending::new(self.routing(path.as_path().to_owned(), None)) + pub fn routed_broadcast(&self, path: impl AsPath) -> kio::Pending { + let mut request = self.routing(path.as_path().to_owned(), None); + request.terminal_refusal = false; + kio::Pending::new(request) } - /// [`Self::routed_broadcast`], refusing any instance but `epoch` when one is pinned. - pub(super) fn routing(&self, path: PathOwned, epoch: Option) -> Routing { + /// Resolve a routed instance, returning a selected handler's refusal directly. + pub(super) fn routing(&self, path: PathOwned, epoch: Option) -> Requesting { // `allowed` keeps narrower permissions intact: if the whole path is not // reachable, no route can ever cover it, so bail rather than loop forever. - let request = (!self.allowed().matches(path.as_str())).then(|| Requesting::failed(Error::Unauthorized)); - Routing { + let request = (!self.allowed().matches(path.as_str())).then(|| Lookup::failed(Error::Unauthorized)); + Requesting { consumer: self.clone(), path, interest: None, watch: None, request, epoch, + discovery: None, + routed: false, + terminal_refusal: true, } } @@ -6196,7 +6244,7 @@ impl Consumer { /// /// The Rust form of JS `request(path, { announced: true })`. The first /// [`available`](AnnouncedBroadcast::poll_available) resolves the instance serving the path - /// once one is announced, riding out churn as [`Self::routed_broadcast`] does. Each + /// once one is announced, retrying route churn but returning a selected handler's refusal. Each /// later call waits for another instance to take over (an /// [`AnnounceEvent::Restart`]), or for the path to be served again after an /// [`AnnounceEvent::End`], even by the same instance. Drop what was read from the @@ -6269,13 +6317,11 @@ impl Consumer { /// when requesting and when an asynchronous answer resolves. `None` leaves lookup /// unpinned. A pinned request never resumes on a route whose epoch disappeared. /// - /// The returned future fails with [`Error::Unroutable`] at once when no - /// announced route covers the path, including a broadcast created on this - /// origin but not announced. A moq-lite client session only discovers what this - /// origin's readers watch, so a path no [`Self::announced`], - /// [`Self::routed_broadcast`], or [`Self::announced_broadcast`] watches is - /// unroutable on it. A broadcast resolved through a discovered route keeps its - /// path watched until dropped. + /// The request owns discovery for its path and retries when its covering routes change. + /// It reports [`Error::Unroutable`] once discovery has synced without a covering route + /// for the requested instance. A selected handler's explicit refusal is returned as-is. + /// A broadcast resolved through a discovered route keeps + /// its path watched until dropped; no separate announcement watcher is needed. /// A route claims capability, not inventory: resolving a covered path /// succeeds optimistically, and a path that names nothing surfaces as /// [`Error::NotFound`] on its tracks instead. @@ -6284,15 +6330,32 @@ impl Consumer { path: impl AsPath, epoch: impl Into>, ) -> kio::Pending { - let epoch = epoch.into(); - self.request(path.as_path(), epoch.as_ref()) + let path = path.as_path(); + let mut routing = self.routing(path.to_owned(), epoch.into()); + match self.follow(&path) { + Ok(discovery) => { + routing.discovery = Some(discovery); + let named = self.root.join(&path); + if let Some(resolved) = self.scope.resolve(&named) { + let mut table = self.shared.lock(); + let watch = table.watch(&self.shared, &resolved); + let seen = watch.seen(); + drop(table); + routing.watch = Some((watch, seen)); + } + // A dynamic handler hears an already-routed request at creation time. + routing.request = Some(self.request(path, routing.epoch.as_ref()).into_inner()); + } + Err(err) => routing.request = Some(Lookup::failed(err)), + } + kio::Pending::new(routing) } /// [`Self::request_broadcast`], refused with [`Error::Unroutable`] unless the /// winning route serves `epoch`: a peer asking for one publisher instance must /// not be handed another. // pending: /quest/m1/public-model/answer.md - pub(crate) fn request(&self, path: Path<'_>, epoch: Option<&crate::Epoch>) -> kio::Pending { + pub(crate) fn request(&self, path: Path<'_>, epoch: Option<&crate::Epoch>) -> kio::Pending { // The path as this handle names it, absolute: what its scope authorizes and // what its egress is counted under, so a read through a mount bills where // the reader asked. @@ -6305,20 +6368,20 @@ impl Consumer { // Routes only cover paths within this consumer's scope. if !self.scope.permits(&named) { - return kio::Pending::new(Requesting::failed(Error::Unauthorized)); + return kio::Pending::new(Lookup::failed(Error::Unauthorized)); } // Key requests by the absolute path on the origin, past any mount, so scoped, // rooted, and mounted consumers and handlers agree on the same entry and front. let Some(absolute) = self.scope.resolve(&named).map(|path| path.to_owned()) else { - return kio::Pending::new(Requesting::failed(BoundsExceeded.into())); + return kio::Pending::new(Lookup::failed(BoundsExceeded.into())); }; let mut state = self.shared.lock(); // The origin's driver dropped: nothing will ever serve this. if state.closed { - return kio::Pending::new(Requesting::failed(Error::Closed)); + return kio::Pending::new(Lookup::failed(Error::Closed)); } let horizon = self.horizon.effective(&state.routes, &absolute.as_path()); @@ -6328,7 +6391,7 @@ impl Consumer { // route retracted takes no newcomers. let best = match state.best_route(&absolute.as_path(), horizon, &HashSet::new(), |_| true) { Some(best) if epoch.is_none_or(|epoch| best.epoch.as_ref() == Some(epoch)) => best.instance(), - _ => return kio::Pending::new(Requesting::failed(Error::Unroutable)), + _ => return kio::Pending::new(Lookup::failed(Error::Unroutable)), }; // Join the live front for this path and horizon, if any: its watcher @@ -6352,7 +6415,7 @@ impl Consumer { if let Some(held) = held { state.next_route += 1; front.joined.store(state.next_route, Ordering::Release); - let pending = Requesting::queued(front.request.consume(), held) + let pending = Lookup::queued(front.request.consume(), held) .with_path(requested) .with_stats(scope) .with_epoch(epoch.cloned()); @@ -6405,7 +6468,7 @@ impl Consumer { self.tasks.clone(), )); kio::Pending::new( - Requesting::queued(consumer, held) + Lookup::queued(consumer, held) .with_path(requested) .with_stats(scope) .with_epoch(epoch.cloned()), diff --git a/rs/moq-net/tests/integration/lazy_discovery.rs b/rs/moq-net/tests/integration/lazy_discovery.rs index 92cbc1ca2e4..edfa9b5d8bf 100644 --- a/rs/moq-net/tests/integration/lazy_discovery.rs +++ b/rs/moq-net/tests/integration/lazy_discovery.rs @@ -85,13 +85,18 @@ impl Lazy { .announced() } - /// Whether the client's origin routes `path` right now. + /// Inspect the current table without running discovery for the observation itself. async fn routes(&self, path: &str) -> bool { - match self.subscriber.consume().request_broadcast(path, None).await { - Ok(_) => true, - Err(Error::Unroutable) => false, - Err(err) => panic!("{path}: {err}"), - } + let consumer = self + .subscriber + .consume() + .scope("", &Patterns::from(Pattern::literal(path).unwrap())) + .unwrap(); + let mut announced = consumer.announced(); + matches!( + announced.poll_next(&kio::Waiter::noop()), + std::task::Poll::Ready(Some(announce::Event::Start(_))) + ) } } @@ -352,9 +357,56 @@ async fn serving_the_peer_asks_nothing() { .filter(|kind| *kind == ANNOUNCE) .count(); assert_eq!(requests, 0, "{version}"); - assert!(matches!( - local.consume().request_broadcast("a/x", None).await, - Err(Error::Unroutable) - )); + // An application request is a reader, unlike the peer's serving view. + let _read = local.consume().request_broadcast("a/x", None).await.unwrap(); + let requests = pair + .client_transport + .bidi_types() + .into_iter() + .filter(|kind| *kind == ANNOUNCE) + .count(); + assert_eq!(requests, 1, "{version}: only the application request starts discovery"); + } +} + +/// Resolving a path owns the discovery that makes the peer's announcement visible. +#[moq_clock::test] +async fn requesting_an_unwatched_path_discovers_its_instance() { + for version in VERSIONS { + let lazy = Lazy::new(version).await; + assert_eq!(lazy.requests(), 0, "{version}"); + let broadcast = lazy + .subscriber + .consume() + .request_broadcast("a/x", None) + .await + .expect("request discovers the announced instance without a separate watcher"); + assert_eq!(broadcast.info().path.as_str(), "a/x"); + assert_eq!(lazy.requests(), 1, "{version}"); + } +} + +/// Absence is answered by the peer's sync boundary, without a timer in resolution. +#[moq_clock::test] +async fn an_unwatched_missing_path_is_unroutable_after_sync() { + for version in VERSIONS { + let lazy = Lazy::new(version).await; + let result = moq_clock::timeout(SETTLE, lazy.subscriber.consume().request_broadcast("missing", None)) + .await + .expect("the peer synced"); + assert!(matches!(result, Err(Error::Unroutable)), "{version}"); + assert_eq!(lazy.requests(), 1, "{version}"); + let broadcast = lazy.subscriber.consume().request_broadcast("a/x", None).await.unwrap(); + moq_clock::sleep(LINGERED).await; + assert!( + lazy.routes("a/x").await, + "{version}: request ownership keeps discovery alive" + ); + drop(broadcast); + moq_clock::sleep(LINGERED).await; + assert!( + !lazy.routes("a/x").await, + "{version}: dropping the last reader releases discovery" + ); } } diff --git a/rs/moq-net/tests/integration/model.rs b/rs/moq-net/tests/integration/model.rs index 5dbcf90053c..f3e656685ed 100644 --- a/rs/moq-net/tests/integration/model.rs +++ b/rs/moq-net/tests/integration/model.rs @@ -29,7 +29,7 @@ fn origin_front_serves_media_with_only_explicit_polls() { broadcast.announce(origin::Route::default()).unwrap(); // Resolving and subscribing pass through the origin's core front tasks. - let requesting = origin.consume().request_broadcast("room/live", None); + let mut requesting = origin.consume().request_broadcast("room/live", None); assert!(requesting.poll_ok(&waiter).is_pending()); driver.poll(now, &waiter).unwrap(); let receiving: broadcast::Consumer = ready(requesting.poll_ok(&waiter)).unwrap(); diff --git a/rs/moq-stats/src/aggregate.rs b/rs/moq-stats/src/aggregate.rs index 1e234c37147..5a95b48a6e9 100644 --- a/rs/moq-stats/src/aggregate.rs +++ b/rs/moq-stats/src/aggregate.rs @@ -525,15 +525,8 @@ impl Mergeable for Prefix { /// One node's subscription to the merged track. enum Reader { - /// Resolving the announced path into a broadcast. `queued` records whether - /// the request was handed to a serving route (fixed at request time): a - /// queued request that fails `Unroutable` was killed by its serving route - /// retracting (the table has already changed), while an unqueued - /// `Unroutable` means nothing serves the path at all. - Resolving { - pending: Pending, - queued: bool, - }, + /// Resolving the instance while owning discovery and retrying route churn. + Resolving(Box>), /// Awaiting the subscription handshake. Subscribing(Pending), /// Reading frames. Boxed: the snapshot consumer dwarfs the other variants, @@ -877,7 +870,7 @@ fn advance( let mut rearmed = false; loop { match &mut node.reader { - Reader::Resolving { pending, queued } => match pending.poll_ok(waiter) { + Reader::Resolving(pending) => match pending.poll_ok(waiter) { // An unpinned retry on a known lineage can reach a replacement publisher // before its announcement drains here. Its counters belong to its own entry, // which that announcement creates, so this lineage keeps its last frame. @@ -900,15 +893,7 @@ fn advance( return changed | node.depart(); } }, - // A queued request killed by its route retracting: an identical - // standby swaps in without any announce update, so re-resolve - // through the already-updated table. Each retry consumed a real - // retraction, so this cannot spin; an instant Unroutable instead - // means nothing serves the path (the retraction that empties the - // table also unannounces this node). - Poll::Ready(Err(moq_net::Error::Unroutable)) if *queued => { - node.reader = resolve(origin, &node.path, node.epoch.clone()); - } + Poll::Ready(Err(err)) => { tracing::debug!(?err, name, "stats: node broadcast unresolvable"); return changed | node.depart(); @@ -963,8 +948,7 @@ fn advance( /// Start resolving `path` (relative to the announce cursor) into a broadcast. fn resolve(origin: &origin::Consumer, path: &PathOwned, epoch: Option) -> Reader { let pending = origin.request_broadcast(path, epoch); - let queued = pending.is_queued(); - Reader::Resolving { pending, queued } + Reader::Resolving(Box::new(pending)) } #[cfg(test)] @@ -1443,7 +1427,7 @@ mod tests { .announce(origin::Route::default().with_epoch(epoch_b.clone())) .unwrap(); new.publish("acme/room", 30); - let pending = origin.consume().request_broadcast(".stats/acme/node/a", None); + let mut pending = origin.consume().request_broadcast(".stats/acme/node/a", None); let front = futures::executor::block_on(kio::wait(|waiter| { driver.poll(now, waiter).unwrap(); pending.poll_ok(waiter) diff --git a/swift/MIGRATE.md b/swift/MIGRATE.md index ea2f0d9cce8..eab388e73fb 100644 --- a/swift/MIGRATE.md +++ b/swift/MIGRATE.md @@ -19,8 +19,8 @@ To keep a value's moq-lite byte, subtract 128 from it, widening first so it does ### A client asks only about what it watches (#6165) On moq-lite, a client session asks its relay for announcements only under paths something watches, through `announced()` or `announcedBroadcast()`, instead of under its whole scope at connect. -`OriginConsumer.requestBroadcast()` watches nothing, so on a client it fails with an unroutable error for a path nothing watches, even when the relay announces it. -Resolve the path with `announcedBroadcast()`, or hold `announced()` over its prefix while requesting. +`OriginConsumer.requestBroadcast()` owns discovery of its path while resolving and reports an unroutable path only once discovery has synced without a covering route. +Request the path directly; no separate announcement stream is needed for resolution. An explicit selected-handler refusal is returned directly, including while following announcements. Handle that error before explicitly trying a later resolution. moq-transport and moq-lite-03/04 sessions are unchanged. ### `ContainerFormat.fmp4` unwraps to Legacy (#6250) diff --git a/swift/ffi/MIGRATE.md b/swift/ffi/MIGRATE.md index e50bf21fcd7..d72a46ea99d 100644 --- a/swift/ffi/MIGRATE.md +++ b/swift/ffi/MIGRATE.md @@ -7,8 +7,8 @@ How to update your code for each breaking change, newest first. ### A client asks only about what it watches (#6165) On moq-lite, a client session asks its relay for announcements only under paths something watches, through `announced()` or `announcedBroadcast()`, instead of under its whole scope at connect. -`MoqOriginConsumer.requestBroadcast()` watches nothing, so on a client it fails with an unroutable error for a path nothing watches, even when the relay announces it. -Resolve the path with `announcedBroadcast()`, or hold `announced()` over its prefix while requesting. +`MoqOriginConsumer.requestBroadcast()` owns discovery of its path while resolving and reports an unroutable path only once discovery has synced without a covering route. +Request the path directly; no separate announcement stream is needed for resolution. An explicit selected-handler refusal is returned directly, including while following announcements. Handle that error before explicitly trying a later resolution. moq-transport and moq-lite-03/04 sessions are unchanged. Regenerate the bindings for the changed `request_broadcast` checksum. From 9c462ab325ceb53cf8d9b3332fcb5a8ac89e4fde Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 28 Oct 2026 10:03:50 -0700 Subject: [PATCH 3/4] fix(js): a plain request fails Unroutable once its discovery syncs without a route A pending plain request now settles `closed` with `Unroutable` once every attached session discovers and none still owes an initial set covering its path, matching Rust's `request_broadcast`. The check is slot-scoped: snapshot releases and session changes recheck only the requests under the affected prefix, in one microtask. A session releases its snapshot on a failed announce stream together with the downgrade, so a refusal never reads as synced absence. Co-Authored-By: Claude Opus 5.5 --- doc/lib/js/net.md | 4 +- js/net/src/connection/forward.ts | 9 ++-- js/net/src/origin-request.test.ts | 36 +++++++++++++++ js/net/src/origin.ts | 74 ++++++++++++++++++++++++++++--- quest/m1/api-audit/resolve.md | 24 +++++----- 5 files changed, 121 insertions(+), 26 deletions(-) diff --git a/doc/lib/js/net.md b/doc/lib/js/net.md index 6d05c601615..3e0aa334b20 100644 --- a/doc/lib/js/net.md +++ b/doc/lib/js/net.md @@ -42,8 +42,8 @@ publication.announce(); - **Answer claimed paths with `using`.** `requests(prefix)` claims a prefix and yields each requested path. Use `using prepared = request.prepare(epoch)`, fill its broadcast, then `prepared.publish()` to answer with a new publisher instance and keep the `Publication` it returns. Leaving the scope without publishing, including on a throw, refuses the request as unroutable. Explicit `prepared.close()` or closing its unpublished broadcast does the same; disposal after publishing leaves the returned publication and its fill broadcast live. Reject before preparing with `request.reject(err)`. A retained, unclosed prepared answer keeps the request pending; JavaScript garbage collection provides no prompt cleanup guarantee. - **End content by finishing tracks.** A broadcast has no finished state. When the input ends, `finish()` each track, then `close()` it; closing a track without finishing aborts it. The broadcast stays announced and keeps serving them until you `close()` it. How long to keep it up for late readers is yours to decide. - **Requests can pin an epoch.** `consumer.request(path, { epoch })` resolves only through a route announcing that [publisher epoch](/concept/moq-lite#publisher-epochs). The resolved broadcast's `epoch` names the route it came through, pinned or not. -- **Follow restarts.** `origin.request(path, { announced: true })` follows whichever publisher instance serves the path: its `active` changes to a fresh broadcast on a restart, clears on an end, and resolves again on the next start, so read it reactively and close the request when done. Instances are never stitched, so subscribe again to each new broadcast. Another route of the same epoch taking over (epochs travel only on `moq-lite-07-wip`) keeps `active` as is, and each track subscription resumes there from the first group it lacks. A refusal ends the request. Add `epoch` to pin one instance; a plain `request(path)` keeps its accepted instance, can resolve blindly, and ends once that instance stops serving. To list what is live, iterate `announced(scope)`. -- **Discovery follows what you watch.** A `consume` origin asks the relay for announcements only under the prefixes its readers watch with `announced(scope)` or `request(path, { announced: true })`, stops asking about a prefix 2s after nothing at or beneath it is watched, and asks again on reconnect. A plain `request(path)` asks nothing and subscribes blind, but once it resolves through a discovered route it watches its path until closed, so it outlives the listing that found it. A relay that refuses an announce request turns that session's announced requests blind too. +- **Follow restarts.** `origin.request(path, { announced: true })` follows whichever publisher instance serves the path: its `active` changes to a fresh broadcast on a restart, clears on an end, and resolves again on the next start, so read it reactively and close the request when done. Instances are never stitched, so subscribe again to each new broadcast. Another route of the same epoch taking over (epochs travel only on `moq-lite-07-wip`) keeps `active` as is, and each track subscription resumes there from the first group it lacks. A refusal ends the request. Add `epoch` to pin one instance, which the request waits for again after an end. A plain `request(path)` keeps its accepted instance and ends once that instance stops serving; while pending, it fails `Unroutable` once discovery of its path has synced without a route for it. To list what is live, iterate `announced(scope)`. +- **Discovery follows what you watch.** A `consume` origin asks the relay for announcements only under the prefixes its readers watch with `announced(scope)` or `request(path)`, stops asking about a prefix 2s after nothing at or beneath it is watched, and asks again on reconnect. Every request watches its path from creation until closed, so it outlives the listing that found it. A relay that refuses an announce request downgrades that session: plain requests subscribe blind through it, and announced requests keep waiting for a session that can discover. - **Connections share by URL and versions.** `new Connection({ url })` pools and reconnects with backoff, which the elements use. An ordered `versions` list, spelled like `moq-lite-06` as in Rust, applies to both WebTransport and WebSocket; equivalent lists share, while a different order or an omitted list gets its own pool entry. Supplying your own transport options or origin selects a private loop. Receive estimates are on demand: observe `connection.probe` reactively or subscribe while you need them; `peek()` alone opens no PROBE stream. - **GOAWAY moves the session.** The connection dials the replacement at once while the old session keeps serving its groups, up to `goaway.handover` (default 10s, or the relay's deadline when that is sooner). New requests keep opening on the old session until the replacement's route outranks it, which is a restart without an epoch: an unpinned announced request follows the replacement, while a blind or epoch-pinned request stays on its accepted instance. With an epoch, which travels only when `moq-lite-07-wip` is offered, the replacement serves the same broadcast, so open subscriptions move across without missing a group. An empty GOAWAY redials the same URL. A redirect stays on the same host unless `goaway.redirect` is `"follow"`, which also presents the tokens on the connection's `auth` handle to the new host. - **One send estimate per connection.** `Bandwidth.Allocator` divides it by track priority, max-min fair within a tier. An idle track claims nothing, though its reservation still reads the share it would get. Publishers reserve against it so their targets sum to the estimate. diff --git a/js/net/src/connection/forward.ts b/js/net/src/connection/forward.ts index 0f8d1c0d6ba..9bbab37870d 100644 --- a/js/net/src/connection/forward.ts +++ b/js/net/src/connection/forward.ts @@ -70,8 +70,8 @@ interface Reported { * session to the same origin and re-opens whatever is still watched. * * A peer that refuses or resets an announce request downgrades the whole session to blind - * answers: gated requests stop waiting for an announcement, and later watches open nothing - * on it. + * answers: plain requests subscribe through it without waiting for an announcement, and + * later watches open nothing on it. * * @internal */ @@ -183,10 +183,11 @@ export function forwardAnnounced(conn: Established, origin: OriginProducer): voi // The origin's readers under the prefix wait on this request's initial set. Released // once the session stream has synced, which it reports only after the last of those - // events is reported here. + // events is reported here. A closing stream also reads as synced, but a failure is not + // an answer: the loop below releases it with the downgrade, in one step. const snapshot = originWire.snapshot(prefix); const synced = interest.announced.synced.subscribe((synced) => { - if (synced) snapshot(); + if (synced && interest.announced.closed.peek() === undefined) snapshot(); }); // A request with no initial set to wait for is synced before the listener exists. if (interest.announced.synced.peek()) snapshot(); diff --git a/js/net/src/origin-request.test.ts b/js/net/src/origin-request.test.ts index 62fe77963da..484f375fbb3 100644 --- a/js/net/src/origin-request.test.ts +++ b/js/net/src/origin-request.test.ts @@ -618,6 +618,42 @@ test("a plain request owns its scoped discovery until closed", async () => { origin.close(); }); +test("a pending plain request fails Unroutable once its discovery syncs without a route", async () => { + const origin = new Producer(); + const wire = wireOf(origin); + const detach = wire.attach(true); + const initialSets: (() => void)[] = []; + const stop = wire.interests((prefix, wanted) => { + if (wanted) initialSets.push(wire.snapshot(prefix)); + }); + const missing = origin.request(Path.from("room/missing")); + const found = origin.request(Path.from("room/found")); + const pinned = origin.request(Path.from("room/pinned"), { epoch: Epoch.mint() }); + const follower = origin.request(Path.from("room/followed"), { announced: true }); + // The initial set reports these before it lands, and nothing at all for the rest. + const route = wire.receive(Path.from("room/found")); + const other = wire.receive(Path.from("room/pinned"), { epoch: Epoch.mint() }); + await settle(); + for (const request of [missing, found, pinned, follower]) expect(request.closed.peek()).toBeUndefined(); + + for (const synced of initialSets) synced(); + await settle(); + for (const request of [missing, pinned]) { + const err = request.closed.peek(); + expect(err).toBeInstanceOf(StreamError); + expect((err as StreamError).code).toBe(StreamCode.Unroutable); + } + expect(found.closed.peek()).toBeUndefined(); + expect(follower.closed.peek()).toBeUndefined(); + + for (const request of [missing, found, pinned, follower]) request.close(); + route.close(); + other.close(); + stop(); + detach(); + origin.close(); +}); + test("an announced request retains a selected handler's explicit unroutable refusal", async () => { const origin = new Producer(); const path = Path.from("room/audio"); diff --git a/js/net/src/origin.ts b/js/net/src/origin.ts index 0968c6c1475..77454784b07 100644 --- a/js/net/src/origin.ts +++ b/js/net/src/origin.ts @@ -247,6 +247,8 @@ export interface RequestSlot { blind: number; answer?: broadcast.Consumer; readonly handles: Set>; + /** Pending plain handles, each ending itself once synced discovery leaves it no route. */ + readonly absent: Set<() => void>; readonly route: Signal; /** The front a detached slot took from the table, closed with its last handle. */ retired?: broadcast.Consumer; @@ -620,9 +622,40 @@ class OriginState { if (count > 0) counts.set(prefix, count); else counts.delete(prefix); }); + this.settle(prefix); }; } + // The prefixes whose pending plain requests may have lost their last reason to wait. + #unsettled = new Set(); + + /** + * Recheck the pending plain requests under the absolute `prefix` once the current task + * settles, so a session releasing its initial set and downgrading reads as one step. + */ + settle(prefix: Path.Valid): void { + if (this.#unsettled.size === 0) queueMicrotask(() => this.#settled()); + this.#unsettled.add(prefix); + } + + #settled(): void { + const prefixes = [...this.#unsettled]; + this.#unsettled.clear(); + for (const [path, slot] of [...(this.requests.peek() ?? [])]) { + if (slot.absent.size === 0 || !prefixes.some((prefix) => Path.hasPrefix(prefix, path))) continue; + for (const absent of [...slot.absent]) absent(); + } + } + + /** Whether every attached session discovers and none owes an initial set covering `path`. */ + synced(path: Path.Valid): boolean { + const { total, discovery } = this.sessions.peek(); + if (total === 0 || discovery < total) return false; + const snapshots = this.snapshots.peek(); + for (const prefix of coveringPrefixes(path)) if (snapshots.has(prefix)) return false; + return true; + } + // The literal heads readers are watching, counted, as a trie: announcement streams and // announced requests. Sessions ask their peer for announcements under the broadest of // these and nothing else, and hear each change to that covering set as it happens, so a @@ -1394,6 +1427,8 @@ export class Producer implements Table { total: total + delta, discovery: d + (discovery ? delta : 0), })); + // Losing a session without discovery can leave every pending request synced. + this.#state.settle(Path.empty()); } // Run `release` once, at the first of its own call or this derived handle's close, so a @@ -1586,7 +1621,8 @@ export class Requesting { /** * Settles on refusal, origin shutdown, or explicit close. - * A plain request also ends when its accepted instance stops serving; + * A plain request also ends when its accepted instance stops serving, and fails + * `Unroutable` while pending once discovery syncs without a route for it; * an announced request waits for a later start, even when pinned. */ readonly closed: GetPromise; @@ -1694,9 +1730,10 @@ export class Consumer { /** * Resolve one publisher instance, or follow announcements when `announced` is true. - * Every request owns discovery of its path until closed. A plain request reports absence - * only after discovery syncs and can use a session without discovery. A follower requires - * discovery and waits for its pinned instance to return instead of closing on a gap. + * Every request owns discovery of its path until closed. A pending plain request fails + * `Unroutable` once every session's discovery has synced without a route for it, and can + * use a session without discovery instead. A follower requires discovery and waits for its + * pinned instance to return instead of closing on a gap. */ request(path: Path.Valid, options: RequestOptions = {}): Requesting { if (options.announced) return this.#following(path, options); @@ -1831,6 +1868,7 @@ export class Consumer { const created: RequestSlot = { blind: 0, handles: new Set(), + absent: new Set(), route: new Signal(this.#state.route(path, {})), }; slot = created; @@ -1895,12 +1933,31 @@ export class Consumer { // holder that only ever peeked would then pin a route that has already been retracted // until it happened to read again. Following the route as well retires it promptly, // and the memo makes the two paths agree: whichever runs first does the swap. - const unsubscribe = route.subscribe(own); + // A pending plain request reports absence, as Rust's request does, once discovery of + // its path has synced without a route for its instance. Sessions hold that sync from + // when the watch opens, so a fresh request waits for its peer's answer. A follower + // keeps waiting for a start, and a resolved request ends only with its instance. + const absent = () => { + if (released || source || closed.peek() !== undefined) return; + const resolution = route.peek(); + if (resolution && (epoch === undefined || resolution.epoch === epoch)) return; + if (!this.#state.synced(path)) return; + closed.set(unroutable()); + release(); + }; + if (!announced) taken.absent.add(absent); + + const unsubscribe = route.subscribe((resolution) => { + own(resolution); + if (!announced) absent(); + }); - return makeRequesting(relative, active, closed, () => { + const release = () => { // Releases this request's handle; the route itself belongs to the table. + if (released) return; released = true; unsubscribe(); + taken.absent.delete(absent); logical?.conclude(); logical = undefined; handle?.close(); @@ -1935,7 +1992,10 @@ export class Consumer { this.#state.releaseMaterialized(path); this.#state.forget(path); }); - }); + }; + + if (!announced) absent(); + return makeRequesting(relative, active, closed, release); } /** diff --git a/quest/m1/api-audit/resolve.md b/quest/m1/api-audit/resolve.md index a5879f675a5..d0a7ea317fc 100644 --- a/quest/m1/api-audit/resolve.md +++ b/quest/m1/api-audit/resolve.md @@ -29,10 +29,11 @@ is private to sessions. `Requesting::is_queued` and the public `Routing` task ar gone; `Requesting` is the owned task. The stats reader uses it instead of its own retry on `is_queued`; the mux binding keeps its pinned `routed_broadcast` wait. Rust and JS have same-epoch follow-return coverage, and every JS request -owns its discovery watch from creation. JS announcement-following no longer -silently uses a blind peer. The existing `routed_broadcast` helper retains its -route-change retry policy for the CLI, gateway, mux binding, and relay HTTP -consumers. Its removal belongs to the remaining rollout. +owns its discovery watch from creation. A pending plain JS request fails +`Unroutable` once that discovery syncs with no route for it, matching Rust. JS +announcement-following no longer silently uses a blind peer. The existing +`routed_broadcast` helper retains its route-change retry policy for the CLI, +gateway, mux binding, and relay HTTP consumers. Its removal belongs to the remaining rollout. The approved public method names have not rolled out. What remains: @@ -46,13 +47,10 @@ The approved public method names have not rolled out. What remains: and `moqsrc` already follow through `moq_mux::Source::follow`. Do not add a new public route API or compatibility shim to make the privatization pass. - JS: expose `request(path, {epoch})` and `follow(path, {epoch})` instead of the - `announced` option and migrate actual callers. Make a one-instance request's - synced-absence verdict terminal, settling `closed` with `Unroutable`, matching - Rust and the bindings, while a follower remains open. A plain JS request - currently stays pending after its discovery syncs with no route, since - `Requesting.unroutable` is gone. The checkpoint covers pending - one-instance retry through a route gap without retargeting an already resolved - instance. Retain synchronous request peeks and path-local wakeups. + `announced` option and migrate actual callers. Keep the checkpoint's + synced-absence `Unroutable` for `request` while `follow` stays open, and its + pending retry through a route gap without retargeting a resolved instance. + Retain synchronous request peeks and path-local wakeups. `Producer` pass-throughs stay only where `Table` needs them. - Bindings: mirror `request` and `follow`, including the optional epoch, in the FFI and every actual wrapper/consumer. Regenerate from source, update @@ -65,8 +63,8 @@ The approved public method names have not rolled out. What remains: epoch pin. No caller should hand-roll synced resolution or rely on a wall clock to decide table absence. -Tests cover an announced but unwatched path over lite-05/06/07-wip, Rust synced -absence, discovery retention and release, pinned follow return, no follower +Tests cover an announced but unwatched path over lite-05/06/07-wip, Rust and JS +synced absence, discovery retention and release, pinned follow return, no follower fallback on a blind peer, and unchanged explicit refusal. Finish the API and caller rollout with the same lifecycle and churn checks, then the required Nix gate and all-language interop. From fdb3d53a1a04ab4e79d79ebedfd05f08b3f2df05 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 28 Oct 2026 10:40:05 -0700 Subject: [PATCH 4/4] fix(js): settle discovery path-locally and keep blind answers from followers Synced-absence settlement walks the watch trie beneath each landed prefix instead of scanning every request slot, and a resolved handle drops its check. A follower sharing a slot with a plain request no longer takes the slot's blind answer. A new requests bench sweeps pending requests against initial sets landing at once. Co-Authored-By: Claude Opus 5.5 --- js/net/bench/requests.ts | 36 ++++++++++++++++++++++++++++++- js/net/src/origin-request.test.ts | 12 +++++++++++ js/net/src/origin.ts | 32 +++++++++++++++++++++------ 3 files changed, 72 insertions(+), 8 deletions(-) diff --git a/js/net/bench/requests.ts b/js/net/bench/requests.ts index 57de2aeff2b..4f519d0deb5 100644 --- a/js/net/bench/requests.ts +++ b/js/net/bench/requests.ts @@ -1,4 +1,4 @@ -/** Sweep request restart and cancellation over independent origin and waiter dimensions. */ +/** Sweep request restart, cancellation, and discovery settlement over independent origin and waiter dimensions. */ import { Producer as Broadcast } from "../src/broadcast"; import * as Epoch from "../src/epoch"; import { Publisher as IetfPublisher } from "../src/ietf/publisher"; @@ -94,6 +94,40 @@ for (const unrelated of [8, 128, 2048]) origin.close(); } +// An initial set landing settles only the pending requests beneath its prefix, never every +// request in the table, however many land in one task. +console.log("pending,landed,settle_us"); +for (const pending of [128, 1024, 8192]) + for (const landed of [1, 16, 128]) { + const samples: number[] = []; + for (let round = 0; round < 5; round++) { + const origin = new Producer(); + const wire = wireOf(origin); + const detach = wire.attach(true); + const initialSets = new Map void>(); + const stop = wire.interests((prefix, wanted) => { + if (wanted) initialSets.set(prefix, wire.snapshot(prefix)); + }); + const held = Array.from({ length: pending }, (_, i) => origin.request(Path.from(`held/${i}`))); + const touched = Array.from({ length: landed }, (_, i) => origin.request(Path.from(`touched/${i}`))); + await settle(); + const start = performance.now(); + for (let i = 0; i < landed; i++) initialSets.get(Path.from(`touched/${i}`))?.(); + // The settlement is one microtask queued by the first landing, ahead of this one. + await Promise.resolve(); + if (round > 0) samples.push((performance.now() - start) * 1000); + if (touched.some((request) => request.closed.peek() === undefined)) throw new Error("absence unsettled"); + if (held.some((request) => request.closed.peek() !== undefined)) throw new Error("unsynced path settled"); + for (const request of [...held, ...touched]) request.close(); + for (const release of initialSets.values()) release(); + stop(); + detach(); + origin.close(); + } + samples.sort((a, b) => a - b); + console.log(`${pending},${landed},${samples[2].toFixed(2)}`); + } + // Keep old instances on distinct same-epoch failovers, then cancel new demand. // This exercises ownership checks inside one cleanup, independently of wire sharing. console.log("failovers,extra_routes,cancel_us"); diff --git a/js/net/src/origin-request.test.ts b/js/net/src/origin-request.test.ts index 484f375fbb3..a3cd00c2e19 100644 --- a/js/net/src/origin-request.test.ts +++ b/js/net/src/origin-request.test.ts @@ -144,10 +144,22 @@ test("only a plain request can use a session without discovery", async () => { expect(wire.blind(slot)).toBe(false); const requested = origin.request(path); expect(wire.blind(slot)).toBe(true); + // The blind answer lands in the shared slot, but only the plain handle takes it. + const source = new BroadcastProducer(); + const withdraw = wire.answer(path, source.consume()); + await settle(); + expect(requested.active.peek()?.closed).toBe(source.closed); + expect(followed.active.peek()).toBeUndefined(); + const joined = origin.request(path, { announced: true }); + await settle(); + expect(joined.active.peek()).toBeUndefined(); + joined.close(); requested.close(); await settle(); expect(wire.blind(slot)).toBe(false); followed.close(); + withdraw?.(); + source.close(); detach(); origin.close(); }); diff --git a/js/net/src/origin.ts b/js/net/src/origin.ts index 77454784b07..3d1bff155f8 100644 --- a/js/net/src/origin.ts +++ b/js/net/src/origin.ts @@ -639,12 +639,24 @@ class OriginState { } #settled(): void { - const prefixes = [...this.#unsettled]; - this.#unsettled.clear(); - for (const [path, slot] of [...(this.requests.peek() ?? [])]) { - if (slot.absent.size === 0 || !prefixes.some((prefix) => Path.hasPrefix(prefix, path))) continue; - for (const absent of [...slot.absent]) absent(); + const requests = this.requests.peek(); + const visited = new Set(); + for (const prefix of this.#unsettled) { + // Every request watches its own path, so the watches beneath the prefix name exactly + // the requests it can settle, without scanning the rest of the table. + let node: WatchNode | undefined = this.#watches; + for (const part of prefix === Path.empty() ? [] : prefix.split("/")) node = node?.children.get(part); + const stack = node ? [node] : []; + for (let next = stack.pop(); next; next = stack.pop()) { + if (visited.has(next)) continue; + visited.add(next); + // Children first: settling a request may prune its node. + stack.push(...next.children.values()); + const slot = requests?.get(next.path); + if (slot) for (const absent of [...slot.absent]) absent(); + } } + this.#unsettled.clear(); } /** Whether every attached session discovers and none owes an initial set covering `path`. */ @@ -1902,7 +1914,9 @@ export class Consumer { let logical: Front | undefined; const own = (resolution: Resolution | undefined): broadcast.Consumer | undefined => { if (released) return undefined; - const front = epoch === undefined || resolution?.epoch === epoch ? resolution?.front : undefined; + // A follower takes only a front something announced; a blind answer is for plain handles. + const offered = announced && !resolution?.source ? undefined : resolution?.front; + const front = epoch === undefined || resolution?.epoch === epoch ? offered : undefined; if (logical && source?.epoch !== undefined && resolution?.epoch === source.epoch) { // Between routes of the instance, readers wait for the next one to answer. if (front) logical.serve(front); @@ -1938,7 +1952,11 @@ export class Consumer { // when the watch opens, so a fresh request waits for its peer's answer. A follower // keeps waiting for a start, and a resolved request ends only with its instance. const absent = () => { - if (released || source || closed.peek() !== undefined) return; + if (released || closed.peek() !== undefined) return; + if (source) { + taken.absent.delete(absent); + return; + } const resolution = route.peek(); if (resolution && (epoch === undefined || resolution.epoch === epoch)) return; if (!this.#state.synced(path)) return;