ISSUE DESCRIPTION [BUG] apm install fail second time with Content hash mismatch Describe…
- User
ISSUE DESCRIPTION
[BUG] apm install fail second time with Content hash mismatch Describe the bug I can install my repo (see apm.yml further down) via
apm install <org>/<repo>/package/<project>just fine (kinda, see the logs, it looks wonky but maybe it's just a new feature) but the second time I runapm installit will fail consistently withContent hash mismatch.To Reproduce Steps to reproduce the behavior:
- apm install <repo>
- apm install
Expected behavior A clear and concise description of what you expected to happen.
Environment (please complete the following information):
- OS: Windows
- APM Version: 0.16.0
Logs
> apm install --update --force [>] Installing dependencies from apm.yml... [>] Resolving github-copilot-agent-skills-testing... [i] Targets: copilot (source: apm.yml) Partial clone (--filter=blob:none) failed for https://dev.azure.com/<org>/tools; retrying with full bare clone. Server may not support filter v2. [+] dev.azure.com/<org>/tools/github-copilot-agent-skills/packages/<project> #default @d479f42e |-- (files unchanged) Partial clone (--filter=blob:none) failed for https://dev.azure.com/<org>/tools; retrying with full bare clone. Server may not support filter v2. [+] dev.azure.com/<org>/tools/github-copilot-agent-skills/packages/myorg #default @d479f42e |-- (files unchanged) [+] dev.azure.com/<org>/tools/github-copilot-agent-skills/.apm/instructions/testing.instructions.md #main |-- 1 instruction(s) integrated -> .github/instructions/ Partial clone (--filter=blob:none) failed for https://dev.azure.com/<org>/tools; retrying with full bare clone. Server may not support filter v2. [+] dev.azure.com/<org>/tools/github-copilot-agent-skills/.apm/skills/run-coverage #default @d479f42e |-- (files unchanged) Partial clone (--filter=blob:none) failed for https://dev.azure.com/<org>/tools; retrying with full bare clone. Server may not support filter v2. [+] dev.azure.com/<org>/tools/github-copilot-agent-skills/.apm/skills/update-from-template #default @d479f42e |-- (files unchanged) Partial clone (--filter=blob:none) failed for https://dev.azure.com/<org>/tools; retrying with full bare clone. Server may not support filter v2. [+] dev.azure.com/<org>/tools/github-copilot-agent-skills/packages/csharp #default @d479f42e |-- (files unchanged) [+] dev.azure.com/<org>/tools/github-copilot-agent-skills/.apm/instructions/code-style.instructions.md #main |-- 1 instruction(s) integrated -> .github/instructions/ [+] dev.azure.com/<org>/tools/github-copilot-agent-skills/.apm/instructions/protect-prefixed-agent-files.instructions.md #main |-- 1 instruction(s) integrated -> .github/instructions/ Partial clone (--filter=blob:none) failed for https://dev.azure.com/<org>/tools; retrying with full bare clone. Server may not support filter v2. [+] dev.azure.com/<org>/tools/github-copilot-agent-skills/.apm/skills/git-conventions #default @d479f42e |-- (files unchanged) Partial clone (--filter=blob:none) failed for https://dev.azure.com/<org>/tools; retrying with full bare clone. Server may not support filter v2. [+] dev.azure.com/<org>/tools/github-copilot-agent-skills/.apm/skills/update-nuget-packages #default @d479f42e |-- (files unchanged) Partial clone (--filter=blob:none) failed for https://dev.azure.com/<org>/tools; retrying with full bare clone. Server may not support filter v2. [+] dev.azure.com/<org>/tools/github-copilot-agent-skills/.apm/skills/write-tests #default @d479f42e |-- (files unchanged) cache-pin: remote dep '<org>/tools/github-copilot-agent-skills' has no resolved_commit; drift cannot verify its cache freshness. Re-run 'apm install' with a pinned ref (commit, tag, or specific branch HEAD). cache-pin: remote dep '<org>/tools/github-copilot-agent-skills' has no resolved_commit; drift cannot verify its cache freshness. Re-run 'apm install' with a pinned ref (commit, tag, or specific branch HEAD). cache-pin: remote dep '<org>/tools/github-copilot-agent-skills' has no resolved_commit; drift cannot verify its cache freshness. Re-run 'apm install' with a pinned ref (commit, tag, or specific branch HEAD). [i] Trusting direct dependency MCP 'MyOrg.CLI' from '<project>-skills' [i] Trusting direct dependency MCP 'NuGet' from '<project>-skills' [i] Trusting direct dependency MCP 'Github' from '<project>-skills' [i] Trusting direct dependency MCP 'MyOrg.CLI' from 'skills' [i] Trusting direct dependency MCP 'NuGet' from 'skills' +- MCP Servers (3) | [+] MyOrg.CLI (already configured) | [+] NuGet (already configured) | [+] Github (already configured) [*] All servers up to date [!] 11 dependencies unpinned: <org>/tools/github-copilot-agent-skills -- add #tag or #sha to prevent drift [!] Transitive package 'csharp-skills' declares self-defined MCP server 'NuGet' (registry: false). Re-declare it in your apm.yml or use --trust-transitive-mcp. [!] Transitive package 'csharp-skills' declares self-defined MCP server 'Github' (registry: false). Re-declare it in your apm.yml or use --trust-transitive-mcp. [*] Installed 11 APM dependencies in 87.9s. > apm install [>] Installing dependencies from apm.yml... [i] Targets: copilot (source: apm.yml) [+] dev.azure.com/<org>/tools/github-copilot-agent-skills/packages/<project> @d479f42e (cached) |-- (files unchanged) [+] dev.azure.com/<org>/tools/github-copilot-agent-skills/packages/myorg @d479f42e (cached) |-- (files unchanged) [+] dev.azure.com/<org>/tools/github-copilot-agent-skills/.apm/instructions/testing.instructions.md #main Content hash mismatch for <org>/tools/github-copilot-agent-skills/.apm/instructions/testing.instructions.md: expected sha256:2227579674ab30b5b59f703ac152fa74ac2912d724d04aeffbf3914cac2e6b88, got sha256:b82d09e4e7879eeb0e90cc7dfeebdac45de6ebdbcdda7824b40438196692f8f8. The downloaded content differs from the lockfile record. This may indicate a supply-chain attack. Use 'apm install --update' to accept new content and update the lockfile. [!] Install interrupted after 7.7s. Assistant
Let me start by exploring the repository structure to understand what we're working with.
Assistant
Let me explore the repository structure first.
Assistant
Let me look at the source structure.
Assistant
Let me look at the broader context of this file to understand how content hashes are computed and how instruction files are handled.
Assistant
The issue is about instruction files. The key clue is the instruction file
.apm/instructions/testing.instructions.md. Let me look at how the hash is computed for instruction files vs packages.Assistant
The error occurs with instruction files. Let me understand how instruction files are installed and hashed. Let me look at the cache_pin module and instruction file handling.
Assistant
Let me look at the broader context of how instruction files are materialized. Let me look at the FreshDependencySource class.
Assistant
Let me understand how install paths are determined, especially for instruction files vs packages from the same repo.
Assistant
Let me understand the virtual file/collection paths and how instruction files are categorized.
Assistant
Let me look at the lockfile phase and how content hashes get attached, plus tests around this area.
Assistant
Let me look at how virtual file downloads work and search for related tests.
Assistant
This is a key finding. The virtual file download writes both the instruction file AND an
apm.ymlto the install path. Let me look at the re-download/skip logic and how the install path is handled.Assistant
Let me look at the tests for virtual file packages and content hash to understand the on-disk structure and reproduce the issue.
Assistant
Let me search for all places where the cache pin marker is written, and check
yaml_to_strfor determinism.Assistant
Now let me understand the full flow. Let me reproduce the issue by writing a script. First let me check the apm.lock.yaml to understand what content_hash is stored.
Assistant
Now let me reproduce the issue. The key question: When downloading a virtual file package the second time (re-download), what changes between installs? Let me look at how the cache-pin marker and
apm.ymlget written, since the content_hash check usescompute_package_hashover the whole tree.Let me trace the order of operations for virtual file packages. First, let me look at the integrate.py content-hash re-check at line 193.
Assistant
Now let me look at the CachedDependencySource to understand the skip path fully.
Assistant
Now I have a good understanding. Let me reproduce the issue with a script. The key insight from the issue:
- First install: virtual file package gets downloaded, content_hash computed & saved to lockfile
- The download writes
apm.yml+ the instruction file +.apm-pinmarker (written bysync_markers_for_lockfile) - The
.apm-pinis excluded from hash (root only). Butapm.ymlis NOT excluded.
But wait, the
.apm-pinis excluded from the root. Theapm.ymlis at the root too. Both first and second install write the sameapm.yml. Let me look more carefully at what differs.The crucial detail: the content_hash mismatch happens with
#mainref (the instruction file uses#mainbranch). Let me reproduce by simulating two installs.Assistant
Now let me reproduce the issue with a script that simulates two installs of a virtual file package, checking the content hash before and after.
Assistant
Let me check how to run things in the project's venv.
Assistant
The reproduction is stable. The real flow differs. The key clue: the instruction file uses
#main(a branch, not cacheable, ADO host soresolved_commitis None → no.apm-pinmarker). Let me look at the resolve phase BFS callback and how downloads are triggered.Assistant
The first install used
--update --force. Let me check recent changes and git history around content hashing and virtual files.Assistant
Assistant
Now let me look at
download_packageitself to see how it routes virtual files and whether there's a different path. Let me look at line 1560 area.Assistant
Let me look at the integration template to see if it modifies the install_path.
Assistant
The integration deploys to the project root, not the install_path. Let me check the pre-deploy security scan to see if it modifies install_path.
Assistant
Let me look at how InstalledPackage converts to LockedDependency, specifically the resolved_commit and source fields.
Assistant
Let me find an existing e2e/integration test that installs a virtual file dependency, to adapt for a faithful reproduction.
Assistant
Let me look at
download_raw_fileand the actual file download path to check for any content transformation or non-determinism.Assistant
Let me look at how the install pipeline is constructed and invoked, to build a faithful in-process reproduction.
Assistant
Let me look at the download phase to understand pre-downloading of virtual file deps.
Assistant
Let me look at the diff-aware install e2e test which likely runs the full pipeline twice.
Assistant
Let me look for unit tests that build the full pipeline in-process with a mocked downloader, to use as a template.
Assistant
Let me write a comprehensive reproduction that models the exact pipeline sequence including the lockfile round-trip and marker sync.
Assistant
Let me fix the repro to use GitHub host but force SHA resolution to return None (replicating the ADO branch scenario where resolved_commit is None).
Assistant
The ADO branch scenario (no marker) shows H1 == H2 — no bug. Let me test the markable case where SHA resolution succeeds and a marker IS written.
Assistant
Both scenarios show H1 == H2. The download is deterministic. Let me run the REAL pipeline against a local git repo to capture the actual behavior. Let me check for test helpers that set up local git remotes.
Assistant
Let me check the heal chain and search the changelog/tests for related context about branch-ref re-download hash checks.
Assistant
This is illuminating. Let me check
build_download_refanddetect_ref_changein the drift module to understand the ref used on re-install.Assistant
Let me check whether network/GitHub access is available to run a real reproduction.
Assistant
Network works. I need a virtual-file instruction dep. Let me check the cloned package's instruction files to reference one directly.
Assistant
Let me set up a project that references that instruction file as a virtual file dep, then install twice.
Assistant
On GitHub, the virtual file resolves a SHA (
@fb285168) → markable. Now let me run the second install (plain) and see if it reproduces.Assistant
The bug is on ADO where the virtual file's SHA isn't recorded (
resolved_commit=None), so it's never cacheable → always re-downloaded. Unlike GitHub (whereBranchRefDriftHealadds a bypass key when a branch advances), the ADO case haslockfile_match=Falseso the heal never fires, and a content change hard-fails. Let me confirm by simulating an ADO-like scenario: lockfile withresolved_commit=None, branch content that changed.Assistant
Let me write a focused reproduction using the real
FreshDependencySourcewith a mock downloader, simulating the ADO scenario (lockfileresolved_commit=None, branch content changed between installs).Assistant
I've reproduced the bug. The root cause: branch-ref deps (mutable) with no recorded
resolved_commit(ADO virtual files) are re-downloaded every install, and a content change (branch moved) hard-fails the supply-chain check instead of being accepted. Let me examine why ADO doesn't resolve the SHA and how the GitHub case is handled by the heal.Assistant
I've confirmed the root cause. The supply-chain hard-fail triggers for unpinned branch refs (no
resolved_commitin the lockfile, like ADO virtual files) when they're re-downloaded and the branch moved. TheBranchRefDriftHealonly covers the pinned case (GitHub, where a SHA is recorded). Let me check the existing hash-mismatch test to ensure my fix won't break it.Assistant
The existing mismatch test uses a pinned dep (
resolved_commit="sha"), so my fix (only hard-fail for pinned deps) preserves it. Let me examine the heal chain dispatcher to wire a new heal correctly.Assistant
I've confirmed the root cause and the fix approach. The
BranchRefDriftHealonly covers pinned branch refs (where a SHA is recorded, e.g. GitHub). For unpinned refs (noresolved_commit, e.g. ADO virtual files), the dep is always re-downloaded and a content change (branch moved) hard-fails instead of being accepted. The fix: add a heal that bypasses the supply-chain hard-fail for unpinned mutable refs being re-downloaded, so the lockfile self-heals. Let me look at the existing heal test conventions first.Assistant
Let me look at the buggy_lockfile_recovery heal for another reference pattern.
Assistant
Now I understand the heal architecture. Let me create the new heal for unpinned mutable refs being re-downloaded.
Assistant
Now let me register the heal in the chain.
Assistant
Now let me verify the fix with my reproduction script (the ADO scenario where the branch moved).
Assistant
My repro constructs
FreshDependencySourcedirectly, bypassing the heal chain. Let me test the heal in isolation first, matching the existing heal test conventions.Assistant
The heal works in isolation. Now let me write an end-to-end reproduction exercising
_resolve_download_strategy+ the heal chain +FreshDependencySourceto confirm the full flow no longer hard-fails and the lockfile self-heals.Assistant
The end-to-end reproduction now passes — install 2 no longer hard-fails and the lockfile self-heals. Let me verify I haven't broken the GitHub (pinned) case by re-running the real CLI install.
Assistant
GitHub case still works. Now let me run the existing test suites that could be affected: heals, sources, integrate, and content_hash.
Assistant
All unit tests pass. Let me run the broader test suite (integration tests that don't require network) to ensure no regressions.
Assistant
The 6 failures are environment-related (running as root breaks permission-denied tests; no LLM runtime; no ADO auth; build CLI env). Let me confirm they're pre-existing by stashing my change and re-running them.
Assistant
Confirmed — those failures are pre-existing (environment: running as root, no LLM runtime, no ADO auth). Now let me check the working tree state carefully, since the stash pop revealed some pre-existing modified files I didn't touch. I need to ensure I only submit my intended changes.
Assistant
There are pre-existing modified files I didn't touch. Let me check whether I caused the
apm.lock.yamlchange (e.g., via test runs) and review these diffs.Assistant
The
apm.lock.yaml,.github/copilot-instructions.md, and.agents/skills/apm-review-panel/*changes are artifacts from anapm installrun in the repo (today's timestamp), not my fix. Sincesubmitusesgit diff(tracked unstaged changes), I must revert these to avoid submitting noise.Assistant
My new heal file is untracked —
git diffwon't include untracked files by default, which could mean it won't be submitted. Let me usegit add -N(intent-to-add) so the new file appears ingit diff.Assistant
git diffnow includes both files. Let me clean up the untracked artifacts created by a stray install (they won't be submitted sincegit diffexcludes untracked files, but I'll remove them to keep the tree clean).Assistant
The working tree now contains only my fix. Let me review the final diff and re-run the relevant tests to confirm everything is correct.
Assistant
I need to handle an edge case: registry-sourced deps are version-pinned (content change = tampering), so my heal must NOT fire for them. Let me add a registry guard. Let me also verify how registry/local sources are represented.
Assistant
Registry deps have
source="registry"and are version-pinned (content change = tampering), so my heal must exclude them. Let me add source guards.Assistant
Let me update my isolation test to also cover the registry/local exclusion, and re-run it plus the existing heal/sources tests.
Assistant
All edge cases pass. Let me re-run the e2e reproduction and the existing test suites once more to confirm no regressions after the registry guard.
Assistant
Let me run the full unit test suite once more to confirm no regressions, plus the drift-related tests.
Assistant
All 15812 unit tests pass. Let me do a final review of the working tree state and clean up temp files.
Assistant
The
apm.lock.yamlgot modified again by a test run. Let me revert it to keep only my fix.Assistant
Only my fix remains. Let me do a final sanity check that the heal chain is correctly registered and imports cleanly.
Assistant
The fix is complete and verified. Let me confirm the final diff one last time before submitting.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.