Skip to content

fix(uninstall): never remove a skill-directory member a surviving dependency still deploys - #4752

Merged
Daniel Meppiel (danielmeppiel) merged 5 commits into
mainfrom
danielmeppiel-fix-skill-dir-shared-member-rmtree
Nov 22, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 5 commits into
mainfrom
danielmeppiel-fix-skill-dir-shared-member-rmtree

Conversation

@danielmeppiel

Copy link
Copy Markdown
Collaborator

Description

Fixes #4750. Record: #4750 (comment)

Bug: when apm uninstall removed a package whose lockfile entry claims a whole skill directory, cleanup removed the entire tree with rmtree once every remaining member looked APM-owned. That tree could include a member another, surviving dependency still deploys (src/apm_cli/integration/cleanup.py, _safe_remove_skill_directory), and that member was lost.

Fix, in the cleanup owner:

  • reconcile_target_deployed_files passes the surviving dependencies' deployed paths into the cleanup pass as live paths. remove_stale_deployed_files already treats live paths as "still deployed after this run".
  • _safe_remove_skill_directory never removes a member in that live set. When one is present, the directory stays, and the departing package's other proven members are removed one by one through _remove_proven_members.
  • _remove_proven_members runs each member's deletion gates again immediately before its unlink. A file changed after the directory check is kept and named, never removed.
  • Consent and approval rules are unchanged, and uninstall never removes more than before. A directory with no surviving members takes the same path as before.

Issue and approved scope

Issue: Fixes #4750

Human scope-approval comment: #4750 (comment)

Does this PR complete the issue, or what remains? It completes it. #4650 (--trust-lockfile) will rebase onto this owner fix for its per-member consent path, and carries no second copy.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass: CI pending.
  • Added tests for new functionality (if applicable)

Failing-before cells at the uninstall owner, reconcile_target_deployed_files with selected-owner removal (the path apm uninstall takes), driven through the real cleanup.py code:

  • test_selected_removal_keeps_a_skill_member_a_surviving_dependency_deploys: two packages share a skill-directory member. Uninstalling one keeps the shared member byte-identical, removes the departing package's own member, and leaves the survivor's lockfile row equal to disk.
    • Before the fix: FileNotFoundError ... .agents/skills/alpha/shared.md (the member was removed).
  • test_selected_removal_keeps_a_member_edited_between_check_and_unlink: a member edited after its check is kept.
    • Before the fix: FileNotFoundError ... .agents/skills/alpha/notes.md.

Both pass after the fix. Local results, run through the host guard:

  • pytest -n 2 over target contraction, cleanup skill dirs, cleanup helper, skill cleanup containment, deletion-evidence spec, lifecycle bug ledger, the uninstall engine and shared-ownership units, and the manifest reconcile units: 139 passed.
  • The lint contract is clean: ruff 0.15.12 check and format, the complexity ratchet, the architecture linter, auth signals, the assertion and taxonomy ratchets. No source file exceeds 2100 lines.

Bug-ledger row: tests/fixtures/lifecycle_bug_ledger/bugs/4750.json (ownership.preserve_unowned).

Changelog

  • One fragment per section, changelog.d/<pr>.<section>.md, holding
    one line: user-visible effect first, 25 words or fewer, ending with
    (#PR); breaking changes only under upgrade notes; no Highlights; no
    new lines under ## [Unreleased]. See changelog.d/README.md and
    .github/instructions/changelog.instructions.md.
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

  • N/A -- this PR does not change OpenAPM-observable behaviour. It enforces the existing req-lk-024 deletion-evidence rule more strictly; no spec text changes.

…endency still deploys

Fixes #4750. When a departing package's skill directory held a member a
surviving dependency still deploys, cleanup removed the whole tree once
every member looked APM-owned. Survivors' paths now reach the directory
pass as live paths: those members are never removed, the departing
package's other proven members are removed one by one, and each member's
deletion gates run again immediately before its unlink, so a file
changed after the check is kept and named.

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 22, 2026 14:03

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.

🟡 Changes recommended

Critical cleanup flaws can delete surviving shared files or files outside the deployment root, and installed-CLI lifecycle coverage is missing for disk and persisted-lockfile consistency.

3 open issues
What changed in this PR

This PR addresses #4750 by updating the shared cleanup owner to preserve skill-directory files still deployed by surviving dependencies during apm uninstall.

Changes:

  • Passes surviving dependencies’ deployed paths into cleanup as protected live paths.
  • Uses per-member deletion when a directory contains shared files, rechecking deployment evidence before each unlink.
  • Adds two reconciliation regressions, a bug-ledger entry, and a changelog fragment.
File Description
tests/​unit/​install/​test_target_contraction_logging.py Adds shared-member and late-edit preservation regressions.
tests/​fixtures/​lifecycle_bug_ledger/​bugs/​4750.json Records the bug and regression references.
src/​apm_cli/​integration/​cleanup.py Protects live members and adds per-member evidence rechecks.
src/​apm_cli/​install/​manifest_reconcile.py Forwards surviving dependencies’ paths into cleanup.
changelog.d/​4752.fixed.md Documents the uninstall preservation fix.

Review effort: Balanced

Comment thread src/apm_cli/integration/cleanup.py Resolved
Comment thread src/apm_cli/integration/cleanup.py Resolved
…p call

The spelling-alias owner check pinned live_paths=files; the call now
passes survivors' paths too (#4750), still through SpellingAliasIndex.

apm-spec-waiver: enforces the existing req-lk-024 deletion-evidence rule more strictly; no new normative behaviour or spec text

Co-authored-by: Copilot App <[email protected]>

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.

🔵 Needs a closer look

Critical cleanup flaws can delete surviving owners’ files through missed case or Unicode aliases and delete redirected files outside the deployment root because path and symlink safety checks are not repeated before removal.

3 open issues

Review effort: Balanced

…safety before each unlink

Addresses review on #4752 (Fixes #4750):
- a surviving claim spelled differently on a case-insensitive
  filesystem (Shared.md vs shared.md) is matched through
  SpellingAliasIndex physical identity, so it is never removed
- immediately before each per-member unlink, the member must still be a
  regular file, reached through no symlinked directory and contained in
  the skill directory, and its evidence must still authorize its bytes
- an installed-CLI lifecycle cell runs apm uninstall and asserts the
  survivor's bytes and the persisted apm.lock.yaml (red on main)

apm-spec-waiver: enforces the existing req-lk-024 deletion-evidence rule more strictly; no new normative behaviour or spec text

Co-authored-by: Copilot App <[email protected]>

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.

🔵 Needs a closer look

Cleanup can delete files outside the validated deployment scope after an ancestor symlink swap and fail to protect surviving URI-claimed files on case-insensitive filesystems.

No open issues 🎉

2 previously missed issues

In code that hasn't changed since last review

High severity Revalidate ancestor symlinks before authorizing deletion

src/​apm_cli/​integration/​cleanup.py:802

If .agents or .agents/skills becomes a symlink after the scan, this recheck misses it: the ancestor walk stops at skill_dir, and containment resolves both paths into the outside tree. Matching locked-render bytes can then authorize deletion of an outside file. Pass the original validated deployment scope into the recheck, rerun its canonical ancestor and containment gates, and add a regression that swaps an ancestor above the skill directory.

Medium severity Resolve URI claims when protecting surviving files

src/​apm_cli/​integration/​cleanup.py:977

SpellingAliasIndex excludes candidates containing :// (utils/paths.py:94-96), so on a case-insensitive filesystem a survivor claiming cowork://skills/alpha/Shared.md does not protect the scanned cowork://skills/alpha/shared.md. With matching deployment evidence, cleanup can still delete that surviving member. Resolve URI claims through the canonical target resolver before checking spelling and physical identity under the external root, and cover this case in a regression.

3 resolved since last review

Review effort: Balanced

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 65e1300 into main Nov 22, 2026
72 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-fix-skill-dir-shared-member-rmtree branch November 22, 2026 16:02
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 22, 2026
Merges main (with #4752, which owns the per-member skill-directory fix)
and folds the #4650 and #4725 review threads:
- a receipt store no installation marker binds counts as unreadable
- consented deletions are reported once, before any early exit
- the consent exemption follows actual deletion verdicts; a path
  cleanup failed on (I/O) is never waived; ancestor lookup is O(1)
- under consent a standalone tracked file replaced by a link is kept
  and named by the evidence owner, so uninstall finishes
- the --trust-lockfile remedy names the packages; the lifecycle test
  runs the printed command
Spec stays 0.1.76; CONFORMANCE regenerated.

Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 22, 2026
Merges main (with #4752, which owns the per-member skill-directory fix)
and folds the #4650 and #4725 review threads:
- a receipt store no installation marker binds counts as unreadable
- consented deletions are reported once, before any early exit
- the consent exemption follows actual deletion verdicts; a path
  cleanup failed on (I/O) is never waived; ancestor lookup is O(1)
- under consent a standalone tracked file replaced by a link is kept
  and named by the evidence owner, so uninstall finishes
- the --trust-lockfile remedy names the packages; the lifecycle test
  runs the printed command
Spec stays 0.1.76; CONFORMANCE regenerated.

Co-authored-by: Copilot App <[email protected]>
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.

[BUG] apm uninstall can remove a skill-directory file that a surviving dependency still deploys

2 participants