Skip to content

fix(install): record a local bundle's MCP server only where the install claims it - #4657

Merged
Daniel Meppiel (danielmeppiel) merged 6 commits into
mainfrom
w2-fix-4634-bundle-lost-lock-mcp
Nov 22, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 6 commits into
mainfrom
w2-fix-4634-bundle-lost-lock-mcp

Conversation

@danielmeppiel

Copy link
Copy Markdown
Collaborator

Description

Reinstalling a local plugin bundle after apm.lock.yaml was lost (apm install ./bundle.zip) exited 0. The lock it left was rejected by both gates. apm audit --ci failed config-consistency with p-exec-mcp: in lockfile but not in manifest (declared by bundle:p-exec), and apm install --frozen exited 1 with MCP server 'p-exec-mcp' is no longer declared in apm.yml.

Cause. With no lock, the bundle's server already sits in .mcp.json as an identical entry that APM has no record of writing. The MCP integrator therefore treats it as MATCHING_FOREIGN: equality alone never establishes ownership (install/mcp/ownership.py). It claims no runtime and records no native-entry receipt for it. run_owned_mcp_integration still wrote the server into mcp_servers, mcp_configs and mcp_config_provenance (bundle:p-exec). The MCP view reads a bundle: provenance back only as a deployment, meaning a claim with its receipt (mcp_config_view._bundle_owned_baseline). So the server became lock-only and both gates rejected it.

Fix (owner: install/mcp/integration.py run_owned_mcp_integration). A bundle install now records a server only when it claims it on at least one runtime. For a selected server left to an unmanaged entry, the install names the entry and the remedy, the same way the hook beside it is skipped in that step:

[!] Skipping MCP server 'p-exec-mcp' from bundle p-exec -- an entry with that name exists that APM does not manage. Remove the entry, then reinstall the bundle to manage it.

Running that hint makes APM own the server again: the next reinstall records it with bundle:p-exec provenance and both gates pass. A first bundle install and a reinstall with the lock in place record the same rows as before.

Scope note: the approved scope says the reinstall "records the bundle's MCP servers exactly as a first bundle install does". A first install's record includes the native-entry receipt, which would require adopting an identical entry APM did not write. That conflicts with the ownership rule and with this issue's out-of-scope line (re-adopting what has unknown provenance, #4626). This PR leaves the entry with the user and keeps both gates green. If adoption is wanted instead, it is a change to run_owned_mcp_integration only.

Issue and approved scope

Issue: Fixes #4634

Human scope-approval comment: #4634 (comment) (the deviation noted above keeps the scope's out-of-scope line and the ownership rule)

Does this PR complete the issue, or what remains? It completes the fix. The T-6b lifecycle scenario named in "Done when" (test_ownership_siblings.py::test_a_local_bundle_never_replaces_the_users_hook[present-provenance-unknown]) is not on main yet. Its strict known cells for #4634 are dropped when that corpus branch rebases onto this fix. This PR carries its own real-CLI regression test for the same flow.

Type of change

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

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)
promise: P-INV-I3 / P-LAW-outcome.status_matches_state -- a successful install leaves a state install --frozen and audit --ci accept (source: tests/lifecycle/oracles.py)
cell: OP=bundle-install SRC=local-bundle PRIM=mcp DEPLOYED=present-provenance-unknown   owner: src/apm_cli/install/mcp/integration.py
instrument: lifecycle test -> tests/lifecycle/test_local_bundle_lost_lock_mcp.py::test_bundle_reinstall_after_lost_lock_leaves_a_state_the_gates_accept (new: no local-bundle ownership scenario on main)
oracles: [I1-I9 via StepRunner.step on every step, I3 gate pair, snapshot of .mcp.json entry]  decisive: audit --ci exits 0 after the lost-lock reinstall
failing-before: pytest tests/lifecycle/test_local_bundle_lost_lock_mcp.py -> FAILED (audit --ci exit 1, config-consistency)
passing-after: pytest tests/lifecycle/test_local_bundle_lost_lock_mcp.py -> 1 passed
guard+mutation: n/a     ledger: tests/fixtures/lifecycle_bug_ledger/bugs/4634.json
hints executed: remove the .mcp.json entry, reinstall the bundle -> server recorded with bundle:p-exec, audit --ci and install --frozen exit 0

Commands run locally (all passed):

  • pytest tests/lifecycle/test_local_bundle_lost_lock_mcp.py tests/integration/test_local_bundle_mcp_lifecycle.py tests/integration/test_local_bundle_mcp_retire_lifecycle.py (APM_E2E_TESTS=1): 9 passed
  • pytest tests/unit/install/test_owned_mcp_integration.py tests/unit/install/test_copilot_project_mcp_destination.py tests/integration/test_architecture_lockfile_write_authority.py tests/quality/test_lifecycle_bug_ledger.py: 45 passed
  • ruff check / ruff format --check (0.15.12), pylint R0801, scripts/lint-auth-signals.sh, scripts/check_complexity_ratchet.py --base-ref origin/main, python -m tests.quality.taxonomy --changed, python -m tests.lifecycle.generator --check: clean

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

…ll claims it

Reinstalling a local bundle after apm.lock.yaml was lost recorded its MCP
server with bundle provenance although the identical .mcp.json entry was not
APM's (equality never establishes ownership), so audit --ci and
install --frozen rejected the lock. The bundle install now records only the
servers it claims on a runtime and names the unmanaged entry to remove.

Fixes #4634

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 21, 2026 17:48

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 warning incorrectly treats an unsupported-transport skip as an unmanaged entry, prompting users to remove a nonexistent entry and reinstall without resolving the issue.

1 open issue
What changed in this PR

Fixes local-bundle reinstalls after a lost lockfile by recording MCP servers only when the install claims ownership on at least one runtime. This preserves unmanaged entries while avoiding lock state rejected by audit and frozen install.

Changes:

  • Filters bundle MCP lock records by runtime ownership and adds a remediation warning.
  • Adds unit and real-CLI regression coverage, including recovery after removing an unmanaged entry.
  • Records the regression in the bug ledger and changelog.
File Description
tests/​unit/​install/​test_owned_mcp_integration.py Verifies only claimed servers are recorded while unrelated records remain.
tests/​lifecycle/​test_local_bundle_lost_lock_mcp.py Covers lost-lock reinstall, gate acceptance, entry preservation, and recovery.
tests/​fixtures/​lifecycle_bug_ledger/​bugs/​4634.json Links the ownership and outcome regression to its tests.
src/​apm_cli/​install/​mcp/​integration.py Filters bundle lock records and reports unrecorded selected servers.
changelog.d/​4657.fixed.md Documents the user-visible reinstall fix.

Review effort: Balanced

Comment thread src/apm_cli/install/mcp/integration.py Resolved
apm-spec-waiver: bug fix in bundle MCP lock recording; no OpenAPM-observable behaviour changes (#4634)

Co-authored-by: Copilot App <[email protected]>
A server can stay unclaimed because a runtime skipped it (for example an unsupported transport); the remediation is printed only when a selected runtime's config holds an entry under that name.

apm-spec-waiver: bug fix in bundle MCP lock recording; no OpenAPM-observable behaviour changes (#4634)

Co-authored-by: Copilot App <[email protected]>
@danielmeppiel Daniel Meppiel (danielmeppiel) added the full-integration Run the full integration suite (ci-integration.yml) on this PR before merge label Nov 21, 2026
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 87b8494 into main Nov 22, 2026
62 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the w2-fix-4634-bundle-lost-lock-mcp branch November 22, 2026 09:19
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 22, 2026
The local-bundle hook row at present-provenance-unknown credits its pair and
asserts the converged pair state; the obligation is required.

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

full-integration Run the full integration suite (ci-integration.yml) on this PR before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reinstalling a local bundle after the lockfile is lost leaves MCP lock state that audit --ci and install --frozen reject

2 participants