Skip to content

fix(uninstall): keep a direct dependency another package still needs (#4749) - #4765

Merged
Daniel Meppiel (danielmeppiel) merged 10 commits into
mainfrom
danielmeppiel-4749-uninstall-keep-transitive-lock-row
Nov 22, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 10 commits into
mainfrom
danielmeppiel-4749-uninstall-keep-transitive-lock-row

Conversation

@danielmeppiel

@danielmeppiel Daniel Meppiel (danielmeppiel) commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Description

apm uninstall A dropped 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 next apm install --frozen failed.

Fix at the owner, install/orphans.py (decide_orphan_removal / _decide_uninstall):

  • The reachability walk now covers the removal roots as well as orphan candidates. A root that a surviving package still reaches is returned in the new OrphanRemovalDecision.rescued_roots, with a re-parent repair.
  • commands/uninstall/cli.py splits those "still needed" packages out of the removal set:
    • they are removed from apm.yml only, through manifest_declarations_of() as before;
    • they stay installed (no apm_modules/ or deployed-file removal);
    • their lock row is re-parented (resolved_by names the surviving parent; commit, files and identity are unchanged).
  • Output says so:
    • dry run: Would remove test/e from apm.yml only; it stays installed because test/d still depends on it
    • real run: test/e stays installed because test/d still depends on it (not a Kept ... line: that vocabulary belongs to core/remediation for files left in place)
    • the summary also counts these declarations.
  • Survivor intent, the deletion-evidence projection and the selection shrink use the declaration-removal set, so the direct edge leaves the skill/target union (review follow-up).
  • The decision returns rescued_depths: the rescued root and its recorded subtree move one level below the new parent, as install records it (review follow-up).
  • An incomplete walk still rescues every root it reached; with replacement evidence it refuses whenever an orphan or an unreached root is unverifiable (review follow-up).
  • A package nothing else needs is removed exactly as before (control cell).

Docs: reference/cli/uninstall.md (Behavior step 1) and the apm-usage commands.md uninstall 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

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

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)

Lifecycle evidence (apm-lifecycle-tests):

promise: P-INV-I3 -- install --frozen and audit --ci agree after every mutating command (source: .agents/skills/apm-lifecycle-tests/SKILL.md I1-I9; ledger property lockfile.frozen_preserves_bytes)
cell: OP=uninstall SRC=git LOCK=present DEPLOYED=yes TGT=claude DRYRUN={off,on} (direct dep also reached transitively)   owner: src/apm_cli/install/orphans.py (decide_orphan_removal)
instrument: today test (ReplayWorld published git repos) + selection cell tests/integration/test_skill_selection_merge_lifecycle.py::test_uninstalling_a_direct_dependency_a_parent_still_selects_shrinks_to_that_edge (extends) -> tests/integration/test_uninstall_shared_direct_dependency_lifecycle.py::test_uninstall_keeps_a_direct_dependency_another_package_still_needs (new: no module covers a direct dep that is also transitive; local paths get separate lock keys and cannot reproduce it)
oracles: [I1, I3, I5, I6, I7, snapshot-absence]  decisive: lock row test/e kept with resolved_by == test/d and depth 2, then install --frozen and a full install leave the lock bytes unchanged
failing-before: pytest <module> -n 0 -> 1 failed, 1 passed (row test/e missing from apm.lock.yaml)
passing-after: pytest <module> -n 0 -> 2 passed
guard+mutation: install-deployment-uninstall-selection (unchanged; mutation case passes)     ledger: 4749
hints executed: none printed

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 -rln on 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): clean
    • pylint R0801: 10.00
    • lint-auth-signals: clean
    • complexity ratchet: clean
    • tests.quality.taxonomy --changed: clean
  • Review 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 edited beta/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, then install --frozen passes.
    • With the fix, both pass (2 passed, local, via the host guard).
    • Metadata-only findings (nearest-parent tie, chained depth, descendant dev status) are deferred to uninstall: re-derive parent, depth and dev status like install after a declaration-only removal #4804.

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)

  • Spec edit
  • Manifest edit
  • Test edit
  • CONFORMANCE.{md,json} regenerated
  • N/A -- this PR does not change OpenAPM-observable behaviour.

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]>
Copilot AI balanced review requested due to automatic review settings November 22, 2026 16:07

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 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

Comment thread src/apm_cli/commands/uninstall/cli.py Resolved
Comment thread src/apm_cli/commands/uninstall/cli.py Resolved
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]>

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

Uninstall handling can bypass transitive trust checks through stale dependency depths and delete still-needed shared packages when reachability evidence is incomplete.

3 open issues

Review effort: Balanced

Comment thread src/apm_cli/install/orphans.py Resolved
…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]>

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.

Comment thread src/apm_cli/commands/uninstall/cli.py Resolved
Comment thread src/apm_cli/commands/uninstall/cli.py Resolved
Comment thread src/apm_cli/commands/uninstall/cli.py Resolved
Comment thread src/apm_cli/install/orphans.py Resolved
Comment thread src/apm_cli/install/orphans.py Resolved
…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]>

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.

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

A critical stale-selection bug in replacement reintegration can redeploy skills that were just uninstalled instead of honoring surviving parent selections.

1 open issue

Review effort: Balanced

…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]>

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

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

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit d43915c into main Nov 22, 2026
74 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-4749-uninstall-keep-transitive-lock-row branch November 22, 2026 21:51
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 22, 2026
Merge main d43915c and fold #4765 into the [0.38.0] block.

Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 22, 2026
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]>
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 drops the lock row of a direct dependency that another package still needs transitively

2 participants