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 code related to content hash verification during
apm install. - Assistant
Searching the codebase for content hash mismatch handling.
- Assistant
rg is not available, let me use grep.
- Assistant
The failure is in content-hash verification on reinstall. Inspecting the hash and install-source code next.
- Assistant
Looking at the hash verification logic around the mismatch error in
sources.py. - Assistant
The failing dep is a single-file instruction path. Checking how hashes are computed and stored for those deps.
- Assistant
Looking for related tests, changelog notes, and how file-path dependencies are installed.
- Assistant
Investigating how virtual file packages are handled and how their hashes are recorded.
- Assistant
Let me look at download_virtual_file_package
- Assistant
Let me read the download_virtual_file_package function
- Assistant
So for virtual file packages, the download creates:I think the core issue is that the content hash for virtual file packages (like
.apm/instructions/testing.instructions.md) is being computed differently between the first--updateinstall and subsequent ones. The error shows two very different SHA256 values for the same file, which strongly suggests the downloaded content isn't identical. - Assistant
Checking recent git history and tests for virtual-file content hashing.
- Assistant
Examining how install decides skip_download and records hashes for virtual file packages.
- Assistant
Checking how
is_cacheableis determined for virtual file packages. - Assistant
Comparing first vs second install path: resolver callback vs integrate-phase download may hash different trees.
- Assistant
Looking at resolve phase download when install_path.exists - may return without computing hash. Hash happens during integrate in sources. I think the root cause is in how virtual packages (like the
.apm/instructions/testing.instructions.mdone) are handled on subsequent installs. - Assistant
Looking at download_package routing for褲子 virtual vs subdirectory.
- Assistant
Let me look at yaml_to_str and how description parsing might differ. Also ado file download - maybe LF vs CRLF? The issue you're describing is a classic Windows newline (LF vs CRLF) problem combined with how APM's content hashing and lockfile merging works.
Here's what happened:
- Assistant
Looking at install path for virtual file:
- Assistant
There's a known similar bug with
.apm-pinmarkers! The pin is written AFTER hash, and was falsely tripping mismatch. They fixed excluding.apm-pin. - Assistant
Looking for related issues or PRs, and building a reproduction.
- Assistant
Checking whether the instruction integrator mutates source package files.
- Assistant
Integration doesn't mutate source. Let me check FreshDependencySource download path more carefully. Maybe target is not cleared before redownload and leftoverfiles from somehow different structure exi...I think the root cause is in how FreshDependencySource handles the first install vs. subsequent ones, specifically around the download path and whether it properly clears the target directory before rewriting files.
Let me break this down:
- First install behavior: When you run
apm installthe first time, it downloads fresh content for.apm/instructions/testing.instructions.md(no "(cached)" tag in logs). This goes through the Fresh path, which downloads the file and writes it to the target location. The hash is recorded in the lockfile after download.
- First install behavior: When you run
- Assistant
Looking at the first install log more carefully again, examining the full FreshDependencySource.acquire download call.
- Assistant
There's
build_download_ref- maybe first install downloads with one ref, lock hashes temp, second_or ha install locks to different_ref_with different content? - Assistant
Let me look at build_download_ref
- Assistant
OK so if locked has resolved Commit, second install pins to that SHA... But for virtual files without resolved_commit, uses #main again.
- Assistant
Looking at resolve download_callback when path already exists:
- Assistant
Soeedoveon on second install:I can see the root cause here — the second install is failing because the content hash for
.apm/instructions/testing.instructions.mdis being recomputed against a file that has been rewritten with Windows line endings (\r\ninstead of\n), while the lockfile still records the original Unix-style hash. - Assistant
Checking whether virtual file packages clear the target directory, and looking for recent related fixes.
- Assistant
Confirmed:
download_virtual_file_packagedoes not clear the target directory. Checking if leftover files or hashing of generatedapm.ymlcould cause the mismatch. - Assistant
There was a syntax error in my script. Let me fix it.
- Assistant
I need to rewrite the Python script carefully to avoid syntax errors.
- Assistant
I'll write the reproduction as a file instead to avoid shell quoting issues.
- Assistant
The lockfile stores the post-download hash without
.apm-pin; subsequent installs that skip when content matches would work. Checking the parallel pre-download path and whether first vs second download yield different layouts. - Assistant
Looking «at --force and pricing its effect on hashing/skip logic.
- Assistant
force is only for file collisions, not hash. Looking at SHA resolution for ADO virtual files.
- Assistant
Let me look at git_reference_resolver for ADO
- Assistant
Confirmed: ADO virtual files never get a esolved_commit. Simulating double download to spot hash drift.
- Assistant
So double download with pin is deterministic on Linux. On Windows write_text would get CRLF - but still both times same. I think the root cause is in how the second install path handles the
testing.instructions.mdfile when the directory already exists from the first run.The first install (cold) does a full download + integration, computes the hash on the fresh content, and records it in the lockfile.
- Assistant
So for virtual files without resolved_commit, no pin is written. Logs show cache for monorepo bags without resolved_commit:
- Assistant
Checking VIRTUAL_FILE_EXTENSIONS and path parsing for paths starting with
.apm/. - Assistant
Looking for reinstall/roundobst-trip tests involving virtual packages.
- Assistant
There's test_ado_e2e.py for virtual package. And test_github_downloader_single_file_sha.py. Let me also check git log for recent changes related to this.
- Assistant
There's a related fix for content hash mismatch on re-install when git dirs are absent. Checking whether virtual files can also be materialized from document bare clones.
- Assistant
Looking at the ADO API URL builder and whether the response is JSON base64 or raw.
- Assistant
Let me see build_ado_api_url
- Assistant
Trying a different approach — looking at git issues and recent fix commits.
- Assistant
Checking whether content_hash could be confused with deployed file hashes.
- Assistant
Reproducing the full install pipeline twice with mocking.
- Assistant
I'll use the create command to write a clean reproduction script.
- Assistant
I'll redwrite the subrep script using the create special command.
- Assistant
Let me remove it and creaite.
- Assistant
Now edit the file
- Assistant
Good. Now run it.
- Assistant
Leftover files after the first install explain the mismatch. Searching for what writes into virtual package install paths post-download.
- Assistant
security/gate.py mentions excluding .apm-pin and?symlinks. Looking at that.
- Assistant
Checking factory logic for fetched_this_run and how the log
(cached)suffix is chosen. - Assistant
Checking_how_fetched_now is set in the integrate loop.
- Assistant
I may have found it: the ADO Items API can return JSON metadata by default; if there's no
download=true/$format=octetStream, the "file content" hashed may change between requests. - Assistant
Looking at the #763 fix that added content-hash fallback, and where registry got special-cased.
- Assistant
The bug is that virtual file packages (e.g.
.instructions.mdfrom ADO) have noresolved_commit, so the content-hash skip-download path never runs—only registry deps get that. They always redownload on the second install and fail the hash check. Implementing the fix. - Assistant
Applying the integrate.py fix first.
- Assistant
Verifying the full if/elif structure after the edit.
- Assistant
Updating the parallel download phase.
- Assistant
I need to add an elif after the block ending at 105 for deps without resolved_commit.
- Assistant
Next, making virtual-file downloads wipe the target directory and write
apm.ymlwith deterministic newlines. - Assistant
Also fixing frontmatter entretien parsing so CRLF/LF differences don't change the generated
apm.yml. - Assistant
There's.a typo with non-ASCII characters to fix.
- Assistant
Checking whether ADO download tests assert a specific URL format.
- Assistant
Adding
download=trueto the ADO API URL so we get raw file content rather than JSON metadata. - Assistant
Checking and updating tests for the ADO URL builder.
- Assistant
Let me check those tests to see if they need updating.
- Assistant
Re-running the repro and validating the integrate skip logic with a temporary script.
- Assistant
V-file wipe fixes leftover-junk hash drift. Validating integrate skip next.
- Assistant
Edit the file
- Assistant
Need PYTHONPATH
- Assistant
Checking how
resolved_refis stored for virtual packages — ref_change detection may be the real culprit. - Assistant
My test used the wrongเป็นการ
resolved_ref. Fixing it and re-running. - Assistant
Skip works. Running related unit tests.
- Assistant
All those passed. Running more related tests.
- Assistant
Checking whether those test failures are pre-existing.
- Assistant
Pre-existing failures. Checking whether we accidentally modified
apm.lock.yaml. - Assistant
Running virtual-file and integrate phase tests.
- Assistant
Verifying CRLF frontmatter handling and reviewing the final diff.
- Assistant
Using a clean file to avoid Unicode issues.
- Assistant
edit
- Assistant
There's still a typo on line 28. Fix it.
- Assistant
Cleaning temp files and reviewing the final diff.
- Assistant
Confirming the ADO URL test still passes, then submitting.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.