fix(watcher): handle on_created events for hot-reload in empty directories #1506
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.
Description
When the
./toolsdirectory is empty at Agent initialization and a new tool file is created, the watchdog observer fires anon_createdevent (noton_modified). The previous implementation only handledon_modifiedevents, causing the first tool added to an empty directory to not be hot-reloaded.This fix adds
on_createdhandlers to bothToolChangeHandlerandMasterChangeHandlerclasses, ensuring tools are loaded when files are created as well as modified.Root Cause
The
watchdoglibrary fires different events for different file system operations:on_created: When a new file is createdon_modified: When an existing file is modifiedWhen adding a file to an empty directory, only
on_createdfires. The previous code only handledon_modified, so the first tool added to an empty./toolsdirectory was never detected.Changes
ToolChangeHandler: Addedon_createdmethod that delegates to the same logic ason_modified(via_handle_tool_change)MasterChangeHandler: Addedon_createdmethod that delegates to all registered handlers (via_delegate_event)on_createdevent handlingRelated Issues
Fixes #264
Documentation PR
No documentation changes required - this is a bug fix.
Type of Change
Testing
hatch run prepareon_createdevent handlingChecklist