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 the codebase.
Assistant
Let me explore the relevant files.
Assistant
Now I see the part where the second install path triggers theerror. Let me look at what
_should_skip_redownloaddoes.Assistant
Let me look at how
content_hashis computed and how virtual packages work.Assistant
Let me look more carefully at the
integrate.pyfile to find the full call chain:Assistant
Let me look at how virtual packages (single files) are downloaded and installed:
Assistant
Let me look at how virtual packages are downloaded and cached:
Assistant
Let me look at the relevant state:
Assistant
Let me look at the resolve phase:
Assistant
Let me look at how virtual packages are processed in the lockfile:
Assistant
Let me look at the cache_pin module:
Assistant
Let me look at the lockfile structure to see what content_hash is recorded for virtual file packages:
Assistant
Let me look at how
get_install_pathworks for virtual packages:Assistant
Let me look at how virtual packages are integrated after install:
Assistant
Let me look at how the install pipeline works step by step. First let me try to reproduce the issue:
Assistant
Let me look at what's actually placed in the install path for a virtual file package during download:
Assistant
Let me look at how the download_package handles virtual file packages:
Assistant
Let me look at the template module to see what integration does:
Assistant
Let me now look at
integrate_package_primitivesto see what happens during integration:Assistant
Let me look at the existing tests for virtual packages:
Assistant
</mm:think>
Assistant
</mm:think>
Assistant
</mm:think>
Assistant
</mm:think>
Assistant
</mm:think>
Assistant
</mm:think>
Assistant
Let me look at detect_ref_change:
Assistant
</mm:think>
Assistant
</mm:think>
Assistant
Let me look at how the BFS callback's return value is used:
Assistant
</mm:think>
Assistant
</mm:think>
Assistant
</mm:think>
Assistant
</mm:think>
Assistant
</mm:think>
Assistant
</mm:think>
Assistant
</mm:think>
Assistant
</mm:think
Assistant
Let me look more carefully at the workflow. Maybe the issue is about how content_hash is computed for virtual packages and where the file is stored. Let me search for "compute_package_hash" usage:
Assistant
Let me write a test to reproduce the bug:
Assistant
Let me look at how virtual packages get resolved_commit:
Assistant
Let me look at when the sync_cache_pin_markers is called:
Assistant
Let me look at how subdirectory virtual packages are downloaded:
Assistant
Let me look at the tests for the install pipeline to understand the test patterns:
Assistant
Let me look at the tests for the resolve phase and related content-hash tests:
Assistant
Now let me look at the current cache_pin logic and checktests for it:
Assistant
Let me look at the relevant code section once more, focusing on the cache skip logic:
Assistant
Now let me look at the parallel pre-download phase more carefully:
Assistant
Let me trace through the logic and write a reproducer:
Assistant
Let me look at how yaml_to_str works:
Assistant
Let me write a more thorough reproducer using actual install code:
Assistant
Let me check how the ADO URL is parsed:
Assistant
Let me look at the actual install behavior in detail:
Assistant
Let me look at the description extraction in more detail:
Assistant
Let me look at git history for changes related to this issue:
Assistant
Let me look at the test cases for #763:
Assistant
Let me look at the apm.yml:
Assistant
Let me create a real reproducer to see what's actually happening:
Assistant
Let me take a more direct approach and write a unit test that demonstrates the bug:
Assistant
Let me also verify the supply-chain check would fire if the hash mismatches:
Assistant
Let me verify my fix logic works by simulating what should happen:
Assistant
Now I have a clear understanding of the bug. Let me implement the fix:
Assistant
Now let me implement the fix. I'll modify both the integrate.py and download.py:
Assistant
Let me invoke a tool tomake the fix.
Assistant
Now let me make the fix in integrate.py:
Assistant
Now let me also fix download.py:
Assistant
Now let me verify the fix works:
Assistant
The fix works. Now let me also run the existing tests to make sure I didn't break anything:
Assistant
All 1477 tests pass! Let me also run the broader test suite to make sure nothing else is broken:
Assistant
All tests pass. Now let me also check the integration tests:
Assistant
These failures are unrelated to my fix - they're test failures due to running as root in a Docker container (the chmod test doesn't work as root). Let me confirm:
Assistant
Let me check the unintended changes:
Assistant
Let me revert the unintended changes:
Assistant
The untracked files are notchanges I made. Let me check if those were there before:
Assistant
These are existing files that got reverted to untracked state by the stash. Let me verify my changes are still correct:
Assistant
Now let me write a proper test for the bug fix to add to the existing tests:
Assistant
All my tests pass. Now let me also run the integration test:
Assistant
Let me also test the install pipeline specifically:
Assistant
All tests pass. Let me also think about edge cases and verify the fix handles them correctly:
Assistant
Let me simplify the edge case tests:
Assistant
Assistant
Let me trace through more carefully:
Assistant
Interesting! When I mock
detect_ref_changeto return False,skip_downloadbecomes True. So the issue is thatdetect_ref_changeis returning True for the registry dep, which makesref_changed=True, and then my new branch doesn't fire.Let me check what
detect_ref_changereturns for aregistry dep:Assistant
Ah, so
detect_ref_changereturns True for a registry dep because the lockfile hasresolved_commit=Nonebut the manifest ref is also None. Wait, let me look at this again.Actually, looking at
detect_ref_change:def detect_ref_change( dep_ref: DependencyReference, locked_dep: LockedDependency | None, *, update_refs: bool = False, logger=None, ) -> bool: """Return ``True`` when the manifest ref differs from the locked resolved_ref.""" ...For our test case:
dep_ref.reference = Nonelocked_dep.resolved_commit = None(not set)
Hmm, looking at the code:
if dep_ref.reference != locked_dep.resolved_ref: return TrueBut wait,
dep_ref.referenceis None andlocked_dep.resolved_refis also None (not set). So they should be equal. Letme check more carefully.Assistant
Let me look at
_registry_range_covers_locked_version:Assistant
My test is unrealistic - registry deps would have a version set. Let me fix the test:
Assistant
Let me also verify by running the existing tests:
Assistant
All 1544 tests pass. Let me also check the specific tests that might be affected by my change:
Assistant
Let me also run the test for
apm install:Assistant
Let me also look at how to test the fix with the full install flow:
Assistant
Let me set up a more realistic test:
Assistant
Let me check what URL formats are supported:
Assistant
The issue is that the local path doesn't have the file at that exact location (it's inside
.apm/instructions/). The path is being interpreted as a local package path. Let me look at how virtual packages are detected.Actually, looking at the output:
Local package path does not exist. So this is being parsed as a local path, not as a virtual package URL.Let me look at the
DependencyReference.parsetounderstand the parsing logic better.Assistant
Let me try with an ssh URL:
Assistant
Let me set up a git daemon to do a real end-to-end test:
Assistant
The git daemon isn't working, but my fix is verified at the unit test level. Let me also test the download.py fix:
Assistant
The download test is hard to set up with mocks. Let me trust the unit test for
_resolve_download_strategysince the fix is symmetric. Let me also test the download.py path with the proper dep_ref:Assistant
Let me check why the download.py fix isn't working:
Assistant
Hmm, my elif branch should work. Let me debug it more carefully. Let me addprint statements.
Assistant
Let me check the function properly:
Assistant
I see the issue! The actual install path is different from what I was creating. Let me fix the test:
Assistant
Both fixes work. Let me now also run the broader tests:
Assistant
Let me also check the CHANGELOG and see if I need to add an entry:
Assistant
Let me add a changelog entry:
Assistant
Let me now verify all my changes one final time:
Assistant
Let me also run the full test suite one more time:
Assistant
All 15812 unit tests pass. Let me also check my fix doesn't break the existing tests for the specific area I modified:
Assistant
All tests pass. Let me clean up the temporary test files:
Assistant
Let me do a final review of my changes:
Assistant
Let me also check if there are any other places where the same pattern might exist:
Assistant
This is the semver resolution path - not related to my issue.
Let me also check if there are other places that might have similar issues. Let me look at how
_resolve_commit_sha_for_refis called and where.Assistant
Let me also run the install-related tests once more:
Assistant
All 1477 install tests pass. Let me also do a final review of all the changes:
Assistant
Let me show the final diff:
Assistant
Now let me also check the checklist:
Checklist Review
-
If an error was reported in the issue description, I have successfully reproduced it.
- I created a reproducer script (
/tmp/test_bug_repro.py) that demonstrated_resolve_download_strategyreturningskip_download=Falsefor an ADO virtual file package even when the on-disk content matches the lockfile record. This is exactly the scenario described in the bug report.
- I created a reproducer script (
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.