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
I'll start by exploring the repository structure and locating the content-hash mismatch logic related to
apm install. - Assistant
I'll search the codebase for where content hash mismatches are detected and reported.
- Assistant
rg is not available, I'll use grep instead.
- Assistant
The failure centers on single-file instruction dependencies; I'll inspect how their content hashes are computed and verified.
- Assistant
Let me look at the content_hash.py and sources.py around the mismatch logic.
- Assistant
Let me look at sources.py around line 777 for the content hash mismatch.
- Assistant
Next I'll inspect how single-file (instruction) dependencies are downloaded and hashed.
- Assistant
There's already a test/comment about false content-hash trips; I'll open that next.
- Assistant
I'll dig into how subpath and single-file dependencies are resolved and installed.
- Assistant
I'll inspect virtual-file download handling in github_downloader.py.
- Assistant
Let me continue reading more of this function.
- Assistant
I'll check how
download_raw_filebehaves and how azure/dev.azure hosts are handled. - Assistant
Let me look at download_raw_file thoroughly, especially Azure DevOps path.
- Assistant
I'll search the changelog and recent commits for related content-hash issues.
- Assistant
I'll inspect skip-redownload / cache logic and when content_hash is verified.
- Assistant
Let me look at the entire FreshDependencySource and CachedDependencySource, and also how the source is selected.
- Assistant
Let me look at CachedDependencySource and FreshDependencySource specifically.
- Assistant
Let me read CachedDependencySource and FreshDependencySource fully.
- Assistant
I'll inspect integrate.py next, focusing on source selection and the content-hash path.
- Assistant
I'll check how content hashes get recorded into the lockfile.
- Assistant
Let me look at _attach_content_hashes
- Assistant
Checking CachedDependencySource's hash handling next.
- Assistant
Let me continue reading for content hash in CachedDependencySource.
- Assistant
I'll check whether integration or link-rewriting modifies files under install_path after hashing.
- Assistant
I'll locate
_should_skip_redownloadand inspect any virtual-package-specific behavior. - Assistant
I'll read
_redownload.pyand the virtual-package install path logic. - Assistant
I'll inspect the Azure DevOps file download path for nondeterminism.
- Assistant
Let me read:download_ado_file
- Assistant
I'll check
build_ado_api_urland how ADO content responses are parsed. - Assistant
Let me read build_ado_api_url
- Assistant
There may be a JSON-vs-raw content issue on ADO downloads; I'll check the tests next.
- Assistant
Looking at the issue again: packages from the same monorepo work with cloning (subdir sparse checkout). Instruction files goPieces through the virtual file path and API download.
- Assistant
I'll compare how the resolve-phase callback downloads virtual files versus the integrate-phase path.
- Assistant
I'll inspect more of the resolve callback and download_package.
- Assistant
I'll check whether downloads clean the install path قبل hashing.
- Assistant
I'll check how install paths are derived for virtual packages and subdirs.
- Assistant
Maybe it's under models/dependency
- Assistant
Let me read get_install_path and get_virtual_package_name.
- Assistant
Let me read get_install_path at 382.
- Assistant
I'll carefully review FreshDependencySource.acquire for hash and download ordering.
- Assistant
Let me continue reading the download part.
- Assistant
I'll inspect
build_download_ref— second install may download a different ref. - Assistant
Let me read the full build_download_ref function.
- Assistant
I'll search for tests that reinstall and expect hash stability.
- Assistant
I'll inspect cache_pin behavior next.
- Assistant
Let me look at how codebase mightmodify install path during integration - specifically_instruction integrator or link rewriting written back to source.
- Assistant
I'll read more of resolve.py's download_callback where it handles the result.
- Assistant
I'll check what headers the host client sends for HTTP requests.
- Assistant
I'll compare how GitHub file downloads extract content.
- Assistant
I'll inspect how Contents API responses are decoded as raw file content.
- Assistant
I'll scan recent docs and issues for mentions of this bug.
- Assistant
I'll check what
--forcedoes during install. - Assistant
Let me look at how gitlab or generic hosts handle virtual filesverket - maybe there's a path that uses git show for file content which would be better, and ADO should use that too. I think the root cause is in how the content hash is computed for files that come from remote git hosts (like Azure DevOps) versus the local cache.
Let me break this down:
-
First install with --update --force:
- Creates lockfile with hash A (from cached path)
- Downloads files via virtual file API (no .apm-pin yet)
- Records hash A in lockfile
-
Second install:
- Uses cached path (files unchanged)
- But the directory now contains .
-
- Assistant
I'll inspect the heal handlers too next.
- Assistant
I'll inspect yaml_to_str for nondeterminism.
- Assistant
Let me read yaml_io defaults.
- Assistant
Interesting!
dump_yamlusesopen(pathrecognized, "w", encoding="utf-8")which on Windows translates newlinesto CRLF.I think the root cause is in how the content hash is computed for virtual packages (like.apm/instructions/testing.instructions.md) when the dependency is resolved from a subdirectory clone of the monorepo. - Assistant
I'll check if FreshDependencySource cleans the install path before download.
- Assistant
I'll check how subdirectory download handles existing target paths.
- Assistant
I'll inspect
_resilient_getand any default Accept headers. - Assistant
I'll check whether link resolution ever writes back into package sources.
- Assistant
Syntax error in command.
- Assistant
I'll check whether loading apm.yml rewrites the file on disk.
- Assistant
I'll inspect the integration template for post-acquire disk mutations.
- Assistant
There was a test mention of
apm_content_hash— I'll check that next. - Assistant
I'll examine the integrate content-hash fallback path and its history.
- Assistant
I'll read the virtual-package variant tests in the e2e suite.
- Assistant
I'll check how download_complete formats the output when there's no SHA.
- Assistant
I'll write a quick unit test reproduction for install twice without resolved_commit.
- Assistant
I had typos in that script; fixing and rerunning.
- Assistant
I'll check whether the lockfile ever mixes up content_hash with deployed_file_hashes.
- Assistant
I'll look for existing unit tests around
_resolve_download_strategyand content-hash skip. - Assistant
I'll systematically test cache-pin exclusion and other files that might land under install_path.
- Assistant
Thumbs.db would change hash but wouldn't appear entre between File and second on Linux.
- Assistant
I'll search for other post-install writers under apm_modules.
- Assistant
I'll inspect ADO download tests for expected response payloads.
- Assistant
I'll also check host_backends for ADO download notes.
- Assistant
I'll check frontmatter parsing against CRLF line endings.
- Assistant
I'll craft a focused test that simulates two install acquires for a virtual package.
- Assistant
The script had bad characters; I'll rewrite it more carefully.
- Assistant
I'll write the script to a file and run it.
- Assistant
I'll search for writes targeting
'install_path'during or after install. - Assistant
Again bad<html syntax.
- Assistant
Empty - maybe ensl other patterns.
- Assistant
There's interesting stuff:
package_resolution.pydumps yaml to apm.yml, and github_downloader at 1662 dumps yaml to apm.yml! - Assistant
I'll check git reference resolution for ADO virtual files.
- Assistant
Let me read that section.
- Assistant
I'll check marker.sync when resolved_commit is missing.
- Assistant
I have a clear fix path. I'll inspect related tests, then apply the changes.
- Assistant
I'll check the RemoteRef structure and how list_remote_refs is used.
- Assistant
I'll check how resolve() matches refs from list_remote_refs.
- Assistant
Looking at RemoteRef structure:
- Assistant
Checking whether bare-cache can serve single-file virtual downloads:
- Assistant
Root cause: virtual files (especially on ADO) lack
resolved_commit, so every reinstall re-downloads; combined with unclean virtual-package dirs and brittle ADO downloads, content hashes diverge. Implementing fixes. - Assistant
I'll check how ls-remote output parsing builds ref names.
- Assistant
Let me check parse_ls_remote_output in git_remote_ops
- Assistant
Implementing the fixes now.
- Assistant
Next I'll improve ADO commit SHA resolution and clean virtual-package installs.
- Assistant
Updating virtual file package download for clean installs and CRLF-safe frontmatter:
- Assistant
Checking Python version for
write_text(..., newline=)support: - Assistant
Adding a general content-hash skip path for deps without resolved_commit:
- Assistant
Fixing the typo in that variable name.
- Assistant
Adding an Accept header for ADO octet-stream downloads:
- Assistant
I accidentally removed the try-body—restoring it.
- Assistant
I'll check the project's supported Python versions.
- Assistant
I'll verify the fix with a local reproduction script and related unit tests.
- Assistant
The script got corrupted; writing a clean version.
- Assistant
I'll determineping unit tests for the resolve SHA and content-hash skip logic.
- Assistant
I'll use a simpler approach to write the test file.
- Assistant
I'll have Python write and run the test file.
- Assistant
Running related unit tests next.
- Assistant
Looking into that failure—it may be preexisting. Running more targeted tests.
- Assistant
I'll treat that as an environment issue and run the more relevant suites.
- Assistant
All 459 passed. Running download strategy and install-related unit tests next.
- Assistant
Updating the outdated comment about non-GitHub SHA resolution.
- Assistant
Removing the accidental
\footnotefrom the comment. - Assistant
There's a boundary issue with the elif content-hash branch: when first
ifhas resolved_commit but all attempts to match fail lockfile_match stays False - we don't enter elif. Goodrepeating. - Assistant
Verifying the structure of the reviled git_reference_resolver methods:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.