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(uninstall): keep the lock claim on a hook file sync cannot remove - #4866
apm uninstall deleted the removed package's lock row in Step 9, before Step 10 hook sync. If hook sync then could not remove a hook file, uninstall exited 1 and named the file. But apm.lock.yaml was persisted without the row, or removed entirely when it was the last package, so the lock stopped tracking a file still on disk.
Step 9 now keeps the removed rows aside. After reconciliation, retain_failed_claims (commands/uninstall/lockfile_state.py) returns each removed row narrowed to the files sync failed on, with their recorded hashes, through DeploymentLedgerCodec.replace_legacy_owners. The lock keeps tracking what is still on disk, and the next run can retry.
Does this PR complete the issue, or what remains? It completes it.
Type of change
Bug fix
New feature
Documentation
Maintenance / refactor
Testing
Tested locally
All existing tests pass
Added tests for new functionality (if applicable)
Red-first command-level cell: tests/unit/test_uninstall_hook_sync_failure_claims.py::test_uninstall_keeps_the_claim_of_a_hook_sync_could_not_remove. It runs a real apm install then apm uninstall in process. Only the Path.unlink I/O boundary is faked: selected cleanup's unlink is undone, and the later hook-sync unlink of the same file is denied. It asserts exit 1, the hook still on disk, and its claim still in apm.lock.yaml.
On main d0a48e1: fails, because apm.lock.yaml is gone (the claim is lost).
Bug-ledger row: tests/fixtures/lifecycle_bug_ledger/bugs/4851.json. The lint mirror (ruff 0.15.12, R0801, architecture boundaries, auth signals, complexity ratchet, assertion ratchet, taxonomy) is 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.
Step 9 deleted the removed package's lock row before Step 10 hook sync,
so a hook file sync then failed to remove stayed on disk while
apm.lock.yaml stopped tracking it. The removed rows are kept aside, and
after reconciliation each returns, narrowed through the ledger owner to
the files sync failed on.
Fixes#4851
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Failed-hook claim restoration loses canonical ownership and provenance and can retain invalid parent references that block lockfile saves, while required command-level symlink-race coverage is missing.
When a failed hook claim is retained, this call rebuilds unrelated surviving deployments from legacy path lists and collapses distinct target records for a shared path, such as codex and cursor claims for .agents/skills/shared/SKILL.md. This loses ownership information that the preceding reconciliation preserves and can make later target-specific cleanup overlook the dropped target. Restore failed claims through a ledger-owner operation that preserves unrelated canonical records, and add a regression with multiple surviving target records for one path.
Test omits parent-symlink race and reported-path assertions
The approved scope for #4851 requires a command-level parent-symlink race as well as an I/O failure, but this test only injects PermissionError and never checks the reported path. Add the late parent-symlink case and assert exit 1, the named path, the surviving hook, and its persisted lock claim for both failure modes.
…onical hashes and a valid graph
Addresses Copilot review on #4866: a claim-only row is restored after MCP,
LSP and native survivor derivation (and drops its native_plugin record), its
hash baseline comes from the pre-removal canonical snapshot, and parent edges
to rows removed in the same uninstall re-anchor at the root so the lock still
serializes.
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Retained file-only claims can leave a shared MCP server configured after both packages are uninstalled, and the required parent-directory symlink-swap regression is missing.
Addresses Copilot review on #4866: an aborted hook sync (a path-safety
refusal through a parent swapped for a symlink) reports no per-path result,
so every removed path still on disk keeps its claim, and the refusal is
named without --verbose. Root anchoring of a retained claim's replacement
requests moves to ReplacementBinding.retain_parents_or_root, guarded by
contracts-tooling-source-replacements.
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 sync-abort handling can mistake path-safety or inspection failures for hook absence, dropping a claim and potentially deleting the last-package lockfile while the original hook remains.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Two unresolved issues can redirect retained local dependencies to incorrect sources and discard lock claims when symlink destinations are empty, dangling, or inaccessible.
…im sources
Addresses Copilot review on #4866: after an aborted sync, a removed path
loses its claim only when its absence is proven through real, inspectable
directories (a symlinked parent, an empty or dangling destination, or a
denied lstat keeps it). A local claim whose declaring parent goes is
re-spelled against the project root by the path-anchoring owner
(root_anchored_local_path), so it still names the same source directory.
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Legacy local-claim restoration can leave invalid parent references or colliding serialized identities, preventing lockfile persistence or overwriting a surviving root dependency on reload.
…entity collisions
Addresses Copilot review on #4866: every retained claim's final key is
computed before restoration and parent edges are remapped onto it, so two
retained legacy local generations stay a valid graph; a claim whose
re-spelled identity matches a row the lock keeps joins that row through the
ledger owner instead of shadowing it on reload.
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
apm uninstalldeleted the removed package's lock row in Step 9, before Step 10 hook sync. If hook sync then could not remove a hook file, uninstall exited 1 and named the file. Butapm.lock.yamlwas persisted without the row, or removed entirely when it was the last package, so the lock stopped tracking a file still on disk.Step 9 now keeps the removed rows aside. After reconciliation,
retain_failed_claims(commands/uninstall/lockfile_state.py) returns each removed row narrowed to the files sync failed on, with their recorded hashes, throughDeploymentLedgerCodec.replace_legacy_owners. The lock keeps tracking what is still on disk, and the next run can retry.Issue and approved scope
Issue: Fixes #4851
Human scope-approval comment: #4851 (comment)
Does this PR complete the issue, or what remains? It completes it.
Type of change
Testing
Red-first command-level cell:
tests/unit/test_uninstall_hook_sync_failure_claims.py::test_uninstall_keeps_the_claim_of_a_hook_sync_could_not_remove. It runs a realapm installthenapm uninstallin process. Only thePath.unlinkI/O boundary is faked: selected cleanup's unlink is undone, and the later hook-sync unlink of the same file is denied. It asserts exit 1, the hook still on disk, and its claim still inapm.lock.yaml.apm.lock.yamlis gone (the claim is lost).pytest tests/unit/test_uninstall_hook_sync_failure_claims.py tests/unit/test_uninstall*.py tests/unit/commands/test_uninstall*.py: 186 passed.Bug-ledger row:
tests/fixtures/lifecycle_bug_ledger/bugs/4851.json. The lint mirror (ruff 0.15.12, R0801, architecture boundaries, auth signals, complexity ratchet, assertion ratchet, taxonomy) is 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.