Repository navigation
fix(mcp): keep the .mcp.json move pending across lock rewrites and frozen upgrades - #3899
Conversation
Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Ownership adoption can incorrectly claim and later delete user-authored MCP entries, while immediate post-upgrade changes or removals can still cause conflicts or leave stale entries.
3 open issues
What changed in this PR
This PR hardens the migration of Copilot project MCP servers to root .mcp.json, preserving legacy ownership claims across lock rewrites and adding recovery for entries moved during frozen installs.
Changes:
- Preserve the legacy lock version until the MCP phase translates ownership claims.
- Add conditional ownership recovery for matching root entries after frozen upgrades.
- Add lifecycle regressions and document the migration behavior.
| File | Description |
|---|---|
tests/unit/install/test_mcp_integration_extraction.py |
Update expectations for version-stamping calls. |
tests/integration/test_copilot_root_mcp_json_lifecycle.py |
Add lock-rewrite and frozen-upgrade regression cases. |
src/apm_cli/integration/mcp_integrator.py |
Add explicit lock-version stamping support. |
src/apm_cli/integration/mcp_integrator_install.py |
Record ownership for matching managed entries. |
src/apm_cli/install/phases/lockfile.py |
Preserve versions associated with untranslated claims. |
src/apm_cli/install/mcp/retired_destinations.py |
Identify pending claims and entries absent from retired files. |
src/apm_cli/install/mcp/ownership.py |
Add conditional root-entry adoption. |
src/apm_cli/install/mcp/integration.py |
Coordinate adoption and post-translation version stamping. |
docs/src/content/docs/reference/lockfile-spec.md |
Document version preservation and ownership recovery. |
CHANGELOG.md |
Summarize the migration fixes. |
Review effort: Balanced
APM Review Panel: advisory recommendationFixes #3881: the pending panel-mode=lean; personas=python-architect, test-coverage-expert, apm-ceo cc Daniel Meppiel (@danielmeppiel) Panel summary
CEO arbitrationNo panelist returned a blocking finding. The remaining gaps are in fail-closed paths, not the happy path. The most important: The architect findings are design, not correctness. The Principle alignment
Recommended follow-ups (prioritized)
Ship recommendation: ship with follow-upsMerge once the requested review from Advisory only: this panel does not gate merge. Panel-reviewed: head Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
To allow these domains, add them to the network:
allowed:
- defaults
- "pypi.org"See Network Configuration for more information.
|
Panel folds on #3899: - An entry --frozen wrote from the locked declaration is APM's even after apm.yml changes: it is updated instead of reported as a conflict. - A copilot claim counts as moved only while .github/mcp.json still exists (the heal never deletes it), so a deleted file never grants adoption. - Real-binary traps for every adoption bound on installs that succeed, and a unit test that runs the package phase and the MCP stamp as a 0.37 binary. - lockfile-spec states exactly when ownership is taken. apm-spec-waiver: upgrade-heal hardening of the 0.37 copilot .mcp.json move; no normative spec surface changes Co-authored-by: Copilot App <[email protected]>
APM Review Panel:
|
| Persona | B | R | N | Takeaway |
|---|---|---|---|---|
| Python Architect | 0 | 3 | 0 | Hold and stamp share one predicate, and the ContextVar adoption is tightly bounded. Gaps: frozen then edit args still conflicts, apm_version is now overloaded, and a missing retired file widens adoption. |
| Test Coverage Expert | 0 | 3 | 0 | Both defects fail on main, and bounds 3-4 are trapped. Bound 5's trap is masked by its own conflict, bounds 1-2 have no negative trap, and the D1 symptom is only a proxy at 0.36.1. |
| Supply Chain Security Expert | 0 | 2 | 0 | Adoption is bounded and fails closed on symlinked or unreadable files, and it records a fresh fingerprint. But a missing retired file still counts as proof of a frozen move. |
B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.
Top 3 follow-ups
- [Python Architect] Add a regression test showing a held pre-0.37
apm_versioncannot re-armlegacy_plugin_compat(==0.28.0) orbuggy_lockfile_recovery(<=0.12.2) for entries the running binary wrote. Then file a spec-scoped issue for a dedicated lock field for MCP translation state. --apm_versionnow does double duty. The reasoning is sound but untested, and a future refactor of either compat gate could silently break it. - [Supply Chain Security Expert] Pin the accepted vscode residual (a 0.36 vscode claim with
.vscode/mcp.jsonmissing counts as moved) with a named test for the cross-machine--frozen/ gitignored.vscode/case. -- Leaving a bound unproven on a surface where APM can delete user config is itself a gap. A named contract test makes the residual a deliberate decision. - [Test Coverage Expert] Add a unit test for the no-MCP-deps branch of
run_mcp_integrationasserting that a pre-0.37 lock with untranslated copilot claims is stamped (stamp_version=True). -- It is the only stamp path without its own assertion. If it regressed, the heal would stay pending forever for projects that drop all MCP deps.
Recommendation
Merge this before cutting 0.37.0. Both defects that could lose or corrupt user MCP entries are fixed within the accepted #3881 scope. Every non-blocking finding that fits that scope is folded, and the folds are covered by mutation-checked tests. Track the three follow-ups. The most important is the guard test that pins the held apm_version against the 0.28 and 0.12.2 compat gates, together with the spec-scoped dedicated-field proposal, because that is where a future refactor could silently undo this fix.
Full per-persona findings
Python Architect
- [recommended] D2 still reproduces when the user edits the server's args before the first plain install after
--frozenatsrc/apm_cli/install/mcp/ownership.py:352
Adoption fired only when the entry equalled the CURRENT render. Running--frozen, then changing args, gave CONFLICT on every later install.
Suggested: for adoptable names, also accept the render of the locked declaration and return UPDATE_MANAGED. (Folded at 5d45502.)
Proof (missing at):tests/integration/test_copilot_root_mcp_json_lifecycle.py::test_frozen_upgrade_keeps_the_root_entry_apm_wrote (missing variant: change args before the first plain install)-- proves: after a --frozen upgrade, a user can change an MCP server's args on the next install without a conflict --force cannot clear. [portability-by-manifest,devx] - [recommended] The lock-wide
apm_versionnow also marks whether MCP claims are translated, and existing readers already gate on it atsrc/apm_cli/install/phases/lockfile.py:637
One predicate drives the hold and the stamp, and the stamp lands in the same write that persists the heal. The cost:legacy_plugin_compat.py:60/116(==0.28.0) also reads the field, and that path stays armed during the hold. No test shows it stays inert.
Suggested: a regression test, a guard note, and a dedicated lock field as a follow-up.
Proof (missing at):tests/integration/test_copilot_root_mcp_json_lifecycle.py-- proves: an old lock version kept for MCP reasons does not re-trigger unrelated version-gated compat upgrades. [portability-by-manifest] - [recommended] A missing retired file counts as "moved by --frozen", so a fresh clone with a gitignored
.vscode/can adopt the user's identical root entry atsrc/apm_cli/install/mcp/retired_destinations.py:398
The ContextVar hook itself is tightly bounded: it is set only aroundMCPIntegrator.install, reset infinally, applies only when a request exists and the name is unmanaged, and is copilot-only. The weak point is the input set.
Suggested: tighten for copilot, or accept with a test. (Copilot half folded; vscode half accepted.)
Proof (missing at):tests/integration/test_copilot_root_mcp_json_lifecycle.py-- proves: a hand-written .mcp.json entry is not taken over just because a gitignored retired file is missing. [secure-by-default,multi-harness-support]
Test Coverage Expert
- [recommended] The "undeclared" half of
test_moved_claim_never_adopts_a_differing_or_undeclared_root_entrycannot fail, so bound (5) has no trap attests/integration/test_copilot_root_mcp_json_lifecycle.py:637
The install fails on purpose and re-raises before cleanup, so the undeclared assertion holds whatever the code does.
Suggested: split the test, and add a case where the install succeeds. (Folded.)
Proof (missing at):tests/integration/test_copilot_root_mcp_json_lifecycle.py::test_moved_claim_never_adopts_an_undeclared_root_entry_on_a_successful_install-- proves: an identical entry for an undeclared server is never adopted or deleted. [secure-by-default,portability-by-manifest] - [recommended] Bounds (1) and (2), and the fail-closed branch of bound (3), have no negative trap at
tests/integration/test_copilot_root_mcp_json_lifecycle.py:637
No test seeds a 0.37.0 lock with a vscode claim, a lock claiming another name, or a symlinked retired file.
Suggested: parametrized successful-install cases. (Folded.)
Proof (missing at):tests/integration/test_copilot_root_mcp_json_lifecycle.py::test_moved_claim_never_adopts_an_undeclared_root_entry_on_a_successful_install[lock_037_vscode_claim|lock_036_claims_other|retired_symlinked]-- proves: APM adopts only when a pre-0.37 lock claimed that exact server and no retired file holds it. [secure-by-default,portability-by-manifest] - [recommended] The D1 real-binary test traps the version hold but cannot show the >=0.37 symptom, and no unit test runs the package phase plus restamp as a 0.37 binary at
tests/unit/install/test_copilot_project_mcp_destination.py
The binary is 0.36.1, so a restamped lock still predates 0.37, andstamp_versionis only covered by two exact-kwargs mocks.
Suggested: a unit test patchinginstalled_apm_versionto 0.37.0. (Folded intests/unit/install/test_mcp_lockfile_determinism.py; no-MCP-deps path open.)
Proof (missing at):tests/unit/install/test_copilot_project_mcp_destination.py::test_untranslated_claims_keep_the_lock_version_until_the_mcp_phase_stamps_it-- proves: under a 0.37 APM, a partial install never relabels a pre-0.37 lock. [portability-by-manifest,secure-by-default]
Supply Chain Security Expert
- [recommended] A missing retired file is not proof that
--frozenmoved the entry; an identical user-authored root entry could be adopted and later deleted atsrc/apm_cli/install/mcp/retired_destinations.py:389
Fail-closed handling covers symlinked, unreadable and non-dict files, but a missing file is the normal state of a fresh clone with a gitignored.vscode/. Impact is limited: the entry is byte-identical to APM's render of a declared server, and a crafted lock gains nothingapm.ymlcannot already do.
Suggested: narrow the proof of absence, or accept with a test. (Copilot half folded; vscode half accepted.)
Proof (missing at):tests/integration/test_copilot_root_mcp_json_lifecycle.py::test_legacy_vscode_claim_with_absent_retired_file_and_identical_user_root_entry-- proves: a user's hand-written .mcp.json entry is not deleted just because an old lock named the same server and the retired file is missing. [secure-by-default,portability-by-manifest] - [recommended] lockfile-spec said adoption happens "when
apm install --frozenalready moved the entry", but the code triggers on absence atdocs/src/content/docs/reference/lockfile-spec.md:185
The documented contract understated when APM takes ownership.
Suggested: reword to match the code. (Folded.)
This panel is advisory. It does not block merge. Re-apply the
panel-review label after addressing feedback to re-run.
Generated by autopilot-pr-review-worker. This comment is AI-generated and may contain errors.
…ct JSON proof Review folds on #3899: - After an `apm install --frozen` upgrade, removing a self-defined server from apm.yml now removes the .mcp.json entry that --frozen wrote, on the same proof as adoption (pre-0.37 claim, no retired entry, .github/mcp.json present for copilot claims, entry JSON-identical to APM's render of the locked declaration). Registry entries stay where they are. - Adoption compares by JSON type as well as value (true is not 1). - Real-binary tests for removal (both cleanup branches), an edited entry that is kept, and the accepted vscode residual in a clone without .vscode/; unit tests for exact-JSON adoption and the no-MCP-deps stamp. apm-spec-waiver: upgrade-heal hardening of the 0.37 copilot .mcp.json move; no normative spec surface changes Co-authored-by: Copilot App <[email protected]>
…ozen upgrades Two ways the copilot root .mcp.json move (#3875) could strand or disown MCP entries after an upgrade: - The package phase restamped a pre-0.37 lock with the running version while carrying its copilot claims verbatim (apm install --only apm, or a first install whose MCP phase failed). The next install then read the 0.36 .github/mcp.json claim as .mcp.json ownership: the old entry was never moved, and an identical user .mcp.json entry was adopted and later deleted. The lock now keeps its pre-0.37 apm_version until the MCP phase has translated those claims, and that phase stamps it. - apm install --frozen moves entries but cannot record the write, so the next install read APM's own .mcp.json entry as foreign: removing the server left it behind and changing it failed with a conflict. For a pre-0.37 copilot/vscode claim no retired file holds any more, a declared server's .mcp.json entry equal to the requested render is now adopted; any other entry stays a conflict. apm-spec-waiver: upgrade-heal hardening of the 0.37 copilot .mcp.json move; no normative spec surface changes Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Panel folds on #3899: - An entry --frozen wrote from the locked declaration is APM's even after apm.yml changes: it is updated instead of reported as a conflict. - A copilot claim counts as moved only while .github/mcp.json still exists (the heal never deletes it), so a deleted file never grants adoption. - Real-binary traps for every adoption bound on installs that succeed, and a unit test that runs the package phase and the MCP stamp as a 0.37 binary. - lockfile-spec states exactly when ownership is taken. apm-spec-waiver: upgrade-heal hardening of the 0.37 copilot .mcp.json move; no normative spec surface changes Co-authored-by: Copilot App <[email protected]>
…ct JSON proof Review folds on #3899: - After an `apm install --frozen` upgrade, removing a self-defined server from apm.yml now removes the .mcp.json entry that --frozen wrote, on the same proof as adoption (pre-0.37 claim, no retired entry, .github/mcp.json present for copilot claims, entry JSON-identical to APM's render of the locked declaration). Registry entries stay where they are. - Adoption compares by JSON type as well as value (true is not 1). - Real-binary tests for removal (both cleanup branches), an edited entry that is kept, and the accepted vscode residual in a clone without .vscode/; unit tests for exact-JSON adoption and the no-MCP-deps stamp. apm-spec-waiver: upgrade-heal hardening of the 0.37 copilot .mcp.json move; no normative spec surface changes Co-authored-by: Copilot App <[email protected]>
a09f651 to
98d26b1
Compare
Merge worker: ready to merge at
|


Description
This fixes two data-safety defects in the move of copilot project MCP servers to root
.mcp.json(#3875). I reproduced both with the real binary onmainfirst.copilotclaims forward unchanged. This happened underapm install --only apm, and on a first install whose MCP phase failed, for example on a connection conflict. The next install then read the 0.36.github/mcp.jsonclaim as.mcp.jsonownership. The old entry was never moved, and an identical user.mcp.jsonentry was adopted and then deleted when the server leftapm.yml.copilot/vscodeclaims keeps itsapm_version(lock_holds_untranslated_mcp_claims). Only the MCP phase stamps the running version, once it has persisted the translated claims.--frozenupgrade disowned APM's own.mcp.jsonentry.--frozenmoves the entries but cannot record that write. The next install treated APM's entry as foreign: removing the server left the entry behind, and changing it failed with a conflict.copilot/vscode;copilotclaim,.github/mcp.jsonstill exists (the heal never deletes it);apm.ymlchanged), and an undeclared self-defined server's entry is removed. Any other entry keeps today's behavior.vscodeclaim, a missing.vscode/mcp.jsoncounts as moved. The frozen heal deletes that file itself, and.vscode/is often gitignored. A contract test pins this.apm_versionnow doubles as the "claims translated" marker, but only until the first successful MCP phase stamps it. Onmain, MCP-only projects already keep an oldapm_versionindefinitely, so the window gets shorter, not longer.Not planned, per the binding record: canonicaliser unification, shared-destination derivation, the launcher helper, the sensitive-env warning and the UX nits. Merge-time deferrals that do not meet the data-safety bar on
main:test_legacy_copilot_claim_never_adopts_a_user_root_entry).Issue and approved scope
Issue: Closes #3881
Human scope-approval comment: #3881 (comment)
This PR completes the issue under the pruned record. Every item that meets the data-safety bar is fixed; the rest is not planned.
Type of change
Testing
New real-binary tests in
tests/integration/test_copilot_root_mcp_json_lifecycle.py. Each new behavior test failed onmainor under a mutation of its guard:test_a_lock_rewrite_before_the_mcp_phase_keeps_the_heal_pending[only-apm|mcp-conflict]test_frozen_upgrade_keeps_the_root_entry_apm_wrote[copilot|vscode]test_frozen_upgrade_then_a_changed_declaration_updates_the_root_entrytest_frozen_upgrade_then_removing_the_server_removes_its_root_entry[last-server|one-of-two]test_frozen_upgrade_keeps_an_edited_root_entry_of_a_removed_server,test_moved_claim_never_adopts_a_differing_root_entry,test_identical_root_entry_stays_the_users_unless_every_adoption_bound_holds[lock-0.37|claims-another-name|github-file-missing|github-symlinked]test_a_committed_frozen_move_is_adopted_in_a_clone_without_vscode_dirNew unit tests:
test_package_phase_keeps_a_pre_root_version_until_the_mcp_phase_stamps_it(runs as a 0.37 binary)test_moved_root_entry_is_adopted_only_when_json_identicaltest_no_deps_stamps_a_lock_whose_claims_it_translatedResults:
APM_E2E_TESTS=1 APM_BINARY_PATH=$PWD/.venv/bin/apm .venv/bin/python -m pytest -p no:xdist tests/integration/test_copilot_root_mcp_json_lifecycle.py tests/integration/test_mcp_retired_shape_heal_lifecycle.py tests/integration/test_install_mcp_lockfile_determinism.py tests/integration/test_frozen_native_service_lifecycle.py tests/integration/test_json_mcp_native_conflict_lifecycle.py tests/integration/test_native_mcp_collision_lifecycle.py tests/integration/test_target_manifest_upgrade_lifecycle.py tests/integration/test_ownership_invariant_lifecycle.py tests/integration/test_selective_install_mcp.py: 206 collected, 0 failed at the first head. At the final head:test_copilot_root_mcp_json_lifecycle.py38 passed, and the heal/determinism/frozen/conflict/upgrade suites 123 passed.tests/unit/install/andtests/unit/integration/(mcp, lockfile, retired, native, uninstall): 1252 passed.lint-auth-signals.shandlint_architecture_boundaries.py --root .: clean.Fail-before check: with only
src/reverted, the four new behavior tests fail. Onmain,apm_versionreads '0.36.1' where '0.35.0' is expected, andmcp_target_serversis{}where{'copilot': ['echo']}is expected.Note: the binary on
mainreports 0.36.1, so a real-binary test cannot show the D1 symptom itself. A restamp to 0.36.1 still reads as pre-0.37. The tests instead assert the invariant that closes D1: a pre-0.37 lock keeps its version until the MCP phase has moved its claims.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.