Skip to content

[0.38] fix(install): refuse registry and recorded MCP collisions before any write (#4741) - #4763

Merged
Daniel Meppiel (danielmeppiel) merged 10 commits into
mainfrom
danielmeppiel-p2-4741-mcp-preflight-recorded
Nov 22, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 10 commits into
mainfrom
danielmeppiel-p2-4741-mcp-preflight-recorded

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

#4268 (#4745) made apm install refuse a colliding self-defined MCP server
the lockfile never recorded before writing anything. Two cases still reached
the MCP write path, where the collision stopped the install after earlier
files were already written:

  • registry-backed servers;
  • servers the lockfile already records.

The install preflight (install/mcp/collision_preflight.py, called from
check_before_deploy and, for service-only installs, from
run_mcp_integration) now projects both cases through the same comparator,
compare_native_mcp_connection, and reports a conflict with the same
_report_native_conflict diagnostic before any write.

  • Registry servers. The server info is looked up the way the install
    looks it up: the registry snapshot that org policy judged comes first, then
    a fetch, with the declaration overlaid on top. A server whose render needs
    values the MCP stage may prompt for (package environment variables,
    runtime or package argument variables, docker ${...} args) is not
    projected. Neither is one whose lookup fails. Both stay on the write path.
    No prompt is ever shown in preflight.
  • Recorded servers. These are compared as managed, against the stored
    declaration and every native hash the lockfile records for the name, on
    any runtime. A pair counts as a conflict only when every baseline
    conflicts. A conflict against a managed baseline implies a conflict as
    unmanaged, so the MCP stage's comparison conflicts too, whatever ownership
    it settles on (inherited shared-destination claims, migrations). This
    avoids false refusals.
  • Not projected (left to the write-path backstop, which keeps the
    writes that reached other targets): a --frozen replay of recorded claims
    (adoptable root entries settle only in the MCP stage), and a lockfile from
    APM 0.36 or earlier that records Copilot or VS Code claims (translated by
    split_mcp_claims in the MCP stage).

Three safeguards prevent false refusals:

  • check_before_deploy prepares the projected MCP set with the packages the
    write plan routes to Claude natively (PackageDeploymentPlan.claude_native).
    A now-native plugin's loose entry is therefore retired by the MCP stage, as
    before, rather than refused. Claude routing is only queued during
    integration, after this gate. The policy check's own inputs are unchanged.
  • A native config the comparator cannot read (for example an invalid server
    map) is left to the MCP stage's own error.
  • A declaration with an invalid env map is not projected.

The write path keeps the same comparison as its backstop. No second collision
rule is added. The preflight reads the --frozen disposition through
InstallService.frozen_disposition (it passes replay_claims), as the
frozen-flag reader guard requires.

Issue and approved scope

Issue: Fixes #4741

Human scope-approval comment: #4741 (comment) (amended apm-scope:v1 record; earlier amendment #4741 (comment))

Does this PR complete the issue, or what remains? It completes the issue.
These pairs cannot be projected without prompting, or settle only in the
MCP stage, so they stay on the write-path backstop:

  • a registry server whose render needs prompted environment or runtime
    values;
  • a registry lookup that fails;
  • a --frozen replay of recorded claims;
  • a pre-0.37 lockfile with Copilot or VS Code claims.

Recorded-claim post-registration cell (P2 lead ruling; rationale): since
#4594, MCP and LSP reconciliation runs before native registration. With this
PR, a colliding recorded claim is refused in preflight before any write,
including native registration.

The state "the lock claims commit-point-srv while ~/.claude.json holds
the user's entry" is created by the user's edit after a clean install. A
refused install must not write, so it cannot make the lock equal to disk. The
cell therefore asserts four things: the refusal, unchanged apm.lock.yaml
and ~/.claude.json bytes, an unchanged home tree, and that clearing the
entry converges with lock == disk.

The ruled "apm audit --ci reports the drift" assertion was dropped.
Verification showed that audit passes for a user-edited recorded native MCP
entry. That pre-existing gap is #4757.

Cells rewritten to the refusal contract, because they pinned a partial
write for a recorded or registry collision that is now refused before any
write:

  • test_partial_install_retains_deferred_names_in_active_target. The refusal
    keeps the edited claim, so retiring the undeclared server then preserves the
    user's entry and exits 1 until the user removes it. After that, the install
    converges.
  • test_registry_partial_conflict_does_not_skip_managed_self_defined_update.
  • test_installed_global_prune_intersects_each_targets_ownership.

The write-path partial branch stays covered by the req-lk-006 spec cell
test_partial_mcp_conflict_persistence_respects_lock_write_suppression, which
simulates an unprojectable pair.

Done-when mapping (all fail before this PR on the #4745 base and pass after):

  • test_a_colliding_registry_server_is_refused_before_any_write[project|user x claude|codex]:
    • a registry server colliding with a user entry exits 1 with the conflict
      diagnostic;
    • the user config bytes are unchanged, and the other runtime is not
      written;
    • no claim is recorded.
    • Control: after the user removes the entry, the install succeeds, and a
      repeat install of the now-recorded registry server succeeds (no false
      refusal).
  • test_a_recorded_mcp_server_collision_is_refused_before_any_write[user-edit]:
    • a recorded self-defined server whose entry the user edited refuses
      before any write;
    • the primitive change is not deployed;
    • .mcp.json and lockfile bytes are unchanged.
  • test_a_recorded_mcp_server_collision_is_refused_before_any_write[declaration]
    (control): a changed declaration of the recorded server installs and
    updates APM's entry.
  • test_a_recorded_native_plugin_mcp_collision_is_refused_and_converges:
    the recorded-claim fixture moved from Detect MCP server config collisions during install preflight #4268, as described above.

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 the [0.38] feat(install): refuse an MCP server collision before any file is written (#4268) #4745 base):
    • test_a_colliding_registry_server_is_refused_before_any_write: 4 failed.
    • test_a_recorded_mcp_server_collision_is_refused_before_any_write[user-edit]
      and test_a_recorded_native_plugin_mcp_collision_is_refused_and_converges:
      failed.
  • Green after:
    • test_a_colliding_registry_server_is_refused_before_any_write: 4 passed.
    • tests/integration/test_lockfile_commit_point_lifecycle.py: see the CI
      integration run.
  • ruff check / ruff format --check (0.15.12, CI paths): clean.
  • scripts/lint_architecture_boundaries.py --root .: exit 0 (frozen-flag
    reader guard satisfied).
  • pylint R0801: 10.00/10. lint-auth-signals.sh: clean.
  • check_complexity_ratchet.py --base-ref main: clean.
  • check_test_assertions.py: ratchet clean. tests.quality.taxonomy --changed: clean.
  • Spec Mode B: apm-spec-waiver trailer. 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.

…l preflight (#4741)

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]>
…e-plugin cell (#4741)

Audit does not yet report a user edit to a recorded native MCP entry (#4757).

Co-authored-by: Copilot App <[email protected]>
…ite (#4741)

The install preflight now also projects registry servers whose render
needs no prompted value (looked up as their install looks them up) and
servers the lockfile records, compared as managed against every recorded
baseline and refused only when each one conflicts. A --frozen replay and
pre-0.37 Copilot/VS Code claims still settle in the MCP stage.

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 16:04

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

Collision preflight can reject matching foreign entries because it omits group-level environment overrides and can unexpectedly prompt for unresolved header values, violating its prompt-free contract.

2 open issues
What changed in this PR

Extends the existing MCP collision preflight to cover registry-backed and already-recorded servers, addressing #4741. Predictable conflicts are checked before deployment, while cases requiring prompts or later ownership resolution remain on the write-path backstop.

Changes:

  • Projects eligible registry configurations and recorded baselines through the existing collision comparator.
  • Wires the expanded preflight into package and service-only installs.
  • Adds refusal and convergence coverage, updates architecture guards, and documents deferred cases.
File Description
tests/​integration/​test_native_mcp_collision_lifecycle.py Adds registry collision refusal and repeat-install controls.
tests/​integration/​test_lockfile_commit_point_lifecycle.py Checks recorded collisions preserve state and recovery converges.
src/​apm_cli/​install/​mcp/​integration.py Calls the expanded preflight with frozen replay context.
src/​apm_cli/​install/​mcp/​collision_preflight.py Adds registry projection, recorded baselines, and deferral checks.
src/​apm_cli/​install/​commit_gate.py Passes canonical frozen disposition into pre-deployment checks.
scripts/​architecture_linter/​checks/​install_frozen_and_audit.py Updates required-call guards for the renamed preflight.
docs/​src/​content/​docs/​troubleshooting/​common-errors.md Describes early refusals and write-path exceptions.
docs/​src/​content/​docs/​reference/​cli/​install.md Updates the documented collision behavior.
changelog.d/​4763.fixed.md Announces expanded early collision detection.
.apm/​architecture/​owners/​install-deployment.json Updates the install commit-order ownership description.

Review effort: Balanced

…le pair (#4741)

The install preflight now refuses the recorded collision this req-lk-006
cell used; the write-path branch stays reachable for pairs the preflight
declines (a registry render needing prompted values), simulated here.

Co-authored-by: Copilot App <[email protected]>
…eadable configs (#4741)

check_before_deploy prepares the projected MCP set with the write plan's
natively routed packages, so a now-native plugin's loose entry is retired
rather than refused; a config the comparator cannot read is left to the MCP
stage's own report; an invalid env map is not projected. Cells that pinned a
partial write for a recorded or registry collision assert the 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]>

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 prompt for unresolved header variables and falsely reject valid installs because its environment inputs differ from the grouped write path.

2 open issues
1 previously missed issue

In code that hasn't changed since last review

Medium severity Per-dependency rendering falsely conflicts with pooled environment overrides

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

Using only this dependency's environment overrides can falsely refuse a valid install: _install_registry_group pools collected values and overrides across the registry/runtime group (mcp_integrator_install.py:362-372). On Gemini, if A's header references ${VALUE} and a later server B overrides A's supplied VALUE, an existing foreign A entry matching the pooled value conflicts with this per-dependency render, even without prompting. Reuse the write path's effective grouped inputs, or defer groups whose inputs cannot be determined without prompting, and add a two-server matching-entry control.

Review effort: Balanced

…v registry render to the install (#4741)

A remote header, URL or docker placeholder may make an adapter prompt, and
declared env feeds the install's group-wide overrides, so neither is
projected. The deferred-names cell no longer asserts ownership of an entry
the preserved retirement wrote unrecorded.

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

Active preflight defects reject valid installs with mixed claims or shared registry inputs and allow legacy header placeholders to trigger interactive prompts, violating the prompt-free contract.

No open issues 🎉

3 previously missed issues

In code that hasn't changed since last review

Medium severity Detect legacy placeholders to keep preflight prompt-free

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

Legacy <VAR> header placeholders still bypass this check. A Gemini registry remote with X-Custom: <MISSING_VALUE> can therefore call Prompt.ask during preflight when the variable is unset and the terminal is interactive, violating the prompt-free contract. Use the adapter's placeholder detector alongside the existing ${ check, and add an interactive prompt-trap regression test.

Medium severity Defer preflight for arguments using group-level inputs

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

_needs_input accepts an argument such as {"type": "named", "name": "--org", "value": "{org}"} when that server has no variables declaration. If another server in the registry group supplies org, installation renders the shared value while preflight renders literal {org}, falsely rejecting a matching foreign connection. Defer argument templates that consume group-level inputs, and add a matching-foreign control with two registry servers.

Medium severity Preserve hashless claims when fingerprinted claims coexist

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

A recorded, hashless Codex claim loses its None baseline when another runtime has a fingerprint for the same server. Codex accepts legacy env: {TOKEN: "${TOKEN}"} entries without a receipt, but an unrelated fingerprint makes them conflict, so preflight rejects an otherwise valid install. Preserve None for recorded claims lacking fingerprints and add a mixed hashless/fingerprinted-claim regression control.

2 resolved since last review

Review effort: Balanced

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 25fe239 into main Nov 22, 2026
74 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-p2-4741-mcp-preflight-recorded branch November 22, 2026 21:19
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 22, 2026
… the --mcp preflight (#4759)

#4763 renamed refuse_unrecorded_mcp_collisions; the direct --mcp preflight,
its architecture guard edge and mutation case now use the new owner name.

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.

[BUG] Install preflight does not yet project registry-backed or already-recorded MCP servers for collisions (from #4268)

2 participants