Skip to content

fix(uninstall): LSP cleanup works without MCP state (#4045) - #4057

Merged
Daniel Meppiel (danielmeppiel) merged 2 commits into
mainfrom
danielmeppiel-uninstall-lsp-4045
Nov 20, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 2 commits into
mainfrom
danielmeppiel-uninstall-lsp-4045

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

apm uninstall failed 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.json at project scope, ~/.copilot/lsp-config.json at user scope.

Root cause (src/apm_cli/commands/uninstall/cli.py): apm_package starts as None and was loaded only inside the MCP cleanup branch, which runs only when there are pre-uninstall MCP servers or MCP target ownership. _cleanup_stale_lsp then passed None to reconcile_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_lsp loads it through APMPackage.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 the None rejection 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

Type of change

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

Testing

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

New installed-CLI lifecycle tests in tests/integration/test_uninstall_lsp_without_mcp_lifecycle.py run at project scope and at user scope with APM_HOME outside HOME. There is no MCP state anywhere in the scope, and the target is copilot.

  • LSP-only uninstall with a survivor: the uninstall exits 0. The removed server is gone from the target config and from all four lockfile LSP views (lsp_servers, lsp_configs, lsp_target_servers, lsp_config_provenance) and from the deployments ledger rows. The surviving package's server stays. Uninstalling the survivor then empties every view.
  • Mixed MCP+LSP package (control): it still uninstalls cleanly.
  • Real target refusal (control): a malformed lsp.json still exits nonzero. The foreign bytes are preserved, and the message never says "without a valid project manifest".
  • [BUG] apm uninstall of a package with LSP dependencies exits 1 and leaves the LSP entry behind #3768: tests/integration/test_opencode_lsp_lifecycle.py::test_uninstall_removes_the_opencode_lsp_entry now 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.

Command Result
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.py 39 passed
Same, with the src/ change reverted 5 failed (as above)
uv 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> 1688 passed
ruff check / ruff format --check / pylint R0801 / lint-auth-signals.sh / lint-architecture-boundaries.sh clean

Note, not changed here (target selection is out of scope per the record): the LSP reconciler resolves targets from apm.yml targets: or harness detection, not from the recorded lsp_target_servers. A project installed only with --target copilot, with no targets: and no harness signal, therefore still fails LSP cleanup with "No harness detected". The tests declare targets: [copilot], as apm install bootstrapping does.

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: docs/src/content/docs/specs/openapm-v0.1.md updated
    (new/changed <a id="req-XXX"></a> anchor + prose + Appendix C
    row).
  • Manifest edit: docs/src/content/docs/specs/manifests/openapm-v0.1.requirements.yml
    updated.
  • Test edit: a @pytest.mark.req("req-XXX") test under
    tests/spec_conformance/ added or extended.
  • CONFORMANCE.{md,json} regenerated via
    uv run --extra dev python -m tests.spec_conformance.gen_statement
    and committed.
  • N/A -- this PR does not change OpenAPM-observable behaviour.

No docs change: the docs already say uninstall removes the LSP servers it configured.

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]>
@danielmeppiel
Daniel Meppiel (danielmeppiel) marked this pull request as ready for review November 20, 2026 08:55
Copilot AI balanced review requested due to automatic review settings November 20, 2026 08:55
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit ab6d005 into main Nov 20, 2026
36 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-uninstall-lsp-4045 branch November 20, 2026 08:55

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

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):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants