Repository navigation
fix(uninstall): keep a direct dependency another package still needs (#4749) - #4765
Conversation
apm uninstall of a remote direct dependency that another installed package still needs transitively dropped the shared lock row, so the next apm install --frozen failed. The orphan owner now walks the removal roots too: a root still reachable from a survivor is removed from apm.yml only, stays installed, and its lock row is re-parented to the dependent package. Dry run and real run say which package still needs it. Fixes #4749 Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Critical uninstall defects retain selections inconsistent with deleted declarations and misclassify rescued dependencies, causing frozen-install failures and bypassing transitive MCP trust checks.
2 open issues
What changed in this PR
Addresses #4749 by extending uninstall’s orphan handling to retain a direct dependency when another installed package still needs it, rather than deleting its shared lockfile row and installed content.
Changes:
- Adds reachability-based rescue and parent reassignment for requested dependencies.
- Separates declaration-only removal from physical removal, with explanatory dry-run and completion output.
- Adds lifecycle regression tests, a bug-ledger entry, documentation, and a changelog fragment.
| File | Description |
|---|---|
tests/integration/test_uninstall_shared_direct_dependency_lifecycle.py |
Tests shared-dependency retention, dry-run safety, frozen replay, and ordinary removal. |
tests/fixtures/lifecycle_bug_ledger/bugs/4749.json |
Records the regression and its lifecycle coverage. |
src/apm_cli/install/orphans.py |
Includes removal roots in reachability checks and returns rescue repairs. |
src/apm_cli/commands/uninstall/cli.py |
Handles declaration-only removal, retained lock rows, and reporting. |
packages/apm-guide/.apm/skills/apm-usage/commands.md |
Documents retention of still-needed dependencies. |
docs/src/content/docs/reference/cli/uninstall.md |
Explains declaration-only removal in the uninstall reference. |
changelog.d/4765.fixed.md |
Announces the shared-dependency uninstall fix. |
Review effort: Balanced
Kept lines belong to core/remediation (files left in place); a package that stays installed now reads '<pkg> stays installed because <parent> still depends on it'. Re-anchor the lifecycle generator rule evidence for the uninstall options that moved. Co-authored-by: Copilot App <[email protected]>
…pile anchors) Co-authored-by: Copilot App <[email protected]>
…erive depth; rescue reached roots Review follow-ups on #4765: - Survivor intent, the deletion-evidence projection and the selection shrink now drop the still-needed declarations too, so the direct edge leaves the skill/target union and the row narrows to what the dependent package still selects. - The orphan owner returns rescued_depths: a rescued root sits one level below its new parent and its recorded subtree follows, so trust and tree consumers stop treating it as direct and a later install writes the same lockfile. - An incomplete walk still rescues every root it reached, and replacement evidence refuses whenever an orphan or an unreached root cannot be verified, instead of returning early. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Declaration-only uninstall can bypass edited-file protection when cleanup keys are empty, allowing apm.yml to change despite an edited skill file.
5 open issues
Declaration-only removal bypasses edited-file protection · New Removed declarations leave stale root requests in replacements · New Orphaned descendants retain incorrect production status · New Repaired parents differ from the deterministic nearest-parent choice · New Moved dependency depths are calculated before parent repairs · New
3 resolved since last review
Review effort: Balanced
…eppiel-4749-rebase
…nd drops the replacement root request Review follow-ups on #4765 (blocking under the time-box): - The deletion-evidence refusal no longer returns early when only a survivor-selection shrink retires files, so an edited skill the shrink would remove still refuses before apm.yml changes. - A still-needed replacement-backed row drops the removed declaration's root request through the replacement owner, keeping requests from surviving parents. Red-first lifecycle cells for both. Metadata follow-ups: #4804. Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block the change to preserve shared dependencies during uninstall.
No open issues 🎉
5 resolved since last review
Declaration-only removal bypasses edited-file protection Moved dependency depths are calculated before parent repairs Repaired parents differ from the deterministic nearest-parent choice Orphaned descendants retain incorrect production status Removed declarations leave stale root requests in replacements
Review effort: Balanced
Co-authored-by: Copilot App <[email protected]>
…ts' selection Dropping the removed declaration's root request left replacement.original carrying that declaration's skill/target selection, so survivor reintegration redeployed skills uninstall had just removed. The replacement owner now re-derives the node selection from the retained requests, as from_dict does. The replacement lifecycle cell selects a narrower skill set on the surviving parent and asserts the extra skill stays removed (red before the fix). Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
Human assessment is needed because combined uninstall operations can retain stale parent requests and unexpectedly redeploy selections associated with a removed parent.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
Merge main d43915c and fold #4765 into the [0.38.0] block. Co-authored-by: Copilot App <[email protected]>
Takes main's shared Known constants in test_ownership_siblings. Converts test_user_scope's #4744 known to a Known, since credits() now carries Known values (#4727). Refreshes known_cell_issue_states.json. Co-authored-by: Copilot App <[email protected]>


Description
apm uninstall Adropped A's lock row even when another installed package B still needs A transitively. For a remote dependency, the direct and transitive uses share one lock key (owner/repo), so removing the direct row also removed the row B depends on, and the nextapm install --frozenfailed.Fix at the owner,
install/orphans.py(decide_orphan_removal/_decide_uninstall):OrphanRemovalDecision.rescued_roots, with a re-parent repair.commands/uninstall/cli.pysplits those "still needed" packages out of the removal set:apm.ymlonly, throughmanifest_declarations_of()as before;apm_modules/or deployed-file removal);resolved_bynames the surviving parent; commit, files and identity are unchanged).Would remove test/e from apm.yml only; it stays installed because test/d still depends on ittest/e stays installed because test/d still depends on it(not aKept ...line: that vocabulary belongs tocore/remediationfor files left in place)rescued_depths: the rescued root and its recorded subtree move one level below the new parent, as install records it (review follow-up).Docs:
reference/cli/uninstall.md(Behavior step 1) and the apm-usagecommands.mduninstall row.Issue and approved scope
Issue: Fixes #4749
Human scope-approval comment: #4749 (comment)
Does this PR complete the issue, or what remains? It completes the issue.
apm-spec-waiver: uninstall lock-row re-parenting is CLI cleanup behaviour; OpenAPM v0.1 defines resolved_by but specifies no uninstall semantics
Type of change
Testing
Lifecycle evidence (apm-lifecycle-tests):
Commands (local, via the host guard):
pytest tests/integration/test_uninstall_shared_direct_dependency_lifecycle.py -n 0: 1 failed before the fix, 2 passed after.Neighbour uninstall/orphan tests (
grep -rlnon the owner symbols): 656 passed.test_architecture_owner_rule_mutations.py -k "orphan or uninstall": the uninstall-selection guard fired on the first draft (Step 4 changed the guarded call shape). It was fixed by routing through_manifest_declarations_to_drop();lint_architecture_boundaries.py --root .now exits 0.Lint chain:
ruff check/format --check(0.15.12): cleanlint-auth-signals: cleantests.quality.taxonomy --changed: cleanReview round 2 (blocking), red-first cells:
test_skill_selection_merge_lifecycle.py::test_declaration_only_uninstall_refuses_when_its_shrink_would_remove_an_edited_skill: before the fix uninstall updated apm.yml and only warned about the editedbeta/SKILL.md; after it, uninstall refuses with nothing changed.test_dependency_replacement_lifecycle.py::test_declaration_only_uninstall_drops_the_replacement_root_request: the root request (parent: null) goes and the surviving parent's request stays, theninstall --frozenpasses.Changelog
changelog.d/<pr>.<section>.md, holdingone line: user-visible effect first, 25 words or fewer, ending with
(#PR); breaking changes only under upgrade notes; no Highlights; nonew lines under
## [Unreleased]. Seechangelog.d/README.mdand.github/instructions/changelog.instructions.md.Spec conformance (OpenAPM v0.1)
CONFORMANCE.{md,json}regenerated