Repository navigation
Retire stale source paths when watched files move between directories - #1238
Merged
mmguero merged 1 commit intoOct 15, 2026
Conversation
Merged
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.
Description
A FileMovedEvent removes the tracked source path only when source and destination have the same parent directory. With recursive watching or multiple watched directories, moving a queued file between subdirectories leaves its old name in the processing queue or staging history. The worker can then invoke the processor on a nonexistent source path as well as the destination.
Retire any tracked source from both queues before handling the destination, irrespective of the parent directory. Moves from an untracked source remain harmless because removal uses pop with a default. The staging-event fix already present on contributor-prs is preserved.
Related issue(s)
New reproducible regression found on current contributor-prs. No existing tracking issue or overlapping open PR was found. This branch is based directly on contributor-prs, including its previously merged watcher fixes.
Type of change
How has this been tested?
python -m pytest -q shared/tests/test_watch_moved_paths.py12 cases pass on macOS, Python 3.12 and watchdog 6.0.0. Eight cases fail against unchanged contributor-prs. Tests import the actual watcher and worker, move real files inside temporary directories, deliver real watchdog event objects, and check both pending and staged queues. Coverage includes same-directory renames, cross-directory moves after created/modified/closed events, unrelated queued files, and worker callbacks in polling and native-event modes. Worker scheduling is controlled in the tests; no full Malcolm container deployment or live observer was started.
Black (120-column, skip string normalization), Python compilation and git diff --check pass. Ruff correctness checks pass with the existing unused defaultdict import left unchanged.
Documentation
Was AI used in writing the code, tests, or description for this pull request?
OpenAI ChatGPT generated the patch, tests and this description. Validation included inspecting the diff against current contributor-prs, checking open and previously merged contributions for overlap, reproducing the regression before the fix, and running the actual test suite after it. Maintainer review is still required.