Skip to content

Fix watcher missing watch.lock removal during full rebuilds - #8730

Open
cknitt wants to merge 5 commits into
masterfrom
fix-watcher-lock-race
Open

cknitt wants to merge 5 commits into
masterfrom
fix-watcher-lock-race

Conversation

@cknitt

@cknitt cknitt commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

Fixes the flaky rewatch test on the macOS Intel runner:

Test: Watcher ignores changes outside source dirs
- 🛑 Watcher process 67625 did not exit after watch.lock was removed

Cause

notify 5's FSEvents backend stops and recreates its event stream on every watch/unwatch call (the new stream starts at kFSEventStreamEventIdSinceNow), so events that happen in between are dropped.

On every full rebuild the watcher unwatched and re-watched all paths. The test removes src/WatchProbe.res (a Remove event → full rebuild) and then immediately removes lib/watch.lock. On a slow runner the lock removal often lands while the watches are being re-registered, so its event is lost and the watcher keeps running.

Fix

  • Re-register watches incrementally: only unwatch paths that went away and watch paths that are new. In the common case (same paths, same directories), the event stream is never restarted.
    • Only successfully registered watches are recorded, so a path whose registration failed is retried on the next full rebuild.
    • Each watch records the identity (device + inode) of its directory. inotify ties a watch to the directory rather than its path, so a directory replaced at the same path is registered again. Platforms without stable file identities (Windows) always re-register.
  • After a full rebuild, check whether lib/watch.lock still exists and exit if not. This catches a removal that falls into a gap when watches did have to be re-registered.

Tests

  • New unit test registered_watch_is_invalid_after_directory_is_replaced in watcher.rs (Unix only): a registered watch stays valid for its directory and becomes invalid once the directory is replaced at the same path.

The lockfile race itself is FSEvents-specific and not deterministically reproducible, so it has no dedicated test.

🤖 Generated with Claude Code

cknitt and others added 2 commits October 6, 2026 19:08
On macOS, notify's FSEvents backend stops and recreates its event stream
on every watch/unwatch call, and events in between are lost. Full
rebuilds unwatched and re-watched every path, so a watch.lock removal
right after a source file removal (as in the rewatch watch tests) could
be dropped, leaving the watcher running.

Only unwatch/watch the paths that actually changed, and check that
watch.lock still exists after a full rebuild.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Christoph Knittel <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Christoph Knittel <[email protected]>
@cknitt
cknitt marked this pull request as ready for review October 6, 2026 19:40
@pkg-pr-new

pkg-pr-new Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript@8730

@rescript/belt

npm i https://pkg.pr.new/@rescript/belt@8730

@rescript/darwin-arm64

npm i https://pkg.pr.new/@rescript/darwin-arm64@8730

@rescript/darwin-x64

npm i https://pkg.pr.new/@rescript/darwin-x64@8730

@rescript/linux-arm64

npm i https://pkg.pr.new/@rescript/linux-arm64@8730

@rescript/linux-x64

npm i https://pkg.pr.new/@rescript/linux-x64@8730

@rescript/runtime

npm i https://pkg.pr.new/@rescript/runtime@8730

@rescript/win32-x64

npm i https://pkg.pr.new/@rescript/win32-x64@8730

commit: 3134b0d

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

@cknitt
cknitt requested a review from fhammerschmidt October 7, 2026 05:48
@cknitt

cknitt commented Oct 7, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 7, 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-07T09:29:49.124992Z 3134b0d Manual request
ℹ️ 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.

@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: 36d9041140

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

Comment thread rewatch/src/watcher.rs Outdated
Only record successfully registered watch paths, so that a path whose
registration failed is retried on the next full rebuild instead of being
treated as already watched.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Christoph Knittel <[email protected]>
@cknitt

cknitt commented Oct 7, 2026

Copy link
Copy Markdown
Member Author

@codex review

@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: be54c50377

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

Comment thread rewatch/src/watcher.rs Outdated
@codecov

codecov Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.86%. Comparing base (30ce369) to head (3134b0d).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff            @@
##           master    #8730    +/-   ##
========================================
  Coverage   79.86%   79.86%            
========================================
  Files         467      464     -3     
  Lines       63357    63090   -267     
========================================
- Hits        50600    50388   -212     
+ Misses      12757    12702    -55     

see 38 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

cknitt and others added 2 commits October 7, 2026 07:16
inotify ties a watch to the directory rather than its path, so a source
directory that is deleted and recreated at the same path is no longer
watched. Record each watched directory's identity (device and inode) and
re-register watches whose directory changed on the next full rebuild.
Platforms without stable file identities always re-register.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Christoph Knittel <[email protected]>
The integration test only exercised the identity check on Linux while
adding another timing-sensitive watch test on every platform. Test the
identity check directly instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Christoph Knittel <[email protected]>
@cknitt

cknitt commented Oct 7, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 3134b0deef

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

This branch has not been deployed

No deployments
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.

1 participant