Repository navigation
fix(uninstall): re-land #4866, keep the lock claim on a hook file sync cannot remove - #4952
Conversation
…c cannot remove Reverts 970f2a6 (the #4950 revert), restoring #4866 (#4851). Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…last server #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]>
…config removal Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Uninstall can drop a lock claim while leaving the original hook behind on POSIX, and the changelog fragment’s mismatched PR reference blocks validation and release rendering.
2 open issues
What changed in this PR
Re-lands #4866 to preserve lockfile ownership when uninstall cannot remove a hook file, and updates regression coverage for #4862's deletion of emptied MCP configs.
Changes:
- Restores failed file claims with their hash baselines and valid dependency graph links.
- Adds regression coverage for cleanup failures, local-source anchoring, and simultaneous MCP config removal.
- Adds an architecture guard, bug-ledger entry, and changelog fragment.
| File | Description |
|---|---|
tests/unit/test_uninstall_hook_sync_failure_claims.py |
Tests retained claims and the empty MCP config interaction. |
tests/unit/deps/test_replacement_binding.py |
Tests parent pruning and root anchoring. |
tests/fixtures/lifecycle_bug_ledger/bugs/4851.json |
Records the bug and regression tests. |
src/apm_cli/models/dependency/replacement.py |
Adds root anchoring when replacement parents are removed. |
src/apm_cli/deps/path_anchoring.py |
Preserves local source locations after reparenting. |
src/apm_cli/commands/uninstall/lockfile_state.py |
Restores failed claims through the deployment ledger. |
src/apm_cli/commands/uninstall/cli.py |
Saves removed rows and restores claims after sync failures. |
scripts/architecture_linter/checks/contracts_dependency_replacements.py |
Guards use of the canonical replacement owner. |
changelog.d/4952.fixed.md |
Documents the uninstall ownership fix. |
Review effort: Balanced
…agment ends with #4952 Addresses Copilot review on #4952. Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
… tree fixed Co-authored-by: copilot-swe-agent[bot] <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
A critical symlink race in hook inspection can falsely establish absence and drop the hook’s lock claim during an aborted sync, requiring a stable no-follow walk and a parent-swap regression test.
1 open issue
Review effort: Balanced
#4851) A parent swapped for a symlink between its check and the final lookup could redirect the lookup to an empty directory and drop a hook's lock claim. Where the platform supports it, each parent is now opened as a no-follow directory handle and the next lookup goes through it. Co-authored-by: copilot-swe-agent[bot] <[email protected]>
… or a part is . or .. (#4851) On Windows a junction lstats as a directory, so the lstat walk could still prove a hook absent through a swapped parent. Without no-follow directory handles nothing is proven and the claim stays; '.' and '..' parts are refused. Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…rt durable state (#4851) Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…ed root no-follow (#4851) A '//server/share' claim parsed to an absolute '//' part that os.open resolved outside the deploy root. Absolute paths are now refused, and the resolved deploy root is opened with O_NOFOLLOW so a root swapped for a symlink after resolving proves nothing. Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: Copilot App <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…ved (#4851) A root replaced by a link to an empty directory was resolved and walked, proving a hook absent while it remained in the moved root. The root is now opened as given with O_NOFOLLOW, so a link root proves nothing. Co-authored-by: Copilot App <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: Copilot App <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
Human assessment is needed because an ancestor-directory symlink swap can falsely prove hook absence, allowing uninstall to discard its tracking claim while the hook survives.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
…e uninstall (#4851) O_NOFOLLOW guards only the root's last component, so a root reached through a swapped ancestor could prove a hook absent while it remained in the moved tree. The root's identity is pinned before uninstall changes anything, and absence is proven only when the opened root is that directory. Co-authored-by: Copilot App <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: Copilot App <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…ll/hook_absence.py (#4851) Moves the no-follow absence proof and root pin out of uninstall/cli.py, unchanged, so the merged cli.py stays under the file-length guardrail. Co-authored-by: Copilot App <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
The new selector lacks a registered guard and mutation regression enforcing uninstall’s pinned-root/no-follow absence check, allowing a bypass that could reintroduce symlink-related claim loss.
1 open issue
Review effort: Balanced



Description
Re-land of #4866 (reverted in #4950), plus a fix for its clash with #4862.
apm uninstallused to drop a removed package's lock row before hook sync. A hook file that sync then failed to remove stayed on disk whileapm.lock.yamlstopped tracking it. Now the row comes back narrowed to the files sync could not remove: canonical hash baseline, valid replacement and local-source graph, and no service membership. The full design and the Copilot review history are on #4866.Why #4866 was reverted. #4862 landed after #4866's CI base. It deletes a
.mcp.jsonthat APM created once its last entry leaves.test_a_retained_hook_claim_does_not_keep_its_mcp_serverread that file unconditionally, so main went red on every OS. The behavior was correct; only the test was wrong.This PR
ceaa9e9ereverts the revert (970f2a6). Thesrc/andscripts/trees are byte-identical to fix(uninstall): keep the lock claim on a hook file sync cannot remove #4866's merge (c22ccbe).29491406treats a missing.mcp.jsonas no servers in that test.87f6369eadds a clash cell,test_a_retained_hook_claim_survives_the_removal_of_an_emptied_mcp_config. One uninstall both retires the package's only MCP server (fix(mcp): delete the emptied config file APM created when its last entry leaves (#4852) #4862 deletes the emptied.mcp.json) and keeps the hook claim sync could not remove ([BUG] apm uninstall drops a removed package's lock claim when hook sync fails after the row is deleted #4851). It asserts exit 1,.mcp.jsongone, nomcp_serversin the lock, the hook on disk, and the lock still claiming it. Red on main (the lock is removed, so the claim is lost); green here.Issue and approved scope
Issue: Fixes #4851. Refs #4896 (the follow-up MCP survivor fix is #4900).
Human scope-approval comment: #4851 (comment)
Does this PR complete the issue, or what remains?
It completes #4851. The rest of #4896 (LSP and native membership) follows after this lands.
Type of change
Testing
Validation evidence:
src/(post-revert: #4866 (main red c22ccbe8: test_a_retained_hook_claim_does_not_keep_its_mcp_server) #4950),uv run --extra dev pytest -q -p no:xdist tests/unit/test_uninstall_hook_sync_failure_claims.py -k emptied_mcp_configgives 1 failed (FileNotFoundError: app/apm.lock.yaml). With this branch it passes.uv run --extra dev pytest -q -p no:xdist tests/unit/test_uninstall_*.py tests/unit/commands/test_uninstall_*.py tests/unit/deps/test_replacement_binding.py tests/quality/test_lifecycle_bug_ledger.py: 228 passed.--base-ref origin/main, taxonomy--changed,lint_architecture_boundaries.py --root .): all clean.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.