Skip to content

Fail closed when CLI is older than lockfile apm_version #2334

Closed

Description

@lidorcg

Problem

APM records the generating CLI in top-level apm_version, but current mutating commands validate lockfile_version without rejecting a running CLI older than that generator. A structurally compatible older CLI can therefore rewrite a newer-generated lockfile before the operator realizes that the tool itself is stale.

This was reproduced downstream with APM 0.24.0 against a lockfile generated by 0.25.0: the older CLI rewrote the newer lockfile. Refreshing dependencies or deleting caches cannot correct this because neither upgrades the running CLI.

Downstream evidence: https://gitlab.com/spiritt/tenants/spiritt/coding-agent-kit/-/issues/256

Requested behavior

Before any command that may write apm.lock.yaml:

  1. Read the single top-level apm_version when a lockfile exists.
  2. Detect the running CLI version.
  3. Fail before mutation when the CLI is older than the lockfile generator.
  4. Name both versions and recommend apm self-update or a documented compatible installer.
  5. Treat malformed or duplicate version metadata as unsafe rather than silently continuing.
  6. Keep dependency/cache failures distinct from CLI compatibility failures.

The comparison needs to support APM's accepted prerelease forms (aN, bN, rcN) as well as stable releases. Build metadata should not affect precedence.

Acceptance evidence

  • A 0.24.0 CLI is rejected before writing a lockfile generated by 0.25.0.
  • Equal and newer CLIs continue normally.
  • Stable/prerelease ordering is covered.
  • The rejected command leaves the lockfile byte-for-byte unchanged.
  • The guard covers every mutating path, not only install.

Activity

  1. github-actions commented on Jul 22, 2026

    @github-actions

    Triage Panel Verdict -- #2334

    Fail closed when CLI is older than lockfile apm_version

    Thank you for the detailed report and downstream reproduction evidence, @lidorcg. The panel ran three specialist reviews.


    DevX UX Expert

    The failure mode described (older CLI silently rewrites a newer-generated lockfile) is among the worst UX a package manager can produce: the user gets no error, no warning, and a subtly corrupted lockfile. The requested behavior -- an explicit, actionable error message naming both versions and recommending apm self-update -- is exactly right. The acceptance criteria are precise, testable, and cover the full semver shape APM uses (stable, prerelease aN/bN/rcN, build metadata). Accept. High-priority UX fix.

    Supply Chain Security Expert

    The lockfile is APM's integrity anchor. An older CLI silently overwriting a lockfile generated by a newer one can silently drop security metadata introduced between those versions (new hash fields, new integrity checks, new dependency constraint syntax). This is effectively a downgrade attack vector on the lockfile. The fix is straightforward: compare semver(running_cli) < semver(lockfile.apm_version) before any mutation. The request correctly excludes read-only commands from the guard and calls out malformed/duplicate version metadata as unsafe. The combination of apm_version in the lockfile + a strict CLI-side guard is a correct defense-in-depth pattern. Accept. High priority from an integrity standpoint.

    APM CEO Arbiter

    This is a correctness invariant that APM should have had from the start. The downstream reproduction in a real tenant repository confirms this is not hypothetical. Shipping the guard in the next patch establishes a contract that lockfiles are forward-only from the perspective of the generating CLI -- important for enterprise adopters who need to reason about lockfile stability. The acceptance criteria are complete and the change is well-scoped (version comparison utility + guard in every mutating path). Accept. Priority high -- ship in next patch.


    Synthesized Decision

    Verdict: ACCEPT

    Dimension Decision
    Type Feature (missing correctness guard; effectively a bug)
    Area CLI, Lockfile
    Theme Governance (lockfile integrity contract)
    Priority High
    Milestone Next patch release

    Suggested next action: Implement a cli_version_guard() utility (semver comparison of running CLI vs lockfile.apm_version), call it at the entry point of every mutating command, and add tests covering the six acceptance criteria. The guard should be skipped when no lockfile exists (first install) and should surface a clear, named-versions error when the CLI is stale.


    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 · 69.1 AIC · ⌖ 8.5 AIC · ⊞ 9.2K · ◷

  2. added
    area/cli
    area/lockfile
    priority/high
    status/triaged
    type/feature
    on Jul 22, 2026
  3. added
    triage/recommended
    and removed
    status/triaged
    on Sep 12, 2026
  4. added
    status/deferred
    on Sep 18, 2026
  5. added
    pillar/govern
    and removed on Nov 12, 2026
  6. danielmeppiel commented on Nov 19, 2026

    @danielmeppiel
    Collaborator

    Decision: approve
    Area: project
    Scope: For #2334, refuse to use a lockfile whose top-level apm_version names a newer APM than the running CLI. One canonical owner decides generator compatibility, using the existing APM release-version comparison: aN, bN and rcN prereleases sort numerically before their release, and +build metadata is ignored. Commands that write, replay or certify the lockfile refuse before any change: install (including --frozen, --dry-run and -g), update, uninstall, prune, lock, audit (lockfile-backed modes), pack, and the deprecated deps update. LockFile.write refuses as the last-line backstop for every other writing path. Read-only commands warn once. A missing apm_version or the APM-written "unknown" is accepted. A duplicate or otherwise invalid apm_version fails closed, and so does a running CLI that reports an uncomparable version. The message names both versions and the documented upgrade routes (apm self-update, brew upgrade apm, python3 -m pip install --upgrade apm-cli). Include a static guard, installed-CLI lifecycle tests, docs and packaged usage guidance.
    Done when: Installed-CLI APMLifecycle tests prove that an older CLI refuses every listed command against a newer generator's lockfile, leaving apm.yml, apm.lock.yaml and deployed files byte-identical, and that read-only commands warn and continue. Equal, older, own-prerelease, +build and "unknown" generators continue and are restamped normally. Duplicate and invalid apm_version fail closed. The user-scope lockfile is guarded for -g. Unit tests cover the ordering (stable versus prerelease, numeric prerelease, ignored build metadata) and the write backstop. Dependency and cache failures stay distinct from the compatibility refusal.
    Out of scope: Any override flag or environment variable, automatic CLI installation or version switching (see the no-automatic-cli-version-management decision), project-level CLI version pinning, lockfile schema changes, changes to lockfile_version handling, and refusing read-only commands.
    Review contact: Daniel Meppiel (@danielmeppiel)

  7. added
    status/accepted
    and removed
    status/deferred
    on Nov 19, 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/cliarea/lockfilepillar/governpriority/highstatus/acceptedtriage/recommendedtype/feature

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions