Skip to content

Conversation

Acren
Copy link
Contributor

@Acren Acren commented Aug 5, 2025

Problem

The file watcher was not detecting files created by editors that use a "create temp file then move to final location" pattern.
This caused newly created files to be missed by the auto-indexing system.

Root cause: File watcher only checked event.src_path (temporary file) but ignored event.dest_path (final file location) for move events.

e.g.

  1. User creates file my_file.py
  2. Editor saves as my_file.py.tmp.2644.1754398445351 or similar
  3. Editor renames my_file.py.tmp.2644.1754398445351 -> my_file.py
  4. Because only the source path is checked, the file watcher ignores the file and discards the event

Solution

  • Enhanced move event handling: Check dest_path for moved events to detect final file location
  • Refactored path checking: Extract filtering logic to reusable _should_process_path() method

Testing

  • Created test files that trigger the temp-file-move pattern
  • Verified move events now properly detect destination files with supported extensions
  • Confirmed temporary files are still filtered out correctly

Files Changed

  • src/code_index_mcp/services/file_watcher_service.py: Enhanced move event handling

File watcher was only checking source path for moved events, causing it
to miss files created by editors that use temp-file-then-move pattern.
Now checks dest_path for move events to properly detect final files.

- Add dest_path checking for moved events
- Extract path filtering logic to reusable _should_process_path method

Fixes issue where code editors create temp files that get moved to final
location but file watcher never processes the final file.
@Acren Acren mentioned this pull request Aug 5, 2025
johnhuang316 added a commit that referenced this pull request Aug 6, 2025
Simplify should_process_event() method to eliminate ambiguous fallback behavior
and make event handling more predictable.

Changes:
- Unified path checking logic for all event types
- Move events now exclusively check dest_path (no fallback to src_path)
- Cleaner conditional flow with single path validation call
- Better error handling with consistent exception management
- Reduced code complexity from 35 to 23 lines

This improves upon PR #17's move event handling by removing the potential
for inconsistent behavior when dest_path validation fails.
johnhuang316 added a commit that referenced this pull request Aug 6, 2025
Enhance file watcher service with improved event processing logic and code quality fixes.

Event Processing Improvements:
- Unified path checking logic for all event types
- Move events now exclusively check dest_path (no fallback to src_path)
- Cleaner conditional flow with single path validation call
- Better error handling with consistent exception management
- Reduced code complexity from 35 to 23 lines

Code Quality Improvements:
- Fix all f-string logging warnings (W1203) using lazy % formatting
- Add docstrings to fallback classes for better documentation
- Fix multiple-statements warnings by splitting single-line methods
- Move imports to top-level to follow PEP 8 conventions
- Disable docstring warnings for stub methods with appropriate comment

This improves upon PR #17's move event handling by removing the potential
for inconsistent behavior when dest_path validation fails, while also
significantly improving code quality and Pylint compliance.
@johnhuang316 johnhuang316 merged commit 852fcda into johnhuang316:master Aug 6, 2025
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