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 dealing with. This appears to be the APM (Agent Package Manager) repository itself. The issue is about
apm installfailing on second run with "Content hash mismatch". Let me explore the codebase first.Assistant
This looks like a Python project. Let me explore the
srcdirectory to understand the code structure.Assistant
Let me search for the "Content hash mismatch" error message in the codebase
Assistant
Let me look at the relevant source files. First, let's see the
sources.pyfile where the error is raised.Assistant
Let me try the open command differently.
Assistant
Let me find the exact line with "Content hash mismatch":
Assistant
Let me see the context around line 777.
Assistant
Let me look at the
_compute_hashfunction and understand the flow better.Assistant
Let me look at the
compute_package_hashfunction insrc/apm_cli/utils/content_hash.py.Assistant
Let me open and read the content_hash.py file.
Assistant
Let me see the rest of the file and also look at the cache_pin module.
Assistant
Let me understand the cached dependency source flow. Let's look at the
CachedDependencySourceclass and how it handles hash comparisonAssistant
Let me read the CachedDependencySource class
Assistant
Let me now read the CachedDependencySource class starting at line 303.
Assistant
Let me read the rest of the
acquiremethodAssistant
Let me continue reading the
acquiremethod.Assistant
Let me look at the install phases to understand the flow
Assistant
Let me look at the integrate.py file where the hash check might be done for cached
Assistant
Let me continue reading from line 100.
Assistant
Let me look at the
_should_skip_redownloadfunction.Assistant
Let me look at the cache_pin module.
Assistant
Let me look at the rest of the integrate phase to see how skip_download is resolved
Assistant
Let me go back to integrate.py to read the rest of the resolve strategy.
Assistant
Let me go to line 183 and read from there.
Assistant
Let me look at the
make_dependency_sourcefunction to understand source selection.Assistant
Let me read the
make_dependency_sourcefunction.Assistant
Let me open the sources.py file again and go to the
make_dependency_sourcefunction.Assistant
Let me go to line 828 in sources.py
Assistant
Let me understand how the install path is determined and how content gets on disk for virtual packages. Let me search for "install_path" and "is_virtual" or "virtual".
Assistant
Let me look at the dependency reference model.
Assistant
Let me search for
get_install_pathin the codebaseAssistant
Let me search for get_install_path
Assistant
Let me look at the
get_install_pathfunction at line 382 of reference.py.Assistant
Let me read the FreshDependencySource class starting from line
Assistant
Let me read the
FreshDependencySourceclass in sources.py starting from line 537Assistant
Let me continue reading the FreshDependencySource
Assistant
Let me read from line 703 to see the hash verification.
Assistant
Let me look at how the lockfile writes the content hash.
Assistant
Let me look at the lockfile phase, specifically
_attach_content_hashes.Assistant
Let me look at
_attach_content_hashes:Assistant
Let me check what the
--forceflag does.Assistant
Let me search for the install command and how force is used there
Assistant
Let me read around line 920 in install.py
Assistant
Let me look at the download phase
Assistant
Let me continue reading download.py
Assistant
Let me look at the heal chain and the branch_ref_drift heal
Assistant
Let me look at the heal base context and how bypass keys work
Assistant
Let me look at the heal chain runner
Assistant
Let me look at the
detect_ref_changefunction in drift.pyAssistant
Let me open drift.py and look at detect_ref_change
Assistant
Let me read the detect_ref_change function
Assistant
Let me look at
build_download_refin drift.pyAssistant
Let me read
build_download_refAssistant
Let me search for how
--forceaffects installAssistant
Let me look at how force is used in the context of install
Assistant
Let me read the InstallContext class.
Assistant
Let me read the rest of the context
Assistant
Let me look at what
--forcedoes more carefully. Let me search for where force is used in the install flowAssistant
Let me look at lines around 1486 where force is used
Assistant
Let me open install.py and look at the force usage
Assistant
Let me check again the
InstallContextused in sources.py.Assistant
Let me search for the InstallContext import in install.py
Assistant
Let me look at the InstallContext in install.py
Assistant
Let me look at how locked dependencies store the resolved_ref
Assistant
Let me find how
InstalledPackageis converted toLockedDependencyAssistant
Let me look at the
from_installed_packagesfunction at line 550Assistant
Let me find the
from_dependency_refmethodAssistant
Let me read the
from_dependency_refmethod.Assistant
Let me look at the
get_virtual_package_nameandis_virtual_file/is_virtual_subdirectorymethodsAssistant
Let me read these virtual package methods
Assistant
Let me open the reference.py file and look at the virtual methods.
Assistant
Let me look at the tests for content hash mismatch to understand the expected behavior.
Assistant
Let me look at the hash mismatch test in this file.
Assistant
Let me read the hash mismatch test.
Assistant
Let me look at the apm.lock.yaml for examples
Assistant
Let me look at the git log for recent changes to relevant files
Assistant
Let me look at the git log for changes to the hash-related files
Assistant
Let me look at the branch ref drift fix
Assistant
Let me check the MARKER_FILENAME constant
Assistant
Let me look at the E2E tests for branch ref drift
Assistant
Let me read the virtual package test
Assistant
Let me look at the E2E test file for the virtual package test
Assistant
Let me go to line 504 in the E2E test file
Assistant
Let me read more of the test.
Assistant
Let me read the virtual package test at line 504
Assistant
Let me search for how virtual files are downloaded and extracted.
Assistant
Let me look at the download_virtual_file_package method
Assistant
Let me open the github downloader file.
Assistant
Let me go to the download_virtual_file_package method.
Assistant
Let me read more of this method.
Assistant
Let me look at
download_raw_fileto see how it handles the refAssistant
Let me look at download_raw_file.
Assistant
Let me look at the download strategies for Azure DevOps.
Assistant
Let me look at the download_ado_file method.
Assistant
Let me find the download_ado_file method
Assistant
Let me look at
build_ado_api_urlto see how it handles refsAssistant
Let me read the build_ado_api_url function
Assistant
Let me take a different approach and look for potential issues with the hash verification flow. Let me look at how
expected_hash_change_depsis populated in the resolve phaseAssistant
Let me write a simple Python script to test the hash computation for edge
Assistant
Let me look at
_resolve_commit_sha_for_refto understand how it resolves refsAssistant
Let me look at the resolve_commit_sha_for_ref method
Assistant
Let me look at how
download_packagehandles virtual file packages and whetherresolved_commitis set.Assistant
Let me look at
download_packageAssistant
Now I have a good understanding of the issue. Let me verify my hypothesis by looking at the specific code path more closely.
The root cause is: For Azure DevOps virtual file packages,
_resolve_commit_sha_for_refreturnsNone(line 239 ofgit_reference_resolver.py), which meansresolved_commitisNonein the lockfile. Then in_resolve_download_strategy, the check at line 115 requireslocked_dep.resolved_committo be truthy, solockfile_matchis never set for these packages. This causes them to be re-downloaded on everyapm install, and if the branch has advanced, the content hash mismatch causessys.exit(1).Let me look at the exact lines we need to fix:
Assistant
Let me check the
yaml_to_strfunction for determinismAssistant
Let me read the
yaml_to_strfunctionAssistant
Let me check if there's an Azure DevOps backend that could resolve commit SHAs
Assistant
Let me look at the ADOBackend's build_commits_api_url method
Assistant
Now I have a clear understanding of the issue. Let me implement the fix.
The root cause is: For Azure DevOps virtual file packages,
resolved_commitis alwaysNone(because_resolve_commit_sha_for_refreturnsNonefor Azure DevOps). This causeslockfile_matchto always beFalsein_resolve_download_strategy, because the check at line 115 requireslocked_dep.resolved_committo be truthy. Sincelockfile_matchis alwaysFalse, the package is re-downloaded on everyapm install, and if the branch has advanced, the content hash mismatch causessys.exit(1).The fix is to add a fallback in
_resolve_download_strategyfor whenresolved_commitis missing butcontent_hashexists. Let me implement this:Assistant
Let me use the edit command with the file option and proper syntax
Assistant
Now let me also check the download phase for the same issue. The parallel download phase has similar logic.
Assistant
The download phase has the same issue. Let me fix it too.
Assistant
Now let me run the existing tests to verify the fix doesn't break anything.
Assistant
Let me install the project in development mode
Assistant
Now let me run the tests.
Assistant
Let me run the branch_ref_drift tests and integrate tests.
Assistant
Let me run the broader install unit tests
Assistant
All 1477 tests pass. Let me verify my changes look correct by reviewing the
Assistant
Let me restore the lockfile that was inadvertently modified during installation.
Assistant
Let me verify the final diff shows only my intended changes.
Assistant
Let me run the full test suite one more time to make sure everything is solid.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.