Skip to content

test(watch): fix flaky watch buildDelay - #11175

Merged
shulaoda merged 3 commits into
mainfrom
claude/fix-flaky-tests-watch-build-delay
Oct 24, 2026
Merged

shulaoda merged 3 commits into
mainfrom
claude/fix-flaky-tests-watch-build-delay

Conversation

@Brooooooklyn

@Brooooooklyn Brooooooklyn commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Requested by Brooklyn · project thread

Before: watch/watch.test.ts > watch buildDelay sometimes saw two rebuilds for two edits made 20ms apart and failed with expected "vi.fn()" to be called 1 times, but got 2 times. On the affected runners all three built-in retries failed.

After: the test always makes the two edits arrive at the watcher as separate changes, and the debounce window is wide enough to batch them every time.

This is a test-only change; the watcher's buildDelay behaves as designed.

Occurrences on main (2026-10-02 to 2026-10-09)

Neighbouring runs on main passed. Error both times, at expect(restartFn).toBeCalledTimes(1):

AssertionError: expected "vi.fn()" to be called 1 times, but got 2 times

Symptom vs. cause

The symptom is an extra restart. The cause is the test's timing setup.

  • The test sets buildDelay: 50 on a polling watcher whose pollInterval is also 50ms (from the watch() wrapper).
  • The notify poll loop scans, then sleeps pollInterval, so scans are pollInterval + scan time apart.
  • The coordinator sets the debounce deadline when it processes a change, which happens after the scan and the onInvalidate call.
  • When a scan falls between the two writes, the second edit reaches the watcher about one scan period after the first. Whether it lands before the 50ms deadline depends on a few milliseconds of scan time versus processing latency. On fast Linux the processing latency usually wins. On slower filesystems the scan time wins, the deadline fires first, and the second edit starts a second rebuild.
  • Phase: the poll loop starts with the watcher, and the edits are timed from the end of the initial build, so the scan phase at edit time is roughly fixed for a given machine. That would explain why the failing runners failed all three retries in a row (inferred).

Measured locally with a temporary timing probe (not committed), sweeping the edit time across the poll phase: when the two edits were seen as separate changes, they were seen 47 to 53ms apart, right at the 50ms window.

What changed

  • buildDelay is now pollInterval * 10 (500ms), so the window covers the polling gap with margin. The poll interval is passed explicitly so the relationship is visible in the test.
  • The victim is hardened: the second write happens only after onInvalidate reports the first. The two edits are therefore always separate observed changes, so the test exercises batching every time instead of sometimes passing because both writes landed in one scan.
  • The test's poller now has compareContentsForPolling: true. Because the second write follows the first right away, on a filesystem with whole-second mtimes it could keep the first write's mtime, and the poller would never report it. The test would then hang on secondSeen until it timed out. This came from review.
  • The fixed sleep(20) and sleep(200) between and after the writes are gone. The existing sleep(1000) for the mtime boundary stays.
  • The assertion now records how many changes the watcher had seen when each restart fired, and expects exactly one restart after both ([2]). A split batch fails deterministically with [1].

Stress-run truth table

Linux x64, 4 cores, CI=1 ROLLDOWN_TEST=1, run from packages/rolldown/tests. "Alone" is vitest run watch.test.ts -t "^watch buildDelay$". "CI order" is the test:watcher file set (vitest run watch.test.ts dev-watch.test.ts). "Load" is the alone run with 4 busy-loop CPU hogs. Counts are attempts that failed, out of runs, read from each test's retry count, since the test's own retry: 3 hides failures in the final result. Control: PluginContext addWatchFile, unchanged, run the same way. "After" is the current head (both commits).

Run (25 each) Victim, before Victim, after Control, before Control, after
Alone 1 failed attempt (exact CI error), 25/25 passed after retry 0 failures 0 0
CI order 0 0 0 0
Alone under CPU load 1 failed attempt (exact CI error) 0 failures 0 0

How sensitive the race is, on the hardened test with buildDelay set back near the poll interval (10 runs each):

  • buildDelay = pollInterval (50ms): 0 of 10 failed locally, because processing latency still edges out scan time on this machine.
  • buildDelay = pollInterval - 10 (40ms), which stands in for about 10ms more scan latency: 10 of 10 failed, every retry, with expected [ 1 ] to deeply equal [ 2 ].

Coarse-mtime check: a temporary edit (not committed) reset the file's mtime after the second write to the first write's mtime, to stand in for whole-second mtimes.

  • Without content comparison, every attempt timed out waiting for the second edit.
  • With content comparison, 3 of 3 runs passed.

What I ran and did not run

Ran:

  • The loops above.
  • vp fmt --check and vp lint (type-aware) on the changed file: clean.
  • tsc --noEmit -p packages/rolldown/tests/tsconfig.json: clean.

Repo-wide vp check stops at formatting issues in three docs files (docs/development-guide/testing.md, docs/in-depth/manual-code-splitting.md, internal-docs/dev-engine/implementation.md). They are already on main and untouched here.

Not run:

  • macOS and Windows, where the failures happened. This PR's CI skips node-test-macos and node-test-windows, so those platforms are only exercised after merge, on main.

Risk

Test-only. The test takes about 450ms longer because of the wider buildDelay, and it hashes one small file per poll scan.

Revert: git revert this PR's two commits.

🤖 Generated with Claude Code

https://claude.ai/code/session_01PqYVzjPAy93pRGj7VdGsf2

The test used `buildDelay: 50` with the polling watcher's 50ms interval.
The poller only reports an edit on its next scan, so two edits that
straddle a scan reach the watcher one poll interval plus the scan time
apart. With the debounce window equal to the poll interval, whether the
edits share one rebuild was a race between that next scan and the
debounce deadline, decided by a few milliseconds of scan and callback
latency. Slower filesystems (macOS, Windows runners) lose it and the
test sees two restarts.

Make `buildDelay` cover the polling gap (10x the poll interval), and
sequence the edits on `onInvalidate` so the second edit is always seen
as a separate change: the test now always exercises batching across two
observed changes, and asserts the single rebuild started after both.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01PqYVzjPAy93pRGj7VdGsf2
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-24T19:10:54.905214Z 04ea69e New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@netlify

netlify Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for rolldown-rs ready!

Name Link
🔨 Latest commit 04ea69e
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/6add027aef068c4644d8b130
😎 Deploy Preview https://deploy-preview-11175--rolldown-rs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6503d84aa8

ℹ️ 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".

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview URL: https://claude-fix-flaky-tests-watch-build-delay-rolldown-rs.voidzero-docs.workers.dev (commit 04ea69e)

This URL reflects your latest Preview deployment

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://4358064f-rolldown-rs.voidzero-docs.workers.dev 04ea69e 2026-10-24T19:11:54.059Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://9eac0278-rolldown-rs.voidzero-docs.workers.dev 9b7afa3 2026-10-10T06:54:10.603Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://928add21-rolldown-rs.voidzero-docs.workers.dev 6503d84 2026-10-09T19:17:33.700Z Visit the dashboard ↗

The second write now happens right after the watcher reports the first,
which can be within the same mtime second on filesystems with coarse
timestamps. Without content comparison the poller would not report it
and the test would wait for `secondSeen` until it times out. Enable
`compareContentsForPolling` for this test's watcher.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01PqYVzjPAy93pRGj7VdGsf2

Copy link
Copy Markdown
Member Author

@IWANABETHATGUY @hyfdev @shulaoda this has been waiting about two weeks for a first review. It is a test-only fix for the flaky watch buildDelay test that failed every retry on macOS and Windows main runs.

I merged main in today with no conflicts. On the merged head, watch buildDelay passed 5 of 5 runs alone with no retries, the whole watch/watch.test.ts file passed (37 of 37) on Linux, and vp fmt --check, vp lint and tsc are clean for the changed file. Could one of you take a look?


Generated by Claude Code

@shulaoda
shulaoda merged commit 9b5f62e into main Oct 24, 2026
57 of 58 checks passed
@shulaoda
shulaoda deleted the claude/fix-flaky-tests-watch-build-delay branch October 24, 2026 21:25
This was referenced Oct 29, 2026
shulaoda added a commit that referenced this pull request Oct 29, 2026
## [1.2.16] - 2026-10-29

### 🚀 Features

- perf-kit: check rendered output against the original build (#11140) by @IWANABETHATGUY
- perf-kit: node/deno server startup mode (#10601) by @IWANABETHATGUY
- perf-kit: browser page-load perf harness for coding agents (#10365) by @IWANABETHATGUY
- devtools: report mode - agent-readable build metrics report (#10364) by @IWANABETHATGUY
- inline-common-chunks: print record factories parenthesized so they compile eagerly (#11282) by @mattlewis92
- fold `'key' in ns` on namespace imports with statically known exports (#11333) by @danielroe
- inline-common-chunks: inline chunks using `import.meta.hot` in dev mode (#11339) by @hyfdev
- support `experimentalInlineCommonChunks` in dev mode (#11335) by @hyfdev
- use `INVALID_TLA_FORMAT` error for Rollup compatibility (#11266) by @sapphi-red

### 🐛 Bug Fixes

- await bundle.close() in loadConfig and clean up every generated config file (#10347) by @Brooooooklyn
- deps: update mimalloc-safe to 0.1.69 (#11376) by @shulaoda
- transform: don't crash when the working directory has been deleted (#11352) by @shulaoda
- import-glob: follow directory symlinks on the wasm binding (#10624) by @hyfdev
- tree-shaking: preserve exported rest bindings from dynamic imports (#11365) by @shuvroroy
- transform: report `tsconfigFilePaths` for a tsconfig resolved through `TsconfigCache` (#11346) by @cainrus
- tsconfig: don't apply tsconfig when resolving imports from virtual modules (#11089) by @rubas
- code-splitting: handle emitted entries the same as `input` entries when placing the runtime (#11353) by @IWANABETHATGUY
- error: make Diagnostic::add_file idempotent (#10610) by @Nic-Polumeyv
- avoid retaining callable builtin callback owners (#10961) by @IWANABETHATGUY
- code-splitting: only host the runtime in a chunk that every consumer's entries load (#11293) by @IWANABETHATGUY
- code-splitting: keep the source order of chunk imports (#11298) by @IWANABETHATGUY
- dev: don't treat a wrapped module's init as a no-op in dev mode (#11334) by @hyfdev
- treat `cwd` as a literal path in relative glob filters (#11291) by @onmax
- deps: update emnapi to 2.0.0-beta.2 and pin `@napi-rs/wasm-runtime` to 1.2.6 (#11292) by @IWANABETHATGUY
- chunk-import-map: hash stable module ids so keys don't depend on the build folder (#11277) by @mandyheg
- respect CPU limits when sizing native runtime workers (#11280) by @Brooooooklyn
- deconflict the namespace of a module without module syntax (#11256) by @IWANABETHATGUY
- code-splitting: rebuild an absorbed dynamic entry's namespace from what its imports read (#11200) by @mattlewis92
- escape line terminators in debug-info comments (#11258) by @IWANABETHATGUY

### 🚜 Refactor

- extract callable builtin hook wrapper (#10964) by @IWANABETHATGUY

### 📚 Documentation

- add an in-depth explanation for inline common chunks (#11239) by @hyfdev

### ⚡ Performance

- incremental cycle check for `avoidRedundantChunkLoads` (#11320) by @IWANABETHATGUY
- avoid copying module code for `renderedLength` and share `chunk.code` across plugins (#11342) by @IWANABETHATGUY
- count UTF-16 lengths with `simd-utf16-len` (#11259) by @IWANABETHATGUY
- don't load consola when importing rolldown (#11257) by @magurotuna

### 🧪 Testing

- dev: cover hot updates that need modules the tab never received (#9647) by @matthewdavis-oai
- dev: add dynamic import rebuild test (#7123) by @sapphi-red
- code-splitting: import file URLs in fresh-process runtime host tests on Windows (#11354) by @shulaoda
- esbuild: mark loader_data_url_base64_invalid_utf8 as an intentional difference (#10790) by @CoderSerio
- watch: fix flaky `watch buildDelay` (#11175) by @Brooooooklyn

### ⚙️ Miscellaneous Tasks

- install `cmake-core` instead of the `cmake` metapackage on FreeBSD (#11361) by @shulaoda
- deps: update oxc to 0.156.0 (#11326) by @Dunqing
- stop the Discord notification when the metric workflow fails (#11357) by @IWANABETHATGUY
- connect to the Void platform before the docs deploy (#11350) by @shulaoda
- deps: update rust crates (#11297) by @renovate[bot]
- deps: update dependency vite-plus to v1.4.0 (#11288) by @renovate[bot]
- deps: update npm packages (#11296) by @renovate[bot]
- deps: update napi (#11287) by @renovate[bot]
- deps: update rollup submodule for tests to v4.65.1 (#11331) by @rolldown-guard[bot]
- deps: update test262 submodule for tests (#11332) by @rolldown-guard[bot]
- deps: update dependency rolldown-plugin-dts to v0.28.8 (#11286) by @renovate[bot]
- deps: bump tokio to 1.53.3 (#11317) by @Brooooooklyn

### ❤️ New Contributors

* @mattlewis92 made their first contribution in [#11282](#11282)
* @shuvroroy made their first contribution in [#11365](#11365)
* @cainrus made their first contribution in [#11346](#11346)
* @matthewdavis-oai made their first contribution in [#9647](#9647)
* @rubas made their first contribution in [#11089](#11089)
* @danielroe made their first contribution in [#11333](#11333)
* @onmax made their first contribution in [#11291](#11291)
* @mandyheg made their first contribution in [#11277](#11277)
* @magurotuna made their first contribution in [#11257](#11257)

Co-authored-by: shulaoda <[email protected]>
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.

3 participants