Skip to content

fix(fs): await watcher readiness instead of yield_now#2533

Open
domenkozar wants to merge 4 commits intomainfrom
fix/fs-watcher-readiness
Open

fix(fs): await watcher readiness instead of yield_now#2533
domenkozar wants to merge 4 commits intomainfrom
fix/fs-watcher-readiness

Conversation

@domenkozar
Copy link
Member

@domenkozar domenkozar commented Mar 1, 2026

Summary

  • Uses watchexec's new fs_ready signal (from feat(config): add fs_ready signal for watcher readiness watchexec/watchexec#1024) to wait for OS watches to be registered before returning from FileWatcher::new()
  • Fixes a race condition where file changes immediately after watcher construction were missed because inotify/FSEvents watches weren't set up yet
  • Adds WatcherHandle::watch_async() for runtime path additions that need the same readiness guarantee

Test plan

  • All 7 fs::tests pass consistently across 5 runs
  • test_multiple_files and test_handle_adds_path_at_runtime (previously flaky) now pass reliably

🤖 Generated with Claude Code

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Mar 1, 2026

Deploying devenv with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6eaf4bd
Status: ✅  Deploy successful!
Preview URL: https://2b18e927.devenv.pages.dev
Branch Preview URL: https://fix-fs-watcher-readiness.devenv.pages.dev

View logs

@github-actions
Copy link
Contributor

github-actions bot commented Mar 1, 2026

🔍 Suggested Reviewers

Based on git blame analysis of the changed lines, the following contributors have significant experience with the modified code:

  • @sandydoo - 100.0% of changed lines (50 lines)

Please consider reviewing this PR as you have authored significant portions of the code being modified. Your expertise would be valuable! 🙏

This comment was automatically generated by git-blame-auto-reviewer

Last updated: 2026-03-02T01:04:49.307Z

@sandydoo
Copy link
Member

sandydoo commented Mar 1, 2026

Oh, nice! We should remove the old watch and take it's place then?

@domenkozar domenkozar force-pushed the fix/fs-watcher-readiness branch 3 times, most recently from fb3c83f to 56e9982 Compare March 1, 2026 23:07
domenkozar and others added 4 commits March 2, 2026 01:04
Use watchexec's new fs_ready signal to wait for OS watches to be
registered before returning from FileWatcher::new(). This fixes a
race where file changes immediately after construction were missed
because inotify/FSEvents watches weren't set up yet.

Also makes WatcherHandle::watch() async so runtime path additions
get the same readiness guarantee.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
On CI, inotify events can be dropped under resource pressure or on
overlay filesystems even after watches are confirmed registered.
Retry file writes until an event is received instead of writing once.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Drain the watchexec error channel instead of dropping it so watch
registration failures (e.g. inotify limits) are visible. Add tracing
to the two CI-flaky tests for diagnostics.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
macOS FSEvents requires directory paths; individual file paths may be
silently ignored. Watch parent directories and filter events against the
actual watched file set. This matches watchexec's own recommendation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@domenkozar domenkozar force-pushed the fix/fs-watcher-readiness branch from 56e9982 to 6eaf4bd Compare March 2, 2026 01:04
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.

2 participants