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
Let me look at the relevant files to understand how this contenthash mismatch error is generated.
Assistant
Let me get more context around this code:
Assistant
Let me look at the
_should_skip_redownloadfunction:Assistant
Let me look at the issue in more detail. The error shows a
.apm/instructions/testing.instructions.mdis having a content hash mismatch. Let me understand what's going on with file-type deps:Assistant
Let me look at the install path construction:
Assistant
Let me look at where
install_pathis constructed for sub-path deps:Assistant
Now I need to understand the install path for sub-paths.
For a sub-path dep like
dev.azure.com/<org>/tools/github-copilot-agent-skills/.apm/instructions/testing.instructions.md:- It's an ADO dep:
repo_parts = ['dev.azure.com', '<org>', 'tools', 'github-copilot-agent-skills'](no - that's the repo URL) - Wait, let me check the repo_url structure
Looking at
get_install_path:- For ADO: result = apm_modules_dir / org / project / repo
- For subdirectory: result = apm_modules_dir / org / project / repo / virtual_path
So the install path for
dev.azure.com/<org>/tools/github-copilot-agent-skills/.apm/instructions/testing.instructions.mdwould be:apm_modules/dev.azure.com/<org>/tools/github-copilot-agent-skills/.apm/instructions/testing.instructions.md
That means
install_pathis the file itself, not a directory! Let me verify by looking at the install path structure for the issue.Actually wait, looking at the
get_virtual_package_name()function:- It's an ADO dep:
Assistant
Let me look at how virtual file packages are installed:
Assistant
Let me check the cache_pin module to see if it writes any files that could affect hashing:
Assistant
Let me look at the resolve phase that adds to
expected_hash_change_deps:Assistant
Let me look at the heal.py file:
Assistant
Let me look at the heal chain to understand what it does.
Assistant
Let me look at how instructions get integrated after install, this could be a clue:
Assistant
Let me trace through the actual code path more carefully. Let me look at lines 720-790 of sources.py:
Assistant
Let me look at the
_resolve_download_strategyfunction:Assistant
OK, so
FreshDependencySourceis only used whenskip_download=False. Whenskip_download=True, it usesCachedDependencySource.Let me seeCachedDependencySource:Assistant
Let me re-read the integrate code more carefully:
Assistant
Let me look at the resolve phase for this scenario:
Assistant
Let me check the github_downloader to understand
resolve_git_reference:Assistant
Let me look at the tiered resolver and how it handlesthe resolution:
Assistant
Let me search for tests related to this issue and look at what install_path actually contains:
Assistant
Let me look at the apm.yml in this repo to set up a test case:
Assistant
Let me look for similar test cases and look at the apm_resolver to see how virtual packages are stored:
Assistant
Let me check the github_downloader for virtual file packages to see if there's anything that writes different content:
Assistant
Let me look at the template that runs after acquire:
Assistant
Let me check
integrate_package_primitives:Assistant
Let me check what
--forcedoes:Assistant
Let me look at
get_unique_key:Assistant
Let me reproduce this issue locally with a script:
Assistant
Let me check how virtual file is downloaded and check if any text mode is involved:
Assistant
Let me look at the install flow more carefully:
Assistant
Let me look at
download_virtual_file_packageagain carefully:Assistant
Let me look at where the display line is generated in FreshDependencySource:
Assistant
Let me check how the install_path is initialized on first install:
Assistant
Let me look at the rest of
download_virtual_file_package:Assistant
Let me check the git history for content_hash.py to find recent changes:
Assistant
Let me look at the diff of content_hash.py:
Assistant
Let me look at the lockfile writing flow:
Assistant
Let me write a script to reproduce the issue locally with mock data:
Assistant
Let me look at the instruction integrator more carefully:
Assistant
Let me check build_download_ref:
Assistant
Let me look at
download_virtual_file_packageto see if it cleans up the existing install_path:Assistant
Let me look at download_package:
Assistant
Let me look at git history of the issue more carefully:
Assistant
Let me look at when
cache-pinmarkers were introduced. The PR #1137 added the .apm-pin marker. Let me see whenthis was added vs when the issue was reported:Assistant
Let me check the version and recent commits:
Assistant
Let me look at recent changes more carefully to find the regression:
Assistant
So the issue is recent. Let me look at PR #1158 which is about "branch-ref drift no longer ships 3-way-inconsistent lockfile":
Assistant
Let me look at the actual changes in integrate.py from PR #1158:
Assistant
Let me look at the integration test for branch-ref drift and similar issues:
Assistant
Let me search for tests that specifically test virtual file re-install:
Assistant
Let me search for tests or code that might reveal what happens with install_path content:
Assistant
Let me look at the integration test that exercises virtual file packages:
Assistant
Let me look at the e2e test for virtual file packages:
Assistant
Let me look at the integration test for virtual file packages to understand the expected behavior:
Assistant
Let me see how virtual packages are declared in tests:
Assistant
Let me look at the original PR #763 that introduced the content-hash fallback:
Assistant
Let me re-read the current integrate.py code:
Assistant
Now let me look at the test file to understand the pattern:
Assistant
Let me understand the existing fix - I need to look at the file structure carefully:
Assistant
Now I understand the bug. Let me trace through the issue one more time to confirm:
-
First install (
apm install --update --force):- Virtual file package (
.apm/instructions/testing.instructions.md) is downloaded viadownload_virtual_file_package install_path(carved-out directory) is created with the file + apm.yml- In
FreshDependencySource.acquire(),
- Virtual file package (
-
Assistant
Let me dig into the install flow more thoroughly to understand what's different:
Assistant
Let me actually run the existing tests for virtual file packages:
Assistant
Let me look at the actual download_virtual_file_package implementation more carefully:
Assistant
Let me look at the issue more carefully - I'll examine the content hash issue and propose a fix. Let me first check if there's a related test that's already failing or if we have a scenario that reproduces the bug:
Assistant
I've reproduced the bug. Now let me understand the fix needed and implement it:
Assistant
Now let me write the fix:
Assistant
Now let me apply the fix:
Assistant
Now I'll apply the fix. Let me add a third
elifbranch for virtual file packages from git sources:Assistant
Now let me verify my fix works with my reproduction test:
Assistant
The fix works. Now let me run the existing tests to make sure I didn't break anything:
Assistant
All tests pass. Let me run a broader test suite to make sure I didn't break anything:
Assistant
All 15812 unit tests pass. Let me write a more thorough test to validate my fix:
Assistant
Let me also verify the fix handles edge cases by looking at
_resolve_commit_sha_for_ref:Assistant
Let me also check the edge case where install_path exists but is empty:
Assistant
All edge cases pass. Let me run the full test suite again to make sure my fix doesn't break anything:
Assistant
All 15812 tests pass. Let me view the final fix:
Assistant
Let me clean up the temporary test files:
Assistant
Let me run a focused set of tests related to my fix one more time to confirm everything works:
Assistant
All 74 related tests pass. Let me also create a temporary script to verify the fix more comprehensively by simulating the full install flow:
Assistant
The fix works correctly. Let me clean up the test files:
Assistant
Let me view the final state of the fix:
Assistant
I notice the apm.lock.yaml was modified by some test runs. Let me revert it because it's not related to my fix:
Assistant
My fix is clean. Let me do a final check to ensure all tests still pass:
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.