Skip to content

fix(disk-cleanup): prune protected cleanup walks - #46610

Closed
BlackishGreen33 wants to merge 2 commits into
NousResearch:mainfrom
BlackishGreen33:bg/disk-cleanup-prune-sweep
Closed

fix(disk-cleanup): prune protected cleanup walks#46610
BlackishGreen33 wants to merge 2 commits into
NousResearch:mainfrom
BlackishGreen33:bg/disk-cleanup-prune-sweep

Conversation

@BlackishGreen33

Copy link
Copy Markdown
Contributor

What does this PR do?

This PR keeps disk-cleanup quick() from walking the whole HERMES_HOME tree when it removes empty directories.

The old code used hermes_home.rglob("*"), so it still scanned protected folders like hermes-agent/, node_modules/, venv/, and desktop release output before deciding what to delete. If the Hermes checkout lives under HERMES_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

  • Replaces the full HERMES_HOME.rglob("*") empty-dir sweep with a bounded stack walk.
  • Skips protected top-level state trees before traversal instead of after traversal.
  • Adds regression tests for protected checkout/vendor paths and normal managed empty-dir cleanup.

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.py
  • git diff --check

Notes

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

  • Focused tests pass
  • Syntax check passes
  • No public API, command output, or tracked.json format changes

Copilot AI review requested due to automatic review settings June 15, 2026 11:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread tests/plugins/test_disk_cleanup_plugin.py Outdated
Comment thread tests/plugins/test_disk_cleanup_plugin.py Outdated
Comment thread plugins/disk-cleanup/disk_cleanup.py Outdated
Comment thread plugins/disk-cleanup/disk_cleanup.py Outdated
@alt-glitch alt-glitch added type/bug Something isn't working comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have labels Jun 15, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Merged via PR #46629: #46629

Your disk-cleanup traversal fix was salvaged onto current main, with your two commits replayed via rebase-merge so your authorship is preserved in git history. I added one small follow-up regression test that asserts quick() never descends into protected hermes-agent/ during the empty-dir sweep.

Thanks for the focused fix.

@teknium1 teknium1 closed this Jun 15, 2026
@BlackishGreen33
BlackishGreen33 deleted the bg/disk-cleanup-prune-sweep branch June 17, 2026 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

disk-cleanup quick() walks all of HERMES_HOME on the gateway event loop → ~20min UI freeze

4 participants