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.Additional context apm.yml
name: <project>-skills version: 1.0.0 description: '<Project> skills and agent for GitHub Copilot.' author: Oskar Klintrot target: vscode dependencies: apm: - dev.azure.com/<org>/tools/github-copilot-agent-skills/packages/csharp - dev.azure.com/<org>/tools/github-copilot-agent-skills/.apm/skills/run-coverage - dev.azure.com/<org>/tools/github-copilot-agent-skills/.apm/instructions/testing.instructions.md mcp: - name: NuGet registry: false transport: stdio command: dnx args: - NuGet.Mcp.Server - --source - https://api.nuget.org/v3/index.json - --yesInterface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /apm, current file: none) bash-$
Assistant
Good, so
ctx.package_hashes[dep_key](already set to the fresh hash before the check) will be written into the lockfile regardless of whether we hard-fail or continue. Let's view lines 155-165 in phases/lockfile.py to confirm.Assistant
Now let's view the full function to see where
resolved_commitis defined relative to the check block, and update the fix.Assistant
Now let's update the actual check block:
Assistant
Now let's verify the change looks correct:
Assistant
Good —
resolved_commit = "abc1234"(truthy, not "cached") andlocked_chk.resolved_commit = "sha"(also truthy, not "cached"), so_unpinnablewill beFalse, and the test will still hit thesys.exit(1)path. Let's run this test file to confirm.Assistant
All passing. Now let's run the broader install test suite (sources, integrate, resolve) to check for regressions.
Assistant
All tests pass. Now let's write a quick reproduction test to simulate the exact scenario from the issue (virtual file with no resolved_commit) to confirm the fix resolves it, rather than sys.exit.
Assistant
The fix works as expected. Now let's clean up the temp script and run the full test suite once more to be safe.
Assistant
All unit tests pass (15812 passed, 2 skipped, 21 xfailed – no failures). Let's also run the integration tests to be thorough.
Assistant
All good. Let's also quickly run the full integration suite to be safe (it might take a while but let's try).
Assistant
Confirmed those 3 failures are pre-existing (running as root breaks chmod-based permission tests) and unrelated to my change. Let's check the other modified files (seems like some git-status artifacts from running the CLI itself during tests, unrelated to our fix). Let's check git diff to make sure only intended file changed, and revert accidental modifications.
Assistant
Clean now — only the intended fix remains. Let's view the final diff.
Assistant
This is exactly the change I intended. Let's re-run the relevant test suites one final time to be certain everything is in order.
Assistant
That failure is the same pre-existing unrelated test (already confirmed failing on the unmodified repo). Everything related to my change passes cleanly.
Assistant
Now only the intended fix file remains modified.
Checklist review
- Reproduced the reported error: Yes — I traced the exact code path (
FreshDependencySource.acquire()insrc/apm_cli/install/sources.py) that triggersContent hash mismatch ... supply-chain attack ... sys.exit(1), and confirmed via a targeted reproduction script that the unpatched logic would hard-abort for a dependency whose commit could never be pinned (e.g. an Azure DevOps virtual single-file dependency, whereresolve_commit_sha_for_refalways returnsNonefor ADO hosts — verified ingit_reference_resolver.py). I confirmed the same code path is exercised by the existing testtest_hash_mismatch_calls_sys_exit.
- Reproduced the reported error: Yes — I traced the exact code path (
Assistant
-
Confirmed the fix resolves it: Yes — I wrote a standalone repro script mimicking the exact scenario (dep with no resolvable commit, both currently and in the lockfile, whose fresh content hash differs from the recorded lockfile hash). Before the fix this scenario aborts install with
sys.exit(1); after the fix, it emits a warning via_rich_warningand lets the install continue (the fresh hash is written intoctx.package_hashes, which the lockfile phase already picks up automatically to update the recordedcontent_hash, so subsequent installs stay quiet). I verified this both by direct inspection of the code path and by running the repro script, which printedPASS. -
Thought about edge cases:
- Pinned dependencies (tag or commit SHA) where a real
resolved_commitexists on both the current run and the lockfile record are still hard-failed as a genuine supply-chain concern — I kept the originalsys.exit(1)+safe_rmtreebehavior for that case, guarded by the_unpinnablecheck requiring both current and previously-locked resolved commits to be missing/"cached". - The
"cached"sentinel (used elsewhere in the codebase for registry/cache-derived deps where no real SHA is known) is treated the same asNone, consistent with existing conventions inintegrate.py/sources.py(resolved_commit != "cached"checks). - Directory-based git deps that do resolve to a real commit (as in the issue's own log, e.g.
packages/csharp @d479f42e) are unaffected — they continue to be verified strictly sinceresolved_commitis populated. - I verified this doesn't disable the check when
ctx.update_refsis set or whendep_keyis already inctx.expected_hash_change_deps— those pre-existing bypass paths are untouched; my change only adds a secondary bypass specific to the "impossible to pin" case.
- Pinned dependencies (tag or commit SHA) where a real
-
Ran existing tests to confirm no regressions: Yes.
tests/unit/install/— 1477 passed (includestest_sources_phase3.py::test_hash_mismatch_calls_sys_exit, which still passes because that test's mocked dependency has a real resolvable commit on both sides).- Full
tests/unit/— 15812 passed, 2 skipped, 21 xfailed (no failures). tests/integration/— 9032 passed, with 3 pre-existing failures unrelated to this change (permission-based tests that fail identically on the unmodified repo because the test suite runs as root, wherechmod 0o000doesn't restrict access) — verified viagit stashthat these 3 failures exist without my patch too.- Cleaned up incidental working-tree mutations produced by the test suite itself (e.g.
apm.lock.yaml, various.agents/skills/*) viagit checkout --, leaving only the intended source change staged.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →