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 hashing, and remote single-file download 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 is raised in source materialization, while integration also has cache hash logic. I’ll inspect both flows and the dependency/reference parsing to determine whether first and second installs fetch the same bytes (for example, raw file versus archive, or a branch inconsistency).
- Assistant
The reported dependency is a virtual single-file package. The likely invariant violation is that virtual-package materialization is not deterministic between a fresh clone and a cached clone. I’ll compare the source implementations and hash exclusions, then inspect tests around virtual installs and cached reinstall behavior.
- Assistant
The hash utility itself is deterministic and excludes only Git metadata and the cache-pin marker. I need the exact cached and fresh acquisition code without truncation, especially when
load_packagemutates or synthesizes files for a virtual dependency. - Assistant
Virtual file download creates a synthetic package around the raw file. I’ll inspect that routine and the raw-file transport, including the Azure branch/ref resolution, because the two observed hashes could represent differing synthetic manifests rather than differing source content.
- Assistant
The synthetic manifest is content-derived and should be stable. However, the downloader defaults every unpinned virtual file to
main, while the first log reports#main; the mismatch occurs after cached packages were deliberately deleted by pre-integration hash verification, causing a fresh fetch. I’ll inspect why the cache hash fails before that fetch—most likely integration modifies the package cache—and identify exactly which files are changed. - Assistant
No integration code appears to intentionally mutate the source cache, and
.apm-pinis already excluded. The next strong Windows-specific suspect is newline conversion when writing the syntheticapm.yml:Path.write_text()defaults to platform newline translation, while the lockfile may be computed from a resolver callback’s package and the later materialization may rewrite it via a different path. I’ll inspect YAML serialization and the resolver callback timing/order to test this hypothesis and find whether the package is downloaded twice in the first run. - Assistant
A direct dependency is indeed downloaded during BFS resolution and then treated as “cached” during integration in the same run. The package hash is computed after BFS. On the second run, if the lock entry has no resolved commit (as the log’s
#mainsuggests for Azure),_resolve_download_strategydoes not consider ordinary git-source dependencies with only a content hash cache-valid; that forces a re-download, after which strict hash comparison catches any nondeterminism. This explains both the unnecessary network call and failure. I’ll verify lockfile semantics and existing tests, then implement content-hash cache reuse for virtual packages lacking a resolvable commit (not broad git repos, where commit identity is required). - Assistant
The tests confirm current behavior intentionally redownloads any package without commit identity, except registry packages. Merely trusting a virtual package’s content hash would stop the crash but would also silently freeze an unpinned branch, conflicting with documented “branches fetch latest” behavior. The root defect is earlier: virtual Azure downloads explicitly make no attempt to resolve a commit SHA, even though the downloader can resolve Git refs generically. I’ll inspect the ref resolver and Azure tests to implement SHA resolution correctly and preserve freshness/security semantics.
- Assistant
Changing Azure SHA resolution would invalidate explicit cross-host behavior and duplicate robust auth/ref logic. The appropriate fallback is therefore narrowly scoped: a virtual package with no resolvable commit may reuse its existing on-disk package only when its lockfile content hash matches.
--updatewill still refetch it, and any local tampering still deletes/refetches it. I’ll first run a temporary reproduction using a real parsed Azure virtual reference and lock entry to confirm the current strategy returnsskip_download=Falsedespite matching bytes. - Assistant
The reproduction setup used the wrong lockfile module path. I’ll locate the model and rerun the same focused scenario.
- Assistant
I found the correct model module. I’ll adjust only the temporary script and verify the pre-fix result.
- Assistant
The lock model derives its version internally and also requires
is_virtual=Truefor keying. I’ll correct those fixture details and rerun. - Assistant
The reproduction confirms the defect: a real Azure virtual package with an exact matching lock hash is unnecessarily marked for download. I’ll add the narrow content-hash lock replay branch for virtual packages without commit identities. This leaves full repositories unchanged and keeps
--updateand manifest-ref changes as explicit refresh paths. - Assistant
The line-range edit started two lines too late and left an incomplete original
elif, while also replacing the self-heal heading comments. I’ll restore this entire local section from the known original structure plus the new branch, then rerun syntax/reproduction immediately. - Assistant
The code now compiles and the reproduction returns cache reuse, but review shows one original documentation line was lost in the repaired range. I’ll restore it, then inspect the heal-chain guard because marking “content-hash-only” could trigger legacy lockfile recovery for this valid no-SHA case.
- Assistant
The heal chain is safe: both drift handlers require a resolved branch SHA, so the valid Azure no-SHA fallback remains cached. I’ll now run both duplicated integration-strategy test modules, the branch-drift suite, and the virtual downloader SHA suite, followed by targeted temporary assertions for matching hash, mismatched hash,
--update, and ref-change edge cases. - Assistant
The focused suite passes (60 tests), and temporary verification confirms matching bytes are reused while tampered bytes and
--updatestill force download. I’ll run the broader install unit suite plus the repository’s virtual-package multi-install test, then run lint/format checks on the changed file and inspect the final diff. - Assistant
All 1,486 broader tests pass and lint/format are clean. The test run modified the repository’s root
apm.lock.yamlas a side effect; that is unrelated and must not be submitted. I’ll restore only that generated change, recheck status/diff, and run one final focused test after restoration.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.