fix(effect): replace hardcoded Date.now() in FiberId.unsafeMake with configurable clock source#6167
Open
copyleftdev wants to merge 2 commits intoEffect-TS:mainfrom
Open
Conversation
…configurable clock source FiberId.unsafeMake() uses Date.now() for startTimeMillis, which feeds into Hash.symbol() and Equal.symbol() on the FiberId. This means fiber identity hashing and equality are non-deterministic across runs — two fibers created with the same counter ID but at different wall-clock times produce different hashes. This contributes to scheduler-related issues like Effect-TS#6124 (scheduler runner isolation) and Effect-TS#6126 (MixedScheduler PROMISE leaks in vitest), where fiber-keyed caches behave inconsistently due to timing-dependent identity. Replace with a globalValue-backed clock source that defaults to Date.now() (zero behavior change) but can be swapped via setClockSource()/resetClockSource() for deterministic testing without monkey-patching Date.now globally. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 377c9ef The changes in this PR will be included in the next version bump. This PR includes changesets to release 36 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Problem
FiberId.unsafeMake()usesDate.now()forstartTimeMillis, which feeds intoHash.symbol()andEqual.symbol():This means fiber identity hashing and equality are non-deterministic across runs. Two fibers created with the same counter ID but at different wall-clock times produce different hashes and are not equal.
This contributes to scheduler-related issues:
WeakMapbehaves inconsistently)@effect/vitest(timing-dependent cache behavior)It also makes deterministic testing of the fiber runtime impossible without monkey-patching
Date.nowglobally, which breaks timers, logging, and concurrent tests.Fix
Replace the hardcoded
Date.now()call with aglobalValue-backed configurable clock source:Date.now()is still calledsetClockSource(fn)/resetClockSource()allow swapping for deterministic testingDate.nowTest plan
Fiber.test.ts— 16 tests passEffect/concurrency.test.ts— 24 tests passEffect/racing.test.ts— 4 tests pass🤖 Generated with Claude Code