Skip to content

[BUG] Deployed files of a dependency removed upstream are orphaned after git pull: audit, install and prune all miss them #3188

Open

Description

@rrazvd

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 --ci passes all checks, including drift. 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 what orphaned means: 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 install does 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 as deployed_files. On the teammate's machine that record was overwritten by the pull before any APM command ran.
  • apm prune detects the orphaned package and removes apm_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  beta

Expected behavior

In order of importance:

  1. apm audit reports .claude/skills/beta/** as orphaned drift (and --ci fails), as documented.
  2. apm install removes 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/beta is 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.
  3. apm prune does not discard apm_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

Activity

  1. added
    type/bug
    on Oct 8, 2026
  2. github-actions commented on Oct 11, 2026

    @github-actions

    [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 its deployed_files) is realistic and leaves silent orphans that audit, install and prune all miss.

    Suggested direction: needs-design. Detecting these files cannot rely on the new lockfile alone, so the design must settle:

    • Data model: how APM learns which files it previously deployed (e.g., persisting a local record of deployed files that survives git pull, or marker/provenance on deployed files).
    • Safety boundary: orphan cleanup must never delete user-authored files; the rule for "APM-owned" must be explicit.
    • Contract: whether drift orphaned should follow the docstring definition, and what prune and install should do.

    Proposed done-when: the teammate scenario is detected by audit --ci and removable via prune without touching user files. A maintainer must approve scope and a review contact (lockfile and drift expertise) first.

    Generated by Triage Panel · copilot · auto · 45.8 AIC · ⌖ 0.747 AIC · ⊞ 12K · ◷

  3. added
    triage/recommended
    on Oct 11, 2026
  4. danielmeppiel commented on Oct 14, 2026

    @danielmeppiel
    Collaborator

    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:

    Teammate removes a skill from the declared dependencies or local sources
      -> commits the updated project state
      -> another teammate pulls
      -> ordinary apm install makes that removal effective
    

    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_files policy, not a new managed_outputs manifest 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_modules are 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 hidden node_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 disposable node_modules: it can contain unrelated settings or session data.

    An isolated ApmLifecycleRunner experiment at fe391190 reproduced 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:

    enforcement: block
    unmanaged_files:
      action: reconcile # Proposed new value; not supported today.
    Action Proposed behavior during ordinary install, with blocking enforcement
    ignore No policy-driven unmanaged-file handling; existing owned-file cleanup remains unchanged.
    warn Report unmanaged content and preserve it.
    deny Preserve unmanaged content and fail for violations.
    reconcile Remove eligible disallowed native skill outputs, then fail if applicable violations remain.

    apm audit stays read-only; it would treat reconcile as 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 deny policies into deletion policies; the name and precise compatibility rules remain open for discussion.

    The report's --no-policy reproduction, 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 ordinary apm install, without an extra per-invocation flag.

    Implementation direction

    1. Harness-derived scope. Resolve targets normally, including legacy routing, and reuse TargetProfile plus install_governance(targets, bounded=True). Replace hardcoded default discovery with adapter-derived native-input surfaces. Respect explicit policy directories and exclude; a broad policy directory is not permission to recursively delete everything beneath it. Preserve other targets' surviving ownership.

    2. 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.

    3. 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 --force or invent historical ownership rows.

    4. 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 prune consistent with the chosen contract without making a separate prune invocation necessary for the target UX.

    5. 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.action preferable to changing existing deny semantics, 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.

  5. danielmeppiel commented on Nov 10, 2026

    @danielmeppiel
    Collaborator

    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 pull followed by apm install should make upstream removals take effect, within the existing unmanaged_files policy 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.

  6. rrazvd commented on Nov 11, 2026

    @rrazvd
    ContributorAuthor

    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 --ci passes, install cleans nothing, prune removes only apm_modules/_local/beta, and .claude/skills/beta stays active.

    Does the unmanaged_files: reconcile proposal cover our scenario? The UX it targets is the right one: git pull followed by an ordinary apm install makes upstream removals take effect. As a delivery path, though, it doesn't reach us, for two reasons:

    Even once #2753 lands, it ties a basic install-correctness behavior to org/team governance, and to enforcement: block across 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.yaml are 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/ with includes: 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, install needs no proof that it created a file. It converges the surface to the desired state, the same way npm treats node_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:

    1. Ideally, this is the default: ordinary apm install removes primitive outputs that are no longer part of the resolved graph or the local .apm/ sources.
    2. If the default has to keep preserving unmanaged content, an explicit opt-in in apm.yml fully 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:

    • Scope is limited to adapter-derived primitive surfaces (.claude/skills/, .claude/agents/, .github/skills/, ...), never whole harness directories. .claude/settings*.json, sessions, .github/workflows and similar stay untouched.
    • Merged/shared configuration (hooks in settings.json, DB-backed registrations) stays out of scope, as you proposed.
    • Path containment, symlink safeguards, frozen-mode rules and the incomplete-install guards stay as described.
    • --dry-run lists what would be removed, and apm audit reports pending removals as orphaned drift. That gives teams a way to check before opting in and covers point 1 of the original report.

    The reconcile policy 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.

  7. danielmeppiel commented on Nov 20, 2026

    @danielmeppiel
    Collaborator

    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.

  8. added
    status/needs-design
    on Nov 21, 2026
  9. danielmeppiel commented on Nov 21, 2026

    @danielmeppiel
    Collaborator

    Moved from 0.38.0 to 0.39.0 in the 0.38 release cut (2026-11-21). Scope and acceptance are unchanged.

  10. danielmeppiel commented on Nov 21, 2026

    @danielmeppiel
    Collaborator

    Moved to 0.38.0: maintainer direction is that open bugs ship in 0.38.

  11. danielmeppiel commented on Nov 25, 2026

    @danielmeppiel
    Collaborator

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status/needs-designtriage/recommendedtype/bug

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions