Skip to content

[0.38] fix(uninstall): check shrinking survivor selections in the evidence preflight (#4313) - #4588

Closed
Daniel Meppiel (danielmeppiel) wants to merge 3 commits into
mainfrom
danielmeppiel-fuzzy-fishstick
Closed

Daniel Meppiel (danielmeppiel) wants to merge 3 commits into
mainfrom
danielmeppiel-fuzzy-fishstick

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

When you uninstall one parent of a diamond, the surviving shared bundle's skill selection shrinks. The skills only that parent selected are then retired. Today those files skip the deployment-evidence preflight. If you edited one, uninstall still rewrites apm.yml and apm_modules, then keeps the file with a warning and exits 0.

With this change, the files a shrinking survivor selection retires join _refuse_uninstall_without_evidence's candidate set. An edited (or unproven) retired file now refuses with Uninstall refused before any change.

  • engine.project_shrunk_selections is the read-only projection of the survivor selections. It uses the existing selection owner declared_node_selections (dependency-selection-merge). The preflight and the shrink apply step (_shrink_surviving_selections) both use it, so there is no second shrink computation.
  • selection_shrink.shrink_retired_paths reads the survivor's recorded paths from the deployment ledger (DeploymentLedgerCodec.from_lockfile). It returns two kinds of path. First, a skill directory and its members when no surviving declaration selects that skill. Second, a path when none of its targets is still selected. A skills root shared by several targets counts every target that deploys there, so a shared root is never over-retired.
  • DeploymentEvidence keeps the verdict. The retired paths are also passed to evidence.prepare, so the locked render materializes while sources exist. Paths still owned by another survivor are excluded.
  • _abort_if_retained_target_cleanup_paths is unchanged and stays as the backstop.
  • The new module commands/uninstall/selection_shrink.py keeps engine.py under the 2100-line guardrail. It is registered under the dependency-selection-merge owner selectors.

Issue and approved scope

Issue: Fixes #4313

Human scope-approval comment: #4313 (comment) (governance eligibility: record-present, contact_confirmation_needed: false)

Does this PR complete the issue? Yes. Out of scope and untouched: the consent path for missing evidence (#4295, stacked on this PR), how survivor selections merge or shrink, install-time selection, and apm prune.

Decisions (taken as recommended defaults, per rule S15):

  • A skill counts as retired only when no surviving pairing selects it for any target. A skill dropped for one target but kept for another target that shares the skills root is not a candidate. This is conservative and never over-refuses.
  • A target-only shrink retires a path only when no target that can deploy there (recorded targets plus every KNOWN_TARGETS profile sharing that skills root) is still selected.
  • The projection runs at preflight on pre-refresh survivor manifests. The apply step re-projects after local survivor refresh, as before.

Landing order

Type of change

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

Testing

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

Red on main (origin/main f8c31a5, same uninstall code as d365b87 for this path). Both new cells fail: rc=0, and the output only warns Skipped removing .agents/skills/alpha/SKILL.md: file has been edited....

  • tests/integration/test_skill_selection_merge_lifecycle.py::test_uninstall_refuses_before_any_change_when_a_shrink_would_remove_an_edited_skill
  • tests/integration/test_skill_selection_merge_lifecycle.py::test_user_scope_uninstall_refuses_before_any_change_when_a_shrink_would_remove_an_edit

Green on head. Each cell asserts exit 1, Uninstall refused naming skills/alpha/SKILL.md, and no Uninstall could not remove tracked target files line. It also asserts that apm.yml, apm.lock.yaml, apm_modules and every deployed skill are byte-unchanged, at project scope and at user scope.

Local evidence:

  • APM_E2E_TESTS=1 APM_BINARY_PATH=.venv/bin/apm uv run --frozen --extra dev pytest -n 8 tests/integration/test_skill_selection_merge_lifecycle.py tests/integration/test_uninstall_skill_selection_lifecycle.py: 35 passed. This includes the unchanged controls test_uninstalling_one_diamond_parent_shrinks_to_the_survivor_selection_then_cleans and test_user_scope_diamond_merges_then_shrinks_on_uninstall.
  • uv run --frozen --extra dev pytest -n 8 tests/unit -k "uninstall or shrink or selection or cleanup or evidence or reachab": 1521 passed. Under host load, 6 failures appeared; all pass when rerun alone or are environment-only (git commit signing in test_check_complexity_ratchet).
  • New unit cases: tests/unit/test_uninstall_engine_helpers.py::TestShrinkRetiredPaths (a dropped skill and a dropped target both retire with their members; an unrestricted survivor retires nothing).
  • Gates passed: ruff check, ruff format --check, pylint R0801, lint-auth-signals, lint_architecture_boundaries.py --root . (exit 0), complexity ratchet vs origin/main, check_test_assertions, tests.quality.taxonomy --changed, check_taxonomy_allowances, and the Mode B detector (no critical-path diff). Running gen_statement leaves CONFORMANCE unchanged.

Changelog

  • One line in one section under ## [Unreleased] in CHANGELOG.md:
    user-visible effect first, 25 words or fewer, ending with (#PR);
    breaking changes only under upgrade notes; no Highlights; see
    .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. It applies the existing req-lk-024 to a deletion path it already governs; no requirement text changes.

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 preflight can miss edited retired files and allow state changes before detecting them, while mishandling shared ownership can also incorrectly block removal.

3 open issues
What changed in this PR

Extends uninstall’s deployment-evidence preflight to files retired when a surviving shared bundle’s selection shrinks, addressing #4313 before manifest, lockfile, or package changes begin.

Changes:

  • Shares a read-only survivor-selection projection between preflight and shrink application.
  • Adds retired deployment paths to evidence preparation and refusal checks.
  • Adds project- and user-scope regression coverage, updates documentation, and registers the new module with its architecture owner.
File Description
tests/​unit/​test_uninstall_engine_helpers.py Tests retired paths for skill and target selection changes.
tests/​lifecycle/​generator/​rules.py Updates uninstall CLI evidence line references.
tests/​integration/​test_skill_selection_merge_lifecycle.py Tests early refusal and unchanged files in project and user scopes.
src/​apm_cli/​commands/​uninstall/​selection_shrink.py Identifies retired paths and applies survivor selection changes.
src/​apm_cli/​commands/​uninstall/​engine.py Extracts the shared, read-only selection projection.
src/​apm_cli/​commands/​uninstall/​cli.py Includes shrinking selections in the evidence preflight.
docs/​src/​content/​docs/​reference/​cli/​uninstall.md Documents refusal for files retired by shrinking selections.
CHANGELOG.md Records the user-visible uninstall fix.
.apm/​architecture/​owners/​install-deployment.json Registers the new module under the selection-merge owner.

Review effort: Balanced

Comment on lines +58 to +74
skills = skill_subset_filter_tokens(selection.skill_subset)
for value in {
record.locator.value.rstrip("/") for record in records if key in record.owners
}:
skill_dir = _enclosing_skill_dir(value)
targets = set(targets_at[value])
if skill_dir is not None:
targets |= sharers.get(skill_dir.rpartition("/")[0], set())
if (
selection.target_subset is not None
and not any(selection.selects_target(target) for target in targets)
) or (
skills is not None
and skill_dir is not None
and skill_dir.rpartition("/")[2] not in skills
):
retired.add(value)
and skill_dir.rpartition("/")[2] not in skills
):
retired.add(value)
return retired
Comment on lines +607 to +608
retired = BaseIntegrator.normalize_managed_files(shrink_retired_paths(lockfile, shrunk))
candidates |= (retired or builtins.set()) - others - builtins.set(other_hashes)
…reflight (#4313)

Files a shrinking shared survivor selection retires now join the uninstall
deployment-evidence preflight, so an edited file refuses before any change
instead of being kept after apm.yml and apm_modules were already rewritten.
The projection reuses declared_node_selections through
project_shrunk_selections (one shrink computation, shared with the apply
step) and reads retired paths from the deployment ledger; DeploymentEvidence
keeps the verdict.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
@danielmeppiel

Copy link
Copy Markdown
Collaborator Author

Superseded by #4620 (same change rebased on main, authorship kept via trailers; this branch's owning session is unreachable).

Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 21, 2026
…ed retained paths (#4313)

Review of #4620:
- Skip dynamic-root targets when mapping shared skills roots, so an
  unrelated Cowork resolution cannot fail a project uninstall.
- Decide retirement per target through the exact pairings: a skill
  selected only for another target retires from this root.
- A retired skill directory also retires members older lockfiles record
  only in deployed_file_hashes.
- A path another shrinking survivor keeps deploying is not a deletion
  candidate.

Supersedes: #4588
Co-authored-by: Copilot App <[email protected]>
Mohammed Alkindi (MohammedAlkindi) pushed a commit to MohammedAlkindi/apm that referenced this pull request Nov 21, 2026
…reflight (microsoft#4313)

Files a shrinking shared survivor selection retires now join the uninstall
deployment-evidence preflight, so an edited file refuses before any change
instead of being kept after apm.yml and apm_modules were already rewritten.
The projection reuses declared_node_selections through
project_shrunk_selections (one shrink computation, shared with the apply
step) and reads retired paths from the deployment ledger; DeploymentEvidence
keeps the verdict.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Supersedes: microsoft#4588
Co-authored-by: Copilot App <[email protected]>
Mohammed Alkindi (MohammedAlkindi) pushed a commit to MohammedAlkindi/apm that referenced this pull request Nov 21, 2026
Mohammed Alkindi (MohammedAlkindi) pushed a commit to MohammedAlkindi/apm that referenced this pull request Nov 21, 2026
…tires (microsoft#4313)

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Supersedes: microsoft#4588
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.

Uninstall: check shared-bundle survivor selections in the evidence preflight

2 participants