fix: Replace rate-limiter debounce with true debounce in ConfigurationFileWatcher#70
Merged
JerrettDavis merged 1 commit intomainfrom Apr 15, 2026
Merged
Conversation
…nFileWatcher The Hot_reload_ignores_invalid_configuration test was failing because FileSystemWatcher fires a Changed event when a file is opened/truncated (before new content is written). The old rate-limiter would immediately trigger TriggerReload on the first event — at that moment the file could be empty, producing an empty config that passes validation and causes the callback to fire erroneously. The fix uses a true debounce (cancel-and-reschedule a Timer on each event, fire once after a 500ms quiet period), ensuring the file is fully written before it is read and validated. Agent-Logs-Url: https://github.com/JerrettDavis/ExperimentFramework/sessions/e1b4bff1-134f-4aa9-9af8-cfb3f7cbc850 Co-authored-by: JerrettDavis <2610199+JerrettDavis@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
JerrettDavis
April 15, 2026 21:11
View session
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Code Coverage |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #70 +/- ##
=======================================
Coverage ? 83.39%
=======================================
Files ? 194
Lines ? 7036
Branches ? 996
=======================================
Hits ? 5868
Misses ? 1168
Partials ? 0
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the intermittently failing
Hot_reload_ignores_invalid_configurationtest.Root Cause
FileSystemWatcheron Linux fires aChangedevent when a file is opened/truncated (before any content is written), as well as after the write completes. The old debounce was a rate-limiter — it firedTriggerReloadimmediately on the first event and suppressed subsequent ones within the 500 ms window. When the first event fired while the file was empty (truncated but not yet written),TriggerReloadloaded an empty config, which passes validation (no trials → no errors), and the callback was incorrectly invoked.Fix
Replaced the rate-limiter with a true debounce using a
System.Threading.Timer:TriggerReloadonly executes after the file has been stable for 500 ms, by which point the write is always complete and the file contains the correct (invalid) contentChanges
src/ExperimentFramework.Configuration/ServiceCollectionExtensions.cs:ConcurrentDictionary<string, DateTime> _lastChangeTime(rate-limiter state)Timer? _debounceTimerandobject _debounceLockScheduleReload()— cancels the pending timer and creates a new 500 ms oneOnFileChangednow callsScheduleReload()instead ofTriggerReload()directlyTriggerReloadwith_disposedcheckDispose()usingTimer.Change(Timeout.Infinite, Timeout.Infinite)beforeDispose()to prevent callbacks firing during teardownTesting
All 11
ConfigurationFileWatcherTestspass, including the previously failing test.