Repository navigation
Description
Describe the bug
When a project's own .apm/skills/<name> is renamed or deleted, apm install removes the old .claude/skills/<name> copy but keeps .agents/skills/<name> on disk and in local_deployed_files / deployments. Later installs, --force, apm update, and apm prune keep carrying it forward, and apm audit reports nothing. Removing a target that uses .agents/skills/ (for example copilot) from targets: leaks the same way. Dependency skills are cleaned correctly in both cases.
Traced on 280b8a7b:
post_deps_localpersists local rows throughDeploymentLedgerCodec.replace_legacy_owner(post_deps_local.py:130), which rebuilds locators from path prefixes. Since fix: avoid attributing shared .agents paths (closes #2743) #2774,.agents/has no prefix, so each local.agents/row is written astarget: legacy. Dependency rows are persisted from the reconciled ledger and keepcopilot/codex.DeploymentReconciler._is_stalenever marks alegacyrow stale. The generic-row fallback inunion_preserving(generic_governed_values) requires the active targets to equal the declared targets, butdeclared_target_profilesalways appends the non-canonical targets, so the fallback never runs whentargets:is declared.
To Reproduce
cd "$(mktemp -d)" && git init -q
mkdir -p .apm/skills/demo-v1
printf -- '---\nname: demo-v1\ndescription: Demo\n---\n\nBody.\n' > .apm/skills/demo-v1/SKILL.md
printf 'name: demo\nversion: 1.0.0\ntargets:\n - claude\n - copilot\n' > apm.yml
apm install
mv .apm/skills/demo-v1 .apm/skills/demo-v2
sed -i.bak 's/demo-v1/demo-v2/' .apm/skills/demo-v2/SKILL.md && rm .apm/skills/demo-v2/SKILL.md.bak
apm install # "2 stale files cleaned": only the .claude copy
find .agents .claude -name SKILL.md
grep -A4 '^local_deployed_files' apm.lock.yaml.agents/skills/demo-v1/SKILL.md remains on disk, and the lockfile still lists it with target: legacy.
Expected behavior
.agents/skills/demo-v1 is removed from disk and the lockfile, the same as .claude/skills/demo-v1 and as dependency skills are.
Environment (please complete the following information):
- OS: macOS
- Python Version: 3.12
- APM Version: 0.33.0; also reproduces on
mainat280b8a7b
Additional context
Deleting apm.lock.yaml and reinstalling clears it until the next rename. #2902 / #2924 fixed the same target loss for dependencies during partial updates. The generic-row fallback added in #2283 was meant to handle unlabeled .agents/skills entries but never runs when targets: is declared.
Proposed fix: persist the local block's reconciled records with concrete targets, as _attach_deployed_files does for dependencies, and let existing legacy rows reconcile when an active target governs their path. I can send a PR if this scope works.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
danielmeppiel commentedon Oct 7, 2026
Decision: approve
Area: project
Scope: Fix cleanup of the project's own
.apm/skills/after a source skill is renamed or deleted, or a declared target is removed. Keep the target information already known during installation in the existing deployment ledger, rather than reducing it to filenames and guessing the target later. Treat.agents/as shared: remove an obsolete target's deployment record, but keep the physical file while another valid target or package still needs it. Only files with no surviving claim become candidates for the existing safe cleanup.Done when: Reproduce the reported Claude/Copilot case on current code, then cover install, source rename, source deletion, declared-target removal, reinstall and read-only audit through the existing APMLifecycle state-machine tests, with independent checks of disk contents and lock records. Cover both new deployments and the local
target: legacyrecords produced by this reproducer, using existing ownership and target-governance rules rather than guessing from.agents/. Prove that removing one of two targets sharing a file keeps it, while removing the last valid claim allows normal cleanup. A target-only install must not discard an unprocessed sibling target's claim. Preserve existing safeguards for user edits, untracked files, shared package ownership and failed materializations. Repeated installs must settle to stable disk and lock state. Investigate the reported clean audit rather than assume its cause; keep audit non-mutating and genuine drift detectable. Reuse the canonical ledger, reconciler and deletion helper, with a registered architecture guard against a second cleanup policy or lossy local persistence, and update directly related guidance.Out of scope: Giving Copilot or any harness ownership of all
.agents/; blanket folder deletion; detecting or chasing renamed installed copies; treating a rename as a new detach feature; automatic adoption of user files; reconstructing every historical ownership record; changing the existing deletion policy for records without saved hashes; resetting the lockfile as the fix; new cleanup commands, ownership schemas or collision policies. If an ambiguous legacy case requires a new ownership policy, preserve it and bring that policy back separately. No implementation dispatch from this decision session, blocked-delivery restart, PR/merge approval or release commitment.Review contact: Daniel Meppiel (@danielmeppiel)
Reason: A source rename currently leaves the reporter with both the old and new skill under
.agents/, although Claude's old copy is removed. The source inspection supports a bookkeeping gap: the old shared-root entry can lose its target identity and never reach stale-file cleanup. This should be a repair of the existing installation contract, not a new rename-management system. For example, if Copilot and Codex need the same file, removing Copilot must not break Codex. #2924 is related dependency-side precedent, not proof that local skills are already fixed. The reporter's PR offer is welcome within this scope; no assignment is made. Recorded by Copilot after Daniel Meppiel (@danielmeppiel) explicitly approved this bounded scope. This is scope acceptance, not a claim that a fresh CLI reproduction or implementation has been completed.fix(install): keep bundle output unattributed and unswept
test(install): cover microsoft#3179 through the lifecycle state machine
fix(install): keep carried bundle provenance non-fatal and cite req-l…
fix(install): keep unprocessed sibling claims and clean deleted .apm …
fix(install): keep cleanup entry from failing without a known target
fix(install): decide local cleanup through the canonical target owner
fix(install): keep the target seam single and install.py within budget
fix(install): share the retained-row cleanup decision with the pipeline
fix(install): resolve cleanup targets once and never fail a preview
refactor(install): reuse the pipeline's target decision for cleanup work
fix(install): reconcile local skills under shared .agents roots
fix(install): reconcile local skills under shared .agents roots
fix(install): reconcile local skills under shared .agents roots
Merge current main for local skill reconciliation
Merge current main while preserving bounded local cleanup
fix(install): recorded-target fallback never turns the #3179 no-op in…
fix(lockfile): sync the #5554 backport to the final main PR head 469bc14