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 first map the repository and locate the install, lockfile hash, and remote file handling paths. Then I’ll reproduce the mismatch with the most focused existing tests or a temporary local fixture before changing the implementation.
- Assistant
The failure occurs for a single-file Git dependency rather than a registry artifact. I found the verification in the integration phase; next I’m tracing exactly which bytes are hashed during initial download versus cached reinstall, with special attention to newline conversion because the report is Windows-specific.
- Assistant
Hashing itself reads raw bytes and is stable. The likely divergence is lifecycle-related: a virtual single-file package is initially hashed in one directory shape, then cached or reconstructed differently. I’m now comparing the fresh-source and cached-source code and the virtual package materialization layout.
- Assistant
The virtual downloader writes downloaded
bytesdirectly, so text-mode newline conversion is not the immediate cause. I need the omitted sections to see whether integration mutates/removes files before the lockfile hash is captured and whether cached acquisition repeats that mutation. - Assistant
Fresh hashing happens immediately after materialization and before integration. Cached hashing appears later in acquisition but should still see the same package tree. The key clue in the report is that the second run first accepts the cache, then deletes/re-downloads it due to mismatch, and the freshly downloaded hash still differs from the lock—meaning the first run likely recorded another dependency’s hash under this dependency’s key. I’m checking key canonicalization and parallel pre-download bookkeeping for collisions among multiple virtual paths from the same repository.
- Assistant
The dependency key includes virtual paths according to the log, so collision is less likely. Another strong possibility is generated
apm.yml:Path.write_text()defaults to platform newline translation on Windows. The source hashes the generated manifest after writing it. On the next run, parsing and some path may rewrite that generated YAML with\n, or the pre-download may replace the directory from an archive. I’m inspecting serialization and download dispatch, and I’ll compare the two reported hashes against plausible CRLF/LF virtual package trees to confirm. - Assistant
A plain Windows newline explanation would affect every fresh download identically, so it cannot explain why the second fresh fetch differs. The initial command uses
--force; that changes integration behavior and may alter files insideapm_modulesafter their hash was captured. I’m tracing integrators for move/delete/normalization operations on source primitives, especially instruction files, and the install path derivation for overlapping virtual packages. - Assistant
The parallel phase can concurrently write different dependencies if their install paths overlap. The issue’s manifest contains a virtual directory (
packages/csharp) plus transitive files from that same repository, but canonical paths should separate them. I’m checking the exact path algorithm now; if file virtual packages flatten to a shared repo-level directory, this would produce nondeterministic hashes and perfectly match the “wonky” first run. - Assistant
The resolver callback has an important flaw: it returns immediately whenever an install directory exists, without checking its content hash. On the reported second run, however, the integration phase catches the stale cache, removes it, and fresh-downloads, so that alone is not the final mismatch.
I still need the exact path/key code (the previous range missed it), then I’ll construct a local mocked two-install reproduction using the downloader and lockfile pipeline rather than relying on the private Azure repo.
- Assistant
The source cache is not mutated by instruction integration. I’m narrowing this to identity/path handling and generated metadata. The exact remaining branch of
get_install_pathwill show whether two files with the same basename collide, and the YAML helper will show whether generated metadata can vary by invocation. - Assistant
The implementation hashes generated virtual-package metadata (
apm.yml) alongside downloaded content. That metadata includes the dependency’s parsed identity. On lockfile replay,build_download_refmay produce a newDependencyReferencewith a commit ref or lose ADO-specific fields, changing the generated YAML author/source while the remote file is unchanged. I’m inspectingbuild_download_refand existing virtual hash tests to verify this object transformation. - Assistant
Lock replay does not alter generated metadata except the ref, which is not serialized, so that hypothesis is ruled out. The report explicitly shows Azure single-file SHA resolution failing (
#mainwithout@sha), while sibling sparse clones resolve tod479f42e. That means the lock cannot pin the file download to the commit, and a raw-file backend difference or branch movement can produce a mismatch. I’m inspecting Azure raw download and SHA resolution support; the correct fix should ensure virtual files on Azure are pinned to the same resolved commit as other package forms. - Assistant
The single-file downloader calls a resolver documented as a GitHub “cheap commits API”; Azure likely falls through unsupported and returns
None. I’ll confirm and implement a host-agnostic fallback using the existing Git reference resolver (ls-remote) rather than inventing Azure API auth logic. - Assistant
Confirmed: Azure is explicitly excluded from commit resolution, so virtual-file lock entries have no
resolved_commit. The robust fix is two-part: resolve Azure through the existing authenticated Git resolver, and download the file using the resolved SHA (not the moving branch) so the recorded identity and bytes are atomic. I’ll implement this narrowly for virtual files, preserving the cheap API and failure-tolerant behavior for existing hosts. - Assistant
Azure’s Items API accepts a commit SHA through the existing version descriptor builder, so no API changes are needed. I’m applying the fallback and pinning the actual file request to the SHA. I’ll also make cleanup-on-redownload explicit in the virtual downloader, since direct unit calls can otherwise leave generated stale files, though the install phase normally removes the directory first.
- Assistant
The code now records and fetches the same immutable revision. I’ll run the focused single-file downloader suites and reference-resolution tests first; these are the most likely to reveal compatibility issues in call arguments or ref typing.
- Assistant
Focused tests pass. To reproduce the reported failure shape without the private Azure repo, I’ll use a temporary mocked ADO dependency whose branch advances after the first install: the first materialization should pin commit A; a replay should still fetch A and produce the identical package hash. This specifically verifies the bug mechanism and fix rather than only testing object fields.
- Assistant
The mocked reproduction confirms stable replay and the broader downloader/hash tests pass. I’ll now run formatting/lint checks and the install-phase tests that govern cache verification and fresh-download mismatch behavior, ensuring the new pinning does not weaken supply-chain checks.
- Assistant
All targeted install safeguards pass, and lint/format checks are clean. Before final verification, I noticed two nearby comments still claim all non-GitHub hosts remain unpinned; I’ll update those comments to reflect Azure’s new Git fallback so the implementation documentation remains accurate.
- Assistant
The first comment replacement did not match due whitespace/text context, as visible in the output. I’ll correct it directly, then perform one final focused test and diff review.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.