Repository navigation
Description
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:
- Read the single top-level
apm_versionwhen a lockfile exists. - Detect the running CLI version.
- Fail before mutation when the CLI is older than the lockfile generator.
- Name both versions and recommend
apm self-updateor a documented compatible installer. - Treat malformed or duplicate version metadata as unsafe rather than silently continuing.
- 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.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
github-actions commentedon Jul 22, 2026
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, prereleaseaN/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 ofapm_versionin 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
Suggested next action: Implement a
cli_version_guard()utility (semver comparison of running CLI vslockfile.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.danielmeppiel commentedon Nov 19, 2026
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)
fix(lockfile): refuse lockfiles written by a newer APM (#2334) (#3916)
test(lockfile): format-decided compatibility tests for #5549 (T1-T4, …