Skip to content

[0.38] feat(install): refuse an MCP server collision before any file is written (#4268) - #4745

Merged
Daniel Meppiel (danielmeppiel) merged 6 commits into
mainfrom
danielmeppiel-p2-4268-mcp-collision-preflight
Nov 22, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 6 commits into
mainfrom
danielmeppiel-p2-4268-mcp-collision-preflight

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

apm install found a collision between a package's MCP server and an existing
native connection (for example a user entry in .mcp.json) only at the MCP
config write, after primitives had already been deployed. The user saw a
partial install for an error that was knowable up front.

check_before_deploy (install/commit_gate.py, owner install-commit-order) now
projects collisions before the first deployed byte. The new
install/mcp/collision_preflight.py asks the canonical comparator,
compare_native_mcp_connection, about each self-defined MCP server the
lockfile never recorded, on each runtime the MCP stage will write. The
runtimes are resolved the way that stage resolves them: the same --runtime
and --exclude, silently. Such a server is compared as unmanaged. On
NativeMcpConnectionState.CONFLICT the preflight reports it with the same
_report_native_conflict diagnostic and raises MCPNativeConflictError.
The install then exits non-zero, and apm.lock.yaml, primitive files and MCP
configs stay untouched.

An install with only MCP servers (no APM packages or local primitives) skips the package
pipeline, so run_mcp_integration runs the same projection
(refuse_unrecorded_mcp_collisions) before its first MCP write, as it already
does for org MCP policy. The MCP write path keeps the same comparison as its backstop. No second
collision rule is added. New required-call rows in the native MCP ownership
guard pin this wiring: check_before_deploy must call
_refuse_native_mcp_collisions, which must call refuse_unrecorded_mcp_collisions, which must call project_native_mcp_conflicts,
and that must call compare_native_mcp_connection and _report_native_conflict; run_mcp_integration must call refuse_unrecorded_mcp_collisions.

Issue and approved scope

Issue: Fixes #4268

Human scope-approval comment: #4268 (comment) (amended apm-scope:v1 record narrowing the original), with the control wording amended in #4268 (comment)

Does this PR complete the issue, or what remains? It completes the issue as
narrowed by the amended record.

The preflight covers self-defined servers the lockfile never recorded. These
cases stay on the existing write-path backstop and move to follow-up #4741:

  • Registry-backed servers. Their render needs registry info and environment or
    runtime variables that can prompt, so projecting them now risks prompts and
    false refusals.
  • Servers the lockfile already records. Their ownership state (retired or
    healed claims, adoptable root entries, shared destinations, legacy keys) is
    only settled inside the MCP stage.

In those cases a collision still exits 1 and keeps the writes that reached
other targets, as in 0.37.

Control test_a_failed_mcp_reconcile_after_native_registration_keeps_the_lock_equal_to_disk
(P2 lead ruling, option B; record #4268 (comment)): its colliding server is self-defined and never
recorded, so the preflight now refuses it before native registration. The cell
keeps its name. Its first install now asserts the refusal contract: exit
non-zero, the conflict diagnostic, no user lockfile, and ~/.claude.json bytes
unchanged. Its convergence tail is unchanged: clear the entry, the install
converges, a repeat is idempotent, and audit and --frozen pass.

Making that server recorded first exposes a separate defect. The write-path
backstop leaves apm.lock.yaml claiming commit-point-srv for claude while
~/.claude.json holds the user's entry. That defect, and the #4329
post-registration failure path with a recorded-claim fixture, move to #4741.

Done-when mapping:

  • test_a_colliding_mcp_install_is_refused_before_any_file_is_written loses
    its #4268 strict-xfail marker and passes. It asserts exit non-zero,
    "conflicts with the existing claude connection" and "MCP installation
    incomplete: beta-srv (claude)". It also asserts no Codex configuration, no
    lockfile, no .claude/agents, no Codex config.toml, and unchanged
    .mcp.json bytes.
  • test_a_partial_mcp_collision_reports_each_write_and_records_what_reached_disk
    is retired: it covered a self-defined unrecorded server, which the refusal
    cell now pins.
  • test_a_recorded_mcp_server_is_left_to_the_mcp_write[declaration|user-edit]
    proves the preflight does not falsely refuse a recorded server. A changed
    declaration installs (exit 0) and updates APM's entry. A user edit to the
    recorded entry is still caught by the write-path comparison after the
    primitives deployed (the backstop).
  • Cells that pinned the partial write of an unrecorded self-defined collision
    now assert the refusal: test_differing_foreign_connection_is_incomplete_with_truthful_ownership
    (no write to the other runtime, no claim) and
    test_a_self_defined_conflict_is_refused_before_the_registry_write (renamed
    from test_registry_write_before_all_self_defined_conflicts_is_persisted).
    The global prune cells seed ownership with a clean install first, so their
    later collision is refused early (unrecorded) or reaches the write path
    (recorded on another target).
  • The non-colliding MCP install control stays green unchanged (the clean
    installs in the cells above, plus the MCP lifecycle suites on CI).
  • Docs: the conflict entry in troubleshooting/common-errors.md says the
    install stops before writing anything for self-defined unrecorded servers
    and names the remaining write-path cases. reference/cli/install.md is
    aligned.

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 (host under a test cap: targeted files only, heavy suites on CI):

  • Red before: on main the refusal cell is a strict xfail (#4268), so it fails there.
  • Without the recorded-name filter, the declaration cell would be refused as
    a conflict. With it, the cell passes.
  • pytest tests/integration/test_lockfile_commit_point_lifecycle.py -n 2 (real binary): 20 passed, 1 skipped.
  • pytest tests/integration/test_native_mcp_collision_lifecycle.py: 78 passed. test_global_cursor_opencode_mcp_lifecycle.py: 25 passed. tests/unit/install/test_commit_gate.py: 33 passed.
  • ruff check / ruff format --check (0.15.12, CI paths): clean.
  • scripts/lint_architecture_boundaries.py --root .: exit 0.
  • pylint R0801: 10.00/10. lint-auth-signals.sh: clean.
  • check_complexity_ratchet.py --base-ref main: clean.
  • check_test_assertions.py: assertion-quality ratchet clean. tests.quality.taxonomy --changed: clean.
  • Spec Mode B: apm-spec-waiver trailer in the fix commit. This is local install ordering; no manifest, lockfile or resolver contract changes.

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
  • Manifest edit
  • Test edit
  • CONFORMANCE.{md,json} regenerated
  • N/A -- this PR does not change OpenAPM-observable behaviour.

…any write (#4268)

check_before_deploy projects each self-defined MCP server the lockfile never
recorded through compare_native_mcp_connection as unmanaged and reports a
CONFLICT with _report_native_conflict before the first deployed byte.
Registry servers and recorded claims stay on the MCP write's comparison
(#4741). The #4329 control now asserts the refusal contract for its first
install; a recorded server cell proves no false preflight refusal.

apm-spec-waiver: install-time MCP collision ordering is local client behaviour; no manifest, lockfile or resolver contract changes

Co-authored-by: Copilot App <[email protected]>
@danielmeppiel Daniel Meppiel (danielmeppiel) added this to the 0.38.0 milestone Nov 22, 2026
Copilot AI balanced review requested due to automatic review settings November 22, 2026 12:26

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

Service-only installs bypass the collision preflight, allowing MCP configuration writes and partial install records before a conflict is reported.

1 open issue
What changed in this PR

This PR moves collision detection for unrecorded, self-defined MCP servers into the install commit gate, aiming to prevent partial installs for #4268. Registry-backed and already-recorded servers remain on the write-path backstop, tracked in #4741.

Changes:

  • Reuses the canonical MCP comparator and diagnostic during pre-deploy checks.
  • Updates lifecycle coverage for early refusal and recorded-server behavior.
  • Documents the scope and adds architecture guards for the new wiring.
File Description
tests/​integration/​test_lockfile_commit_point_lifecycle.py Tests early refusal and recorded-server backstop behavior.
src/​apm_cli/​install/​phases/​services.py Clarifies collision handling in the rollback docstring.
src/​apm_cli/​install/​mcp/​collision_preflight.py Projects collisions using the canonical comparator.
src/​apm_cli/​install/​commit_gate.py Invokes collision preflight before deployment.
scripts/​architecture_linter/​checks/​install_frozen_and_audit.py Guards required preflight calls.
docs/​src/​content/​docs/​troubleshooting/​common-errors.md Explains early refusal and remaining partial-write cases.
docs/​src/​content/​docs/​reference/​cli/​install.md Updates collision and failed-install guarantees.
changelog.d/​4745.changed.md Announces pre-write collision refusal.
.apm/​architecture/​owners/​install-deployment.json Registers collision preflight under install commit ordering.

Review effort: Balanced

Comment thread src/apm_cli/install/commit_gate.py Resolved
…n before any write (#4268)

An install without APM packages or local primitives skips the package
pipeline, so the commit gate never ran. run_mcp_integration now runs the
same projection (refuse_unrecorded_mcp_collisions) before its first MCP
write, as it already does for org MCP policy. Cells that pinned the partial
write of an unrecorded self-defined collision assert the refusal; the prune
cells seed ownership with a clean install first.

apm-spec-waiver: install-time MCP collision ordering is local client behaviour; no manifest, lockfile or resolver contract changes

Co-authored-by: Copilot App <[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

The collision preflight can misclassify MCP entries before skill deployment and create untracked target directories on a refused install, altering subsequent target selection.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity Render conflicts against planned post-deploy skill paths

src/​apm_cli/​install/​mcp/​collision_preflight.py:73

For a first install that deploys a Claude skill, the canonical renderer changes .agents/skills/demo/bin/serve to .claude/skills/demo/bin/serve only after the destination exists (adapters/client/claude.py:209-226). This pre-deploy comparison can therefore falsely refuse an entry matching the final command, or accept one that conflicts after deployment; project-scope Copilot uses the same rewrite. Render against the planned post-deploy skill destinations through the canonical adapter, and cover both cases with regression tests.

1 resolved since last review

Review effort: Balanced

)

_resolve_target_runtimes takes materialize=False so the preflight creates
no target directory before refusing. The service-only refusal cell asserts
the project tree is unchanged; the retired-shape heal cell asserts nothing
heals when the unrecorded collision refuses first.

apm-spec-waiver: install-time MCP collision ordering is local client behaviour; no manifest, lockfile or resolver contract changes

Co-authored-by: Copilot App <[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

The collision preflight can falsely reject matching entries or accept conflicting ones on first skill installs because Claude’s path rendering changes once destination directories exist.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Canonicalize planned skill destinations before pre-deploy comparison

src/​apm_cli/​install/​mcp/​collision_preflight.py:73

On a first project install that deploys a skill, Claude's renderer rewrites .agents/skills/example/bin/serve to .claude/skills/example/bin/serve only after the destination directory exists (adapters/client/claude.py:209-226). This pre-deploy comparison can therefore reject an unrecorded entry that would match after deployment, or accept one that will conflict after primitives are written. Pass planned skill destinations through the canonical adapter renderer before comparing, and cover both cases with first-install regressions.

1 resolved since last review

Review effort: Balanced

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit c07d04d into main Nov 22, 2026
73 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-p2-4268-mcp-collision-preflight branch November 22, 2026 15:07
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 22, 2026
#4745 closed #4268, but on main 84a893b a refused install --mcp still changes apm.yml and .github (I7). The strict cell keeps its assertion and now tracks #4759.

Refs #4759

Co-authored-by: Copilot App <[email protected]>
Jason 'Jay' Jack (jasonjack-jay) pushed a commit to jasonjack-jay/Agent-Package-Manager that referenced this pull request Nov 23, 2026
…soft#4759

microsoft#4745 closed microsoft#4268 for the install path; the inline --mcp side door still
writes before it refuses, so its strict I7 cell now tracks microsoft#4759.

Co-authored-by: Copilot App <[email protected]>
Jason 'Jay' Jack (jasonjack-jay) pushed a commit to jasonjack-jay/Agent-Package-Manager that referenced this pull request Nov 23, 2026
…microsoft#4759)

apm install --mcp NAME -- COMMAND detected a collision with the user's own
.mcp.json entry only in the MCP write path, after apm.yml had been
modified. Run the microsoft#4745 native collision projection
(refuse_unrecorded_mcp_collisions) on the self-defined entry before the
manifest write, so a refused install leaves every durable file
byte-identical (I7). The conflict message and exit code are unchanged.

Flip the strict cell pair|SRC=inline-mcp|DEPLOYED=unowned to required
with a declared refusal, add the bug-ledger row and changelog fragment.

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.

Detect MCP server config collisions during install preflight

2 participants