You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(uninstall): an undeclared, unreachable lock row keeps no shared MCP server alive - #4900
apm uninstall derived surviving MCP servers from every lock row. A direct package that apm.yml no longer declares kept a server it shared with the uninstalled package configured. That happens when the package was removed from apm.yml by hand, or with #4866 when uninstall keeps a row narrowed to a file it could not remove. The leaked server stayed in apm.lock.yaml and in the target MCP config, though no declared package needed it.
Survivors now come from the uninstall orphan owner (install/orphans.py::decide_orphan_removal). Every undeclared direct lock row is passed as a removal root. Only rows a surviving package still reaches (the #3668 rescue) keep their servers; the rest, and their unreachable descendants, do not. Gate-denied packages are excluded as before. If the evidence cannot be read, behavior is unchanged (fail-safe).
New commands/uninstall/mcp_survivors.py, registered under the orphan-package-selection owner. engine.py shrinks (2100 -> 2099 lines): the denied-package warning moves with the helper, and _cleanup_stale_mcp keeps calling gate_retirements as its guard requires.
Does this PR complete the issue, or what remains?
This PR covers the MCP half on apm uninstall, with a red-first command-level regression and a user-added-server cell. Remaining for #4896:
LSP (reconcile_lsp_after_uninstallexcluded_package_keys) and native membership.
Moving the membership derivation into integration/mcp_config_view.py so install derives the same membership. Install already passes its resolved active_package_keys, so install cells are unchanged.
uv run --extra dev pytest -q tests/unit/test_uninstall_undeclared_row_mcp.py: 3 passed. Red-first: test_a_hand_removed_package_keeps_no_shared_server_alive fails on main (shared-srv kept; no "Removed stale MCP server" line).
uv run --extra dev pytest -q -n 8 tests/unit/test_uninstall_*.py tests/unit/commands/test_uninstall_*.py <21 MCP/uninstall test modules> tests/quality/test_quality_baselines.py tests/quality/test_lifecycle_bug_ledger.py tests/integration/test_architecture_owner_rule_mutations.py -k "uninstall or mcp or baseline or ledger or orphan or gate_retire or reachability": 874 passed, 35 skipped.
Lint mirror: ruff check, ruff format --check, pylint R0801, lint-auth-signals, complexity ratchet (--base-ref origin/main), taxonomy --changed, and lint_architecture_boundaries.py --root . all clean. The CI Lint file-length guard currently fails on main itself (core/deployment_ledger.py 2101 lines; fix pending in fix(lint): keep deployment_ledger.py under the 2100-line guard (main red) #4878).
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.
…CP server alive
Uninstall derived surviving MCP servers from every lock row, so a direct
package removed from apm.yml by hand kept a server it shared with the
uninstalled package configured. Survivors now ask the uninstall orphan owner
(decide_orphan_removal) about undeclared direct rows; only those a surviving
package still reaches keep their servers. Fixes#4896.
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
An incomplete reachability walk caused by an unreadable surviving manifest can incorrectly retire an MCP server that is still needed; preserve membership when reachability evidence is missing or incomplete and add regression coverage.
This PR addresses the uninstall MCP portion of #4896 by using the existing orphan-selection owner to exclude undeclared, unreachable lock rows from surviving server membership.
Changes:
Adds a survivor-selection helper and connects it to MCP cleanup.
Adds command-level regressions for stale rows, declared survivors, and user-added servers.
Registers the helper with its architecture owner and records the fix.
File
Description
tests/unit/test_uninstall_undeclared_row_mcp.py
Tests server removal and preservation during uninstall.
…omplete
Addresses Copilot review on #4900: an unreadable surviving manifest leaves
the orphan walk incomplete, so an undeclared row it might still need keeps
its shared server.
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
A failed project-manifest reread can silently classify direct dependencies as undeclared and remove MCP membership that should be preserved, requiring strict error handling and a regression test.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Preserve MCP membership when project manifest reread fails
_read_survivor_direct_refs catches missing-file and YAML parse errors and returns ([], []), bypassing this helper's exception fallback. If the project manifest disappears or becomes malformed before this reread, every direct row becomes undeclared, and an empty-seed walk can report complete and remove MCP membership that should be preserved. Add an opt-in strict mode to the shared reader, use it here so failures return unchanged, and cover a project-manifest read failure with a regression test.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Regression coverage is missing for MCP server preservation when a surviving package depends on an undeclared root and another package is uninstalled, leaving potential removal from the lockfile and target config untested.
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
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 uninstallderived surviving MCP servers from every lock row. A direct package that apm.yml no longer declares kept a server it shared with the uninstalled package configured. That happens when the package was removed from apm.yml by hand, or with #4866 when uninstall keeps a row narrowed to a file it could not remove. The leaked server stayed inapm.lock.yamland in the target MCP config, though no declared package needed it.Survivors now come from the uninstall orphan owner (
install/orphans.py::decide_orphan_removal). Every undeclared direct lock row is passed as a removal root. Only rows a surviving package still reaches (the #3668 rescue) keep their servers; the rest, and their unreachable descendants, do not. Gate-denied packages are excluded as before. If the evidence cannot be read, behavior is unchanged (fail-safe).commands/uninstall/mcp_survivors.py, registered under theorphan-package-selectionowner.engine.pyshrinks (2100 -> 2099 lines): the denied-package warning moves with the helper, and_cleanup_stale_mcpkeeps callinggate_retirementsas its guard requires.apm uninstall B. So the red-first test lands off main, not stacked on fix(uninstall): keep the lock claim on a hook file sync cannot remove #4866.Issue and approved scope
Issue: Refs #4896
Human scope-approval comment: #4896 (comment)
Does this PR complete the issue, or what remains?
This PR covers the MCP half on
apm uninstall, with a red-first command-level regression and a user-added-server cell. Remaining for #4896:reconcile_lsp_after_uninstallexcluded_package_keys) and native membership.integration/mcp_config_view.pyso install derives the same membership. Install already passes its resolvedactive_package_keys, so install cells are unchanged.Type of change
Testing
Validation evidence:
uv run --extra dev pytest -q tests/unit/test_uninstall_undeclared_row_mcp.py: 3 passed. Red-first:test_a_hand_removed_package_keeps_no_shared_server_alivefails on main (shared-srvkept; no "Removed stale MCP server" line).uv run --extra dev pytest -q -n 8 tests/unit/test_uninstall_*.py tests/unit/commands/test_uninstall_*.py <21 MCP/uninstall test modules> tests/quality/test_quality_baselines.py tests/quality/test_lifecycle_bug_ledger.py tests/integration/test_architecture_owner_rule_mutations.py -k "uninstall or mcp or baseline or ledger or orphan or gate_retire or reachability": 874 passed, 35 skipped.--base-ref origin/main), taxonomy--changed, andlint_architecture_boundaries.py --root .all clean. The CI Lint file-length guard currently fails on main itself (core/deployment_ledger.py2101 lines; fix pending in fix(lint): keep deployment_ledger.py under the 2100-line guard (main red) #4878).Changelog
changelog.d/<pr>.<section>.md, holdingone line: user-visible effect first, 25 words or fewer, ending with
(#PR); breaking changes only under upgrade notes; no Highlights; nonew lines under
## [Unreleased]. Seechangelog.d/README.mdand.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.