Skip to content

[0.38] fix(uninstall): rebuild survivors only into lock-recorded targets after a target change (#4636) - #4663

Merged
Daniel Meppiel (danielmeppiel) merged 3 commits into
mainfrom
danielmeppiel-4636-uninstall-new-target
Nov 21, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 3 commits into
mainfrom
danielmeppiel-4636-uninstall-new-target

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

After apm.yml switches or adds a target ([copilot] -> [claude] or [copilot] -> [copilot, claude]), apm uninstall <pkg> rebuilt the remaining packages into the new target. It did not record those files in apm.lock.yaml, which breaks lifecycle invariant I1. It also printed Skipped .claude/commands/ -- create a .claude/ directory, a hint about a root the same command had just created.

Uninstall now rebuilds survivors only into the targets the lock records:

  • Evidence: a target counts as recorded when a lock deployment row names it (deployments[].target, or the legacy prefix attribution for older locks).
  • Not evidence: manifest_targets, which every changed lock write refreshes from apm.yml.
  • Shared roots: a legacy row on a root several targets share (.agents/) counts only for the one candidate target that governs it.
  • New target: uninstall leaves it alone and prints, once, Not deployed to claude: this project was not installed for it yet. Run 'apm install' to deploy the remaining packages to claude and record them in apm.lock.yaml.
  • Unchanged targets: behavior is unchanged.

The decision lives in one place, src/apm_cli/commands/uninstall/recorded_targets.py. The new module is registered under the skills-root-derivation owner alongside engine.py. _sync_integrations_after_uninstall calls it once, after resolve_reintegration_targets. No second target resolver is added. Cleanup of the removed packages' own files is unchanged.

Issue and approved scope

Issue: Fixes #4636

Human scope-approval comment: #4636 (comment)

Does this PR complete the issue, or what remains? It completes the fix. The done-when cells (test_command_after_a_target_change[uninstall-*] in tests/lifecycle/scenarios/test_history_upgrade.py) live on the Q&L corpus train 3 branch danielmeppiel-w3-t6a-history and are not on main yet. I ran them locally against this branch with their #4636 strict known-cell markers removed:

  • This branch: all four uninstall histories pass (single-narrowed, single-widened, multi-widened and the multi-narrowed control).
  • With the fix reverted: single-narrowed and single-widened fail I1 with deployed file is not in the lock: .claude/skills/p-skill/SKILL.md.

Q&L retires the #4636 known cells: the I1 rows and the uninstall-new-target-skipped-hint-repeats output cell. This is coordinated through the Q&L inbox, so the cells are not duplicated here.

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)

Local results, run through the host guard:

  • New unit tests in tests/unit/test_uninstall_engine_validation_logic.py: 28 passed. They cover:
    • narrowed, widened, multi-widened, multi-narrowed and unchanged targets;
    • a refreshed manifest_targets that is not evidence;
    • a named deployment row on a shared root, and a legacy shared-root row;
    • the no-record case and the advice sentence.
  • Review follow-up, end to end on the real binary: three packages installed for [copilot], then targets: [claude], then two consecutive uninstalls. Both print the advice, and no .claude/ exists after either.
  • The W3 T-6a cells described above, run against the installed CLI with APM_E2E_TESTS=1: 4 passed.
  • pytest -n 2 across 8 uninstall integration and lifecycle modules (engine coverage, multi, survivor output, skill selection, summary, global exact removal, LSP recorded targets, wave6): 79 passed, 2 skipped.
  • pytest -n 2 tests/integration/test_architecture_owner_rule_mutations.py tests/unit/scripts/test_architecture_runner.py tests/quality/test_quality_baselines.py: 1334 passed.
  • The lint contract is clean: ruff 0.15.12 check and format, pylint R0801, auth signals, the complexity ratchet, tests.quality.taxonomy --changed, and lint_architecture_boundaries.py --root .. engine.py stays at 2087 lines, under the 2100 guardrail.
  • A bug-ledger row is added in tests/fixtures/lifecycle_bug_ledger/bugs/4636.json, and tests/quality/test_lifecycle_bug_ledger.py passes.
promise: P-INV-I1 -- the lockfile matches the deployed files (source: issue #4636; .agents/skills/apm-lifecycle-tests)
cell: OP=uninstall TGT=single-narrowed|single-widened|multi-widened SCOPE=project   owner: commands/uninstall/recorded_targets.py
instrument: target scenario -> tests/lifecycle/scenarios/test_history_upgrade.py::test_command_after_a_target_change[*-uninstall] (Q&L W3, extends)
oracles: [I1, I9]  decisive: no file under the new target's root that the lock does not record
failing-before: W3 cells with the fix reverted -> 2 failed (I1 deployed file is not in the lock)
passing-after: W3 cells on this branch -> 4 passed
guard+mutation: owner selector added (skills-root-derivation); owner-rule mutations 1334 passed     ledger: 4636
hints executed: 'apm install' is the existing follow-up exercised by test_install_after_a_target_change on W3

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.

)

After apm.yml switched or added a target, uninstall re-integrated the
remaining packages into the new target without recording the files in
apm.lock.yaml (I1), and printed a skip hint for the root it had just
created. Uninstall now reconciles only the targets the lock records
(manifest_targets, else targets owning a recorded file) and says once
that apm install deploys and records the new target. Unchanged targets
behave as before.

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 can mistake updated manifest targets or shared skill paths for deployment evidence, causing surviving packages to be rebuilt into unrecorded target-specific paths.

2 open issues
What changed in this PR

This PR addresses #4636 by filtering uninstall survivor rebuilds through lock-recorded targets, intended to prevent deployments to newly selected targets without matching lockfile records.

Changes:

  • Adds a target filter using recorded declarations or deployed paths.
  • Adds one-time guidance to run apm install for newly selected targets.
  • Adds unit coverage, bug tracking, documentation, and architecture registration.
File Description
tests/​unit/​test_uninstall_engine_validation_logic.py Tests target filtering, fallback behavior, and remediation text.
tests/​unit/​core/​test_remediation_commands_catalog.py Records coverage context for the new remediation entry.
tests/​fixtures/​lifecycle_bug_ledger/​bugs/​4636.json Tracks the bug and regression tests.
src/​apm_cli/​core/​remediation.py Adds install guidance for undeployed targets.
src/​apm_cli/​commands/​uninstall/​recorded_targets.py Implements lock-based filtering and user guidance.
src/​apm_cli/​commands/​uninstall/​engine.py Applies filtering before survivor reintegration.
packages/​apm-guide/​.apm/​skills/​apm-usage/​commands.md Updates the uninstall usage reference.
docs/​src/​content/​docs/​reference/​cli/​uninstall.md Documents behavior after target changes.
changelog.d/​4663.fixed.md Adds the user-facing fix note.
.apm/​architecture/​owners/​install-deployment.json Registers the new module under the existing owner.

Review effort: Balanced

…st_targets (#4636)

Review follow-ups:
- manifest_targets is refreshed from apm.yml on every changed lock
  write, so a second uninstall after a target switch would have
  rebuilt into the new target. The evidence is now the target each
  recorded deployment row names.
- A legacy row on a root several targets share (.agents/) counts only
  for the one candidate target that governs it.

Co-authored-by: Copilot App <[email protected]>
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 73788cc into main Nov 21, 2026
73 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-4636-uninstall-new-target branch November 21, 2026 20:46
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] uninstall after a target change deploys the remaining packages to the new target without recording them in apm.lock.yaml

2 participants