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 issue. The bug is about
apm installfailing on the second run with a "Content hash mismatch" error. The first run with--update --forceworks fine, but the second run fails because the content hash doesn't match.Let me explore the repository structure first to understand what we're working with.
Assistant
This looks like the APM (Agent Package Manager) repository. Let me explore the source code to understand the structure better.
Assistant
Let me search for the "Content hash mismatch" error message in the codebase.
Assistant
Let me look at the sources.py file to understand where the error is raised and how the hash comparison works.
Assistant
Let me look at the broader context around that line.
Assistant
Let me use the open command correctly.
Assistant
Let me understand more about how the hash is computed and how the lockfile is updated.
Assistant
Let me look at the content_hash module.
Assistant
Let me look at the content_hash.py file.
Assistant
Let me look at the cache_pin module and how the lockfile content hash is recorded
Assistant
Let me read the cache_pin module.
Assistant
Let me search for how the content hash gets recorded in the lockfile during installation
Assistant
Let me look at the lockfile builder to understand how content hashes are attached.
Assistant
Let me look at the _redownload.py and the integrate.py phase files
Assistant
Let me look at the integrate.py file for the content hash mismatch
Assistant
Let me look at the full integrate.py file
Assistant
Let me look at the DependencySource implementations for cached sources in sources.py
Assistant
Let me look at the CachedDependencySource class
Assistant
Let me look at the FreshDependencySource class
Assistant
Let me look at how virtual packages (single file dependencies) are handled, especially their install paths
Assistant
Let me look at the DependencyReference model to understand virtual package handling
Assistant
Let me find the DependencyReference class
Assistant
Let me look at the DependencyReference class and get_install_path for virtual packages
Assistant
Let me continue reading get_install_path
Assistant
Let me search for the
--forceflag behaviorAssistant
Let me look at the test files to understand the expected behavior better
Assistant
Let me look at the content hash tests
Assistant
Let me look at the test files related to the sources phase and content hash
Assistant
Let me look at the test that checks content hash mismatch behavior
Assistant
Let me look at the test for content hash mismatch behavior in the integrate orchestration
Assistant
Let me look at the
build_download_reffunction in drift.pyAssistant
Let me look at the build_download_ref
Assistant
Let me look at how virtual file packages are downloaded
Assistant
Let me find the downloader code
Assistant
Let me search for "resolved_commit" in the downloader code
Assistant
Let me look at the download_package method in the github_downloader
Assistant
Let me look at the download_package
Assistant
Let me look at download_virtual_file_package
Assistant
Let me look at download_virtual_file_package
Assistant
Let me look at `_resolve_commit_sha_for_ref
Assistant
Let me look at this method
Assistant
Let me find the GitReferenceResolver class
Assistant
Let me look at the git_reference_resolver
Assistant
Let me look at the full _resolve_download_strategy code
Assistant
Now I understand the bug. The issue is in
_resolve_download_strategyinsrc/apm_cli/install/phases/integrate.py. When a dependency has acontent_hashin the lockfile but noresolved_commit(which happens for Azure DevOps virtual file packages since_resolve_commit_sha_for_refreturnsNonefor ADO), the code doesn't fall back to the content-hash-based_should_skip_redownloadcheck. This means:- On the first
apm install --update, the content is downloaded and its hash is stored in the lockfile, butresolved_commitisNone - On the second
apm install, the git-based lockfile_match check is skipped (no resolved_commit), the registry fallback doesn't apply (not a registry dep), so the package is always re-downloaded - When re-downloaded, if the branch has moved, the new content hash doesn't match the lockfile's hash, causing the error
The fix: add a fallback to
_should_skip_redownloadfor non-registry deps that have acontent_hashbut noresolved_commit.Let me verify by looking at the exact code and creating a fix
- On the first
Assistant
Let me use the bash command to view the file.
Assistant
Now I can see the exact issue. Let me implement the fix. The problem is that after the registry fallback (line 155), there's no fallback for non-registry deps that have a
content_hashbut noresolved_commit(like ADO virtual file packages). I need to add anelifclause that uses_should_skip_redownloadfor these deAssistant
Now let me apply the fix. I need to add an elif clause after the registry fallback to handle non-registry deps that have content_hash but no resolved_commit.
Assistant
Let me now verify that the heal chain won't break this by looking at it briefly
Assistant
Let me check what heals exist
Assistant
Let me find the heals module
Assistant
Let me find the heals directory
Assistant
Let me look at the heals package
Assistant
Now let me run the existing tests to make sure my change doesn't break anything
Assistant
Let me install dependencies and try again
Assistant
Now let me run the tests again
Assistant
All tests pass. Let me also run the broader test suites for the integrate and sources phases
Assistant
Let me run the tests more specifically related to the areas I changed
Assistant
Let me also run the branch ref drift tests and the content hash tests
Assistant
Let me run a broader set of tests to make sure nothing is broken
Assistant
All 1477 unit tests pass. Let me also run the integration tests for install to make sure nothing is broken
Assistant
Let me look at the final state of the changed file to verify the fix
Assistant
Let me see the full diff of my changes
Assistant
I see the
apm.lock.yamlwas modified during package installation. Let me restore it since my fix only modifies the integrate.py fileAssistant
Let me verify only my intended change remains
Assistant
Let me run the full unit test suite one more time to confirm everything is clean
Assistant
The fix is clean and all tests pass. Let me summarize the change:
Summary
Bug:
apm installfails on the second run with "Content hash mismatch" for Azure DevOps virtual file packages (like.instructions.mdfiles).Root Cause: In
_resolve_download_strategy()insrc/apm_cli/install/phases/integrate.py, thelockfile_matchlogic had three branches:- Git-based check (requires
resolved_commit) - skipped for ADO virtual file packages becauseresolved_commitisNone - Registry fallback (requires
source == "registry") - doesn't apply to non-registry deps - No fallback for deps with
content_hashbut noresolved_commitand not a registry dep
- Git-based check (requires
Assistant
Let me check if apm.lock.yaml is still showing changes
Assistant
Let me check git
Assistant
Let me restore the apm.lock.yaml properly
Assistant
Let me verify the state
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.