Delete skill folders for removed packages#1767
Open
sergio-sisternes-epam wants to merge 2 commits into
Open
Conversation
Teach the cleanup safety gate to recognise APM-deployed skill directories and safely remove them after individual files are deleted, instead of emitting a 'Refused to remove directory entry' warning. The fix defers skill directory entries (matching <prefix>/skills/<name>) to a second pass within remove_stale_deployed_files. After all file-keyed deletions complete, each deferred directory is removed when: - it no longer exists (already cleaned), or - it is empty (all files deleted in the first pass), or - all remaining files are APM-tracked with matching content hashes. Directories containing user-created or user-edited files are skipped with a detailed warning listing the blocking files. Non-skill directory entries retain the existing security rejection. Closes #1483 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the stale-deployed-files cleanup helper to treat skill bundle directories (<prefix>/skills/<name>) as a special-case: defer them during the main deletion pass, then attempt safe directory removal after file deletions complete (to avoid the current “Refused to remove directory entry …” warning for skill bundles).
Changes:
- Add skill-directory detection plus a deferred second pass that removes empty skill directories (or removes the whole tree when remaining contents are verified as APM-owned).
- Add a dedicated unit test module covering skill-directory deferral/removal scenarios.
- Add a
CHANGELOG.mdentry under Fixed describing the behavior change.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
src/apm_cli/integration/cleanup.py |
Adds _is_skill_directory_entry() and deferred skill-directory cleanup logic in remove_stale_deployed_files(). |
tests/unit/integration/test_cleanup_skill_dirs.py |
New unit tests validating skill directory pattern matching and deferred cleanup behavior. |
CHANGELOG.md |
Documents the new behavior under Unreleased -> Fixed. |
…tail - Replace non-ASCII box-drawing characters in comments with ASCII - Treat symlinks inside skill directories as blocking (user content) - List blocking file paths in the diagnostic message (not just count) - Fix test to actually exercise rmtree path (drop asset from stale) - Add symlink blocking test - Use PR number in CHANGELOG entry per convention Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
TL;DR
Teach the cleanup safety gate to recognise APM-deployed skill directories and safely remove them after individual files are deleted, instead of emitting a "Refused to remove directory entry" warning.
Problem (WHY)
When a package is removed from
apm.ymlandapm installruns, APM deletes individual files but refuses to delete directories that were deployed as skill bundles (e.g..agents/skills/coding-standards-python/). The user sees:This happens because
services.pyrecords both the skill directory entry and individual file entries indeployed_files, but Gate 2 incleanup.pyunconditionally rejects all directory entries as potentially poisoned lockfile entries -- even those APM itself created.Closes #1483
Approach (WHAT)
remove_stale_deployed_files()to defer skill directory entries (matching<prefix>/skills/<name>) to a second pass instead of immediately rejecting them.Implementation (HOW)
src/apm_cli/integration/cleanup.py_is_skill_directory_entry()-- detects<prefix>/skills/<name>patterns_safe_remove_skill_directory()-- encapsulates safe removal logic (empty check, provenance verification, rmtree)_emit_dir_failure()and_strip_sha256_prefix()helpersremove_stale_deployed_files():stale_pathsiterable into list + set (was single-use)deferred_dirslisttests/unit/integration/test_cleanup_skill_dirs.py(new)19 tests covering:
_is_skill_directory_entrypattern matching (10 cases)Trade-offs
deployed_files+deployed_file_hashesprovide sufficient ownership/provenance data.Validation
How to test
apm installto deploy the skillapm.ymlapm installagain