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 working with.
Assistant
Now let me search for the path of files in the issue (instructions files):
Assistant
Now let me look at theintegrate.py file to understand the context:
Assistant
Let me look at the previous sections to understand the full context:
Assistant
Now let me look at the
_should_skip_redownloadfunction:Assistant
Now let me look at the cache_pin module:
Assistant
Let me search for where the file is mentioned in the issue - the
.apm/instructions/testing.instructions.md:Assistant
Let me look at the virtual package handling:
Assistant
Now let me look at the integrate phase to understand the flow when the file is virtual - i.e., when the dep is a virtual path like
.apm/instructions/testing.instructions.md:Assistant
Let me look at how the virtual path file is handled during download to understand where the install_path is set:
Assistant
Let me look at how install_path is set for virtual packages:
Assistant
Now let me understand the flow. Let me look at where the install_path is set for the virtual file package:
Assistant
Let me look at where the virtual file gets downloaded to:
Assistant
Let me trace the flow more carefully. The issue says the third dep (virtual file) doesn't say "cached" but instead goes through the FreshDependencySource path. Let me look at when the source path is determined:
Assistant
Let me look at the download_raw_file function:
Assistant
Let me look at the resolve_git_reference function:
Assistant
Now I see the issue. Let me read more of the
resolvefunction and understandthe ADO virtual file case.Assistant
Let me look at how the lockfile is created for virtual files:
Assistant
Let me look at how the lockfile is built for virtual files:
Assistant
Let me look at the lockfile that would be created after the first install:
Assistant
Let me look for some tests that involve content_hash to understand the flow:
Assistant
Let me look at the ADO download and see if there's anything related to line ending or content normalization:
Assistant
Let me look at the build_ado_api_url function and understand what's being returned:
Assistant
Let me look at the integration in sources.py where the resolved_commit is recorded:
Assistant
Let me look at the download_package method:
Assistant
Now let me look at how the SHA is recorded for non-virtual packages. Let me look at the part after
resolved_ref = self.resolve_git_reference(dep_ref):Assistant
Let me check the InstalledPackage class:
Assistant
Let me look at the apm.yml generation to understand what is in it for the virtual file:
Assistant
Let me look at the test for ADO virtual file install:
Assistant
Let me first reproduce the issue by creating a simple test scenario:
Assistant
Let me reproduce the issue:
Assistant
Let me write a more comprehensive test that actually downloads from a mock:
Assistant
Let me look at the full download flow:
Assistant
Let me look at the pre-download logic:
Assistant
Let me check compute_package_hash more carefully:
Assistant
Let me look at the yaml_to_str function:
Assistant
Let me write a more comprehensive test that actually exercises the flow:
Assistant
Let me look at the integrate.py code once more to plan the fix:
Assistant
Let me look at how the source field is set for different types:
Assistant
Now let me look at the actual fix needed. Let me check the heal pipeline:
Assistant
Let me look at the heal dispatcher:
Assistant
Let me look at detect_ref_change:
Assistant
Let me look at how local deps flow:
Assistant
Now let me look at the fix approach. Let me look at the structure more carefully:
Assistant
Let me check if there's an ADO-specific commit lookup:
Assistant
Let me look at how
--forceaffects the install:Assistant
Let me look at the install_command.py to see how --force works:
Assistant
Let me look at the actual diff between first and second install to see if the hashes can really differ. Let me check if there's any non-determinism in the install path generation:
Assistant
Let me search for any other places that might create files in install_path:
Assistant
OK so for subdirectory packages, the install_path is wiped if it has content. Letme check virtual files:
Assistant
Let me check what --force does:
Assistant
Let me try a different approach - check if the install does anything else that could modify the install_path:
Assistant
Let me check what --update does:
Assistant
Now let me look at the existing test to understand how to write a proper test:
Assistant
Now let me look at the actual code once more and write the fix:
Assistant
Now let me make the fix. I'll modify the elif branch to also include non-registry deps without resolved_commit:
Assistant
Now let me make the fix:
Assistant
Now let me run my reproduction test to verify the fix works:
Assistant
The fix works. Now let me also verify my first reproduction test:
Assistant
Let me update the first test to use the actual code:
Assistant
The fix works. Now let me run the existing tests to make sure I didn't break anything:
Assistant
All unit tests pass. Now let me run the integration tests:
Assistant
Let me check what's in apm.lock.yaml:
Assistant
Good. Now let me run the rest of the integration tests:
Assistant
The failing tests are pre-existing (not caused by my changes). Let me clean up the test artifacts and reset everything:
Assistant
Hmm, the diff is empty. Let me check if my changes are still in place.
Assistant
My changes were lost when I ran git checkout. Let me re-apply the fix:
Assistant
Now let me run the tests again to verify everything still passes:
Assistant
Now let me look at the unit tests that test the integrate phase to see if I need to add a test for my fix:
Assistant
Let me verify the fix again with the test:
Assistant
Now let me also write a test that simulates the case where the content actually changes (to make sure we still re-download when needed):
Assistant
My fix works correctly for both cases:
- When content matches: skips download (uses cache)
- When content differs: re-downloads (correct behavior)
Now let me also test the case where the dep_ref has resolved_commit (to ensure I didn't break the git-based check):
Assistant
Let me also check that the registry deps still work:
Assistant
The test has a MagicMock issue. Let me fix it:
Assistant
Let me run all the install tests once more to verify nothing is broken:
Assistant
All 1477 install unit tests pass. Now let me run the install-related tests:
Assistant
Tests are being skipped. Let me check why:
Assistant
All tests pass. Now let me also run the heal tests since they are related:
Assistant
Now let me look at any tests that might be specific to the install flow with virtual files:
Assistant
Now let me also check if there are any other places where the bug could manifest. Let me look at the related code more carefully:
Assistant
Let me check the integration test for install scenarios:
Assistant
Now let me also check what happens when there's a GitLab virtual file (since GitLab has its own backend):
Assistant
Let me check ADO-related tests:
Assistant
Let me also check if there are any related integration tests for ADO install:
Assistant
Let me look at one of the ADO tests:
Assistant
Let me now do a comprehensive review of my changes:
Assistant
Let me also clean up test files:
Assistant
Let me also verify the fix one more time by running the unit tests:
Assistant
All 1477 install unit tests pass. Now let me also check what the install command actually outputs by testing with my reproduction script once more:
Assistant
Test 2 failed. Let me debug:
Assistant
The fix is correct. The test 2 failure was due to my test setup issue (I was setting source on the wrong object). Let me verify by running the fix once more:
Assistant
Now let me clean up the temp tests:
Assistant
Now let me verify the final state of the fix by running the tests one more time:
Assistant
All tests pass. Let me also verify the fix one final time by writing a comprehensive test:
Assistant
All tests pass. Let me clean up:
Assistant
Let me also run the broader test suite to ensure I haven't broken anything:
Assistant
All 15812 unit tests pass. Let me verify my final diff:
Assistant
Let me write a final reproduction script and verify the bug is fixed:
Assistant
The bug is fixed. Let me clean up:
Assistant
Let me check the final state of the changes:
Assistant
Let me also run the install tests one final time:
Assistant
All 1477 install unit tests pass. The fix is complete.
Summary of the Fix
The bug was that
apm installfails the second time with "Content hash mismatch" for ADO (Azure DevOps) virtual file dependencies. The root cause was in/apm/src/apm_cli/install/phases/integrate.pyin the_resolve_download_strategyfunction:Bug Analysis:
- ADO virtual files (e.g., ) don't have a in the lockfile because the cheap SHA-resolution API () returns for ADO hosts.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.