Skip to content

refactor(net)!: drive time and cache cleanup explicitly - #3825

Merged
kixelated merged 8 commits into
mainfrom
codex/explicit-driver-time
Sep 21, 2026
Merged

kixelated merged 8 commits into
mainfrom
codex/explicit-driver-time

Conversation

@kixelated

@kixelated kixelated commented Sep 20, 2026

Copy link
Copy Markdown
Collaborator

Problem

Session and origin drivers still depend on runtime timer providers, and cache accesses read ambient time. This makes the public traits harder to follow and time-dependent behavior harder to drive deterministically.

Approach

Supply Instant when polling drivers and let runtime adapters sleep until the driver's next deadline. Replace timer generics with a private driver clock. Add Pool::gc(now), called after origin polling, to date cache activity lazily and reclaim idle groups without an activity queue or separate cache driver.

Supersedes #3822: its caller-owned session driver changes are included here.

Impact

  • Rust session constructors take an initial Instant and return (Session, Driver); drivers are explicitly polled rather than awaited directly.
  • Session and origin drivers implement time::Driver with poll(now, waiter) and timeout(). Public runtime/timer-provider traits and timer generics are removed.
  • Pool::gc(now) -> Option<Instant> exposes standalone cleanup. Origins include its deadline in their own timeout. Due passes scan all cached candidates; activity is dated on observation, so expiration is approximate and delayed cleanup extends retention.
  • Model read/write APIs take no wall-clock time. Datagram writes retain their existing signatures.
  • Rust and JavaScript datagram send buffers retain the newest 64 entries and drop the oldest at capacity, replacing 50 ms arrival-time pruning without adding clock reads.
  • Tokio, WASM, FFI, and io_uring adapters own clock reads and sleeping. Production moq-net does not spawn tasks.
  • moq_tokio::origin::spawn() / spawn_config(config) keep the shape from feat(net)!: simplify origin scoping #3804.
  • No wire-format, TypeScript API, or foreign ABI changes.

Validation

  • just check and just test pass after merging current main (noq-only backend, origin scoping, embedding API changes).
  • Rust and JavaScript regression tests cover a stalled datagram reader alongside an active reader, without advancing a clock or running GC.

Alternatives

Passing an instant through every frame access would make expiration more precise but widen the API. A separate cache driver and activity queue added unnecessary bookkeeping for approximate cleanup.

Follow-ups

  • Close refactor(net)!: return session drivers to callers #3822 once this lands.
  • The run(driver) adapter loop is copied in moq-tokio, moq-wasm, moq-ffi, moq-uring, and moq_net::time::test; a shared web_async-backed helper could replace four of them.
  • The driver return shape is still open: Poll<Output> plus timeout() is kept because Result<Option<Instant>> alone cannot express a live driver waiting only on external activity.
  • Update the stale native JS smoke client (Node/Bun subscriber combinations fail before connecting in smoke-full, unrelated to this PR).

(written by GPT-6, taken over by Claude Opus 5)

🤖 Generated with Claude Code

kixelated and others added 6 commits September 20, 2026 13:39
Replace the spawning Runtime trait with caller-owned session drivers and independent timer providers. Update runtime integrations, tests, and documentation.

Co-Authored-By: GPT-6 <noreply@openai.com>
Supply time when polling session and origin drivers, move runtime sleeping into adapters, and expose Pool::gc for approximate idle cleanup.

Co-Authored-By: GPT-6 <noreply@openai.com>
Restore the original datagram write signatures and bound Rust and JavaScript datagram send buffers to the newest 64 entries without clock reads.

Co-Authored-By: GPT-6 <noreply@openai.com>
Adapt the test to the catalog constructor from main so workspace validation compiles.

Co-Authored-By: GPT-6 <noreply@openai.com>
@kixelated
kixelated marked this pull request as ready for review September 21, 2026 10:21
@moq-bot

moq-bot Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor
  1. Breaking Rust API (!: new Instant constructors, (Session, Driver) return, removed timer traits) targets main while moq-net is published at 0.2.22 (rs/moq-net/Cargo.toml:8, AGENTS.md#development). Retarget to dev and rebase onto origin/dev.
    Verdict: request changes
    (Written by Muse Spark)

New%20session%20-%202026-09-21T10%3A38%3A11.627Z
opencode session  |  github run

@kixelated

Copy link
Copy Markdown
Collaborator Author

Not retargeting: dev was merged into main and deleted on 2026-09-20 (#3793), and later breaking moq-net changes (#3804, #3811) landed on main the same way. The maintainer asked for main on the predecessor #3822.

(written by Claude Opus 5)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant