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 analyze this issue. The bug is about
apm installfailing the second time with "Content hash mismatch". The issue seems to be related to how content hashes are computed and compared between what's stored in the lockfile and what's actually downloaded.Let me start by exploring the repository structure to understand the codebase.
Assistant
Let me explore the source code structure to understand how the project is organized.
Assistant
Let me combine these or use one at a time.
Assistant
It's a Python project. Let me find where "Content hash mismatch" is defined.
Assistant
Let me look at the relevant source files
Assistant
Let me open the file around line 777 to see the context.
Assistant
Let me look at the
_compute_hashfunction.Assistant
Let me look at the content_hash utility
Assistant
Let me look at the content_hash.py module.
Assistant
Let me look at the cache_pin module.
Assistant
Let me look at a broader section of the sources.py file around line 753 to understand the flow
Assistant
Let me look at how the content hash is stored in the lockfile. Let me check the integrate.py module
Assistant
Let me look at the LockfileBuilder to understand the flow
Assistant
Let me look at the lockfile builder, specifically the
_attach_content_hashesmethodAssistant
Let me look at the different dependency source types and how caching works.
Assistant
Let me look at the LocalDependencySource
Assistant
Let me look at lines around 285-295 where LocalDependencySource computes the hash.
Assistant
Let me look at the CachedDependencySource's acquire method
Assistant
Let me look at lines 490-550 of sources.py
Assistant
Let me look at the _redownload module
Assistant
Let me look at the integrate phase to understand the download strategy
Assistant
Let me continue reading the integrate.py to understand the full flow of download strategy.
Assistant
Let me continue reading the rest of integrate.py.
Assistant
Let me search for how
--forceaffects the flowAssistant
Let me look at the InstallContext and InstallRequest
Assistant
Now let me look at the service.py for the install
Assistant
Let me look at the install pipeline
Assistant
Let me look at where the context is created in
Assistant
Let me look at the test files for content hash issues
Assistant
Let me look at the test files
Assistant
Let me search for how virtual packages are handled in the download process
Assistant
Let me find how virtual deps are downloaded
Assistant
Let me look at the dependency reference model
Assistant
Let me look at
get_install_pathAssistant
Let me look at that method.
Assistant
Let me look at the downloader to understand how virtual packages are downloaded
Assistant
Let me look at the download_package method in github_downloader.py
Assistant
Let me look at the
download_virtual_file_packagemethodAssistant
Let me look at the method at line 862.
Assistant
Let me continue reading
Assistant
Let me search for any recent changes related to the content hash issue
Assistant
Let me look at recent changes that might relate to the issue
Assistant
Let me create a test to understand and reproduce the issue
Assistant
Let me look at the CLI handler to understand
--updateand--forceAssistant
Let me look at the drift detection code
Assistant
Let me look at the
detect_ref_changefunctionAssistant
Let me look at that function.
Assistant
Let me look at how the lockfile is built from InstalledPackage
Assistant
Let me look at how LockedDependency is built from an installed package
Assistant
Let me look at how
from_installed_packagescalls this.Assistant
Let me look at where
build_download_refis called in the FreshDependencySourceAssistant
Let me look at the FreshDependencySource acquire method where build_download_ref is called.
Assistant
Let me look at the
download_raw_filemethodAssistant
Let me look at both methods.
Assistant
Let me search for recent changes related to content hash or the issue
Assistant
Let me look at the commit that added
.apm-pinexclusion:Assistant
Let me look at the branch-ref drift fix commit
Assistant
Let me look at the branch_ref_drift heal module
Assistant
Let me look at the buggy_lockfile_recovery heal
Assistant
Let me check the yaml_to_str function
Assistant
Let me look at the yaml_to_str function
Assistant
Let me look at how ADO resolves commit SHAs
Assistant
Let me look at the resolve_commit_sha_for_ref method in git_reference_resolver.py.
Assistant
Let me look for E2E tests that test virtual packages twice
Assistant
Let me look for integration tests related to this issue
Assistant
Let me look at the ADO E2E test for virtual packages
Assistant
Let me trace where
_resolve_download_strategyis calledAssistant
Let me look at integrate.py around line 467.
Assistant
Let me look at how the resolve phase handles pre-downloading for virtual packages
Assistant
Let me look at the download_callback in resolve.py
Assistant
Let me look at the parallel download phase
Assistant
Let me look at the download phase more carefully
Assistant
Let me look at the download phase
Assistant
Let me read the rest
Assistant
Let me look at what
--forcedoes in the install contextAssistant
Let me look at the guardrailing hero E2E
Assistant
Let me look at the branch_ref drift E2E tests
Assistant
Let me look at the diff aware install E2E tests more closely
Assistant
Let me look at the virtual package test at line 504
Assistant
Let me search for all places where resolved_ref is set in the lockfile
Assistant
Let me look at how the dependency reference is parsed
Assistant
Let me create a more detailed reproduction script
Assistant
Let me use the venv
Assistant
Let me check the resolve phase for the update_refs influence on resolution
Assistant
Let me look at these key lines in resolve.py
Assistant
Let me look at line 685
Assistant
Let me look at line 116 in resolve.py
Assistant
Let me look at
_merge_existingin the lockfileAssistant
Let me look at line
Assistant
Let me look at the
is_semantically_equivalentmethodAssistant
Let me look at that method.
Assistant
Let me look at the ADO file download code path
Assistant
Let me look at download_ado_file
Assistant
Let me run the relevant unit tests to see if they pass
Assistant
Let me run more relevant tests
Assistant
Let me look at the ADO E2E test more carefully to see if any test installs twice
Assistant
Let me look at how DependencyReference.parse works to see if it adds a default reference
Assistant
Let me look at the full
make_dependency_sourcefunctionAssistant
Let me look at the callback_downloaded mechanism more carefully
Assistant
Let me look at lines 590+ in resolve.py
Assistant
Let me check the alias field
Assistant
Now I have a much better understanding of the issue. Let me trace through the exact problem:
- For ADO virtual file packages,
resolved_commitis alwaysNone(ADO doesn't support the cheap SHA resolution API) - When
resolved_commitisNone, thelockfile_matchcheck in_resolve_download_strategynever fires (the check at line 115 requiresresolved_committo be truthy) - This means the dep is always re-downloaded on every
apm install - After re-downloading, the content hash is compared against the lockfile
- If the branch content differs from what was recorded in the lockfile, it's a hard error
The issue is that there's no content-hash fallback for non-registry git deps when
resolved_commitisNone. The fallback exists for registry deps (lines 151-160) but not for git deps.Let me look at the exact lines where the fix needs to go:
- For ADO virtual file packages,
Assistant
Now I understand the issue. The problem is in
_resolve_download_strategyinintegrate.py. When a dependency has noresolved_commit(as is the case for ADO virtual file packages), the code at lines 113-160 provides no fallback for non-registry git deps. Thelockfile_matchcheck only works whenresolved_commitis truthy (line 115). For registry deps, there's a content-hash fallback at lines 151-160, but for regular git deps with noresolved_commit, neither block fires.This means:
- The dep is always re-downloaded (even if cached content matches)
- After re-downloading, if the content hash differs from the lockfile (because the branch may have changed), it's a hard error
Let me also look at how the
FreshDependencySourcehandles this to understand the full picture:Assistant
Now I have a clear understanding of the bug. Let me implement the fix.
The issue is in
_resolve_download_strategyinintegrate.py. Whenresolved_commitisNone(common for ADO virtual file packages), and the dep is not registry-sourced, there's no content-hash fallback. The dep is always re-downloaded, and if the content hash differs from the lockfile, it's a hard error.The fix needs to:
- Add content-hash fallback for git deps when
resolved_commitis None - When content hash doesn't match, mark it as expected change to prevent the hard error in `FreshDependencySource.ac
- Add content-hash fallback for git deps when
Assistant
Now I'll implement the fix. I need to add a content-hash fallback for non-registry git deps when
resolved_commitis None or "cached".Assistant
Let me use the replace command instead
Assistant
Now let me verify the change by running the relevant tests.
Assistant
All related tests pass. Let me also run the full install unit test suite to make sure nothing's broken.
Assistant
Let me run the tests without the timeout
Assistant
Let me also run the content hash and heal tests specifically to make sure nothing is broken
Assistant
Let me verify the final state of the edited file
Assistant
The fix looks correct. Let me run the full test suite to make sure nothing is broken.
Assistant
All tests pass. Let me also verify the drift tests and the broader test suite.
Assistant
All drift tests pass. Let me now verify my change once more by looking at the diff.
Assistant
The diff shows only my intended change in
integrate.pyplus some unrelated lockfile regeneration. Let me run the full unit test suite one more time to be completely sure.Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.