Skip to content

fix: debounce watcher file change events#109

Merged
k1LoW merged 2 commits intomainfrom
fix-watcher-debounce
Mar 12, 2026
Merged

fix: debounce watcher file change events#109
k1LoW merged 2 commits intomainfrom
fix-watcher-debounce

Conversation

@k1LoW
Copy link
Owner

@k1LoW k1LoW commented Mar 12, 2026

This pull request introduces a debouncing mechanism for file change events in the server, ensuring that rapid, repeated file changes are consolidated into a single notification. This prevents unnecessary duplicate events and improves system efficiency. The changes include new state fields, logic for debouncing, proper cleanup, and a unit test to verify the behavior.

Debouncing file change events:

  • Added fileChangeDebounce and fileChangeTimers fields to the State struct, along with a default debounce duration constant (defaultFileChangeDebounce).
  • Implemented the scheduleFileChanged method to debounce file change notifications, replacing direct calls to notifyFileChanged. This ensures only one notification is sent within the debounce window for each file. [1] [2] [3]
  • Modified the State constructor and test setup to initialize the new debounce fields. [1] [2]

Resource cleanup:

  • Updated CloseAllSubscribers to stop and remove timers from fileChangeTimers to avoid resource leaks.

Testing:

  • Added a unit test TestScheduleFileChanged_DebouncesDuplicateEvents to verify that duplicate file change events are properly debounced and only a single notification is sent.

@k1LoW k1LoW self-assigned this Mar 12, 2026
@k1LoW k1LoW requested a review from Copilot March 12, 2026 08:15
@github-actions

This comment has been minimized.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Introduces debouncing for filesystem change notifications in the Go server state to coalesce rapid repeated fsnotify events into a single file-changed SSE notification, reducing redundant client refreshes.

Changes:

  • Added per-path debouncing state to State (fileChangeDebounce, fileChangeTimers) with a default debounce duration.
  • Routed fsnotify write/create handling through scheduleFileChanged (debounced) and added timer cleanup in CloseAllSubscribers.
  • Added a unit test verifying duplicate file-change events are debounced.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
internal/server/server.go Adds debounced scheduling for file-changed notifications and cleans up per-file timers on shutdown.
internal/server/server_test.go Initializes new debounce fields in test state and adds a debouncing behavior test.

You can also share your feedback on Copilot code review. Take the survey.

@github-actions
Copy link
Contributor

Code Metrics Report

main (54986b5) #109 (55d8e17) +/-
Coverage 52.2% 52.8% +0.6%
Code to Test Ratio 1:0.5 1:0.5 -0.1
Test Execution Time 39s 36s -3s
Details
  |                     | main (54986b5) | #109 (55d8e17) |  +/-  |
  |---------------------|----------------|----------------|-------|
+ | Coverage            |          52.2% |          52.8% | +0.6% |
  |   Files             |             37 |             37 |     0 |
  |   Lines             |           2900 |           2941 |   +41 |
+ |   Covered           |           1514 |           1555 |   +41 |
- | Code to Test Ratio  |          1:0.5 |          1:0.5 |  -0.1 |
  |   Code              |           4524 |           4570 |   +46 |
+ |   Test              |           2617 |           2619 |    +2 |
+ | Test Execution Time |            39s |            36s |   -3s |

Code coverage of files in pull request scope (72.4% → 73.4%)

Files Coverage +/- Status
internal/server/server.go 73.4% +1.0% modified

Reported by octocov

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


You can also share your feedback on Copilot code review. Take the survey.

@k1LoW k1LoW merged commit d01422c into main Mar 12, 2026
7 checks passed
@k1LoW k1LoW deleted the fix-watcher-debounce branch March 12, 2026 08:42
@github-actions github-actions bot mentioned this pull request Mar 12, 2026
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