fix(disk-cleanup): prune protected cleanup walks - #46610
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates disk cleanup’s “quick” sweep to avoid deep recursive scans under protected and heavy directories, and adds tests to validate the new traversal behavior.
Changes:
- Replace
Path.rglob("*")empty-dir sweep with an explicit, pruned directory traversal that skips protected top-level trees and common heavy dirs (e.g.,node_modules,venv). - Add tests ensuring protected top-level trees are not descended into and managed subtrees have empty directories removed.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| tests/plugins/test_disk_cleanup_plugin.py | Adds regression tests covering pruning behavior and managed-subtree cleanup counts. |
| plugins/disk-cleanup/disk_cleanup.py | Reworks empty-dir removal to prune protected/heavy directories and reduce worst-case traversal cost. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Your disk-cleanup traversal fix was salvaged onto current Thanks for the focused fix. |
What does this PR do?
This PR keeps
disk-cleanup quick()from walking the wholeHERMES_HOMEtree when it removes empty directories.The old code used
hermes_home.rglob("*"), so it still scanned protected folders likehermes-agent/,node_modules/,venv/, and desktop release output before deciding what to delete. If the Hermes checkout lives underHERMES_HOME, that scan can be very large and can freeze the gateway/UI while the session-end hook runs.This PR changes the empty-dir sweep to only enter non-protected top-level folders and to prune vendor/cache directories before descending.
Related Issue
Fixes #46601
Type of Change
Bug fix
Changes Made
HERMES_HOME.rglob("*")empty-dir sweep with a bounded stack walk.How to Test
scripts/run_tests.sh tests/plugins/test_disk_cleanup_plugin.py$HOME/.hermes/hermes-agent/venv/bin/python -m py_compile plugins/disk-cleanup/disk_cleanup.py tests/plugins/test_disk_cleanup_plugin.pygit diff --checkNotes
There are older open disk-cleanup PRs that protect git internals, cron state, or durable paths. This PR is narrower: it only changes the traversal scope so
quick()no longer scans protected trees in the first place.Checklist