Repository navigation
fix(uninstall): LSP cleanup works without MCP state (#4045) - #4057
Merged
Daniel Meppiel (danielmeppiel) merged 2 commits intoNov 20, 2026
Merged
Conversation
Daniel Meppiel (danielmeppiel)
force-pushed
the
danielmeppiel-uninstall-lsp-4045
branch
from
November 20, 2026 02:26
ecfa638 to
a1ef9f1
Compare
Daniel Meppiel (danielmeppiel)
force-pushed
the
danielmeppiel-uninstall-lsp-4045
branch
from
November 20, 2026 07:49
a1ef9f1 to
46c7e2d
Compare
apm uninstall loaded the post-removal manifest only inside MCP cleanup, so a scope with recorded LSP state but no MCP state reached reconcile_lsp_after_uninstall without a manifest: the command exited 1 and left the server in the target config. _cleanup_stale_lsp now loads the manifest through APMPackage.from_apm_yml when MCP cleanup did not and the lockfile records LSP state (has_recorded_lsp_state, shared with the reconciler). The reconciler's behaviour is unchanged. Fixes #4045, fixes #3768 (removes the strict xfail it left behind). Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…ess, flip #4040 gate-cell-e - Ledger row for #4045 (ownership.preserve_unowned, outcome.status_matches_state). - test_lsp_only_uninstall_clears_every_harness_it_wrote: install to copilot, claude and opencode, uninstall, and assert no harness config keeps the server, at project scope and at -g with APM_HOME outside HOME. - #4040 GATE machine: gate-cell-e (#4045) is no longer a known failure. Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Daniel Meppiel (danielmeppiel)
force-pushed
the
danielmeppiel-uninstall-lsp-4045
branch
from
November 20, 2026 08:23
46c7e2d to
55c8c85
Compare
Merged
6 of 10 tasks
Daniel Meppiel (danielmeppiel)
marked this pull request as ready for review
November 20, 2026 08:55
Daniel Meppiel (danielmeppiel)
requested a review
from Sergio Sisternes (sergio-sisternes-epam)
as a code owner
November 20, 2026 08:55
Daniel Meppiel (danielmeppiel)
deleted the
danielmeppiel-uninstall-lsp-4045
branch
November 20, 2026 08:55
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The new helper omits the expected CommandResult return annotation, leaving its caller-facing interface unclear.
1 open issue
What changed in this PR
Fixes LSP cleanup during apm uninstall when no MCP state exists, covering project and user scopes for #4045 and #3768.
Changes:
- Loads the post-removal manifest when recorded LSP state requires reconciliation, using a shared state-check helper.
- Adds lifecycle coverage for surviving packages, multiple harnesses, mixed MCP/LSP packages, and malformed target configs.
- Removes resolved expected failures and records the fix in the regression ledger and changelog.
| File | Description |
|---|---|
tests/unit/commands/test_uninstall_atomic_selection.py |
Supplies the cleanup helper’s new manifest-path argument. |
tests/integration/test_uninstall_lsp_without_mcp_lifecycle.py |
Adds project- and user-scope uninstall regression coverage. |
tests/integration/test_opencode_lsp_lifecycle.py |
Removes the expected failure for OpenCode LSP cleanup. |
tests/integration/_gate_machine_kit.py |
Removes the resolved #4045 known-failure cell. |
tests/fixtures/lifecycle_bug_ledger.json |
Links #4045 to its regression tests. |
src/apm_cli/install/lsp/integration.py |
Centralizes the recorded-LSP-state check. |
src/apm_cli/commands/uninstall/cli.py |
Loads the manifest for LSP cleanup independently of MCP cleanup. |
CHANGELOG.md |
Documents the user-visible uninstall fix. |
Review effort: Balanced
| result = self.scene.install("copilot", user=self.user, extra=extra) | ||
| assert result.returncode == 0, describe(result) | ||
|
|
||
| def uninstall(self, name: str): |
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
apm uninstallfailed for any scope that records LSP servers but no MCP state. It exited 1 with "LSP cleanup failed: Cannot reconcile existing LSP state without a valid project manifest" and left the server in the target config:.github/lsp.jsonat project scope,~/.copilot/lsp-config.jsonat user scope.Root cause (
src/apm_cli/commands/uninstall/cli.py):apm_packagestarts asNoneand was loaded only inside the MCP cleanup branch, which runs only when there are pre-uninstall MCP servers or MCP target ownership._cleanup_stale_lspthen passedNonetoreconcile_lsp_after_uninstall(lsp-lifecycle owner), which correctly rejects a missing manifest.Fix: when MCP cleanup did not load the post-removal manifest and the lockfile records LSP state,
_cleanup_stale_lsploads it throughAPMPackage.from_apm_yml(manifest_path). The load happens inside its existing error handling, so a manifest problem still renders the usual "Uninstall incomplete" error. The "records LSP state" check moves into one helper in the owner module,has_recorded_lsp_state(install/lsp/integration.py). The reconciler uses the same helper, so its behaviour, including theNonerejection and the fail-closed handling of target-write failures, is unchanged. Scopes without LSP state never load the manifest here, so they gain no new failure mode.Issue and approved scope
Issue:
Fixes #4045
Fixes #3768
Human scope-approval comment: #4045 (comment)
This PR completes both issues: #3768 is the same project-scope symptom, and its strict xfail is removed here.
Pre-merge
strict=True.Type of change
Testing
New installed-CLI lifecycle tests in
tests/integration/test_uninstall_lsp_without_mcp_lifecycle.pyrun at project scope and at user scope withAPM_HOMEoutsideHOME. There is no MCP state anywhere in the scope, and the target is copilot.lsp_servers,lsp_configs,lsp_target_servers,lsp_config_provenance) and from thedeploymentsledger rows. The surviving package's server stays. Uninstalling the survivor then empties every view.lsp.jsonstill exits nonzero. The foreign bytes are preserved, and the message never says "without a valid project manifest".tests/integration/test_opencode_lsp_lifecycle.py::test_uninstall_removes_the_opencode_lsp_entrynow passes normally, with its strict xfail removed.Red/green: with the source fix reverted, 5 tests fail on main: both scopes of the LSP-only and refusal tests, plus the former xfail. The refusal test fails because the manifest error pre-empts the real target error. The mixed control passes both before and after.
APM_BINARY_PATH=.venv/bin/apm uv run --extra dev pytest -q -n 4 tests/integration/test_uninstall_lsp_without_mcp_lifecycle.py tests/integration/test_opencode_lsp_lifecycle.py tests/unit/commands/test_uninstall_atomic_selection.pysrc/change reverteduv run --extra dev pytest -q -n auto tests/unit/commands tests/unit/integration/test_lsp_integrator.py tests/unit/install/test_lsp_integration.py <15 uninstall unit files>ruff check/ruff format --check/pylint R0801/lint-auth-signals.sh/lint-architecture-boundaries.shNote, not changed here (target selection is out of scope per the record): the LSP reconciler resolves targets from
apm.ymltargets:or harness detection, not from the recordedlsp_target_servers. A project installed only with--target copilot, with notargets:and no harness signal, therefore still fails LSP cleanup with "No harness detected". The tests declaretargets: [copilot], asapm installbootstrapping does.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)
docs/src/content/docs/specs/openapm-v0.1.mdupdated(new/changed
<a id="req-XXX"></a>anchor + prose + Appendix Crow).
docs/src/content/docs/specs/manifests/openapm-v0.1.requirements.ymlupdated.
@pytest.mark.req("req-XXX")test undertests/spec_conformance/added or extended.CONFORMANCE.{md,json}regenerated viauv run --extra dev python -m tests.spec_conformance.gen_statementand committed.
No docs change: the docs already say uninstall removes the LSP servers it configured.