Skip to content

fix(uninstall): an undeclared, unreachable lock row keeps no shared MCP server alive - #4900

Merged
Daniel Meppiel (danielmeppiel) merged 8 commits into
mainfrom
danielmeppiel-4896-claim-rows-mcp
Nov 23, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 8 commits into
mainfrom
danielmeppiel-4896-claim-rows-mcp

Conversation

@danielmeppiel

Copy link
Copy Markdown
Collaborator

Description

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).

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:

Type of change

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

Testing

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

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_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.
  • 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.

…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]>
Copilot AI balanced review requested due to automatic review settings November 23, 2026 02:13
Co-authored-by: copilot-swe-agent[bot] <[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

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.

1 open issue
What changed in this PR

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.
tests/​fixtures/​lifecycle_bug_ledger/​bugs/​4896.json Records the bug and regression coverage.
src/​apm_cli/​commands/​uninstall/​mcp_survivors.py Derives surviving package keys through orphan selection.
src/​apm_cli/​commands/​uninstall/​engine.py Passes filtered membership into MCP cleanup.
changelog.d/​4900.fixed.md Documents the user-visible uninstall fix.
.apm/​architecture/​owners/​install-deployment.json Registers the helper under the orphan-selection owner.

Review effort: Balanced

…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]>

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.

🔵 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

Medium severity Preserve MCP membership when project manifest reread fails

src/​apm_cli/​commands/​uninstall/​mcp_survivors.py:40

_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.

1 resolved since last review

Review effort: Balanced

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.

🟢 Approval recommended

No active review issues block approval of the uninstall-time MCP cleanup change.

No open issues 🎉

Review effort: Balanced

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.

🟢 Approval recommended

No active review issues remain for the uninstall MCP cleanup change.

No open issues 🎉

Review effort: Balanced

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

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.

1 open issue

Review effort: Balanced

…ts server

Addresses Copilot review on #4900.

Co-authored-by: copilot-swe-agent[bot] <[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.

🟢 Approval recommended

No active review issues remain for the change addressing stale MCP server retention during uninstall.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit be01fcf into main Nov 23, 2026
74 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-4896-claim-rows-mcp branch November 23, 2026 10:58
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
Parity kit and CI durations stay byte-identical to #4916 5a473a7, which
already contains this main.

Co-authored-by: Copilot App <[email protected]>
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.

2 participants