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 understanding the repository structure and the issue.
The issue is about
apm installfailing on the second run with "Content hash mismatch". The error message says:Content hash mismatch for <org>/tools/github-copilot-agent-skills/.apm/instructions/testing.instructions.md: expected sha256:2227579674ab30b5b59f703ac152fa74ac2912d724d04aeffbf3914cac2e6b88, got sha256:b82d09e4e7879eeb0e90cc7dfeebdac45de6ebdbcdda7824b40438196692f8f8.This suggests that when the file is re-downloaded, its content hash doesn't match what was stored in the lockfile. This could be happening because the file is being modified after download (e.g., some post-processing like converting line endings), and the hash is being recalculated after modification but compared against the original download hash.
Let me explore the repository structure first.
Assistant
Let me explore more.
Assistant
This looks like a Python project. Let me look at the src directory and find files related to content hash checking.
Assistant
Let me search for the "Content hash mismatch" error message and the content hash utility
Assistant
Let me look at both files.
Assistant
Let me try to use open with the correct parameter.
Assistant
Let me see the context around line 777 in sources.py.
Assistant
Now let me understand how
ctx.package_hashesis populated.Assistant
Let me look at the integrate.py file where content hash is checked
Assistant
Let me look at the content_hash utility
Assistant
Let me check the cache_pin module
Assistant
Let me look at the sources.py file to understand how the hash is computed during download.
Assistant
Let me look at the other places where
_compute_hashis calledAssistant
Let me look at the FreshDependencySource class around line
Assistant
Let me look at the
_compute_hashfunctionAssistant
Let me understand how install paths are resolved for file deps
Assistant
Let me look at the
get_install_pathmethodAssistant
Let me continue reading this method.
Assistant
Let me look at the FreshDependencySource more carefully to understand the full flow
Assistant
Let me look at the CachedDependencySource class
Assistant
Let me look at the install pipeline to understand the order of operations
Assistant
Let me look at the lockfile phase to understand when hashes and pins are written
Assistant
Let me look at the
--updateflag handlingAssistant
Let me look at the download phase
Assistant
Let me look at the integrate phase
Assistant
Let me look at
_should_skip_redownloadAssistant
Let me search for any line-ending or file normalization that might occur during download
Assistant
Let me look at the normalization module and bare_cache.py more
Assistant
Let me look at the bare_cache.py around the CRLF handling
Assistant
Let me look at the download strategies
Assistant
Let me look at the
download_packagemethod ingithub_downloader.pyAssistant
Let me look at the
download_packagemethodAssistant
Let me look at
download_virtual_file_packageand `download_subdirectory_pAssistant
Let me read
download_virtual_file_packageAssistant
Now let me look at
download_subdirectory_package:Assistant
Let me continue reading more of
download_subdirectory_package:Assistant
Let me look at
build_download_refin drift.pyAssistant
Let me read the
build_download_refAssistant
Let me continue reading
Assistant
Let me check
yaml_to_strAssistant
Let me look at the yaml_io.py module
Assistant
Let me look at `_resolve_commit_sha_for_ref
Assistant
Let me read that method
Assistant
Let me look at the ADO file download
Assistant
Let me read the ADO file download method
Assistant
Let me look at
LockFile.from_installed_packagesAssistant
Let me read that method
Assistant
Let me look at
LockedDependency.from_dependency_refAssistant
Let me read that method
Assistant
Let me continue reading
Assistant
Let me look at the
to_dictand serialization ofLockedDependencyAssistant
Let me look at
to_dictfor LockedDependencyAssistant
Let me look at tests related to content hash verification
Assistant
Let me look for unit tests for content_hash
Assistant
Let me read the test
Assistant
Let me look at `GitReferenceResolver.resolve_commit_sha_for
Assistant
Let me read that method
Assistant
Let me look at the
--forceflag handlingAssistant
Let me look at how force is used
Assistant
Let me look at
safe_rmtreeAssistant
Let me read that function.
Assistant
Let me look at
detect_ref_changeAssistant
Let me read `detect_ref
Assistant
Let me look at the instruction integrator to see if it modifies source
Assistant
Let me look at the git history for recent changes related to this area
Assistant
Let me search for commits related to ADO and commit resolution
Assistant
Let me look at the commit that fixed
.apm-pinexclusion:Assistant
Let me look at the integration template
Assistant
Let me look at
integrate_package_primitivesAssistant
Let me read this function.
Assistant
Let me look at
resolve_git_referencemethodAssistant
Let me read this method
Assistant
Let me look at how
ls-remoteis used elsewhereAssistant
Now I have a clear understanding of the bug. Let me verify by looking at the
_resolve_commit_sha_for_refmethod one more time and the related host backends:Assistant
Let me look at how
GitReferenceResolverdoesls-remotefor reference resolution:Assistant
Now I have a clear understanding of the bug. Let me implement the fix.
Root Cause: In
git_reference_resolver.py, theresolve_commit_sha_for_refmethod explicitly returnsNonefor Azure DevOps (and Artifactory) dependencies. This means:resolved_commitis never stored in the lockfile for ADO virtual file deps- On re-install,
build_download_refcan't pin to a specific commit SHA - The download always uses the mutable branch ref (e.g.,
#main) - If the branch content changes between installs, or if the same ref produces slightly different API responses, the content hash doesn't match the lockfile → "Content hash mismatch" error
Fix: Add a
git ls-remotefallback for ADO and other non-GitHub hosts inresolve_commit_sha_for_refinstead of returningNone.Let me first create a reproduction script to confirm the issue, then apply the fix.
Assistant
Let me set up the Python path properly
Assistant
Now let me implement the fix. The issue is in
resolve_commit_sha_for_refwhich returnsNonefor Azure DevOps deps. I'll add agit ls-remotefallback for non-GitHub hosts.Assistant
Let me use the open command from the terminal.
Assistant
Now I'll implement the fix. I need to replace the early return for ADO with a
git ls-remotebased resolution:Assistant
Let me try the replace command instead
Assistant
Let me verify the full file looks correct around the edited area
Assistant
The fix looks good. Now let me run the existing tests to make sure nothing breaks
Assistant
Let me run tests related to git reference resolver and download strategies
Assistant
Let me run some relevant unit tests.
Assistant
Let me look at the test that passed - it might need to be updated
Assistant
Let me look at the test
Assistant
Let me look at the
_dephelper function inAssistant
Let me check the
_DownloaderContextprotocol to ensure my new method can access the needed attributesAssistant
Let me check what
build_commits_api_urlreturns for generic hostsAssistant
Let me check what the generic GitLab backend returns
Assistant
I should also handle generic hosts where
build_commits_api_urlreturnsNone. Let me update the fix to fall back tols-remotein that case tooAssistant
Let me run the tests again to
Assistant
Let me run more tests to check for regressions
Assistant
Let me run the broader test suite to be safe
Assistant
Let me run the unit tests without the timeout flag
Assistant
Let me run the unit tests most relevant to my changes, skipping the unrelated
Assistant
Let me run just the key tests that are relevant
Assistant
Let me verify the changes I made by looking at the diff
Assistant
Let me verify the full updated method one
Assistant
Let me check if there are other callers of
_resolve_commit_sha_for_refthat might also need attentionAssistant
Now let me do a final review of the changes and run the tests once
Assistant
Let me verify the final state of the changes
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.