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(mcp): delete the emptied config file APM created when its last entry leaves (#4852) - #4862
Retiring APM's last entry from a config file APM created (approval revoked, org policy executables.deny_all, a target dropped) left the file as an empty skeleton -- .mcp.json as {"mcpServers": {}}, .claude/settings.json as {} -- and the lock kept mcp_target_servers: {}. A fresh deploy of the same inputs writes none of them, so the result depended on history.
MCP cleanup of the project .mcp.json (copilot and claude) deletes the file once this cleanup removed every server it held and only empty scaffolding remains (_write_cleaned_json_config in integration/mcp_integrator.py).
Merged-hook cleanup (_clean_apm_entries_from_json, _clean_apm_source_from_json) deletes a hook JSON once what remains equals that target's own injected defaults (Cursor's version: 1), through write_seam.unlink.
LockFile omits an empty mcp_target_servers once no MCP server is left. Serialization and is_semantically_equivalent share one predicate (records_mcp_target_servers in deps/lockfile_container.py), so the lock does not churn. lockfile.py stays under its 2100-line cap.
A file holding the user's own servers or keys, even an empty-valued key, stays with only APM's entries removed.
Known limit: APM keeps no record of file creation. As with the LSP config and #4524, it treats "every entry was APM's and nothing else remains" as proof that it created the file. A file the user created empty and APM then wrote into is deleted; it held no user data. Follow-up: #4867.
Imports W4's lane C differential (tests/lifecycle/security/test_incremental_deploy_differential.py and kit tests/lifecycle/scenarios/_deploy_diff.py, from danielmeppiel-w4-t7-lane-c-differential @ b050939) and flips its three strict Known(#4852) cells.
Red-first: on main + the imported lane C module, pytest tests/lifecycle/security/test_incremental_deploy_differential.py -> 7 passed, 3 xfailed (strict Known #4852: approval-revoked, policy-denies-executables, target-removed). With the fix and the markers kept -> 3 failed (XPASS strict); with the markers removed -> 10 passed.
Guard cells (new): test_retiring_apm_entries_keeps_a_config_file_with_user_content[mcp-user-server|mcp-user-key|claude-settings-user-key] -> 3 passed (a user server or user key keeps .mcp.json / .claude/settings.json, without APM's entry).
Updated anti-oracles that pinned the empty skeleton (unit: hook integrator, dropped-target reconcile, cursor contraction, claude MCP, MCP ownership, lock determinism; integration: test_copilot_root_mcp_json_lifecycle.py, test_lock_derived_expected_state_lifecycle.py) -> 462 passed / 46 passed. Added test_empty_mcp_target_servers_is_omitted_without_mcp_servers, test_constructed_target_servers_equal_their_read_back and test_sync_keeps_settings_with_user_keys[permissions|cursor-default-is-claude-user-key]. After the review folds, the targeted lifecycle and integration run (lane C, lock-derived, copilot root MCP, hooks execution, wave6, hook contraction, reinstall gates, MCP write receipts, gate removal) gives 549 passed, 6 xfailed, and the touched unit files give 602 passed.
Lint mirror: ruff check, ruff format --check, pylint R0801, scripts/lint-auth-signals.sh, scripts/lint-architecture-boundaries.sh, check_complexity_ratchet.py --base-ref origin/main, python -m tests.quality.taxonomy --changed -> all clean. python -m tests.lifecycle.generator --check -> up to date; known_cell_issues --write -> no drift. Ledger row tests/fixtures/lifecycle_bug_ledger/bugs/4852.json -> test_lifecycle_bug_ledger.py 2 passed.
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.
… fresh deploy
Imported from danielmeppiel-w4-t7-lane-c-differential @ b050939 (W4).
Three cells are strict known failures of #4852 until the fix lands.
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…try leaves (#4852)
Retiring APM's last entry left .mcp.json as {"mcpServers": {}} or
.claude/settings.json as {}, and the lock kept an empty
mcp_target_servers; a fresh deploy of the same inputs writes none of them.
- MCP cleanup (copilot and claude project .mcp.json) deletes the file
once this cleanup removed every server in it and only empty
scaffolding remains, as the LSP config and #4524 do.
- Merged-hook cleanup deletes a hook JSON left with only the native
defaults APM injects (Cursor's version: 1).
- The lock omits an empty mcp_target_servers once no MCP server is left.
- A file holding the user's own entries or keys stays.
Flips the three strict Known(#4852) lane C cells and adds user-file
guard cells.
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Cleanup can delete pre-existing configuration files and user-owned keys without proven APM ownership, while lockfile serialization also breaks equality-based no-change detection.
This PR addresses #4852 by cleaning up empty MCP and hook configuration files after APM retires their last managed entry, aiming to make incremental installs match fresh deployments.
Changes:
Adds deletion paths for emptied MCP and merged-hook JSON configurations.
Omits empty MCP ownership metadata when no servers remain and adjusts lockfile equivalence.
Adds differential lifecycle coverage, preservation controls, documentation, and a changelog entry.
File
Description
tests/unit/test_claude_mcp.py
Expects emptied project MCP files to disappear.
tests/unit/integration/test_hook_integrator.py
Tests empty hook-file deletion and user-key preservation.
…ts (#4852)
Review folds:
- A merged hook file is deleted only when what remains equals that
target's own injected defaults (Cursor's version: 1 is a user key in
Claude settings).
- .mcp.json is deleted only when no key other than mcpServers remains,
even an empty-valued user key keeps it.
- LockFile serialization and equivalence share one predicate
(records_mcp_target_servers), so a non-empty map compares equal
whatever its presence flag.
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Cleanup lacks path-containment checks and can delete an external settings.json through a symlinked .claude directory, while the MCP retirement test can pass without deploying the managed entry.
In the mcp-user-server case, deployed.get(container) is already truthy because the fixture contains my-server. All subsequent config assertions also pass if the file remains unchanged and p-exec-mcp was never deployed, so this guard can succeed without exercising MCP retirement at all. Assert that the specific managed entry is present before revoking approval so the test actually proves cleanup preserves the user's server.
…state (#4852)
- _clean_apm_entries_from_json keeps its write_seam.open_for_write write
(the raw-open-for-write owner-rule mutation targets it); deletion goes
through write_seam.unlink behind _only_target_defaults.
- Lock unit tests assert on the written lock text (AQ003).
- test_ownership_siblings reads .mcp.json only while it exists.
apm-spec-waiver: config cleanup residue only; no OpenAPM-observable requirement changes
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Package-target hook reconcile (executables gate, target restriction)
now returns deleted_paths, and install names them under
"Cleaned N emptied hook config file(s) for <pkg>:" so no deletion is
silent. Updates the two lifecycle tests that read the now-deleted
.mcp.json / .claude/settings.json to expect absence.
apm-spec-waiver: config cleanup residue only; no OpenAPM-observable requirement changes
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
hook_file_emptied (hook_ownership) refuses deletion when the target
directory or the file is a symlink; the cleanup rewrites it in place as
before. The MCP user-file guard cell now asserts p-exec-mcp itself was
deployed before the change.
apm-spec-waiver: config cleanup residue only; no OpenAPM-observable requirement changes
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Cleanup can still delete an external hooks.json through a symlinked ancestor and discard a user-modified Cursor config because boolean true is treated as version 1.
No open issues 🎉
2 previously missed issues
In code that hasn't changed since last review
Check symlinked ancestors of user-scoped hooks
src/apm_cli/integration/hook_ownership.py:672
For user-scoped Windsurf hooks at ~/.codeium/windsurf/hooks.json, this check uses .codeium as its base, which has_symlink_component does not inspect. If .codeium is a symlink, retiring the last hook can therefore delete the external hooks.json despite the new guard. Pass the actual project or user containment root through both cleanup paths to this helper, and cover a symlinked ancestor of a nested user target.
Require matching types when removing Cursor skeleton values
src/apm_cli/integration/hook_ownership.py:674
Python considers True == 1, so a cleaned Cursor config containing {"version": true} is treated as the injected {"version": 1} skeleton. If a user changes that value and then removes Cursor or uninstalls, both cleanup paths delete the file instead of preserving the user value. Require matching types as well as values before treating a key as disposable.
…efaults (#4852)
hook_file_emptied takes the project or home containment root from every
caller, so a symlinked ancestor of a nested user target (for example
~/.codeium) blocks deletion; with no root it never deletes. A key matches
an injected default only with the same type, so a user's
{"version": true} keeps a Cursor hooks.json.
apm-spec-waiver: config cleanup residue only; no OpenAPM-observable requirement changes
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…reated to be gone (#4852)
Integration anti-oracles read the file after APM's last entry left;
they now assert absence (or read an absent file as empty).
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because hook cleanup can delete user-owned configuration, and missing static guardrails leave cleanup and lock-field decisions vulnerable to divergence.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Cleanup incorrectly rejects legitimate CLAUDE_CONFIG_DIR paths outside HOME, leaving an empty settings file when retiring the last hook instead of deleting it.
…last server
microsoft#4862 deletes an emptied .mcp.json that APM created, so after hooked-srv is
retired the file is gone. Treat a missing config as no servers.
Co-authored-by: copilot-swe-agent[bot] <[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
Retiring APM's last entry from a config file APM created (approval revoked, org policy
executables.deny_all, a target dropped) left the file as an empty skeleton --.mcp.jsonas{"mcpServers": {}},.claude/settings.jsonas{}-- and the lock keptmcp_target_servers: {}. A fresh deploy of the same inputs writes none of them, so the result depended on history.Following the #4524 / LSP pattern:
.mcp.json(copilot and claude) deletes the file once this cleanup removed every server it held and only empty scaffolding remains (_write_cleaned_json_configinintegration/mcp_integrator.py)._clean_apm_entries_from_json,_clean_apm_source_from_json) deletes a hook JSON once what remains equals that target's own injected defaults (Cursor'sversion: 1), throughwrite_seam.unlink.LockFileomits an emptymcp_target_serversonce no MCP server is left. Serialization andis_semantically_equivalentshare one predicate (records_mcp_target_serversindeps/lockfile_container.py), so the lock does not churn.lockfile.pystays under its 2100-line cap.Known limit: APM keeps no record of file creation. As with the LSP config and #4524, it treats "every entry was APM's and nothing else remains" as proof that it created the file. A file the user created empty and APM then wrote into is deleted; it held no user data. Follow-up: #4867.
Imports W4's lane C differential (
tests/lifecycle/security/test_incremental_deploy_differential.pyand kittests/lifecycle/scenarios/_deploy_diff.py, fromdanielmeppiel-w4-t7-lane-c-differential@ b050939) and flips its three strictKnown(#4852)cells.Issue and approved scope
Issue: Fixes #4852
Human scope-approval comment: #4852 (comment)
Completes the issue.
Type of change
Testing
Red-first: on
main+ the imported lane C module,pytest tests/lifecycle/security/test_incremental_deploy_differential.py->7 passed, 3 xfailed(strict Known #4852: approval-revoked, policy-denies-executables, target-removed). With the fix and the markers kept ->3 failed(XPASS strict); with the markers removed ->10 passed.Guard cells (new):
test_retiring_apm_entries_keeps_a_config_file_with_user_content[mcp-user-server|mcp-user-key|claude-settings-user-key]->3 passed(a user server or user key keeps.mcp.json/.claude/settings.json, without APM's entry).Updated anti-oracles that pinned the empty skeleton (unit: hook integrator, dropped-target reconcile, cursor contraction, claude MCP, MCP ownership, lock determinism; integration:
test_copilot_root_mcp_json_lifecycle.py,test_lock_derived_expected_state_lifecycle.py) ->462 passed/46 passed. Addedtest_empty_mcp_target_servers_is_omitted_without_mcp_servers,test_constructed_target_servers_equal_their_read_backandtest_sync_keeps_settings_with_user_keys[permissions|cursor-default-is-claude-user-key]. After the review folds, the targeted lifecycle and integration run (lane C, lock-derived, copilot root MCP, hooks execution, wave6, hook contraction, reinstall gates, MCP write receipts, gate removal) gives549 passed, 6 xfailed, and the touched unit files give602 passed.Lint mirror:
ruff check,ruff format --check, pylint R0801,scripts/lint-auth-signals.sh,scripts/lint-architecture-boundaries.sh,check_complexity_ratchet.py --base-ref origin/main,python -m tests.quality.taxonomy --changed-> all clean.python -m tests.lifecycle.generator --check-> up to date;known_cell_issues --write-> no drift. Ledger rowtests/fixtures/lifecycle_bug_ledger/bugs/4852.json->test_lifecycle_bug_ledger.py2 passed.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