Skip to content

fix: use chokidar raw events as fallback for suppressed file changes#7025

Draft
graygilmore wants to merge 1 commit intomainfrom
gg-raw-event-fallback-watcher
Draft

fix: use chokidar raw events as fallback for suppressed file changes#7025
graygilmore wants to merge 1 commit intomainfrom
gg-raw-event-fallback-watcher

Conversation

@graygilmore
Copy link
Contributor

Summary

  • Adds a raw event listener on chokidar as a transparent fallback to catch file changes that chokidar suppresses when mtime is unchanged (common with build tools on Linux/Windows)
  • Uses a 100ms debounce: if chokidar's normal change fires within the window, the raw fallback is cancelled; if not, we trigger the handler ourselves
  • Zero impact on macOS where FSEvents works reliably — the normal change always cancels the raw timeout

Problem

chokidar's _handleFile listener (nodefs-handler.js:369) compares mtimeMs and suppresses change events when mtime hasn't changed. Build tools that preserve timestamps cause silent misses on Linux/Windows.

How it works

  1. chokidar emits a raw event unconditionally, even when the mtime check suppresses the change event
  2. We start a 100ms timeout when a raw event fires
  3. If chokidar's normal change fires within that window → cancel the timeout (normal path)
  4. If the timeout expires (mtime unchanged, change suppressed) → trigger the handler ourselves
  5. The existing handleFileUpdate computes MD5 checksums and only syncs when content changed, preventing redundant uploads even if both paths fire

Test plan

  • New test: raw event triggers change handler when chokidar suppresses change
  • New test: raw event is cancelled when chokidar change event fires (normal case)
  • New test: duplicate raw events for the same path are deduplicated
  • All 45 tests pass (42 existing + 3 new)

🤖 Generated with Claude Code

chokidar's _handleFile listener compares mtimeMs and suppresses change events when mtime hasn't changed. Build tools that preserve timestamps (e.g. via touch --reference) cause silent misses on Linux/Windows.

chokidar emits a raw event unconditionally, even when the mtime check suppresses the change event. This adds a raw event listener as a fallback: when a raw event fires, we start a short 100ms timeout. If chokidar's normal change event fires within that window, we cancel the timeout (normal path handled it). If the timeout expires, we trigger the handler ourselves.

The existing handleFileUpdate already computes MD5 checksums and only syncs when content actually changes, so even if both paths fire, the checksum comparison prevents redundant uploads.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Contributor

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements 77.33% 14621/18908
🟡 Branches 70.91% 7252/10227
🟡 Functions 76.33% 3712/4863
🟡 Lines 78.83% 13823/17535

Test suite run success

3814 tests passing in 1474 suites.

Report generated by 🧪jest coverage report action from 2a3fcea

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