Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
d7770fe
quest(m1): claim time/crates
kixelated Oct 21, 2026
25cf1b6
refactor(rs): move the remaining crates onto moq-clock
kixelated Oct 21, 2026
8012e21
fix(rs): keep test-module clock allows inner beside inner attributes
kixelated Oct 21, 2026
e8e0f7a
test(clock): cover timeout_at and interval_at on the sim
kixelated Oct 21, 2026
f368af9
Merge remote-tracking branch 'origin/main' into quest/m1/time/crates
kixelated Oct 21, 2026
1f6bd00
quest(m1): link the time/crates PR from its quest
kixelated Oct 21, 2026
61563ed
Merge remote-tracking branch 'origin/main' into quest/m1/time/crates
kixelated Oct 21, 2026
60c7fd7
feat(clock): convert instants to and from std at third-party boundaries
kixelated Oct 21, 2026
8563c5f
Merge remote-tracking branch 'origin/main' into quest/m1/time/crates
kixelated Oct 21, 2026
3c3afff
refactor(cli): put the stats report on moq-clock
kixelated Oct 21, 2026
ee4653a
Merge remote-tracking branch 'origin/main' into quest/m1/time/crates
kixelated Oct 21, 2026
f8a9d5e
Merge remote-tracking branch 'origin/main' into quest/m1/time/crates
kixelated Oct 21, 2026
edb6866
Merge remote-tracking branch 'origin/main' into merge-6135
kixelated Oct 21, 2026
3b93e92
Merge remote-tracking branch 'origin/main' into merge-6135-b
kixelated Oct 21, 2026
3c91b56
test(srt): drop the host-clock comparison moq-clock now covers
kixelated Oct 21, 2026
53d8014
Merge remote-tracking branch 'origin/main' into quest/m1/time/crates
kixelated Oct 22, 2026
9c11c4b
test(moq-hls): time the unannounced-broadcast test on moq-clock
kixelated Oct 22, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions doc/lib/rs/moq-clock.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ and it pauses the instant but not wall time. The simulator is its own clock
too. A runtime that reads the time itself, like a moq-uring worker, enters a
`Deadlines` queue on its thread, and the ambient clock is that queue.

Instants from different clocks don't compare, and there is no conversion back
to `std::time::Instant`.
Instants from different clocks don't compare. On native, `Instant::into_std()`
and `Instant::from_std()` convert at a third-party API that takes
`std::time::Instant`, through the runtime clock's origin. That is exact on a
running clock, and keeps only durations on paused tokio or the simulator.

## Caller-driven code

Expand Down
10 changes: 9 additions & 1 deletion quest/m1/time/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ reasons, so later sessions don't reopen them:
`disallowed-types` in a per-crate `clippy.toml`, and a biome
`noRestrictedGlobals` override, allowing only the backend modules. The
workspace-wide test and lint sweep follows in m2.
- **Third-party std clocks.** A third-party API that takes
`std::time::Instant` (str0m, srt-tokio, winit, qlog) converts with
`Instant::into_std` and `Instant::from_std`, native only, through the runtime
clock's origin: exact on a running clock, durations only on paused tokio or
the simulator. Device threads outside any runtime keep `std::thread::sleep`
under a per-site `#[allow]`, since they have no ambient clock to wait on
(decided 2026-10-20 by the maintainer, in
[#6135](https://github.com/moq-dev/moq/pull/6135)).
- **Consolidation.** perf/3122 (one clock read per io_uring turn) landed with
moq-uring on moq-clock in [#5926](https://github.com/moq-dev/moq/pull/5926). The relay seam
[bench-relay](/quest/m2/bench-relay.md) needed is `moq_relay::Accepted`:
Expand All @@ -97,8 +105,8 @@ cleanup and the global lint ratchet belong to

## Required

- [Every crate on moq-clock](/quest/m1/time/crates.md) - every remaining crate reads time only through moq-clock, with controlled tests for the production/public API migrations
- [JS timers fire at their own deadlines](/quest/m1/time/js-deadlines.md) - `Manual.advance` (renamed from `advanceAsync`) steps to each deadline, sync `advance` becomes `jump`, and `Effect.interval` arms its first period synchronously
- [Public wall times on moq_clock::Wall](/quest/m1/time/wall.md) - public `SystemTime`s become `moq_clock::Wall`, and the ratchets ban the type

## Related

Expand Down
55 changes: 0 additions & 55 deletions quest/m1/time/crates.md

This file was deleted.

1 change: 0 additions & 1 deletion quest/m1/time/js-deadlines.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,4 @@ target, and the clock never ends past the target or moves backward.

## Related

- [Every crate on moq-clock](/quest/m1/time/crates.md) - the Rust side of the same clock contract
- [Time test sweep](/quest/m2/time-test-sweep.md) - legacy JS tests converted there get stepped `advance` for free
36 changes: 36 additions & 0 deletions quest/m1/time/wall.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# [M] Public wall times on moq_clock::Wall

## Goal

Every public wall time in the Rust crates is a `moq_clock::Wall` instead of a
`std::time::SystemTime`, and the per-crate clippy ratchets ban the
`SystemTime` type wherever it no longer crosses a third-party API.

## Plan

The remaining public `SystemTime`s, as of
[#6135](https://github.com/moq-dev/moq/pull/6135):

- hang: `catalog::Clock::wall_clock` and `echo::Arrival::wall`, plus the
snapshot serializer.
- moq-mux: `Clock::at`, `Clock::wall_clock`, `catalog::Timebase::place`, and
the catalog producer's wall argument; this ripples into moq-gst's sink,
moq-audio's capture, and moq-hls.
- moq-hls: the manifest and playlist `program_date_time`,
`availability_start`, `publish`, and `Renditions::anchor`.
- moq-quic: `TimeSource::now` and the token log's issue times.
- moq-relay: the session's `started`.
- moq-tokio: the certificate `expiry`.
- moq-cli and moq-bench: private wall times, which can move freely.

`Wall` covers 1970 to 2554, so a catalog wall past that range is an error, as
it already is on Windows. A third-party API on `SystemTime`, such as str0m's
sender reports in moq-rtc, converts at its boundary with `From<Wall>` and
`TryFrom<SystemTime>`.

Public API: breaking in hang, moq-mux, moq-hls, moq-quic, moq-relay, and
moq-tokio, each with a `MIGRATE.md` entry. Wire: none.

## Related

- [Time test sweep](/quest/m2/time-test-sweep.md) - the workspace-wide lint follows this
1 change: 1 addition & 0 deletions rs/hang/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ features = ["from", "display", "debug"]

[dev-dependencies]
anyhow = { workspace = true }
moq-clock = { workspace = true }
moq-mux = { path = "../moq-mux" }
moq-tokio = { path = "../moq-tokio", default-features = false, features = ["quic", "aws-lc-rs", "websocket"] }
tokio = { workspace = true, features = ["macros", "fs"] }
Expand Down
23 changes: 23 additions & 0 deletions rs/hang/clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Production uses the ambient clock; legacy test-only clock cleanup is tracked separately.
# `SystemTime` stays an allowed type until its wall times move to `moq_clock::Wall`.
disallowed-methods = [
{ path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" },
{ path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" },
{ path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" },
{ path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" },
{ path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" },
{ path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" },
{ path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" },
{ path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" },
{ path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" },
{ path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" },
{ path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" },
{ path = "tokio::time::interval_at", reason = "tick on the ambient clock" },
]

disallowed-types = [
{ path = "std::time::Instant", reason = "use moq_clock::Instant" },
{ path = "tokio::time::Instant", reason = "use moq_clock::Instant" },
{ path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" },
{ path = "tokio::time::Interval", reason = "use moq_clock::Interval" },
]
6 changes: 3 additions & 3 deletions rs/hang/examples/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ async fn run_broadcast(origin: moq_net::origin::Producer) -> anyhow::Result<()>
};
producer.write(frame)?;

tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
moq_clock::sleep(tokio::time::Duration::from_secs(1)).await;

let frame = moq_mux::container::Frame {
timestamp: moq_net::Timestamp::from_secs(2).unwrap(),
Expand All @@ -113,7 +113,7 @@ async fn run_broadcast(origin: moq_net::origin::Producer) -> anyhow::Result<()>
};
producer.write(frame)?;

tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
moq_clock::sleep(tokio::time::Duration::from_secs(1)).await;

// Marking this frame as a keyframe closes the current group and starts a new one.
let frame = moq_mux::container::Frame {
Expand All @@ -125,7 +125,7 @@ async fn run_broadcast(origin: moq_net::origin::Producer) -> anyhow::Result<()>
producer.write(frame)?;

// Sleep before exiting and closing the broadcast.
tokio::time::sleep(tokio::time::Duration::from_secs(10)).await;
moq_clock::sleep(tokio::time::Duration::from_secs(10)).await;

Ok(())
}
23 changes: 23 additions & 0 deletions rs/libmoq/clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Production uses the ambient clock; legacy test-only clock cleanup is tracked separately.
disallowed-methods = [
{ path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" },
{ path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" },
{ path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" },
{ path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" },
{ path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" },
{ path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" },
{ path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" },
{ path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" },
{ path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" },
{ path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" },
{ path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" },
{ path = "tokio::time::interval_at", reason = "tick on the ambient clock" },
]

disallowed-types = [
{ path = "std::time::SystemTime", reason = "use moq_clock::Wall" },
{ path = "std::time::Instant", reason = "use moq_clock::Instant" },
{ path = "tokio::time::Instant", reason = "use moq_clock::Instant" },
{ path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" },
{ path = "tokio::time::Interval", reason = "use moq_clock::Interval" },
]
1 change: 1 addition & 0 deletions rs/moq-audio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ cpal = { version = "0.18", optional = true }
fixed-resample = { version = "0.13", optional = true, default-features = false, features = ["channel", "resampler"] }
hang = { workspace = true }
kio = { workspace = true, optional = true }
moq-clock = { workspace = true }
moq-mux = { workspace = true }
moq-net = { workspace = true }
# We only use the sinc resampler (Async::new_sinc), so skip the default
Expand Down
23 changes: 23 additions & 0 deletions rs/moq-audio/clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Production uses the ambient clock; legacy test-only clock cleanup is tracked separately.
disallowed-methods = [
{ path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" },
{ path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" },
{ path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" },
{ path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" },
{ path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" },
{ path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" },
{ path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" },
{ path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" },
{ path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" },
{ path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" },
{ path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" },
{ path = "tokio::time::interval_at", reason = "tick on the ambient clock" },
]

disallowed-types = [
{ path = "std::time::SystemTime", reason = "use moq_clock::Wall" },
{ path = "std::time::Instant", reason = "use moq_clock::Instant" },
{ path = "tokio::time::Instant", reason = "use moq_clock::Instant" },
{ path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" },
{ path = "tokio::time::Interval", reason = "use moq_clock::Interval" },
]
1 change: 1 addition & 0 deletions rs/moq-audio/src/aec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ fn channel(rate: u32) -> (ResamplingProd<f32>, ResamplingCons<f32>) {
}

#[cfg(test)]
#[allow(clippy::disallowed_methods, clippy::disallowed_types)]
mod tests {
use std::collections::VecDeque;
use std::time::Duration;
Expand Down
2 changes: 1 addition & 1 deletion rs/moq-audio/src/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ impl Microphone {

// Await the first buffer to surface a permission failure (or dead device)
// as an error rather than a silent hang in the capture loop.
let pending = match tokio::time::timeout(FIRST_BUFFER_TIMEOUT, reader.read()).await {
let pending = match moq_clock::timeout(FIRST_BUFFER_TIMEOUT, reader.read()).await {
Ok(Ok(Some(samples))) => samples,
Ok(Ok(None)) => {
return Err(Failure::retry(Error::Capture(format!(
Expand Down
2 changes: 2 additions & 0 deletions rs/moq-audio/src/capture/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ fn relay(mut pending: HeapCons<Filled>, tx: mpsc::Sender<Filled>) {
if !pending.write_is_held() {
return;
}
// The device thread runs outside any runtime, so it blocks on the host clock.
#[allow(clippy::disallowed_methods)]
std::thread::sleep(RELAY_POLL_INTERVAL);
}
}
Expand Down
4 changes: 3 additions & 1 deletion rs/moq-audio/src/capture/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ use std::sync::{
Arc,
atomic::{AtomicU64, Ordering},
};
use std::time::{Duration, Instant};
use std::time::Duration;

use moq_clock::Instant;

use tokio::sync::mpsc;

Expand Down
2 changes: 1 addition & 1 deletion rs/moq-audio/src/capture/permission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async fn request_access(media: &objc2_av_foundation::AVMediaType) -> Result<(),

unsafe { AVCaptureDevice::requestAccessForMediaType_completionHandler(media, &handler) };

match tokio::time::timeout(PROMPT_TIMEOUT, rx).await {
match moq_clock::timeout(PROMPT_TIMEOUT, rx).await {
Ok(Ok(true)) => Ok(()),
Ok(Ok(false)) => Err(denied()),
// Prompt dismissed without a decision, or the callback never fired within
Expand Down
Loading
Loading