Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion quest/m1/poll-first/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,3 @@ and their alternatives:

- [Generated async wrappers behind a feature](/quest/m1/poll-first/async-feature.md) - each library's `async fn` wrappers are generated from its `poll_*` signatures and compile only with its `async` feature
- [Server::accept and Handshake::ok are kio machines](/quest/m1/poll-first/server-machines.md) - moq-net's `Server::accept` and `server::Handshake::ok` are `#[kio::machine]` `poll_*` methods with one-line async wrappers, like the other straight-line bodies converted in [moq-dev/moq#7284](https://github.com/moq-dev/moq/pull/7284)
- [Libraries spawn nothing](/quest/m1/poll-first/no-spawn/README.md) - moq-ffi, moq-stats, and moq-relay's cluster and auth run as polled `kio::Tasks` children instead of spawned tasks
59 changes: 0 additions & 59 deletions quest/m1/poll-first/no-spawn/README.md

This file was deleted.

18 changes: 0 additions & 18 deletions quest/m1/poll-first/no-spawn/sim-tests.md

This file was deleted.

2 changes: 1 addition & 1 deletion quest/m2/net-wrap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Compression is not a wrapper: it moves into moq-net as a track flag
moq-flate, so moq-flate is out of scope.

Non-goals:
- A runtime seam: libraries poll and spawn nothing ([Libraries spawn nothing](/quest/m1/poll-first/no-spawn/README.md)).
- A runtime seam: libraries poll and spawn nothing ([the remaining library spawns](/quest/m2/spawn-audit.md)).
- The transport seam: custom transports implement moq-net's `transport::poll` traits ([native WebTransport](/quest/m1/quic-api/native-web.md) moves the last backend onto them).

## Plan
Expand Down
34 changes: 26 additions & 8 deletions quest/m2/spawn-audit.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,36 @@

## Goal

Every async task spawn left in a library crate after
[Libraries spawn nothing](/quest/m1/poll-first/no-spawn/README.md) is either converted
to a `kio::Tasks` child its owner polls or listed with the reason it must stay.
Every async task spawn left in a library crate is either converted to a
`kio::Tasks` child its owner polls or listed with the reason it must stay.
Blocking OS threads are out of scope.

## Plan

Planned 2026-10-25 with the maintainer as the follow-up to no-spawn. As of
Planned 2026-10-25 with the maintainer as the follow-up to no-spawn, the m1 epic
that converted moq-ffi, moq-stats, and moq-relay's cluster and auth decider and
moved the relay's in-memory tests onto kio's simulator. Its rule, decided with the
maintainer on 2026-10-25 in place of an m2 runtime trait:

- **Poll everywhere, no spawn.** A spawn trait keeps `'static` detached tasks
in the library, which poll-first rejects; `kio::Tasks` gives a library
structured children with no runtime, and time is `kio::clock`. Only the edges
spawn a root task: binaries and the bindings' runtime.
- **No I/O seam.** I/O stays at moq-net's `transport::poll` traits and
moq-sock.
- **Blocking work is out of scope.** OS threads for blocking capture, encode,
or file I/O are not async tasks and stay.

Spawns no-spawn kept for this audit to convert or list: `Critical`'s web certificate reload
(`rs/moq-relay/src/web.rs`), the io_uring handoff in
`rs/moq-relay/src/connection.rs`, and moq-relay's web, shutdown, and uring
spawns. Each UniFFI call's task on the bindings' runtime stays: that is the
binding boundary. So does moq-ffi's wake dispatch (decided 2026-11-03,
[moq-dev/moq#7720](https://github.com/moq-dev/moq/pull/7720)): a wake its root
raises for a parked host call runs on the blocking pool, so a host continuation
never runs inside the root.

As of
`main` today the spawning library crates include moq-tokio (connection,
server, client), moq-relay (web, shutdown, uring), moq-mux's container
consumer, moq-hls's server (its path follower and each
Expand Down Expand Up @@ -38,7 +60,3 @@ server entry above):

Public API: constructors that spawned return a handle to poll instead; an Impact
migration note per published crate. Wire: none.

## Required

- [Libraries spawn nothing](/quest/m1/poll-first/no-spawn/README.md) - the rule and the pattern this applies
4 changes: 0 additions & 4 deletions quest/m3/video-web.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,3 @@ bump.
rather than silently picking another.
- **Out of scope:** replacing js/publish's or js/watch's internals with these
backends.

## Required

- [Libraries spawn nothing](/quest/m1/poll-first/no-spawn/README.md) - library work polled by its owner, with no runtime to spawn on
2 changes: 1 addition & 1 deletion rs/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ A `Producer` writes and any number of `Consumer`s read, sharing state via `kio`.
# Testing

- Tests are inline `#[cfg(test)] mod tests`; full Client/Server session tests go in the crate's `tests/integration/`.
- Time-dependent async tests call `tokio::time::pause()` (moq-net uses `#[kio::test]`), unless they cross real sockets; those assert lower bounds.
- Time-dependent async tests call `tokio::time::pause()` (moq-net and moq-relay's in-memory tests use `#[kio::test]`), unless they cross real sockets; those assert lower bounds.
- Run tests through `just` (nextest), not `cargo test`. A SLOW test is a bug to fix, not a threshold to raise.
- Local checks build only the host platform; nightly covers the full feature matrix (`just rs features`) and Windows/macOS.
42 changes: 21 additions & 21 deletions rs/moq-relay/tests/integration/connection.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
//! A relay [`Connection`](moq_relay::Connection) over the in-memory transport: admission,
//! the cluster origin, and stats, with no socket and on Tokio's paused clock.
//! the cluster origin, and stats, with no socket and on kio's simulator.

use std::time::Duration;

use moq_net::stats;

use crate::memory::{self, connect, newest};

/// Long enough that only a hang reaches it; paused time skips straight there.
/// Long enough that only a hang reaches it; simulated time skips straight there.
const TIMEOUT: Duration = Duration::from_secs(60);

/// The relay preserves every legal QUIC-varint sequence, including values beyond
/// JavaScript's exact number range, on each flavour used by the browser bindings.
#[tokio::test(start_paused = true)]
#[kio::test]
async fn largest_quic_sequence_reaches_the_subscriber() {
for alpn in ["moq-lite-02", "moq-lite-06", "moq-transport-22"] {
let version = alpn.parse().unwrap();
let auth = memory::public(&["**"], &[], &[]);
let cluster = memory::cluster();
let publisher = moq_tokio::origin::spawn();
let publisher = memory::origin();
let broadcast = publisher.create_broadcast("ladder").unwrap();
let info = moq_net::track::Info::default().with_timescale(moq_net::Timescale::MICRO);
let track = broadcast.create_track("data", info).unwrap();
Expand All @@ -31,7 +31,7 @@ async fn largest_quic_sequence_reaches_the_subscriber() {
)
.await
.unwrap();
let subscriber = moq_tokio::origin::spawn();
let subscriber = memory::origin();
let _subscriber = connect(
moq_net::Client::new().with_subscriber(subscriber.clone()),
version,
Expand Down Expand Up @@ -77,7 +77,7 @@ fn publish(
moq_net::origin::Publication,
moq_net::track::Producer,
) {
let origin = moq_tokio::origin::spawn();
let origin = memory::origin();
let broadcast = origin.create_broadcast(name).expect("create broadcast");
broadcast.announce(Default::default()).expect("announce");
let info = moq_net::track::Info::default().with_timescale(moq_net::Timescale::MILLI);
Expand Down Expand Up @@ -122,7 +122,7 @@ async fn assert_refused(result: Result<moq_net::Session, moq_net::Error>) {
/// A publisher whose grant covers only subscribing is refused during the handshake,
/// instead of accepted to stream into a dropped session forever. Its SETUP's role
/// says it publishes.
#[tokio::test(start_paused = true)]
#[kio::test]
async fn subscribe_only_public_rejects_publisher_role() {
let auth = memory::public(&[], &[], &["**"]);
let (origin, _broadcast, _track) = publish("cam");
Expand All @@ -131,10 +131,10 @@ async fn subscribe_only_public_rejects_publisher_role() {
}

/// The same grant keeps a subscriber: the role gate refuses only the mismatched direction.
#[tokio::test(start_paused = true)]
#[kio::test]
async fn subscribe_only_public_accepts_subscriber_role() {
let auth = memory::public(&[], &[], &["**"]);
let client = moq_net::Client::new().with_subscriber(moq_tokio::origin::spawn());
let client = moq_net::Client::new().with_subscriber(memory::origin());
let session = connect(client, newest(), &memory::cluster(), &auth)
.await
.expect("subscriber connects");
Expand All @@ -145,16 +145,16 @@ async fn subscribe_only_public_accepts_subscriber_role() {
}

/// The mirror: a subscriber whose grant covers only publishing is refused.
#[tokio::test(start_paused = true)]
#[kio::test]
async fn publish_only_public_rejects_subscriber_role() {
let auth = memory::public(&[], &["**"], &[]);
let client = moq_net::Client::new().with_subscriber(moq_tokio::origin::spawn());
let client = moq_net::Client::new().with_subscriber(memory::origin());
assert_refused(connect(client, newest(), &memory::cluster(), &auth).await).await;
}

/// Two publish-only clients share one relay, and a subscriber sees both broadcasts:
/// neither tears the other down.
#[tokio::test(start_paused = true)]
#[kio::test]
async fn two_publish_only_clients_coexist() {
let auth = memory::public(&["**"], &[], &[]);
let cluster = memory::cluster();
Expand All @@ -178,7 +178,7 @@ async fn two_publish_only_clients_coexist() {
.await
.expect("beta connects");

let origin = moq_tokio::origin::spawn();
let origin = memory::origin();
let mut announced = origin.consume().announced();
let _subscriber = connect(
moq_net::Client::new().with_subscriber(origin),
Expand All @@ -197,10 +197,10 @@ async fn two_publish_only_clients_coexist() {
/// The decider is asked about the path, query, and role the SETUP carried, and the
/// grant it answers is rooted at that path: a publisher's broadcast reaches a root
/// subscriber under it, frames and all.
#[tokio::test(start_paused = true)]
#[kio::test]
async fn the_setup_path_reaches_the_decider_and_roots_the_grant() {
let (auth, mut admissions) = moq_relay::auth::Auth::embedded("test");
let decider = tokio::spawn(async move {
let decider = kio::clock::sim::spawn(async move {
let mut seen = Vec::new();
while let Some(admission) = admissions.next().await {
seen.push(admission.request.clone());
Expand All @@ -222,7 +222,7 @@ async fn the_setup_path_reaches_the_decider_and_roots_the_grant() {
.await
.expect("publisher connects");

let origin = moq_tokio::origin::spawn();
let origin = memory::origin();
let consumer = origin.consume();
let mut announced = consumer.announced();
let _subscriber = connect(
Expand Down Expand Up @@ -267,11 +267,11 @@ async fn the_setup_path_reaches_the_decider_and_roots_the_grant() {

/// The relay's stats count an admitted session while it is open and a refused one
/// by its reason, under the default tier.
#[tokio::test(start_paused = true)]
#[kio::test]
async fn stats_count_admitted_and_refused_sessions() {
let mut config = moq_relay::stats::Config::default();
config.enabled = true;
let cluster = crate::spawn_cluster(moq_relay::cluster::Options::default().with_stats(config));
let cluster = memory::spawn_cluster(moq_relay::cluster::Options::default().with_stats(config));
let registry = cluster.stats.clone();
let presence = || {
registry
Expand All @@ -283,13 +283,13 @@ async fn stats_count_admitted_and_refused_sessions() {
};
let auth = memory::public(&[], &[], &["**"]);

let client = moq_net::Client::new().with_subscriber(moq_tokio::origin::spawn());
let client = moq_net::Client::new().with_subscriber(memory::origin());
let session = connect(client, newest(), &cluster, &auth)
.await
.expect("subscriber connects");
kio::clock::timeout(TIMEOUT, async {
while presence().active() != 1 {
tokio::task::yield_now().await;
kio::clock::sleep(Duration::from_millis(1)).await;
}
})
.await
Expand All @@ -303,7 +303,7 @@ async fn stats_count_admitted_and_refused_sessions() {
drop(session);
kio::clock::timeout(TIMEOUT, async {
while presence().active() != 0 {
tokio::task::yield_now().await;
kio::clock::sleep(Duration::from_millis(1)).await;
}
})
.await
Expand Down
24 changes: 12 additions & 12 deletions rs/moq-relay/tests/integration/drain.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! The shutdown drain over moq-net's in-memory transport, on Tokio's paused clock.
//! The shutdown drain over moq-net's in-memory transport, on kio's simulator.
//!
//! The deadline closes every established session the drain still holds, however
//! its GOAWAY is faring, and the drain returns only once each has recorded its end.
Expand Down Expand Up @@ -38,7 +38,7 @@ async fn admit(observer: &shutdown::Observer, version: moq_net::Version, stalled
let (client_link, relay_link) = memory::pair(config);

let observer = observer.clone();
tokio::spawn(async move {
drop(kio::clock::sim::spawn(async move {
let server = moq_net::Server::new().with_versions(version.into());
let handshake = server
.accept_request(moq_net::time::Instant::now(), relay_link)
Expand All @@ -49,13 +49,13 @@ async fn admit(observer: &shutdown::Observer, version: moq_net::Version, stalled
.with_shutdown(observer)
.run()
.await;
});
}));

let all = moq_auth::Pattern::all;
let (lease, consumer) = lease::Producer::new(moq_auth::Grant::new(all(), all()));
tokio::spawn(async move {
drop(kio::clock::sim::spawn(async move {
admissions.next().await.expect("an admission").grant(consumer);
});
}));
let (client, driver) = moq_net::Client::new()
.with_versions(version.into())
.connect(moq_net::time::Instant::now(), client_link)
Expand All @@ -65,7 +65,7 @@ async fn admit(observer: &shutdown::Observer, version: moq_net::Version, stalled
// Polled only while `reading`, and never dropped: a dropped driver would close
// the transport rather than leave it open and unread.
let reading = Arc::new(AtomicBool::new(true));
tokio::spawn({
drop(kio::clock::sim::spawn({
let reading = reading.clone();
async move {
let mut driver = std::pin::pin!(moq_net::time::run(driver));
Expand All @@ -75,9 +75,9 @@ async fn admit(observer: &shutdown::Observer, version: moq_net::Version, stalled
})
.await
}
});
}));

// Paused time advances only once every task is idle, so the relay is
// Simulated time advances only once every task is idle, so the relay is
// supervising the session by the time this returns.
kio::clock::sleep(Duration::from_millis(1)).await;
assert!(
Expand All @@ -89,15 +89,15 @@ async fn admit(observer: &shutdown::Observer, version: moq_net::Version, stalled
}

/// Start the drain and return its end, which [`shutdown::Observer::drained`] reports.
fn drain(trigger: &shutdown::Trigger, observer: &shutdown::Observer) -> tokio::task::JoinHandle<()> {
fn drain(trigger: &shutdown::Trigger, observer: &shutdown::Observer) -> kio::clock::sim::JoinHandle<()> {
trigger.start();
let observer = observer.clone();
tokio::spawn(async move { observer.drained().await })
kio::clock::sim::spawn(async move { observer.drained().await })
}

/// A peer that ignores the GOAWAY is closed at the deadline, and the drain returns
/// only after its lease recorded the shutdown.
#[tokio::test(start_paused = true)]
#[kio::test]
async fn a_session_ignoring_the_goaway_is_closed_at_the_deadline() {
for alpn in ["moq-lite-06", "moq-lite-03", "moq-transport-18"] {
let (trigger, observer) = shutdown::Observer::new(WINDOW);
Expand Down Expand Up @@ -129,7 +129,7 @@ async fn a_session_ignoring_the_goaway_is_closed_at_the_deadline() {
/// A peer that stops reading leaves the relay's GOAWAY stuck on its stream, so the
/// driver never arms its own timer. The drain deadline still closes the session and
/// waits for its end.
#[tokio::test(start_paused = true)]
#[kio::test]
async fn a_stalled_goaway_write_is_still_closed_at_the_deadline() {
let (trigger, observer) = shutdown::Observer::new(WINDOW);
let session = admit(&observer, "moq-lite-06".parse().unwrap(), true).await;
Expand Down
Loading
Loading