Skip to content

fix: do not emit spurious initial-scan change events for items created within FS_ACCURACY of startTime (#295)#299

Open
alexander-akait wants to merge 3 commits intomainfrom
claude/fix-issue-295-JADcx
Open

fix: do not emit spurious initial-scan change events for items created within FS_ACCURACY of startTime (#295)#299
alexander-akait wants to merge 3 commits intomainfrom
claude/fix-issue-295-JADcx

Conversation

@alexander-akait
Copy link
Copy Markdown
Member

DirectoryWatcher previously compared an entry's safeTime
(Math.min(now, mtime) + FS_ACCURACY) against the watcher's
startTime. Because safeTime is intentionally inflated by
FS_ACCURACY to give callers an upper bound on possible modification
time, every file or directory whose actual mtime/birthtime was up to
FS_ACCURACY (initially 2000ms, typically 10ms after a single mtime
is observed) before startTime was being flagged as changed during
the initial scan.

The startTime filter now compares against the raw mtime/birthtime
instead, so only entries actually modified at or after startTime
trigger a change event during initial scan. The change event payload
still carries safeTime as before, and an additional optional
rawTimestamp argument is forwarded so nested directory watchers
can re-filter against the same raw timestamp.

The "outdated on attach" path in watch() continues to use
safeTime because its semantics are different: it represents "the
last time the file was known to be in a stable state", which is the
right value to compare against a newly attached watcher's startTime.

https://claude.ai/code/session_01CfqWhrftEvFkN5GiG82P67

claude added 3 commits April 27, 2026 16:04
…d within FS_ACCURACY of startTime (#295)

DirectoryWatcher previously compared an entry's `safeTime`
(`Math.min(now, mtime) + FS_ACCURACY`) against the watcher's
`startTime`. Because `safeTime` is intentionally inflated by
`FS_ACCURACY` to give callers an upper bound on possible modification
time, every file or directory whose actual mtime/birthtime was up to
`FS_ACCURACY` (initially 2000ms, typically 10ms after a single mtime
is observed) before `startTime` was being flagged as changed during
the initial scan.

The `startTime` filter now compares against the raw mtime/birthtime
instead, so only entries actually modified at or after `startTime`
trigger a change event during initial scan. The change event payload
still carries `safeTime` as before, and an additional optional
`rawTimestamp` argument is forwarded so nested directory watchers
can re-filter against the same raw timestamp.

The "outdated on attach" path in `watch()` continues to use
`safeTime` because its semantics are different: it represents "the
last time the file was known to be in a stable state", which is the
right value to compare against a newly attached watcher's startTime.

https://claude.ai/code/session_01CfqWhrftEvFkN5GiG82P67
…r change

The fix changes which initial-scan `change` events fire for files
created within `FS_ACCURACY` of `startTime`. Downstream consumers
(including webpack) may have been observing those events to invalidate
caches; mark the changeset accordingly.

https://claude.ai/code/session_01CfqWhrftEvFkN5GiG82P67
The fix aligns behavior with the documented "watching can be started
in the past" semantics. The previously-spurious initial-scan events
were undocumented and surprising (as the issue itself notes), so the
realistic risk of breaking a downstream consumer that relied on them
is low — patch is the right level.

https://claude.ai/code/session_01CfqWhrftEvFkN5GiG82P67
@linux-foundation-easycla
Copy link
Copy Markdown

CLA Not Signed

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 29, 2026

🦋 Changeset detected

Latest commit: 7d301fc

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

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 29, 2026

Merging this PR will not alter performance

✅ 36 untouched benchmarks


Comparing claude/fix-issue-295-JADcx (7d301fc) with main (b00ac61)

Open in CodSpeed

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.88%. Comparing base (d9af8b1) to head (7d301fc).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #299      +/-   ##
==========================================
+ Coverage   95.82%   95.88%   +0.06%     
==========================================
  Files           7        7              
  Lines        1173     1192      +19     
  Branches      342      355      +13     
==========================================
+ Hits         1124     1143      +19     
  Misses         44       44              
  Partials        5        5              
Flag Coverage Δ
integration 95.88% <100.00%> (+0.06%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 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.

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