Repository navigation
Tile retry: an early timer waits for the cache's retry time (EXP-296 flake) - #426
Merged
Merged
Conversation
Node timers can fire a millisecond before Date.now() reaches the time they were set for. The scheduler's retry timer then asked the cache, which handed back the failure unread, and the tile settled again: one more canvas redraw, which made the EXP-296 MorphologyCanvas test draw 5 times instead of 4 on CI.
prete
added a commit
that referenced
this pull request
Nov 24, 2026
prete
added a commit
that referenced
this pull request
Nov 24, 2026
The canvas's tile caches already read a failed tile again after 1, 2 and 4 s (TILE_RETRY_DELAYS_MS; the early-timer fix in #426), then keep the error until the tile is evicted, with no way to forget one tile. So the screenshot gets its own TileCache and scheduler per channel: a Retry reads failed tiles again, and a read of hundreds of tiles does not push the canvas's tiles out of its cache. D4, the drawing steps, task C and the risks say so; the code map is rechecked at fe50d70.
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.
Fixes the flaky Vitest test
src/components/MorphologyCanvas.test.tsx> "reads a failed tile again and draws it, with the view still (EXP-296)". It failed in CI on #409, #411 and #412 withexpected "vi.fn()" to be called 4 times, but got 5 times, at line 322 (the lastdrawImagecount).Cause: the scheduler's retry timer, not the test
The tile cache decides a failed tile may be read again with
Date.now() >= retryAt. The scheduler (src/tiff/tileRequestScheduler.ts) sets a timer forretryAt - Date.now()ms. Node timers run on libuv's monotonic millisecond clock, andDate.now()on the wall clock. Because the two round to whole milliseconds at different points, a timer can fire up to a millisecond beforeDate.now()reaches the time.When that happened:
onSettled.onSettledredrew the canvas once more with only the ready tile: 2 → 3 draws.So this is an app bug, not only a test problem: one extra redraw and an extra cache call per early timer. No tile was ever fetched twice.
Fix
When the retry timer fires and
Date.now()is still short of the cache's retry time, the scheduler sets the timer again without asking the cache or settling the tile. The MorphologyCanvas test is unchanged and still checks exact counts: the failed tile is asked for again under the same key and drawn, while the view stays still.Evidence (macOS, Node 25)
{ repeats: 400 }, run 3 times, failed 4 of about 1,200 runs. A log in the mock cache showed that each of those 4 runs had a timer fire beforeDate.now()reachedretryAt, and no other run drew 5 times.setTimeoutpatched to fire 2 ms early, 86 of 101 runs drew too many times (5 or 6) before the fix, and 0 of 101 after.setTimeoutwith a separately controlledDate.now(). It fails without the fix (onSettledcalled twice) and passes with it. The test cache double now hands back a failure unread before its retry time, asTileCachedoes.Checks
npm run format:checknpm run lintnpx tsc -bnpx vitest run: 396 files, 3,836 tests passed. Also passed run in parallel with the repeated EXP-296 runs, and with--sequence.shuffleon the MorphologyCanvas, scheduler and tile cache test files.