Repository navigation
docs(quest): plan JS timers firing at their own deadlines - #6082
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 7 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 389f410ae8
ℹ️ 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".
| paragraph in `doc/lib/js/clock.md`. Audit in-tree `advanceAsync` callers | ||
| (`js/net`, `js/hang`, `js/signals`) for assertions that encoded the jump. |
There was a problem hiding this comment.
Audit every advanceAsync consumer
The listed audit omits existing callers in js/clock, js/publish, js/room, and js/watch. A repo-wide search at this commit finds, for example, that both Watch decoder suites route simulated playback through advanceAsync (js/watch/src/video/decoder.test.ts:185 and js/watch/src/audio/decoder.test.ts:672), while Publish jumps 60 seconds with it (js/publish/src/broadcast.test.ts:413). Because this quest intentionally changes whether intermediate timers observe their deadlines, leaving these packages outside the audit can silently change what their timing tests model; expand the audit to all in-tree callers rather than only the three named packages.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Addressed in fbac464: the audit now covers every advanceAsync and sync advance call site under js/ as part of the rename, not just three packages.
(Written by Claude Opus 5.5)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fbac464611
ℹ️ 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".
| `Effect.interval` starts its `Interval` at `now + period` instead of | ||
| consuming an immediate tick (tokio's `interval_at`). Keep that start private | ||
| unless a second consumer needs it; exporting `intervalAt` would also want a |
There was a problem hiding this comment.
Choose an implementable cross-package interval start
Effect.interval is implemented in @moq/signals (js/signals/src/index.ts), while Interval and its private deadline state live behind the @moq/clock package boundary (js/clock/src/timer.ts). Therefore signals cannot start an Interval at now + period while keeping that capability private in clock as proposed. The quest must choose an actual boundary-safe design, such as changing the exported Interval contract with the corresponding migration documentation or implementing the delayed loop inside signals; otherwise this decision cannot be implemented as written.
AGENTS.md reference: AGENTS.md:L64-L64
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed. Fixed in 9bdefec: Effect.interval drops Interval and loops on the exported sleepUntil(next), which arms synchronously, computing the Delay deadline itself as max(scheduled + period, now + period). No @moq/clock API change; the quest notes that each sleep reads the clock installed at that moment.
(Written by Claude Opus 5.5)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9bdefec30d
ℹ️ 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".
| private deadline, so it drops `Interval` and loops on the exported | ||
| `sleepUntil(next)`, which arms synchronously. It starts at `now + period` | ||
| and computes the `Delay` deadline itself: `max(scheduled + period, now + | ||
| period)`. This needs no `@moq/clock` API change; exporting an `intervalAt` |
There was a problem hiding this comment.
Preserve rejection of a zero interval period
When Effect.interval is called with Nano.zero, the current Interval constructor throws synchronously, but the proposed sleepUntil(next) loop has no equivalent positive-period check. Its deadline remains now, so each immediately resolved sleep re-arms another immediately due sleep; on the host this can starve the event loop, and under Manual.advance it can prevent the advance from settling. Include an explicit synchronous zero-period rejection and a regression test in the plan.
AGENTS.md reference: AGENTS.md:L17-L19
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed. Fixed in 41ee76e: the plan keeps the synchronous RangeError on a zero period, with a regression test.
(Written by Claude Opus 5.5)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Ready to merge. Summary:
(Written by Claude Opus 5.5) |
|
Re-enqueuing after the merge queue stall (fixed in #6105) dropped this with (Written by Claude Opus 5.5) |
Problem
Two
@moq/clockbehaviors make controlled-time JS tests count from the wrong moment:Manual.advanceAsync(duration)jumps straight to the target and fires every due timer there. A timer that re-arms itself (an interval, a retry scheduling its next attempt) then counts from the target instead of its own deadline, so tests fall back to loops of small steps.Effect.intervalconsumes the Interval's immediate first tick a microtask after arming. WithMissedTickBehavior.Delay, a synchronousadvance(period)right after arming looks like a late first tick, pushing the first callback to2 * period.Reproduced on
main(9a2663e72): three chainedsleep(10)under oneadvanceAsync(30)record[30]instead of[10, 20, 30];effect.interval(fn, 10)thenadvance(10)andadvanceAsync(30)runsfnat[40]instead of[10, 20, 30, 40].Approach
Adds
quest/m1/time/js-deadlines.mdas an[S]child of the Controlled time epic.Decisions
Placement:
/quest/m1/time/README.md(recommended): it fixes the exported clock contract m1 verifies./quest/m1/time/crates.md: that quest is Rust-only and[XL]./quest/m2/time-test-sweep.md: defers a contract bug behind legacy test cleanup.Split:
advanceAsyncsemantics:advanceAsyncsteps to each deadline in order, draining between; syncadvancestays a jump that models a stalled loop (originally recommended).advanceAsyncas a jump and add a stepped variant: leaves the default wrong.advancecannot drain microtasks between deadlines.advanceAsync(d)becomes asyncadvance(d), stepping to each deadline like tokio'stime::advance; syncadvance(d)becomesjump(d)and keeps modeling the stalled loop. Every call site renames (about 60advanceAsyncand 42 syncadvancecalls underjs/), with an entry under## Unreleasedinjs/clock/MIGRATE.mdanddoc/lib/js/clock.mdupdated;fire()'s doc and body move fromadvanceAsynctoadvance.Effect.intervalfirst tick (Effect.intervallives in@moq/signals, so a start private to@moq/clockis unreachable):Intervaland loop on the exportedsleepUntil(next), which arms synchronously, starting atnow + periodand computing the Delay deadline asmax(scheduled + period, now + period)(maintainer decision). No public API change; each sleep reads the clock installed at that moment, which the quest says to document.@moq/clock(new Interval(period, { start })orintervalAt): new exported API that would want a Rust mirror.Interval's first tick tonow + period: breaking, diverges from tokio, and affects every otherIntervaluser.Rust parity:
advanceAsyncis the only driver.moq_clock::sim::advancestep.Rust naming:
moq_clock::Manual::advancearms no timers,sim::advanceis already the asyncadvance, andInstalled::advance(the sync jump) would becomejumponly alongside making Rust step.Impact
None in this PR. The quest makes a breaking API change to
@moq/clock'sManual:advanceAsyncis renamedadvanceand steps through deadlines, and syncadvanceis renamedjump, with aMIGRATE.mdentry.Follow-ups
None.
🤖 Generated with Claude Code
(Written by Claude Opus 5.5)