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
I'll start by exploring the repository structure to understand the codebase and locate relevant files related to the bug.
- Assistant
Let me explore the repository structure more broadly to understand what this is.
- Assistant
This looks like a Python project with a
srcdirectory and tests. Let me explore the source code structure. - Assistant
Let me look at the directory structure more closely to understand the project.
- Assistant
Let me look at the install directory and the content hash verification code.
- Assistant
Let me examine these files to understand the content hash mismatch error.
- Assistant
Let me examine these files to understand the content hash mismatch error.
- Assistant
Let me read both files more carefully.
- Assistant
Let me read the sources.py file around line 777 to understand the hash mismatch logic.
- Assistant
Now let me look at the integrate.py file where the other content hash mismatch message appears.
- Assistant
Let me look at the content hash computation and the download/integration flow more carefully.
- Assistant
Let me look at the content hash computation logic.
- Assistant
Now let me understand the flow better. Let me look at how the lockfile records content_hash and how branch refs behave.
- Assistant
Let me understand the full flow better. Let me look at the lockfile persistence to see when and how content_hash is stored.
- Assistant
Now let me look at the broader install flow and understand what's happening. Let me also look at the download mechanism for virtual packages.
- Assistant
Let me look at the
_should_skip_redownloadfunction and the cache pin mechanism, since the issue is about branch references always re-downloading. - Assistant
Now let me look at how the download works for virtual packages (like the instruction file).
- Assistant
Let me search for where the download_package method handles virtual packages (single file paths like
.apm/instructions/testing.instructions.md): - Assistant
Let me look at the
download_virtual_file_packagemethod more closely. - Assistant
Let me look at the
yaml_to_strfunction since it's used to generate apm.yml for virtual packages. - Assistant
Let me look at the rest of the method and the content hash computation:
- Assistant
Let me look at
yaml_to_strmore closely. - Assistant
Let me look at
detect_ref_changein drift.py to understand the reference comparison logic. - Assistant
Let me trace the download flow more carefully. Let me look at the resolve phase to understand when content_hash gets set in the lockfile, and when the download_ref is built.
- Assistant
Now let me look at the key function for understanding the issue - the resolve phase and how download_ref is built, especially for virtual file packages.
- Assistant
Let me look at the lockfile structure and how resolved_ref is stored:
- Assistant
Now I need to understand how
resolved_refis set in the lockfile and howbuild_download_refworks for branch refs. Let me trace the critical path. - Assistant
Let me look at the
from_installed_packagesmethod to understand howresolved_refis stored: - Assistant
Let me look at the
from_installed_packagesmethod: - Assistant
Let me look at
_resolve_commit_sha_for_refand see if it might fail for Azure DevOps: - Assistant
Let me look at the FreshDependencySource more carefully, focusing on the
build_download_refcall: - Assistant
Now let me look at the integration template to understand what happens after download:
- Assistant
Now I need to understand the key issue. Let me look at the tests to understand the expected behavior and what tests already exist.
- Assistant
Let me look at how the integration modifies files. The issue might be that integration modifies files in the install path, causing the hash to differ on subsequent installs.
- Assistant
Let me look at the instruction integrator to understand how instructions are integrated.
- Assistant
Now I understand the flow better. Let me trace the key issue. Let me look at the
_resolve_download_strategyin integrate.py to understand the cache matching logic: - Assistant
Now I see the issue! Let me look more carefully at the logic flow. The key issue is in
_resolve_download_strategyinintegrate.py. Whenlocked_dep.resolved_commitis None (as happens for virtual file packages when SHA resolution fails), the code skips the entire cache match block. Let me verify this theory by looking at what happens: - Assistant
Now let me trace through the flow more carefully. Let me look at how the resolve phase and the BFS download callback interact with the content hash:
- Assistant
Let me search more broadly:
- Assistant
Let me look at the
resolve_linksmethod to check if integration modifies source files: - Assistant
Let me look at how the virtual package name is computed and what
get_virtual_package_namereturns: - Assistant
Let me look at the heal chain to understand if it changes the
lockfile_matchdecision: - Assistant
Let me look at the heal chain implementations to understand what might change
lockfile_match: - Assistant
Let me look at the branch_ref_drift.py since that's likely what's relevant to this issue.
- Assistant
Let me look at
get_install_pathfor virtual packages: - Assistant
Let me check
get_virtual_package_name(): - Assistant
Now let me look at the existing tests to understand the expected behavior and find a way to reproduce the issue:
- Assistant
Let me check the cache pin marker to see if it affects content hash:
- Assistant
Now I have a good understanding of the issue. Let me trace through the exact bug scenario:
- For virtual file packages (like
testing.instructions.md #main),_resolve_commit_sha_for_refmay fail (returns None) for non-GitHub hosts like Azure DevOps - This means
resolved_commitis None in the lockfile - On second install, the condition
locked_dep.resolved_commit and ...in_resolve_download_strategyis False, so the entire lockfile_match block is SKIPPED lockfile_matchstays FalseBranchRefDriftHealdoesn't fire becauselockfile_matchis False- FreshDependencySource downloads fresh, but no bypass key is set
- If the branch has advanced, the content hash differs → supply-chain error
The fix is to add a fallback content-hash check for deps that have no
resolved_commitbut do have acontent_hash. Let me implement this: - For virtual file packages (like
- Assistant
Now let me implement the fix. The issue is that when
locked_dep.resolved_commitis None (as happens for virtual file packages where SHA resolution fails), the entire lockfile_match block is skipped, preventing the BranchRefDriftHeal from properly setting bypass keys. The fix is to add a fallback content-hash check for deps withoutresolved_commit: - Assistant
Now I understand the root cause. The issue is that when
locked_dep.resolved_commitisNone(which happens for virtual file packages where SHA resolution fails), the lockfile_match block is entirely skipped. This prevents theBranchRefDriftHealfrom firing and setting bypass keys. The existing fallback only handles registry deps, not git-source deps with missingresolved_commit.Let me implement the fix:
- Assistant
Now I'll implement the fix. The issue is that the
elifblock only handles registry deps, but git-source deps (like virtual file packages) can also haveresolved_commit = Nonewhen SHA resolution fails. I need to broaden this to handle all deps withoutresolved_commit: - Assistant
The
editcommand doesn't supportfile_path, let me use the--fileoption instead or usereplace. - Assistant
Let me use the replace command to make the edit.
- Assistant
Good, the edit was applied successfully. Now let me run the existing tests to verify the fix doesn't break anything:
- Assistant
I need to install the dependencies first. Let me check how the project is set up.
- Assistant
Good, dependencies installed. Now let me run the tests related to the change.
- Assistant
All 19 tests passed. Let me run more related tests to make sure nothing is broken.
- Assistant
All 1477 unit install tests passed. Let me also run the integration tests related to content hash:
- Assistant
The integration tests are all skipped. Let me check why:
- Assistant
Let me run the broader test suite:
- Assistant
Let me just run without --timeout.
- Assistant
Missing test dependency. Let me install it and try again, or skip that specific test.
- Assistant
Let me install the missing dependency and run the tests again.
- Assistant
Let me run the tests again with the dependency installed.
- Assistant
All 15812 tests passed! The fix doesn't break anything. Let me also verify the specific test for virtual package branch ref drift:
- Assistant
Let me run the heal chain tests too:
- Assistant
All 199 tests related to heal, drift, and content_hash passed. Let me verify the final state of my change:
- Assistant
Let me check the diff to make sure the change is clean:
- Assistant
I see there are unintended changes to
apm.lock.yaml. Let me revert those and only keep my actual code change. - Assistant
Now let me verify the diff is clean.
- Assistant
The diff is clean. Let me run the full test suite one more time to make sure everything passes.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.