Skip to content

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

Merged
Daniel Meppiel (danielmeppiel) merged 5 commits into
mainfrom
danielmeppiel-4313-shrink-preflight
Nov 21, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 5 commits into
mainfrom
danielmeppiel-4313-shrink-preflight

Conversation

@danielmeppiel

Copy link
Copy Markdown
Collaborator

Supersedes #4588 (its owning session became unreachable while still force-pushing the branch). Same change, rebased on current main; authorship kept through commit trailers.

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.

…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]>
Supersedes: #4588
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Supersedes: #4588
Co-authored-by: Copilot App <[email protected]>
…tires (#4313)

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

Critical shrink-preflight gaps let edited retired files bypass refusal or be detected only after package-state changes, alongside false refusals and failures caused by unrelated target resolution.

4 open issues
What changed in this PR

This PR addresses #4313 by extending uninstall’s deployment-evidence preflight to files retired when a surviving shared bundle’s selection shrinks. It aims to refuse edited or unproven files before changing manifests, lockfiles, or deployed state.

Changes:

  • Shares a read-only survivor-selection projection between preflight and shrink application.
  • Adds retired paths to evidence preparation and refusal checks.
  • Adds project- and user-scope regression tests, documentation, and ownership metadata.
File Description
tests/​unit/​test_uninstall_engine_helpers.py Tests retired-path detection and unrestricted selections.
tests/​lifecycle/​generator/​rules.py Updates uninstall source-evidence line references.
tests/​integration/​test_skill_selection_merge_lifecycle.py Tests refusal without state changes at 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 read-only selection projection.
src/​apm_cli/​commands/​uninstall/​cli.py Includes shrink retirements in evidence preflight.
docs/​src/​content/​docs/​reference/​cli/​uninstall.md Documents evidence checks for shrinking shared selections.
CHANGELOG.md Records the intended early-refusal behavior.
.apm/​architecture/​owners/​install-deployment.json Registers the shrink module under the selection owner.

Review effort: Balanced

Comment thread src/apm_cli/commands/uninstall/cli.py Resolved
…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]>
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 11b9dd6 into main Nov 21, 2026
62 of 67 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-4313-shrink-preflight branch November 21, 2026 15:25
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