Skip to content

fix: learn fs accuracy from directory mtimes too - #350

Merged
alexander-akait merged 2 commits into
mainfrom
fix/directory-fs-accuracy
Oct 16, 2026
Merged

alexander-akait merged 2 commits into
mainfrom
fix/directory-fs-accuracy

Conversation

@alexander-akait

@alexander-akait alexander-akait commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Fixes #295.

FS_ACCURACY starts at 2000ms and is lowered by ensureFsAccuracy from the mtimes the watcher sees, but only for files. A scan that finds only directories keeps the 2000ms default, so safeTime = birthtime + 2000 lands after startTime for any directory created in the 2s before it, and it is reported as changed.

The fix feeds the directory's mtime to ensureFsAccuracy at the three places setDirectory gets its value from a stat (watch event, scan, symlink to a directory). It uses mtime, not birthtime: FAT keeps creation times at 10ms but modification times at 2s, so learning from birthtime could shrink the margin below what file mtimes have and miss real changes. The safety margin itself is unchanged, unlike #299.

The issue's script (subdirectory only, Linux):

Wait before watch({ startTime: Date.now() }) Before After
0ms change subdir change subdir (inside the ~10ms margin, as for files)
500ms change subdir none
1500ms change subdir none

No extra rebuilds or missed changes

  • The change only makes FS_ACCURACY drop earlier, which lowers safeTime and can only remove events. A scan that sees any file already reached the same value.
  • A directory created after startTime is still reported, both before watch() and while watching, with and without polling.
  • webpack's WatchTestCases (2487 passed) and WatchCacheUnaffectedTestCases (2439 passed, 4 skipped) pass with this lib/.
  • No API or event changes.

Tests

  • New test in test/Watchpack.test.js loads a fresh module (jest.isolateModules) so FS_ACCURACY starts at 2000ms. It creates real directories and expects no change. It fails without the fix (dir/sub reported) and passes with it, also with WATCHPACK_POLLING=200.
  • Full suite 204/204, npm run lint clean, all added lines covered.

🤖 Generated with Claude Code

https://claude.ai/code/session_01D9gUmpCrb3uVLv6uR8av82


Generated by Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Fixed directory-only scans incorrectly reporting directories created within the previous two seconds as changed.

A scan that saw only directories kept FS_ACCURACY at its 2000ms default,
so directories created up to 2s before startTime were reported as
changed (#295). Use the directory's mtime, not its birthtime, since FAT
keeps creation times finer than modification times.

Claude-Session: https://claude.ai/code/session_01D9gUmpCrb3uVLv6uR8av82
@changeset-bot

changeset-bot Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 67324a2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
watchpack Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Walkthrough

Directory modification times now refine filesystem timestamp accuracy during event handling, scans, and followed directory symlinks. A regression test checks that watching a recently created directory with a current startTime emits no changes during the initial scan. A changeset records the adjustment.

Priority: ⬇️ Low

Severity of issue fixed: Low

Merge Risk: 🔵 Low · up to 67324

The new regression test may fail on filesystems with coarse directory timestamps; make it resolution-aware before merging.

Pre-merge checks: Passed 5
Passed Passed checks: 5 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: using directory modification times to improve filesystem accuracy detection.
Linked Issues check Passed The PR implements the coding requirement in #295 for the directory-only failure. It calls ensureFsAccuracy with directory mtime during watch events, scans, and symlink-to-directory handling. The a…
Out of Scope Changes check Passed All changed files support #295. The DirectoryWatcher.js changes correct timestamp accuracy, the Watchpack.test.js change adds regression coverage, and the changeset documents the patch. No unrelat…
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codspeed

codspeed Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ 1 benchmark spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

✅ 36 untouched benchmarks


Comparing fix/directory-fs-accuracy (67324a2) with main (d5ab9bf)

Open in CodSpeed

@codecov

codecov Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.47%. Comparing base (d5ab9bf) to head (67324a2).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #350      +/-   ##
==========================================
+ Coverage   92.45%   92.47%   +0.02%     
==========================================
  Files           8        8              
  Lines        1338     1342       +4     
  Branches      396      399       +3     
==========================================
+ Hits         1237     1241       +4     
  Misses         95       95              
  Partials        6        6              
Flag Coverage Δ
integration 92.47% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 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.

Copy link
Copy Markdown
Member Author

codecov/project is red (92.47%, −0.13%), but not because of this change:

  • codecov/patch passes, and every added line runs (local coverage hits: DirectoryWatcher.js:685 ×5, :1003 ×5767, :1049–1050 ×3).
  • A local coverage run on e0e867d (this branch's base) and on this branch misses the same lines: 19 in DirectoryWatcher.js on both, and identical counts in every other lib/ file.
  • Codecov compares against c5fb972, not this branch's base. With no codecov.yml, the default threshold fails on any drop, so 2 lines that only some CI runs hit are enough to turn it red.

All 41 test jobs, lint and the benchmark pass. Codecov can't be re-run from here.


Generated by Claude Code

@coderabbitai coderabbitai 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8ee67b4d-eea3-476e-acc7-4d3111686363
📥 Commits

Reviewing files that changed from the base of the PR and between d5ab9bf and 67324a2.

📒 Files selected for processing: 3
  • .changeset/directory-fs-accuracy.md
  • lib/DirectoryWatcher.js
  • test/Watchpack.test.js

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

Comment thread test/Watchpack.test.js Resolved
@alexander-akait
alexander-akait merged commit 6695b9f into main Oct 16, 2026
51 checks passed
@alexander-akait
alexander-akait deleted the fix/directory-fs-accuracy branch October 16, 2026 00:56
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.

change event is fired for directories and files that were created shortly before startTime, when startTime is set

1 participant