Skip to content

fix(mcp): keep the .mcp.json move pending across lock rewrites and frozen upgrades - #3899

Merged
Daniel Meppiel (danielmeppiel) merged 4 commits into
mainfrom
danielmeppiel-improved-garbanzo
Nov 19, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 4 commits into
mainfrom
danielmeppiel-improved-garbanzo

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

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 on main first.

  1. A lock rewrite before the MCP phase made the move skip. The package phase restamped a pre-0.37 lock with the running version and carried its copilot claims forward unchanged. This happened under apm 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.json claim as .mcp.json ownership. The old entry was never moved, and an identical user .mcp.json entry was adopted and then deleted when the server left apm.yml.
    • Fix: a lock that still holds pre-0.37 copilot/vscode claims keeps its apm_version (lock_holds_untranslated_mcp_claims). Only the MCP phase stamps the running version, once it has persisted the translated claims.
  2. A --frozen upgrade disowned APM's own .mcp.json entry. --frozen moves 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.
    • Fix (bounds approved by the captain): APM recognizes the entry as its own only when all of these hold:
      • the lock predates 0.37 and claims that server for copilot/vscode;
      • neither retired file holds the server any more;
      • for a copilot claim, .github/mcp.json still exists (the heal never deletes it);
      • the entry is JSON-identical to APM's render, either the current one or the one from the locked declaration.
    • When those hold, a declared server is adopted (and updated if apm.yml changed), and an undeclared self-defined server's entry is removed. Any other entry keeps today's behavior.
    • Limitation: registry servers cannot be re-rendered from the lock, so they are adopted only on an exact current-render match and are never removed by this path.
    • Accepted bound: for a vscode claim, a missing .vscode/mcp.json counts as moved. The frozen heal deletes that file itself, and .vscode/ is often gitignored. A contract test pins this.

apm_version now doubles as the "claims translated" marker, but only until the first successful MCP phase stamps it. On main, MCP-only projects already keep an old apm_version indefinitely, 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:

  • An identical foreign root entry on a normal (non-frozen) upgrade is not adopted; it heals when the server is dropped (test_legacy_copilot_claim_never_adopts_a_user_root_entry).
  • The retire helper, the dot-segment nit and the dual-retired-file name are refactors or nits.
  • The frozen-check deferral is the D2 fix above.

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

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

Testing

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

New real-binary tests in tests/integration/test_copilot_root_mcp_json_lifecycle.py. Each new behavior test failed on main or 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_entry
  • test_frozen_upgrade_then_removing_the_server_removes_its_root_entry[last-server|one-of-two]
  • negative traps: 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]
  • contract test for the accepted vscode bound: test_a_committed_frozen_move_is_adopted_in_a_clone_without_vscode_dir

New 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_identical
  • test_no_deps_stamps_a_lock_whose_claims_it_translated

Results:

  • 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.py 38 passed, and the heal/determinism/frozen/conflict/upgrade suites 123 passed.
  • Unit tests in tests/unit/install/ and tests/unit/integration/ (mcp, lockfile, retired, native, uninstall): 1252 passed.
  • Lint contract: ruff 0.15.12 check and format, pylint R0801, lint-auth-signals.sh and lint_architecture_boundaries.py --root .: clean.

Fail-before check: with only src/ reverted, the four new behavior tests fail. On main, apm_version reads '0.36.1' where '0.35.0' is expected, and mcp_target_servers is {} where {'copilot': ['echo']} is expected.

Note: the binary on main reports 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)

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

Copilot AI balanced review requested due to automatic review settings November 19, 2026 05:57
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 19, 2026
@danielmeppiel Daniel Meppiel (danielmeppiel) added the panel-review Request an advisory PR review; consumed after review. Not human approval or a merge gate. label Nov 19, 2026
@danielmeppiel Daniel Meppiel (danielmeppiel) added this to the 0.37.0 milestone Nov 19, 2026

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

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

Comment thread src/apm_cli/install/mcp/ownership.py Resolved
Comment thread src/apm_cli/install/mcp/integration.py Resolved
@github-actions github-actions Bot removed the panel-review Request an advisory PR review; consumed after review. Not human approval or a merge gate. label Nov 19, 2026
@github-actions

Copy link
Copy Markdown

APM Review Panel: advisory recommendation

Fixes #3881: the pending .mcp.json move now survives lock rewrites and frozen upgrades, so APM no longer loses track of a root MCP entry it already moved. Both fixes are narrow and correct.

panel-mode=lean; personas=python-architect, test-coverage-expert, apm-ceo

cc Daniel Meppiel (@danielmeppiel) @sergio-sisternes-epam

Panel summary

Persona Blocking Recommended Nit Summary
python-architect 0 2 1 Both fixes correct and narrow. Adoption proof rides a ContextVar; moved_unrecorded cannot tell a --frozen move from a user deletion.
test-coverage-expert 0 2 1 Real-binary traps cover both defects; fail-closed paths, the version predicate and the stamp gate have no unit pins.

CEO arbitration

No panelist returned a blocking finding. The remaining gaps are in fail-closed paths, not the happy path. The most important: _absent_from_retired_files returns moved_unrecorded == set() for a symlinked or malformed retired file, and no unit test pins that. That logic decides whether APM may later delete a file in the user's tree, so a refactor could quietly turn "refuse to adopt" into "adopt". The same applies to lock_holds_untranslated_mcp_claims and update_lockfile(stamp_version=True); CI's binary reports 0.36.1, so only unit pins catch a regression of the D1 half.

The architect findings are design, not correctness. The adoptable_root_mcp_entries ContextVar is a hidden third ownership input read inside compare_native_mcp_connection with a hardcoded copilot target. moved_unrecorded can also match a user who hand-deleted .github/mcp.json and wrote an identical .mcp.json entry; APM would adopt it and later delete it on undeclare. Damage requires an exact render match, but it should be written down as an accepted boundary.

Principle alignment

  • Secure by default: fail-closed on symlinked/malformed retired files, but that branch is unguarded by tests.
  • Governed by policy: ownership proof partly depends on ambient ContextVar state; an explicit input is more auditable.
  • Portable by manifest: the lockfile stays an accurate record of what APM owns across upgrades.
  • Pragmatic as npm: MCP config keeps working across upgrades with no manual cleanup.

Recommended follow-ups (prioritized)

  1. (test-coverage-expert) Parametrized unit tests for the _absent_from_retired_files fail-closed branches (symlinked and malformed retired file => moved_unrecorded == set(), plus a positive case), next to the _split helper tests in tests/unit/install/test_copilot_project_mcp_destination.py.
  2. (test-coverage-expert) Unit tests for lock_holds_untranslated_mcp_claims and update_lockfile(stamp_version=True) restamp/write behavior.
  3. (python-architect) Document the accepted boundary that "absent from both retired files" also matches a hand-deleted retired file plus an identical hand-written .mcp.json entry; optionally pin it with a test.
  4. (python-architect) Make the ContextVar explicit: document it in the compare_native_mcp_connection docstring, or pass it through managed_target_servers.
  5. (python-architect, nit) Comment at the conflict-path update_lockfile call on why stamp_version is omitted.

Ship recommendation: ship with follow-ups

Merge once the requested review from @sergio-sisternes-epam lands and CI is green on the new lifecycle tests. The unit tests for the fail-closed retired-file branches are the follow-up to track first; they can go in this PR or a fast follow-up before 0.37.0 ships. The panel could not run the new lifecycle tests itself (no network in the sandbox), so CI is the confirmation.

Advisory only: this panel does not gate merge. Panel-reviewed: head d96e927.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • pypi.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "pypi.org"

See Network Configuration for more information.

Generated by PR Review Panel for #3899 · copilot · auto · 214.5 AIC · ⌖ 0.55 AIC · ⊞ 5.8K · ◷

Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 19, 2026
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]>
@danielmeppiel

Copy link
Copy Markdown
Collaborator Author

APM Review Panel: ship_with_followups

This PR fixes two data-safety holes in the unreleased copilot root .mcp.json move before 0.37.0 ships. APM no longer leaves the heal stranded across lock rewrites and --frozen upgrades, and it never takes over and then deletes a user's own MCP entry.

panel-mode=lean; personas=python-architect,test-coverage-expert,supply-chain-security-expert

cc Sergio Sisternes (@sergio-sisternes-epam) -- a fresh advisory pass is ready for your review.

What changed. The PR fixes two defects in the copilot root .mcp.json move. Both were first reproduced with the real binary:

  • D1: an install that rewrote the lock before its MCP step finished (--only apm, or an MCP failure) made a pre-0.37 lock look current. The .github entry was then never moved. If the user had written an identical root entry, APM treated it as its own and deleted it when the server was removed.
  • D2: after --frozen, the next install no longer recognized the root entry APM itself had written.

The fix uses one shared check to decide both when to keep the old lock version and when to update it. The ContextVar that lets APM take ownership is set in exactly one place (run_mcp_integration), and only within the five bounds the captain approved. #3875 is unreleased, so this PR decides whether 0.37.0 ships a path that can silently delete user configuration. That makes it release-critical, not polish.

Folds at 5d45502. The three panelists agreed on the main points, and nearly everything is folded:

  • Architect (a): editing args right after --frozen no longer causes a conflict. Proof: test_frozen_upgrade_then_a_changed_declaration_updates_the_root_entry, mutation-checked.
  • Architect (c) / Security (a): a missing retired file no longer proves a move for copilot. A copilot claim counts as moved only while .github/mcp.json still exists. Proof: the [github-file-missing] trap, mutation-checked.
  • Coverage (a)(b): the masked undeclared case and the missing traps for bound 1, bound 2 and the symlink branch now run as real installs that succeed. Proof: test_identical_root_entry_stays_the_users_unless_every_adoption_bound_holds[undeclared|lock-0.37|claims-another-name|github-file-missing|github-symlinked].
  • Coverage (c): the D1 proxy is replaced by a unit test patched to 0.37.0. Proof: test_package_phase_keeps_a_pre_root_version_until_the_mcp_phase_stamps_it[copilot-claim-held|claude-claim-restamped].
  • The lockfile-spec wording now matches the code.

Checks at 5d45502: lint clean, 120 lifecycle tests and 1248 unit tests pass.

Still open. Three items, all recommended:

  1. The overloaded apm_version. The author's rationale holds. On main, MCP-only projects already keep an old version forever, and this PR now limits that to the window before the first successful MCP phase. A dedicated translation-state field would change the lockfile schema, so it is spec scope. Even so, legacy_plugin_compat (==0.28.0) and buggy_lockfile_recovery (<=0.12.2) now read a version that may be held, and no test yet proves they stay inert.
  2. The vscode case is an accepted residual. A vscode claim with a missing .vscode/mcp.json still counts as moved. The frozen heal deletes that file itself, bound (3) needs this, and taking ownership is correct when a teammate ran --frozen and committed .mcp.json while .vscode/ is gitignored. It still needs pinning as a named contract.
  3. No dedicated test for the no-MCP-deps stamp path.

Dissent. None. Architect (c) and Security (a) raised the same missing-file concern. The copilot half is folded. The vscode half is accepted as an approved residual, because bound (3) and the cross-machine --frozen workflow require it. Not folding Architect (b) in this PR is accepted, provided a test follow-up backs that reasoning.

Aligned with: Secure by default: APM takes ownership only when all five bounds hold, symlinked or unreadable files fail closed, a deleted .github/mcp.json never grants a claim, and traps prove an identical user entry outside the bounds is never claimed or deleted. Portable by manifest: the lock again records true root ownership after --frozen and partial installs, so apm.yml edits have predictable effects. Multi-harness: copilot/vscode claims are translated while claude-only locks restamp immediately, so one harness's migration state does not leak into another's. Pragmatic as npm: zero migration commands, no surprise conflict and no --force dead end after --frozen.

Panel summary

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

  1. [Python Architect] Add a regression test showing a held pre-0.37 apm_version cannot re-arm legacy_plugin_compat (==0.28.0) or buggy_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_version now does double duty. The reasoning is sound but untested, and a future refactor of either compat gate could silently break it.
  2. [Supply Chain Security Expert] Pin the accepted vscode residual (a 0.36 vscode claim with .vscode/mcp.json missing 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.
  3. [Test Coverage Expert] Add a unit test for the no-MCP-deps branch of run_mcp_integration asserting 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 --frozen at src/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_version now also marks whether MCP claims are translated, and existing readers already gate on it at src/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 at src/apm_cli/install/mcp/retired_destinations.py:398
    The ContextVar hook itself is tightly bounded: it is set only around MCPIntegrator.install, reset in finally, 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_entry cannot fail, so bound (5) has no trap at tests/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, and stamp_version is only covered by two exact-kwargs mocks.
    Suggested: a unit test patching installed_apm_version to 0.37.0. (Folded in tests/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 --frozen moved the entry; an identical user-authored root entry could be adopted and later deleted at src/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 nothing apm.yml cannot 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 --frozen already moved the entry", but the code triggers on absence at docs/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.

Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 19, 2026
…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]>
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]>
@danielmeppiel

Copy link
Copy Markdown
Collaborator Author

Merge worker: ready to merge at 98d26b174c

The review passed with ship_with_followups. Every in-scope finding is folded into this PR, CI is green at this head, and the canonical-owner gate passed. Merging is left to the maintainer.

Folded in this run

  • (panel) Frozen then edit args before the first plain install no longer conflicts (locked-declaration render). -- resolved in 5d45502.
  • (panel) Copilot claim counts as moved only while .github/mcp.json exists. -- resolved in 5d45502.
  • (panel) Negative real-binary traps for every adoption bound on successful installs. -- resolved in 5d45502.
  • (panel) Unit test running the package phase and MCP stamp as a 0.37 binary. -- resolved in 5d45502.
  • (panel) lockfile-spec wording matches the adoption and removal rules. -- resolved in a09f651.
  • (panel) Named contract test for the accepted vscode residual (clone without .vscode/). -- resolved in a09f651.
  • (panel) Unit test for the no-MCP-deps stamp path. -- resolved in a09f651.
  • (copilot) Exact JSON (type-sensitive) proof for adoption. -- resolved in a09f651.
  • (copilot) Removing a server right after --frozen removes its root entry (self-defined). -- resolved in a09f651.

Copilot signals reviewed

  • src/apm_cli/install/mcp/ownership.py -- LEGIT: Adoption now requires json_identical; unit trap fails under dict equality. Fixed in a09f651.
  • src/apm_cli/install/mcp/retired_destinations.py:382 -- LEGIT: Copilot half folded (.github/mcp.json must exist); vscode half is the captain-approved bound, pinned by a contract test.
  • src/apm_cli/install/mcp/integration.py:490 -- LEGIT: Change folded (locked-declaration render); removal folded for self-defined servers (captain option A); registry limitation stated.

Deferred (out-of-scope follow-ups)

Regression-trap evidence (mutation-break gate)

  • tests/integration/test_copilot_root_mcp_json_lifecycle.py::test_a_lock_rewrite_before_the_mcp_phase_keeps_the_heal_pending[only-apm] -- deleted src/ fix reverted (package phase restamps); test FAILED as expected; guard restored.
  • tests/integration/test_copilot_root_mcp_json_lifecycle.py::test_frozen_upgrade_keeps_the_root_entry_apm_wrote[vscode] -- deleted src/ fix reverted (no adoption); test FAILED as expected; guard restored.
  • tests/integration/test_copilot_root_mcp_json_lifecycle.py::test_frozen_upgrade_then_a_changed_declaration_updates_the_root_entry -- deleted locked-declaration render acceptance; test FAILED as expected; guard restored.
  • tests/integration/test_copilot_root_mcp_json_lifecycle.py::test_identical_root_entry_stays_the_users_unless_every_adoption_bound_holds[github-file-missing] -- deleted .github/mcp.json presence condition; test FAILED as expected; guard restored.
  • tests/integration/test_copilot_root_mcp_json_lifecycle.py::test_frozen_upgrade_then_removing_the_server_removes_its_root_entry[last-server] -- deleted undeclared_moved removal; test FAILED as expected; guard restored.
  • tests/unit/install/test_copilot_project_mcp_destination.py::test_moved_root_entry_is_adopted_only_when_json_identical[True-NativeMcpConnectionState.MATCHING_FOREIGN] -- deleted json_identical (dict equality instead); test FAILED as expected; guard restored.
  • tests/unit/install/test_mcp_integration_extraction.py::TestRunMcpIntegrationEmptyDepsBranch::test_no_deps_stamps_a_lock_whose_claims_it_translated[0.35.0-True] -- deleted stamp_version=translated on the no-deps branch; test FAILED as expected; guard restored.

Lint contract

ruff check and ruff format --check (ruff 0.15.12, the version uv.lock pins) are both silent. Pylint R0801, lint-auth-signals, and both architecture linters exit 0.

CI

gh pr checks 3899 at 98d26b1: 31 pass, 3 skipping, 0 fail; CI run https://github.com/microsoft/apm/actions/runs/44479310294 success (after 0 CI fix iterations).


Generated by autopilot-pr-merge-worker. This comment is AI-generated and may contain errors.

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.

[FEATURE] Harden the copilot root .mcp.json move: heal gate, pre-ownership locks, canonicaliser and UX follow-ups

2 participants