Repository navigation
Description
Describe the bug
When a dependency is removed from apm.yml on one machine and the updated apm.yml / apm.lock.yaml reach a teammate through git pull, the teammate's deployed files for that dependency (e.g. .claude/skills/<name>/) are never cleaned up, and nothing reports them:
apm audit --cipasses all checks, includingdrift. The docs list "orphan files left after their source was removed" as one of the failure modes drift detection catches (orphaned), but the replay starts from the new lockfile, which no longer mentions the dependency. The code itself disagrees on whatorphanedmeans: the module docstring defines it as a file "not present in the scratch replay AND not tracked in the lockfile", while the implementation only reports files that are tracked in the current lockfile and skips untracked ones as user-authored. The docstring's definition would cover this case; the implementation does not.apm installdoes not remove them. On the author's machine the same install cleans them up ("2 stale files cleaned"), because the previous lockfile still recorded them asdeployed_files. On the teammate's machine that record was overwritten by the pull before any APM command ran.apm prunedetects the orphaned package and removesapm_modules/_local/<name>, but leaves its deployed files in place. After that, the package source is gone too, so APM has no remaining way to attribute those files.
As a result, the removed skill stays active for the teammate's agent indefinitely, and every check says the workspace is clean.
This is the common setup where apm_modules/ and the deployed directories are gitignored and only apm.yml + apm.lock.yaml are committed.
To Reproduce
Self-contained script. It uses two local dependencies for portability; the mechanism only depends on the lockfile being replaced by git pull.
set -e
W="$(mktemp -d)" && cd "$W"
# author: project with two local dependencies, each shipping one skill
mkdir author && cd author && git init -q
for p in alpha beta; do
mkdir -p "pkgs/$p/.apm/skills/$p"
printf 'name: %s\nversion: 1.0.0\n' "$p" > "pkgs/$p/apm.yml"
printf -- '---\nname: %s\ndescription: Demo %s\n---\n\nBody.\n' "$p" "$p" > "pkgs/$p/.apm/skills/$p/SKILL.md"
done
printf 'name: demo\nversion: 1.0.0\ntargets:\n - claude\ndependencies:\n apm:\n - ./pkgs/alpha\n - ./pkgs/beta\n' > apm.yml
printf 'apm_modules/\n.claude/\n' > .gitignore # deployed files are not committed
apm install
git add -A && git -c user.name=a -c user.email=a@a commit -qm "add alpha and beta"
# teammate clones and installs
cd .. && git clone -q author teammate && (cd teammate && apm install)
# author drops beta
cd author
sed -i.bak '/pkgs\/beta/d' apm.yml && rm apm.yml.bak
apm install # author's copy: "2 stale files cleaned"
git -c user.name=a -c user.email=a@a commit -qam "drop beta"
# teammate pulls
cd ../teammate && git pull -q
apm audit --ci --no-policy # passes
apm install # does not remove .claude/skills/beta
apm prune # removes apm_modules/_local/beta only
ls .claude/skills # alpha betaExpected behavior
In order of importance:
apm auditreports.claude/skills/beta/**asorphaneddrift (and--cifails), as documented.apm installremoves the deployed files of a package that left the resolved graph, the same way it already does when the previous lockfile is available locally. Attribution is still possible on the teammate's machine:apm_modules/_local/betais present, so APM can recompute what that package deploys and delete only files whose bytes still match. Files the user edited are kept and reported, consistent with how fix(prune): reconcile deployment ledger ownership #2292 preserves user-edited bytes.apm prunedoes not discardapm_modules/<pkg>while that package's deployed files remain. It either cleans them in the same operation or leaves the package in place and reports the files.
Environment (please complete the following information):
- OS: macOS 26 (Darwin 25.3.0, arm64)
- Python Version: N/A (standalone release binary)
- APM Version: 0.33.0 (18c4c43); also reproduces on 0.29.0
- VSCode Version (if relevant): N/A
Logs
Teammate side, after git pull:
### apm audit --ci --no-policy
[>] Replaying install (cache-only)...
[+] Replayed 1 package(s)
[>] Diffing scratch vs working tree...
[+] No drift detected
...
│ [+] │ deployed-files-present │ All deployed files present on disk │
│ [+] │ no-orphaned-packages │ No orphaned packages in lockfile │
│ [+] │ drift │ no drift detected against lockfile │
[*] All 10 check(s) passed
### apm install
[>] Installing dependencies from apm.yml...
[i] Targets: claude (source: apm.yml)
[+] ./pkgs/alpha (local)
|-- 1 skill(s) integrated -> .claude/skills/
[*] Installed 1 APM dependency in 0.1s.
### apm prune
[>] Analyzing installed packages vs apm.yml...
[!] Found 1 orphaned package(s):
[!] - _local/beta
[i] Removed _local/beta
[*] Pruned 1 orphaned package(s)
### ls .claude/skills
alpha
beta
Author side, same change, for comparison:
[i] Cleaned 2 files from packages no longer in apm.yml
[*] Installed 1 APM dependency (2 stale files cleaned) in 0.1s.
Additional context
- Root cause as observed: deployment ownership lives only in
apm.lock.yaml. In a team, the lockfile is a shared, version-controlled file, so it can be replaced underneath a working tree bygit pull,git checkoutor a merge. Cleanup that depends on diffing the previous lockfile against the new one only works on the machine that made the change. - Scope check: with the same script but only
apm_modules/gitignored (deployed files committed), the issue does not occur. The author'sapm installdeletes.claude/skills/beta/SKILL.md, that deletion is committed, andgit pullremoves it on the teammate's side. So this only affects projects that gitignore deployed outputs. That remains a supported repository choice ([FEATURE] Extend .gitignore coverage from apm_modules/ to deployed files #1342 was closed as not planned, leaving commit-vs-ignore to each repository), so APM needs to handle it. apm prune --dry-rundoes flag_local/betabeforeapm pruneruns. That signal disappears after the first prune.- Related but distinct: [BUG] Renamed or removed local .apm/ skills are never cleaned from .agents/skills/ or apm.lock.yaml #3179 (local
.apm/skills not cleaned from.agents/skills/on the same machine), fix(prune): reconcile deployment ledger ownership #2292 (prune reconciling ledger ownership when the lock still knows the departed owner), apm lock deletes dropped deployed files (pre-existing lock-mode disk deletion via _attach_deployed_files) #2296 / fix: apm lock must not delete dropped deployed files (closes #2296) #2304 (apm lockdeferring deletion to the next install).
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsTodo
Activity
github-actions commentedon Oct 11, 2026
[i] Automated advisory, not a maintainer decision.
Thank you for the thorough report, including the docstring-versus-implementation mismatch in
install/drift.py. The scenario (dependency removed upstream, teammate pulls a lockfile that no longer records itsdeployed_files) is realistic and leaves silent orphans thataudit,installandpruneall miss.Suggested direction: needs-design. Detecting these files cannot rely on the new lockfile alone, so the design must settle:
git pull, or marker/provenance on deployed files).driftorphanedshould follow the docstring definition, and whatpruneandinstallshould do.Proposed done-when: the teammate scenario is detected by
audit --ciand removable viaprunewithout touching user files. A maintainer must approve scope and a review contact (lockfile and drift expertise) first.danielmeppiel commentedon Oct 14, 2026
Discussion proposal: policy-driven, harness-aware reconciliation
For discussion only. This is not implementation approval, an accepted scope, or authorization to start delivery. The configuration below is proposed behavior, not an available feature.
Target UX
The desired team workflow is:
People should not need to remember an extra cleanup command, use
--force, or maintain another installation-tracking file. A successful install that leaves a removed skill active violates the package-manager expectation that the working installation reflects the project's desired state. A warning alone does not deliver that outcome.The proposed control belongs in the existing
unmanaged_filespolicy, not a newmanaged_outputsmanifest field or a hardcoded output directory. The policy decides what is permitted; the harness adapters determine actual destinations.Why npm is a useful analogy, but not a drop-in implementation
npm documents that extraneous packages in
node_modulesare pruned automatically during normal operation. A bounded npm 11.11.0 experiment using real Git clone/pull, local package tarballs, offline execution and disabled lifecycle scripts confirmed that ordinary install removes the departed package. It also worked after removing the hiddennode_modules/.package-lock.json; that hidden file is not a necessary explanation for this cleanup behavior.APM has an additional boundary. It installs packages under
apm_modules, but also materializes native agent inputs into harness-specific locations. Those destinations can contain user-authored content, other tools' files, and shared configuration. Removing a recognized cached package does not establish ownership of a separate copied skill. Nor can APM treat an entire harness directory like disposablenode_modules: it can contain unrelated settings or session data.An isolated
ApmLifecycleRunnerexperiment atfe391190reproduced the ownership ambiguity: an APM-deployed native skill and a byte-identical, pre-existing unmanaged skill produced indistinguishable surviving project files after replacement of the shared manifest/lock and pruning. The experiment simulated the file effect of pull; it did not execute Git pull. Matching cached bytes therefore cannot, by itself, prove which history happened.The npm lesson is desired-state convergence during install. For APM, permission to remove otherwise untracked native inputs must be explicit because the output space is not inherently exclusive to APM.
Proposed policy behavior
A possible extension to the existing policy block:
ignorewarndenyreconcileapm auditstays read-only; it would treatreconcileas a requirement to report remaining violations, not permission to mutate.Today, the unmanaged-files check is an audit check and is explicitly excluded from install's dependency-policy seam. Wiring it into install is part of this proposal. An explicit new action avoids silently turning existing
denypolicies into deletion policies; the name and precise compatibility rules remain open for discussion.The report's
--no-policyreproduction, and the independent baseline probe using the same switch, do not test an enabled unmanaged-files policy. This proposal is an opt-in policy-based solution, not a claim that the unchanged policy-disabled reproduction would start deleting files. Once a project adopts it, teammates still use ordinaryapm install, without an extra per-invocation flag.Implementation direction
Harness-derived scope. Resolve targets normally, including legacy routing, and reuse
TargetProfileplusinstall_governance(targets, bounded=True). Replace hardcoded default discovery with adapter-derived native-input surfaces. Respect explicit policydirectoriesandexclude; a broad policy directory is not permission to recursively delete everything beneath it. Preserve other targets' surviving ownership.One inventory for audit and install. Reuse canonical deployment information and native adapter projections to classify actual outputs. For install, compare against the complete desired dependency and local-source deployment, not only successfully copied files or the newly pulled lockfile's remaining rows. Shared hook configuration is deliberately outside ordinary file tracking; an absent flat file claim must not cause whole-file deletion.
Late, explicit reconciliation. Only a complete, eligible install with an effective enforcing policy may perform policy-driven cleanup. Materialize and validate wanted content, account for local primitives and surviving owners, reconcile eligible unexpected outputs through the existing cleanup machinery, and then evaluate remaining violations. Do not reuse
--forceor invent historical ownership rows.Bound the first repair. Cover project-local, file-based skill artifacts across supported harness layouts, including legacy paths. Shared settings, DB-backed registrations and unsupported artifact types must be preserved and reported rather than swept. Keep
pruneconsistent with the chosen contract without making a separate prune invocation necessary for the target UX.Failure and lifecycle behavior. Removing the last dependency must not short-circuit reconciliation. Partial-package installs, incomplete inventories, failed source/materialization gates and policy-disabled or advisory operation must not trigger policy-driven deletion. Preserve path containment, symlink safeguards, exclusions, frozen-mode rules and dry-run behavior. Cleanup failure must be reported; repeated install must retry coherently rather than claim success. No new durable receipt or retirement history is assumed.
The product tradeoff that needs discussion
Under
reconcile, an undeclared manually added or locally edited skill in the governed scope may also be removed unless excluded. The proposed authority is the explicit policy, not recovered proof that APM originally created the file. Projects that need to preserve such content can declare its source, exclude it, or retain a non-destructive policy action.This differs from promising that every unknown user edit will survive automatic cleanup. If that preservation requirement is absolute, an ambiguous artifact must be retained and reported instead. We should settle this distinction explicitly, not hide it behind the word "orphan".
Before accepting implementation scope, the lifecycle evidence should cover the teammate-removal scenario across harness layouts, last-skill removal, skipped updates, cache already pruned, declared local skills, exclusions, surviving owners, incomplete installs and stable repeat runs. The experiment above establishes the current ambiguity, not validation of this proposed fix.
Discussion focus: is policy-authorized reconciliation the right way to obtain the normal-install UX while preserving unmanaged content by default? Is an explicit new
unmanaged_files.actionpreferable to changing existingdenysemantics, and does this opt-in outcome meet this issue's intended scope?AI-assisted investigation and drafting by GitHub Copilot, posted at Daniel Meppiel (@danielmeppiel)'s request.
danielmeppiel commentedon Nov 10, 2026
Status note: this issue stays open. It is not being closed for inactivity, because the 2026-10-14 comment was a discussion proposal from the maintainers rather than a request for evidence from you, Rafael Azevedo (@rrazvd).
The next step sits with the maintainers: a design decision on how ordinary
git pullfollowed byapm installshould make upstream removals take effect, within the existingunmanaged_filespolicy direction described in that discussion proposal. That proposal is still for discussion only; it is not an accepted scope or an invitation to implement yet. Feedback on whether that outcome would cover your teammate scenario is still welcome here.Generated by issue-reduction-lane-b. This comment is AI-generated and may contain errors.
rrazvd commentedon Nov 11, 2026
Daniel Meppiel (@danielmeppiel) Thanks for the detailed proposal. Re-checked on current main (0.35.0,
5753b7efc): the original script still reproduces. After the pull,audit --cipasses,installcleans nothing,pruneremoves onlyapm_modules/_local/beta, and.claude/skills/betastays active.Does the
unmanaged_files: reconcileproposal cover our scenario? The UX it targets is the right one:git pullfollowed by an ordinaryapm installmakes upstream removals take effect. As a delivery path, though, it doesn't reach us, for two reasons:apm installonly applies auto-discovered policy.--policy <file>is audit-only, so a project can't adoptreconcilefor its own installs.Even once #2753 lands, it ties a basic install-correctness behavior to org/team governance, and to
enforcement: blockacross every other rule in that policy.Ownership should come from the project. On the tradeoff you raised: in a repository that adopts APM, we think the harness primitive surfaces should be entirely APM-managed.
apm.yml+apm.lock.yamlare the source of truth, and the deployed directories are gitignored build output. A skill that exists only in.claude/skills/is outside that source of truth by definition. If it is specific to the project, it belongs in.apm/withincludes: auto, so it goes through the same flow and is deployed to every declared target. Personal skills belong at user scope (~/.claude/skills/), not in the project.Under that model,
installneeds no proof that it created a file. It converges the surface to the desired state, the same way npm treatsnode_modules. That also removes the ownership ambiguity from your experiment: the byte-identical unmanaged skill is simply out of contract.What would resolve this for us:
apm installremoves primitive outputs that are no longer part of the resolved graph or the local.apm/sources.apm.ymlfully covers our case. In it, the project declares that APM owns its primitive surfaces for the declared targets. The repository that adopts APM is the right authority to grant permission to delete, and it needs no org policy or [FEATURE] GitLab: support subgroup-scoped policy discovery (team-level apm-policy), not only the top-level group #2753.Either way, we'd keep the safety boundaries from your proposal:
.claude/skills/,.claude/agents/,.github/skills/, ...), never whole harness directories..claude/settings*.json, sessions,.github/workflowsand similar stay untouched.settings.json, DB-backed registrations) stays out of scope, as you proposed.--dry-runlists what would be removed, andapm auditreports pending removals asorphaneddrift. That gives teams a way to check before opting in and covers point 1 of the original report.The
reconcilepolicy action still makes sense on top of this, for orgs that want to require that model across repositories. Project-level opt-in and org-level enforcement would be two layers of the same behavior.Happy to test any design you prefer, including running the lifecycle scenarios from your list.
danielmeppiel commentedon Nov 20, 2026
Additional case from 0.37 release testing, with the same root cause: MCP servers. Developer A removes an MCP server from apm.yml, then commits and pushes the manifest and lockfile. Developer B runs git pull and apm install, which reports 'All servers up to date', but the removed server stays configured in B's harness MCP config, and audit --ci passes. Stale MCP retirement diffs the previous lock against the new one, and git has already replaced the previous lock. Renamed agents, retired skills and Copilot instructions behave the same way, as originally reported here. Planned for 0.38; the 0.37 release notes will call it out.
danielmeppiel commentedon Nov 21, 2026
Moved from 0.38.0 to 0.39.0 in the 0.38 release cut (2026-11-21). Scope and acceptance are unchanged.
danielmeppiel commentedon Nov 21, 2026
Moved to 0.38.0: maintainer direction is that open bugs ship in 0.38.
test(spec): cover receipt-bound orphan cleanup under req-lk-024 and d…
fix(install): an --only install keeps receipted orphans too (#3188)
fix(install): keep pipeline.py in its LOC budget; #3964 audit cell no…
danielmeppiel commentedon Nov 25, 2026
Moved to 0.40.0 at the v0.39.0 scope freeze: v0.39.0 now takes only bug fixes. This item is a feature, design, research or tracking item, or still needs design.