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
I'll explore the repository structure first.
Assistant
This is the APM (Agent Package Manager) tool. Let me explore the source structure.
Assistant
Now let me look at the sources.py file where the "Content hash mismatch" error is raised.
Assistant
Let me look at the integrate.py file which also has the hash mismatch handling.
Assistant
Let me look at the cache_pin module, since the content_hash.py mentions a
.apm-pinmarker that's written after hash recording.Assistant
Let me look at how the lockfile content_hash is set and built.
Assistant
Let me look at the downloader to understand how instruction/file dependencies are downloaded.
Assistant
Let me look at the
download_raw_fileanddownload_virtual_file_packagemethods since instruction files are likely downloaded as single files.Assistant
Let me look at how the dependency source is selected (cached vs fresh vs local).
Assistant
Let me look at the LocalDependencySource and CachedDependencySource acquire methods.
Assistant
Now let me look at the CachedDependencySource acquire and where the source is selected. Let me also see the rest of the CachedDependencySource.
Assistant
Let me look at the full
_resolve_download_strategyin integrate.py.Assistant
Let me look at the existing tests for content hash and virtual packages to understand the expected behavior.
Assistant
Let me look at the diff_aware_install_e2e test and cache_lockfile_parity test, which seem relevant.
Assistant
Let me look at the test fixtures and how the e2e install tests work.
Assistant
Let me look at how the resolve phase pre-downloads and how virtual packages flow through.
Assistant
Let me look at the beginning of the download callback to understand when it skips downloading.
Assistant
Let me look at the
download_packagemethod in the downloader to see if it wipes install_path.Assistant
Let me find where the dependency source (cached/fresh/local) is selected.
Assistant
Let me look at the sources materialisation test and how it mocks the downloader.
Assistant
Let me find the FreshDependencySource hash mismatch test.
Assistant
Let me look at the pre-download phase to understand
pre_download_results.Assistant
Let me look at the full
_attach_content_hashesmethod in the lockfile phase.Assistant
Let me write a reproduction script to understand the hash behavior of virtual file package downloads.
Assistant
I need to use the venv. Let me check.
Assistant
The download itself is deterministic. The issue must be in the pipeline. Let me check if integration writes files into the install_path.
Assistant
Let me look at the virtual package branch-ref-drift test which deals with re-install of virtual packages.
Assistant
Let me search for code that writes files into the install_path/apm_modules during install, besides the downloader.
Assistant
Let me look at the lockfile.py phase around the marker writing and the overall build flow.
Assistant
Let me check what
--forcedoes in the install command.Assistant
Let me look at
_resolve_commit_sha_for_refto understand when it returns None.Assistant
Let me look at the
resolvemethod to understand what it does for ADO/virtual packages.Assistant
Let me set up a real reproduction with a local git repo. First, let me understand how apm handles local git URLs.
Assistant
Let me look at the integrate orchestration test to find a hermetic way to run the pipeline.
Assistant
Let me set up a real reproduction with a local git repo. First, let me create the repo and test how apm parses local git URLs.
Assistant
Let me use the object form with git URL. Let me check the dependency dict parsing.
Assistant
The
file://URL isn't accepted. Let me try with a different host. Let me check how generic git hosts are parsed. Let me look at the parse method to understand what hosts are accepted.Assistant
Let me look at the
parsemethod to find how to specify a local git repo URL.Assistant
Let me check how apm configures git environment (it mentioned forcing an empty global gitconfig).
Assistant
Let me find tests that run the full install pipeline with a fake downloader.
Assistant
Let me look at
get_virtual_package_nameto understand the install_path naming.Assistant
Let me look at how the git environment is built for clones (GitAuthEnvBuilder).
Assistant
Let me check
build_download_refto see if it modifies the dep_ref's virtual status.Assistant
Let me check the CHANGELOG and recent git history around content hash and virtual packages.
Assistant
Let me look at the install command entry point to invoke it programmatically.
Assistant
Let me write a reproduction script that runs the install CLI twice with a mocked downloader, simulating the ADO virtual-file scenario.
Assistant
The CLI ran in
/apminstead of my temp project. Let me fix the working directory.Assistant
Let me use a generic host to avoid ADO auth requirements, while still getting
resolved_commit=None.Assistant
Run 1 succeeded with the same "no resolved_commit" warning. Let me fix the lockfile parsing and see run 2.
Assistant
Let me check where "(files unchanged)" is printed to understand the run 2 flow.
Assistant
Let me add debug instrumentation to understand the run 2 flow in my repro.
Assistant
Let me reproduce with multiple instruction file deps from the same repo, which matches the bug structure better.
Assistant
Let me look at
download_subdirectory_packageto understand what it writes to disk.Assistant
Let me look at the apm repo's own lockfile to understand virtual file entry structure.
Assistant
Let me reproduce with a subdirectory package (csharp) plus the instruction file from the same repo. Let me mock
download_subdirectory_package.Assistant
The subdirectory parsing needs ADO's 3-part structure. Let me find where ADO auth is enforced during resolution so I can bypass it.
Assistant
This is the validation that probes git ls-remote. It's called during dep resolution to validate the dep exists. Let me look at where this is called and patch it. Actually, this is in
validation.py. Let me find the function and patch it to skip for my repro.Actually, the simplest: patch the whole validation to return True for all deps. Let me find the validation entry point. Let me look at what
validate_virtual_package_existsvs this ls-remote validation is.Actually, the ADO auth error came from
pipeline.py:289orvalidation.py:530. Let me look at the validation flow. The dep resolution validates each dep. Let me find the validate function and patch it.Let me look at validation.py around the validate function.
Assistant
Let me update the repro to use ADO host and patch the validation to bypass auth.
Assistant
Let me look at pipeline.py around line 289 for the auth check.
Assistant
This is the
--updatepreflight. Let me find the function and patch it.Assistant
Let me dump the raw lockfile and the apm_modules tree to understand the actual structure.
Assistant
Let me check how the lockfile stores and looks up dependencies - this could be the key.
Assistant
Let me check
LockedDependency.get_unique_keyto confirm the lockfile key includes the virtual path.Assistant
Let me rewrite the repro more faithfully with transitive deps, no explicit ref for testing, and add hash debugging.
Assistant
My deterministic repro doesn't reproduce the bug, suggesting the download content or install_path state must differ between runs. Let me examine the integration template for any writes to install_path after the hash is recorded.
Assistant
Let me look at the content hash unit tests to understand the expected behavior and exclusions.
Assistant
Let me check the security scan for any writes to install_path.
Assistant
Let me try a real reproduction with a local git repo served over HTTP. First, let me check how to specify an http host with allow_insecure.
Assistant
Let me set up a local git repo served over HTTP to test with real git operations for the subdirectory package.
Assistant
Now let me start an HTTP server and write a repro using real git for the subdirectory package, mocking only the instruction file download.
Assistant
Let me set up a bare repo for dumb HTTP cloning.
Assistant
Something else is on port 8080. Let me use a different port.
Assistant
Now let me write the repro with real git for the subdirectory package and mocked instruction file download.
Assistant
Let me fix the csharp package's apm.yml (remove the malformed transitive dep) and rerun with real git.
Assistant
The bare repo is stale. Let me update it.
Assistant
I now understand the root cause. Let me verify my hypothesis: virtual file packages with
resolved_commit=Nonealways re-download (no cache path), and if the branch HEAD moved, the supply-chain check hard-blocks on legitimate drift. Let me confirm by simulating branch movement in my repro.Assistant
Now the branch moved. Let me run the second install against the existing consumer to confirm the mismatch reproduces.
Assistant
Let me reset the branch and write a complete repro script using a fixed consumer dir.
Assistant
I've reproduced the bug exactly. The root cause: virtual file packages with
resolved_commit=None(unpinned branch refs where the SHA can't be resolved, e.g., Azure DevOps) have no cache path, soapm installalways re-downloads the (possibly drifted) branch HEAD, tripping the supply-chain hard-block on legitimate drift.Let me examine the heal chain to ensure my fix (content-hash cache skip) won't trigger unwanted heals.
Assistant
Let me check the branch_ref_drift heal.
Assistant
I've confirmed the root cause. The
BranchRefDriftHealandBuggyLockfileRecoveryHealwon't apply for unpinned deps (locked.resolved_commitis None), so my fix is safe. Let me view the exact code to edit in integrate.py.Assistant
Now let me implement the fix by adding a branch for unpinned git deps (no
resolved_commit) to use content-hash as the cache-skip signal, mirroring the registry-dep behavior.Assistant
Now let me reset the repo to HEAD1 and rerun the full repro to verify the fix.
Assistant
The pre-download phase re-downloads HEAD2 before the integrate phase runs, defeating my fix. I need to also fix the pre-download phase to skip re-download for unpinned deps when the cache matches the lockfile. Let me view the pre-download skip code.
Assistant
Let me add the content-hash skip for unpinned deps in the pre-download phase.
Assistant
Let me rerun the full repro to verify the fix.
Assistant
The fix works—run 2 now reuses the locked cache. Let me verify that
--updatestill re-resolves and accepts the new content (HEAD2).Assistant
--updatecorrectly re-resolves and accepts the new content. Let me verify a subsequent plain install reuses the updated cache.Assistant
The fix works correctly:
apm installreuses the locked cache (reproducible),--updatere-resolves and accepts new content, and a subsequent plain install reuses the updated cache. Now let me run the existing test suite to ensure I didn't break anything.Assistant
All install unit tests pass. Let me run the broader unit test suite, excluding network-required tests.
Assistant
All unit tests pass. Let me run the hermetic integration tests too.
Assistant
Let me verify these failures are pre-existing (not caused by my change) by stashing my changes and re-running a sample.
Assistant
The 2 failures are pre-existing (environment/root-related, not my change). But I see unintended changes to
.agents/,.github/,apm.lock.yamlfrom an earlier repro that ran in/apm. Let me revert those, keeping only my source changes.Assistant
Now only my 2 source changes remain. Let me verify the
.gitignoreandapm.lock.yamlare clean.Assistant
Let me check if any existing tests specifically assert the old hard-block behavior for unpinned virtual packages that my fix might change.
Assistant
Let me review the other
_resolve_download_strategytests to ensure my change doesn't break them.Assistant
Let me verify
_should_skip_redownloaduses the patchedverify_package_hash.Assistant
Let me check for tests of the download phase's skip logic.
Assistant
Let me run the install command and pipeline orchestration tests.
Assistant
Both fixes are needed and working. Let me do a final review of my changes.
Assistant
The changes look clean and well-targeted. Let me kill the HTTP server and run a final confirmation of the fix.
Assistant
The fix is confirmed working. Let me clean up the temporary HTTP server and scripts.
Assistant
The working tree is clean with only my 2 source changes. Let me run the install unit tests one final time to confirm everything passes.
Assistant
Assistant
The
apm.lock.yamlgot modified again (likely by a test run). Let me revert it to keep only my source changes.Assistant
Now only my 2 source changes remain. Let me do a final verification that the changes are intact.
Assistant
Both changes are intact. The fix is complete and verified. Let me submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.