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
[0.38] feat(install): refuse an MCP server collision before any file is written (#4268) - #4745
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.
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.
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.
…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]>
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.
…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]>
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.
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.
)
_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]>
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
Canonicalize planned skill destinations before pre-deploy comparison
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.
#4745closed#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]>
…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]>
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 installfound a collision between a package's MCP server and an existingnative connection (for example a user entry in
.mcp.json) only at the MCPconfig 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) nowprojects collisions before the first deployed byte. The new
install/mcp/collision_preflight.pyasks the canonical comparator,compare_native_mcp_connection, about each self-defined MCP server thelockfile never recorded, on each runtime the MCP stage will write. The
runtimes are resolved the way that stage resolves them: the same
--runtimeand
--exclude, silently. Such a server is compared as unmanaged. OnNativeMcpConnectionState.CONFLICTthe preflight reports it with the same_report_native_conflictdiagnostic and raisesMCPNativeConflictError.The install then exits non-zero, and
apm.lock.yaml, primitive files and MCPconfigs stay untouched.
An install with only MCP servers (no APM packages or local primitives) skips the package
pipeline, so
run_mcp_integrationruns the same projection(
refuse_unrecorded_mcp_collisions) before its first MCP write, as it alreadydoes 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_deploymust call_refuse_native_mcp_collisions, which must callrefuse_unrecorded_mcp_collisions, which must callproject_native_mcp_conflicts,and that must call
compare_native_mcp_connectionand_report_native_conflict;run_mcp_integrationmust callrefuse_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:
runtime variables that can prompt, so projecting them now risks prompts and
false refusals.
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.jsonbytesunchanged. Its convergence tail is unchanged: clear the entry, the install
converges, a repeat is idempotent, and audit and
--frozenpass.Making that server recorded first exposes a separate defect. The write-path
backstop leaves
apm.lock.yamlclaimingcommit-point-srvfor claude while~/.claude.jsonholds the user's entry. That defect, and the #4329post-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_writtenlosesits
#4268strict-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 Codexconfig.toml, and unchanged.mcp.jsonbytes.test_a_partial_mcp_collision_reports_each_write_and_records_what_reached_diskis 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).
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(renamedfrom
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).
installs in the cells above, plus the MCP lifecycle suites on CI).
troubleshooting/common-errors.mdsays theinstall stops before writing anything for self-defined unrecorded servers
and names the remaining write-path cases.
reference/cli/install.mdisaligned.
Type of change
Testing
Validation evidence (host under a test cap: targeted files only, heavy suites on CI):
#4268), so it fails there.declarationcell would be refused asa 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.apm-spec-waivertrailer in the fix commit. This is local install ordering; no manifest, lockfile or resolver contract changes.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)
CONFORMANCE.{md,json}regenerated