Repository navigation
fix(uninstall): LSP cleanup uses recorded targets (#4059) - #4068
Merged
Daniel Meppiel (danielmeppiel) merged 4 commits intoNov 20, 2026
Merged
Conversation
Daniel Meppiel (danielmeppiel)
force-pushed
the
danielmeppiel-uninstall-lsp-4059
branch
2 times, most recently
from
November 20, 2026 04:09
de24ba8 to
97ba1b3
Compare
Daniel Meppiel (danielmeppiel)
force-pushed
the
danielmeppiel-uninstall-lsp-4045
branch
from
November 20, 2026 07:49
a1ef9f1 to
46c7e2d
Compare
Daniel Meppiel (danielmeppiel)
force-pushed
the
danielmeppiel-uninstall-lsp-4059
branch
from
November 20, 2026 07:49
97ba1b3 to
d8928f5
Compare
Daniel Meppiel (danielmeppiel)
force-pushed
the
danielmeppiel-uninstall-lsp-4045
branch
from
November 20, 2026 08:23
46c7e2d to
55c8c85
Compare
Daniel Meppiel (danielmeppiel)
force-pushed
the
danielmeppiel-uninstall-lsp-4059
branch
from
November 20, 2026 08:23
d8928f5 to
d2ef13a
Compare
Merged
6 of 10 tasks
Uninstall-time LSP reconciliation re-selected targets like a fresh install (saved apm config target, then harness autodetection) and never read the lsp_target_servers the lockfile records. A project installed with --target copilot and no targets: failed with "No harness detected", and a saved default moved a surviving package's server to another harness. - core/target_detection.py: resolve_deployment_target_decision reconciles an existing deployment (manifest targets:, then recorded targets, then a caller fallback only when nothing is recorded); resolve_audit_target_decision delegates to it. - install/lsp/integration.py: reconcile_lsp_after_uninstall passes the recorded LSP targets (recorded_lsp_targets) and keeps today's selection as the fallback for a lock without lsp_target_servers. - Guards: lsp lifecycle requires the recorded-target call; the deployment resolver has one owner; two mutation cases. - Tests: installed-CLI lifecycle at project and user scope (APM_HOME outside HOME) plus controls; resolver unit cases. Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Daniel Meppiel (danielmeppiel)
force-pushed
the
danielmeppiel-uninstall-lsp-4059
branch
from
November 20, 2026 08:56
d2ef13a to
9421d22
Compare
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Daniel Meppiel (danielmeppiel)
marked this pull request as ready for review
November 20, 2026 09:31
Daniel Meppiel (danielmeppiel)
requested a review
from Sergio Sisternes (sergio-sisternes-epam)
as a code owner
November 20, 2026 09:31
Daniel Meppiel (danielmeppiel)
deleted the
danielmeppiel-uninstall-lsp-4059
branch
November 20, 2026 09:31
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Uninstalling a package without manifest targets can incorrectly replay surviving package servers into bundle-only targets, requiring package/project-based target selection and a mixed-owner regression test.
1 open issue
What changed in this PR
This PR addresses #4059 by making uninstall-time LSP reconciliation use recorded deployment targets instead of saved defaults or harness detection. It builds on #4057’s fix for LSP cleanup without MCP state.
Changes:
- Shares target precedence between audit and LSP uninstall: manifest targets, recorded targets, then fallback.
- Adds project- and user-scope lifecycle coverage, resolver tests, and architecture guards.
- Documents the cleanup behavior and records the regression in the bug ledger and changelog.
| File | Description |
|---|---|
tests/unit/core/test_audit_target_decision.py |
Tests target precedence and fallback invocation. |
tests/integration/test_uninstall_lsp_recorded_targets_lifecycle.py |
Covers recorded targets, saved defaults, legacy locks, and malformed configs. |
tests/integration/test_architecture_owner_rule_mutations.py |
Tests detection of target-selection bypasses and duplicate owners. |
tests/fixtures/lifecycle_bug_ledger.json |
Records #4059 and its regression coverage. |
src/apm_cli/install/lsp/integration.py |
Reads recorded LSP targets for uninstall reconciliation. |
src/apm_cli/core/target_detection.py |
Introduces the shared deployment-target resolver. |
scripts/architecture_linter/checks/registry_owner_guards.py |
Enforces a single deployment-target resolver owner. |
scripts/architecture_linter/checks/install_lsp_plugin.py |
Requires the recorded-target selection call. |
docs/src/content/docs/reference/cli/uninstall.md |
Explains LSP cleanup target precedence. |
docs/src/content/docs/consumer/install-mcp-servers.md |
Describes recorded-target cleanup behavior. |
CHANGELOG.md |
Announces the uninstall LSP target-selection fix. |
Review effort: Balanced
|
|
||
| def recorded_lsp_targets(lockfile: "LockFile") -> tuple[str, ...]: | ||
| """Return the LSP targets *lockfile* records APM writing servers to.""" | ||
| return tuple(sorted(name for name, servers in _target_server_sets(lockfile).items() if servers)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description
TL;DR
apm uninstallreconciled surviving LSP servers by re-choosing targets the way a fresh install does (savedapm config target, then harness autodetection), never reading thelsp_target_serversthe lockfile records. It now keeps survivors on the recorded targets through one owner incore/target_detection.py. A project installed with--target copilotand notargets:no longer fails with "No harness detected", and a saved default no longer moves surviving servers to another harness.Fixes #4059
Note
Follows #4057 (merged): that PR loads the manifest for LSP-only scopes; this one fixes which targets the reconciliation uses. Now based on main, so CI runs in full.
Problem (WHY)
apm install --target copilot, notargets:, no harness marker:apm uninstall <pkg>exits 1 withLSP cleanup failed: No harness detectedand cleans nothing (install/lsp/integration.pyreconcile_lsp_after_uninstallcalledresolve_package_target_decisionwith no explicit target).apm config target claude, uninstalling one package at project and user scope writes the surviving server into.claude/skills/apm-lsp/...and removes it from.github/lsp.json/~/.copilot/lsp-config.json(lock:{claude: [keep-lsp]}).Why these matter: the target owner already states the rule for existing deployments:
resolve_audit_target_decision— "A saved install default is not a request to retarget an existing deployment." The lockfile reference promises thatlsp_target_serversis the record "Reinstall and uninstall use … to remove stale executable entries" (docs/src/content/docs/reference/lockfile-spec.md).Approach (WHAT)
core/target_detection.pygainsresolve_deployment_target_decision: manifesttargets:→ recorded targets → caller fallback only when nothing is recorded.resolve_audit_target_decisiondelegates to it (one owner, two consumers).reconcile_lsp_after_uninstallpassesrecorded_lsp_targets(lockfile)and keeps today's selection (resolve_package_target_decision) as the fallback for a lock withoutlsp_target_servers.*_cannot_bypass_ownertest proves both guards fire (the registry matrix keeps one case per guard).Implementation (HOW)
src/apm_cli/core/target_detection.pyauto-detectfallback). Install precedence untouched.src/apm_cli/install/lsp/integration.pyrecorded_lsp_targets()reads non-emptylsp_target_serverskeys; reconcile routes through the shared resolver. Removal was already per recorded runtime; only the survivor target set changed.scripts/architecture_linter/checks/{install_lsp_plugin,registry_owner_guards}.pytests/integration/test_uninstall_lsp_recorded_targets_lifecycle.pyAPM_HOMEoutsideHOME): 2 regression tests, 2 controls, and a malformed-config fail-closed test that is a control at user scope and a regression at project scope.src/apm_cli/core/target_detection.py(rebase)MANIFEST_TARGET_SOURCE;resolve_audit_target_decisiondelegates.tests/unit/core/test_audit_target_decision.py,tests/integration/test_architecture_owner_rule_mutations.pytest_uninstall_lsp_target_selection_cannot_bypass_owner(2 source overrides throughrun_selected_rules).Diagrams
Legend: the uninstall-time target decision after this PR; the saved default and autodetection are reachable only from the right-most branch.
flowchart LR R[reconcile_lsp_after_uninstall] --> D{manifest targets declared} D -->|yes| M[EffectiveTargetDecision from apm.yml] D -->|no| L{lsp_target_servers recorded} L -->|yes| K[EffectiveTargetDecision from deployment ledger] L -->|no| F[resolve_package_target_decision fallback] M --> W[run_lsp_integration persist false] K --> W F --> WTrade-offs
targets:wins, as install does); rejected strictly-recorded-on-uninstall because it would diverge from what the nextapm installdoes. Retargeting when they disagree is out of scope per the record..claude/(or another recorded target root) was removed by hand, uninstall writes surviving servers back to it, because the lockfile says APM manages them there. This is intended: the record makes the lockfile's targets authoritative, and the nextapm installwould do the same.lsp_target_serverskeeps today's selection instead of failing; covered by a control test."apm.yml"source string insideresolve_audit_target_decision; the rebase is cosmetic (the literal moves into the shared resolver).Benefits
apm uninstallexits 0 for a--target copilotproject with notargets:(was exit 1, nothing cleaned).apm config targetnever moves a surviving LSP server during uninstall, at project and user scope.Docs re-home after #3996
Rebased onto 0.37.0 (main 2e01e13), which includes #3996.
reference/cli/uninstall.md(step 6, LSP cleanup targets)consumer/install-lsp-servers.md(Stale server cleanup)consumer/install-mcp-servers/install-mcp-servers.md## LSP serversIssue and approved scope
Issue:
Fixes #4059
Human scope-approval comment: #4059 (comment) (
scripts/governance/eligibility.cjs→record-present, approver Daniel Meppiel (@danielmeppiel))Completes the issue: installed-CLI lifecycle at project and user scope with controls, docs by topic, one CHANGELOG line.
Type of change
Testing
Red on base, green on branch (
APM_E2E_TESTS=1 APM_BINARY_PATH=.venv/bin/apm, basesrc= a1ef9f1):uninstall_without_targets_key_uses_the_recorded_target[project]uninstall_without_targets_key_uses_the_recorded_target[user]saved_default_target_never_moves_a_surviving_server[project]saved_default_target_never_moves_a_surviving_server[user]malformed_recorded_target_config_still_fails_closed[project]malformed_recorded_target_config_still_fails_closed[user]manifest_targets_still_win_over_the_recorded_target[project, user](asserts the claude plugin contents)lock_without_recorded_targets_keeps_the_fallback[project, user]Local evidence (no CI on a stacked base)
How to test:
apm install --target copilotin a project with an LSP package and notargets:, thenapm uninstall <pkg>→ exit 0, server gone from.github/lsp.jsonand the lock.apm config set target claude, uninstall one → survivor stays in.github/lsp.json; no.claude/skills/apm-lsp.--globalandAPM_HOMEoutsideHOME.Changelog
## [Unreleased]inCHANGELOG.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.Spec conformance (OpenAPM v0.1)
CONFORMANCE.{md,json}regeneratedCo-authored-by: Copilot [email protected]