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
fix(install): retire MCP entries APM wrote when the lockfile is absent - #4760
Without apm.lock.yaml, apm install had no record of which MCP server entries it had written to a runtime config, so it could not retire an entry for a server it no longer deploys, and apm audit --ci passed.
This change:
Records machine-local, per-entry write evidence for each MCP entry install (and update) actually writes: runtime, config file, native key and the fingerprint of the entry as written. The record sits next to the deployment receipts ($APM_HOME/deployment-receipts/mcp/) and carries the same installation binding (DeploymentMaterializationSession.binds / binding). An entry that already matched is never recorded, so an identical entry the user wrote never becomes APM's.
When apm.lock.yaml is absent, install removes an entry that evidence proves is unchanged and no longer deployed. An entry with no record (including one identical to a declaration) is never considered. An entry it cannot prove (edited since, or unusable record) is kept, reported on every install (Kept MCP server '<name>' in <config>), and marked kept.
Adds the kept-mcp-entries baseline check: apm audit --ci fails while a kept entry remains and the lockfile does not manage its server.
Behaviour with a lockfile is unchanged.
Owner registry (install-deployment.json) and remediation catalog (KEPT_MCP_ENTRIES) are updated; docs (install.md, deny.md, baseline-checks.md) and packages/apm-guide governance list describe the new behaviour.
Does this PR complete the issue, or what remains? Completes it. Files and hooks (#4644), pre-receipt files, lockfile format and MCP behaviour with a lockfile are out of scope and unchanged.
Type of change
Bug fix
New feature
Documentation
Maintenance / refactor
Testing
Tested locally
All existing tests pass
Added tests for new functionality (if applicable)
Lifecycle cells (installed CLI, LOCK=absent PRIM=mcp MCPOWN=copilot) in tests/lifecycle/scenarios/test_mcp_write_receipts.py:
Unit tests: tests/unit/install/test_mcp_write_receipts.py. Bug-ledger row: tests/fixtures/lifecycle_bug_ledger/bugs/4737.json.
Validation evidence: pending (updated below once targeted runs finish).
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.
apm install now records, on this machine, evidence for each MCP entry it
writes to a runtime config: the runtime, the config file, the native key
and the fingerprint of the entry as written. The record lives next to the
deployment receipts and carries the same binding (project root and its
identity, scope, installation identity).
When apm.lock.yaml is absent, install uses that record to remove an entry
APM wrote for a server it no longer deploys, when the entry is unchanged.
An entry with no record stays, including one identical to a declaration.
An entry the record cannot confirm (changed since, or an unusable record)
stays, install names it, and apm audit --ci reports it under
kept-mcp-entries. MCP behaviour with a lockfile is unchanged.
Co-authored-by: Copilot App <[email protected]>
… remediation catalog
Register install/mcp/write_receipts.py with the MCP ownership owner, allow
its use of the deployment session binding in the provenance guard, render
the kept-mcp-entries advice from core/remediation.py, and keep the
deployment ledger's binding checks in their guarded shape.
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Receipt ownership can misidentify and delete user-managed MCP entries while leaving installed entries behind, and cleanup and audit gaps can leave stale configurations undetected.
This PR extends APM’s deployment receipts to MCP entries, addressing #4737 after the file-cleanup work in #4644. It aims to retire entries APM wrote when the lockfile is missing, while preserving user-owned or edited entries.
Changes:
Records installation-bound MCP write evidence during install and update.
Adds lockless retirement and a kept-mcp-entries audit check.
Adds regression coverage, ownership guards, remediation guidance, and documentation.
File
Description
tests/unit/install/test_mcp_write_receipts.py
Tests receipt binding, retirement, and preservation.
… install
With nothing deployed before, the first MCP write records its evidence
against this checkout's installation identity, so .apm-local/ is created
in the unowned state of test_operations_beside_a_users_skill_keep_its_bytes.
Co-authored-by: Copilot App <[email protected]>
…ery retirement
- Journal the native key the adapter wrote from its requested info, so a
registry server written under its short key never claims an identical
user entry under the full name.
- Treat a config the adapter reader cannot parse as unreadable: keep its
evidence and say so, instead of forgetting the records as removed.
- Remove Hermes YAML and OpenCode v2 nested entries through the canonical
exact-key remover; forget a record only after a re-read confirms removal.
- apm audit --ci reports unusable MCP write evidence under kept-mcp-entries.
- Audit reads user-scope evidence against the deployment root, as install
records it.
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Unresolved retirement and cleanup flaws can delete still-needed or explicitly excluded MCP entries and remove external files through a symlinked receipt directory.
Keep warning about unmanaged entries on later installs
src/apm_cli/install/mcp/integration.py:965
If a lockless install keeps edited server A while server B remains declared, it rebuilds a lock containing B. The next install skips this block, so A's promised repeated keep warning disappears even though its entry remains unmanaged. Keep retirement limited to the absent-lock case, but report still-present, unmanaged kept receipts on subsequent installs too; cover a surviving dependency in the rerun lifecycle case.
Use JSONC-aware cleanup for IntelliJ configs
src/apm_cli/install/mcp/write_receipts.py:310
For an IntelliJ target, this new retirement path sends a valid JSONC configuration to _remove_native_entry, whose fallback cleaner uses json.loads. Adding comments or trailing commas without changing the receipted server still passes the adapter's reader and fingerprint check, but cleanup raises RequiredIntegrationError and leaves the server configured. Route this runtime through its JSONC-aware canonical-config cleanup while retaining exact-key ownership protection; tests/integration/test_intellij_mcp_config_lifecycle.py:587 already covers this supported format for uninstall.
Journal MCP writes from the local Claude bundle path
src/apm_cli/install/service_integration.py:216
The local Claude-bundle install returns through a separate path whose _wire_legacy_bundle_mcp_servers calls run_owned_mcp_integration without this journal. Those successful MCP writes therefore produce no receipts, so losing the lockfile still makes their entries impossible to retire or report. Journal the bundle write boundary too, or move journaling to a shared boundary that covers both install paths.
…canonical exclusion
- An entry whose config is unreadable or whose native key is unknown has
unknown presence: its record is kept, marked kept and reported by
apm audit --ci until absence can be established.
- A record is not retired when a declared server now deploys to the same
native key (registry owner/demo replaced by self-defined demo).
- --exclude goes through filter_excluded_mcp_runtimes (case-folded, aliases).
- Collecting receipts of deleted checkouts never follows a symlinked MCP
receipt path.
- Unit tests observe durable config state and patch only the JSON cleanup
I/O boundary.
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
An unbounded YAML fallback bypasses resource limits and can exhaust memory or hang install/audit, while receipt-handling gaps can let audits pass with obsolete MCP entries still configured.
- A declared server protects only the native key it deploys to, computed
from its stored declaration (_native_config_key), not every short name.
- The unreadable-config probe parses YAML with the bounded loader.
- apm audit --ci reports MCP write evidence that exists but is
inaccessible or symlinked, without following it.
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
An unreadable optional MCP receipt incorrectly fails audit --ci even when an intact lockfile manages every server and no lockless retirement occurred, causing a false failure in locked projects.
… is absent
With apm.lock.yaml present the lockfile governs MCP cleanup and the
machine-local record is unused, so a corrupt record no longer fails
apm audit --ci there; lockless audits still report it.
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Lock regeneration can hide a corrupt receipt encountered during lockless installation, allowing subsequent audit --ci checks to pass without reporting the unusable evidence.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Lock regeneration can suppress unusable-evidence findings, allowing audit --ci to pass despite stale MCP entries that installation warned could not be retired.
…ver cannot rewrite
- A receipt whose "writes" is not a list is unusable evidence, not an
empty record.
- A config the exact-key remover cannot rewrite (for example JSONC) keeps
the entry and reports it instead of aborting the lockless install.
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The kept-receipt filter leaves a stale registry receipt when an entry is redeclared as self-defined without a write, causing audit --ci to fail for an entry the project now deploys.
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
Without
apm.lock.yaml,apm installhad no record of which MCP server entries it had written to a runtime config, so it could not retire an entry for a server it no longer deploys, andapm audit --cipassed.This change:
$APM_HOME/deployment-receipts/mcp/) and carries the same installation binding (DeploymentMaterializationSession.binds/binding). An entry that already matched is never recorded, so an identical entry the user wrote never becomes APM's.apm.lock.yamlis absent, install removes an entry that evidence proves is unchanged and no longer deployed. An entry with no record (including one identical to a declaration) is never considered. An entry it cannot prove (edited since, or unusable record) is kept, reported on every install (Kept MCP server '<name>' in <config>), and marked kept.kept-mcp-entriesbaseline check:apm audit --cifails while a kept entry remains and the lockfile does not manage its server.Owner registry (
install-deployment.json) and remediation catalog (KEPT_MCP_ENTRIES) are updated; docs (install.md,deny.md,baseline-checks.md) andpackages/apm-guidegovernance list describe the new behaviour.Issue and approved scope
Issue: Fixes #4737
Human scope-approval comment: #4737 (comment)
Does this PR complete the issue, or what remains? Completes it. Files and hooks (#4644), pre-receipt files, lockfile format and MCP behaviour with a lockfile are out of scope and unchanged.
Type of change
Testing
Lifecycle cells (installed CLI,
LOCK=absent PRIM=mcp MCPOWN=copilot) intests/lifecycle/scenarios/test_mcp_write_receipts.py:audit --cipasses.audit --ciexits 1 naming the entry.Unit tests:
tests/unit/install/test_mcp_write_receipts.py. Bug-ledger row:tests/fixtures/lifecycle_bug_ledger/bugs/4737.json.Validation evidence: pending (updated below once targeted runs finish).
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)
docs/src/content/docs/specs/openapm-v0.1.mdupdated(new/changed
<a id="req-XXX"></a>anchor + prose + Appendix Crow).
docs/src/content/docs/specs/manifests/openapm-v0.1.requirements.ymlupdated.
@pytest.mark.req("req-XXX")test undertests/spec_conformance/added or extended.CONFORMANCE.{md,json}regenerated viauv run --extra dev python -m tests.spec_conformance.gen_statementand committed.