feat(net)!: model test clock, origin Driver::run(timers), and kio sheds time - #3009
Merged
Conversation
…t timers The model layer never arms a wakeup: its time is passive measurement against its own stamps (group arrival vs the latency budget, cache access ticks, datagram age). So it gets no clock abstraction and no runtime handle. It reads a crate-internal now() that is the real clock in production and, under cfg(test), a paused clock moved only by an explicit advance(), minting real std::time::Instants as base plus offset. No public API, no Instant type swap, and safe as process-global state because nextest runs one process per test. The origin driver is the one model component with reactive timers (route hold-down, subscription idle linger), so it takes them explicitly: Runtime splits into a Timers supertrait (timer + clock) plus Runtime (transport + spawn), and origin::Driver::run(timers) installs a type-erased copy in the origin's shared state and returns the runnable future. Driver no longer implements Future, so polling the origin without timers is unrepresentable; the serve tasks fetch their timers lazily at first poll, which is provably after run installs them. moq_tokio::runtime::Runtime<S = ()> doubles as the transportless Timers handle, and moq_tokio::origin::spawn keeps its signature. With that, kio::time and kio::tokio are deleted along with kio's web-async and tokio dependencies: kio is waker and channel primitives only, and the only reactive clock in the stack is the one the injected runtime provides. The invariant that makes the two remaining clock domains safe is documented: instants never cross between model stamps and runtime-armed deadlines, durations may. Part of #2875; follows #3007. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BCxzHiGxN5qi8Gd687nsgm
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fa1988d73d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Make the passive model test clock thread-local so cargo test concurrency cannot age another test. Start pre-run handover holds only after the driver clock is installed, and reuse moq-tokio's timer adapter across downstream tests. Co-Authored-By: GPT-5 <noreply@openai.com>
Collaborator
Author
|
Codex Review: Didn't find any major issues. Hooray! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PR 2 of the #2875 plan (follows #3007): the model layer and the origin driver come off
kio::time, and kio'stime/tokiomodules are deleted along with its web-async and tokio dependencies. kio is now pure waker/channel primitives, and the only reactive clock in the stack is the one the injected runtime provides.The design came out of review discussion on top of #3007 and amends the epic plan once more:
now()that is the real clock in production and a paused clock undercfg(test): frozen at each test thread's start, moved only by an explicit test-onlyadvance(), minting realstd::time::Instants as base plus a thread-local offset. No public API, no type swap (mock_instantand friends substitute theInstanttype, which is exactly what we avoid), one branch of overhead only in test builds, and isolation under both nextest and standardcargo testconcurrency.origin::Driver::run(timers)installs them and returns the runnable future. It is now impossible to poll the origin without timers, by construction.Runtimesplits intoTimers+Runtime. Timer minting and the clock move to aTimerssupertrait, so the origin can borrow a runtime's timers without pretending to have a transport. Downstream Tokio tests dev-depend on the sharedmoq-tokioadapter instead of carrying local timer copies.API
moq_net::runtime(re-exported:moq_net::{Runtime, Timers})Behind the
test-runtimefeature:moq_net::origin(breaking)moq_tokio::runtimemoq_tokio::origin::spawnand the rest of moq-tokio's public surface are unchanged;moq_wasm::runtime::Runtime(browser: microtask spawn, wasmtimer timers) likewise implements the split traits.kio (breaking)
kio::timeandkio::tokioare deleted, along with thetime/tokiofeatures and the web-async and tokio dependencies. kio is waker/channel primitives only.(Everything else is crate-private: the model's paused test clock and the type-erased late-bound timers behind
Driver::runadd no public surface.)Wire behavior changes
None. No draft or JS changes.
Test plan
nix develop --command just fix/ CI-strictjust check/ CI-strictjust test(3,473 Rust tests passed, 2 skipped; 52 Python tests passed)tokio::time::pause/advanceto the model test clock'sadvance; origin driver tests keep their tokio paused-clock semantics through.run(tokio_test::Tokio::<()>::new());runtime/test.rsandmodel/clock.rscarry their own unit tests. Regression coverage verifies test-thread clock isolation and rebases pre-run handover holds onto the installed driver clock. No assertion was weakened or dropped.One inference note for reviewers: a defaulted type parameter does not drive expression inference, so the transportless handles are written
Runtime::<()>::new()rather than a bareRuntime::new().(Written by Claude Fable 5)
🤖 Generated with Claude Code
https://claude.ai/code/session_01BCxzHiGxN5qi8Gd687nsgm
(Updated by GPT-5)