Repository navigation
Description
Environment
| Component | Value |
|---|---|
| APM CLI version | 0.28.0 (also reproduces on 0.26.0) |
| Windows | Windows 11, Python 3.12 |
| Linux | python:3.12-slim Docker image (Debian) |
git core.autocrlf |
Irrelevant -- disproven as cause (see below) |
Description
When resolving a git dependency with a skills: subset (subdirectory package), APM writes a synthetic apm.yml into apm_modules/<owner>/<repo>/. This file is written with the platform's native line endings (CRLF on Windows, LF on Linux). compute_package_hash() in src/apm_cli/utils/content_hash.py hashes raw file bytes with no CRLF normalisation, producing a different content_hash on each OS for byte-identical upstream content.
This makes apm.lock.yaml non-portable: a lockfile generated on Windows fails apm install --frozen on Linux CI and vice versa.
Relation to #2187 / PR #2223
This is the same bug class as #2187 ("[BUG] Virtual single-file package content hashes differ across OSes due to synthetic apm.yml line endings"), which was fixed by PR #2223 and shipped in 0.26.0.
However, that fix only covered download_virtual_file_package(). The code path exercised here -- download_subdirectory_package() -- was never patched. That is why the bug still reproduces on 0.26.0 and 0.28.0.
Minimal Reproduction
apm.yml
name: apm-hash-repro
version: 1.0.0
dependencies:
apm:
- git: anthropics/skills#2c7ec5e78b8e5d43ea02e90bb8826f6b9f147b0c
skills:
- pdfWindows
# Clear cache
Remove-Item "$env:LOCALAPPDATA\apm\cache" -Recurse -Force -ErrorAction SilentlyContinue
mkdir C:\Temp\apm-mvr-win
Set-Content C:\Temp\apm-mvr-win\apm.yml -NoNewline -Value @"
name: apm-hash-repro
version: 1.0.0
dependencies:
apm:
- git: anthropics/skills#2c7ec5e78b8e5d43ea02e90bb8826f6b9f147b0c
skills:
- pdf
"@
cd C:\Temp\apm-mvr-win
apm lock
# Inspect synthetic file
$b = [IO.File]::ReadAllBytes("$PWD\apm_modules\anthropics\skills\apm.yml")
$crlf = 0; for ($i=0; $i -lt $b.Length-1; $i++) { if ($b[$i] -eq 13 -and $b[$i+1] -eq 10) { $crlf++ } }
"size=$($b.Length) crlf=$crlf"
Get-Content apm.lock.yamlLinux (Docker)
mkdir -p /tmp/apm-mvr && cd /tmp/apm-mvr
cat > apm.yml <<'EOF'
name: apm-hash-repro
version: 1.0.0
dependencies:
apm:
- git: anthropics/skills#2c7ec5e78b8e5d43ea02e90bb8826f6b9f147b0c
skills:
- pdf
EOF
docker run --rm -v "$PWD:/work" -w /work \
-e GH_TOKEN -e GITHUB_TOKEN \
python:3.12-slim bash -c '
apt-get update -qq && apt-get install -y -qq git >/dev/null 2>&1
pip install -q apm-cli==0.28.0
apm lock
echo "--- synthetic manifest ---"
wc -c apm_modules/anthropics/skills/apm.yml
od -c apm_modules/anthropics/skills/apm.yml | grep -c "\\\\r" || echo "no CR bytes"
grep content_hash apm.lock.yaml
'(Run natively on Linux without Docker if preferred -- the container is only used here to
contrast against a Windows host.)
Observed Results
Synthetic apm_modules/anthropics/skills/apm.yml content (identical text, different encoding)
name: skills
version: 2c7ec5e
description: ''
type: hybrid
Measurements
| OS | Synthetic file size | CRLF pairs | content_hash |
|---|---|---|---|
| Windows | 63 bytes | 4 | sha256:e93ee1488ddae2ec5f09839f9aa258c432888edf7ae767ca86b0c4baac6ce7c4 |
| Linux | 59 bytes | 0 | sha256:606a7fcbcd7d293a932db6e97644f7e60e0a868607bc9ac5b82802d334f7d518 |
The 4-byte delta (63 - 59 = 4) corresponds exactly to the 4 CRLF pairs (\r\n -> \n saves 1 byte each). No other files differ.
Note that content_hash covers the whole downloaded package tree while skill_subset is
recorded separately in the lockfile, so the divergence is independent of how many skills are
selected. Verified: selecting a single skill (pdf) and selecting three (pdf, pptx,
xlsx) both produce e93ee148... on Windows and 606a7fcb... on Linux. A one-skill subset
is therefore the smallest form that reproduces.
Expected Behaviour
content_hash must be identical on all platforms for the same dependency at the same commit. The lockfile must be portable.
Root Cause
In src/apm_cli/utils/content_hash.py:
compute_package_hash()reads file bytes as-is and feeds them to SHA-256. Its docstring assumes content is already platform-canonical from git checkout, but the syntheticapm.ymlis written by APM itself, not checked out from git.- The sibling function
compute_file_hash()already normalises CRLF via_canonical_hash_bytes()-- so the inconsistency is within APM's own codebase. - The synthetic file is written in
download_subdirectory_package()using Python's default text-modeopen(), which emits platform-native line endings.
Disproven Alternative: core.autocrlf
Setting core.autocrlf=false and core.eol=lf globally on Windows does not change the hash. The synthetic file is written by APM's Python code (not checked out by git), so git's line-ending settings are irrelevant to this code path.
Real-World Impact
- Teams using mixed OS (Windows dev machines + Linux CI) cannot share lockfiles
apm install --frozenfails in CI (ubuntu-24.04) with "content hash mismatch" when the lockfile was generated on Windows- Workaround: regenerate lockfile in CI (defeats the purpose of a lockfile)
Suggested Fix
Either (or both):
-
Write the synthetic
apm.ymlwith explicit LF line endings indownload_subdirectory_package()(useopen(..., newline='\n')or write in binary mode). This mirrors the fix in PR fix(deps): canonicalize virtual package manifest bytes #2223 for the virtual-file path. -
Route
compute_package_hash()through_canonical_hash_bytes()to normalise CRLF before hashing, making the hash immune to platform line endings regardless of how files were written.
Option 1 is the more surgical fix; option 2 is defence-in-depth.
Versions Affected
- 0.26.0 (post-fix(deps): canonicalize virtual package manifest bytes #2223 fix) -- still affected
- 0.28.0 (latest) -- still affected
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
McNultyyy commentedon Aug 18, 2026
Reproduction confirmed (on current
main, not just 0.28.0)Ran the minimal repro from the description on Windows 11 (Python 3.13, isolated
APM_CACHE_DIR, APM installed frommainsource) and on Linux (python:3.12-slim, Docker, same source):content_hashmain)sha256:e93ee148…main)sha256:606a7fcb…Both hashes match this issue's table exactly. Additionally verified that converting only the synthetic
apm.ymlto LF in the Windows tree reproduces the Linux hash bit-for-bit — confirming the 4 CRLF pairs are the sole divergence.Two corrections to the root-cause analysis
Code path. This exact repro does not go through
download_subdirectory_package().anthropics/skillshas a.claude-plugin/directory, so it is detected as amarketplace_pluginand the whole repo is downloaded viadownload_package()(theskills:subset only filters deployment).download_subdirectory_package()is equally affected, though, because both paths share the writes below.Write sites. The synthetic
apm.ymlis not written directly in the downloader. It is written twice by shared helpers invoked from both download paths:plugin_parser.synthesize_apm_yml_from_plugin()— initial synthesis duringvalidate_apm_package(), via plain text-modeopen()(CRLF on Windows);package_validator.stamp_plugin_version()— rewrites it with the short commit SHA viayaml_io.dump_yaml(), whoseopen()lackednewline="". This second write produces the final on-disk bytes (henceversion: 2c7ec5ein the observed content).An exhaustive audit of every APM-written file landing in hashed package trees found one more affected site: inline
plugin.jsonhooksobjects serialized to.apm/hooks/hooks.jsonviaPath.write_text()(platform-native newlines and locale encoding).Fix
Draft PR #2620 takes suggested option 1 (LF-deterministic writes at every affected site, mirroring #2223). Option 2 (normalizing CRLF inside
compute_package_hash()) was deliberately avoided: it would silently change recorded hashes for packages whose git-canonical content legitimately contains CRLF, invalidating existing correct lockfiles.With the fix, Windows and Linux both produce
sha256:606a7fcb…for this repro, and a Windows-generated lockfile passesapm install --frozenon Linux (verified end-to-end in Docker).github-actions commentedon Aug 19, 2026
Triage decision
accept
Proposed labels
Milestone
null
Suggested next action
Apply the same LF-deterministic write fix used in PR #2223 (for
download_virtual_file_package) todownload_subdirectory_package(), usingopen(..., newline='\n')or binary mode when writing the syntheticapm.yml.Suggested issue comment
Per-lens notes (collapsed)
DevX UX Expert -- User-Need Reviewer
Cross-platform lockfile portability is a first-class promise of any
package manager. The user need is concrete: mixed-OS teams (Windows
dev + Linux CI) cannot share lockfiles because
apm install --frozenfails in CI with a content hash mismatch. The issue maps directly to
the APM lockfile contract and the reproducible-install guarantee. The
reproduction steps are complete and the delta measurement (4 CRLF
pairs = 4 extra bytes) is convincing. Full alignment with the npm/pip
mental model where a committed lockfile should be portable.
Supply Chain Security Expert -- Risk-Surface Reviewer
This touches
area/lockfiledirectly. Thecontent_hashinapm.lock.yamldiverges by platform, undermining the integrityguarantee of the lockfile: a verifier consuming the Windows-generated
lockfile will reject the Linux-installed tree and vice versa. Not a
security vulnerability, but a correctness failure in the supply chain
integrity surface. Theme
theme/portabilityis correct; notheme/securityelevation warranted since the root cause is line-ending encoding rather than a trust or authenticity gap.
OSS Growth Hacker -- Contributor-Tone Reviewer
McNultyyy has
author_association: NONE-- likely a first-timecontributor to
microsoft/apm. The report quality is exceptional(measurements, root cause, suggested fix, disproven alternative). The
reply acknowledges that quality explicitly and invites a PR, naming
the exact files and suggesting a regression test. Tone is warm,
specific, and actionable. The contributor can go from reading the
reply to opening a PR without any follow-up questions.
Python Architect -- Architecture Reviewer
Not activated -- the fix is surgical (one write-mode change at a
named call site), following a well-established pattern from PR #2223;
no cross-cutting design decision is required before code can land.
Doc Writer -- Documentation Reviewer
Not activated -- this is a bug fix to an internal write path; no
new user-facing documentation is required, and the existing lockfile
portability contract in the README does not need revision.
APM CEO -- Triage Arbiter
Clear
accept. The bug class is confirmed (same as #2187/PR #2223),the affected code path is named, and the fix pattern is established.
priority/highis warranted because silent CI failures in frozeninstalls are a high-friction blocker for mixed-OS teams. No open
milestone exists at this time, so milestone is null; the fix should
ride the next patch release whenever that milestone opens.
{ "decision": "accept", "decision_detail": "", "theme": "theme/portability", "areas": ["area/lockfile"], "type": "type/bug", "status": "status/accepted", "priority": "priority/high", "preserved_labels": [], "milestone": null, "next_action": "Apply the LF-deterministic write fix to download_subdirectory_package(), mirroring PR #2223, and add a regression test that asserts a stable content_hash across platform line-ending settings.", "comment_markdown": "Thank you for this excellent, thorough bug report -- the reproduction steps, OS measurements, and root cause analysis are exactly what makes a fix straightforward to land.\n\nThis is confirmed as a regression gap from PR #2223: the CRLF fix applied to download_virtual_file_package() was never ported to the sibling download_subdirectory_package() path. Because the synthetic apm.yml is written by APM's Python code (not by git checkout), the platform's default text-mode line endings produce a different SHA-256 on Windows vs Linux, making the lockfile non-portable.\n\nThe fix is surgical: in download_subdirectory_package(), write the synthetic file with open(..., newline='\\n') or in binary mode -- mirroring the PR #2223 approach.\n\nThis is marked priority/high because it silently breaks apm install --frozen in Linux CI for teams developing on Windows. If you would like to send a PR, the relevant code is in src/apm_cli/utils/content_hash.py and the write site is in the downloader for subdirectory packages. Happy to review!" }fix(deps): write synthetic package manifests with LF so content hashe…
fix(deps): write synthetic package manifests with LF so content hashe…
feat(install): auto-migrate legacy CRLF-domain lockfiles and warm tre…
feat(install): auto-migrate legacy CRLF-domain lockfiles and warm tre…
feat(install): auto-migrate legacy CRLF-domain lockfiles and warm tre…
fix(utils): write project YAML with deterministic LF so apm.yml stops…
feat(install): auto-migrate legacy CRLF-domain lockfiles and warm tre…