apm icon indicating copy to clipboard operation
apm copied to clipboard

[BUG] Git-semver subdirectory dep: `--frozen` redeploys the older release, repeat `install` drops `constraint`/`resolved_tag`

Open Kaustubh1235 opened this issue 1 month ago • 2 comments

Found while writing the real-binary contract for #3224. Reproduces on unmodified main 29200432 with the unmodified binary; the #3224 branch produces byte-for-byte the same lock and deployed state at every step, so it is not caused by that change.

Setup

One local bare repo acme/mono with a subdirectory package packages/pkg-a (its own apm.yml, one skill). Commit 1 is pkg-a 1.0.0, tagged v1.0.0 and pkg-a-v1.0.0. Commit 2 is pkg-a 1.1.0, tagged pkg-a-v1.1.0 and pkg-a--v1.1.0. Consumer declares acme/mono/packages/pkg-a#^1.0.0, target copilot, --no-policy, --parallel-downloads 0, isolated environment with the URL rewritten to the local origin.

What happens

install        constraint='^1.0.0'  resolved_tag='pkg-a-v1.1.0'  resolved_ref='pkg-a-v1.1.0'  version='1.1.0'  commit=<c2>  deployed='# two'
install --frozen
               constraint='^1.0.0'  resolved_tag='pkg-a-v1.1.0'  resolved_ref='pkg-a-v1.1.0'  version='1.1.0'  commit=<c2>  deployed='# one'   <-- content from 1.0.0
install        constraint=None      resolved_tag=None            resolved_ref='^1.0.0'        version='1.1.0'  commit=<c2>  deployed='# two'   <-- raw range as resolved_ref
update --yes   constraint='^1.0.0'  resolved_tag='pkg-a-v1.1.0'  resolved_ref='pkg-a-v1.1.0'  version='1.1.0'  commit=<c2>  deployed='# two'
install --frozen
               ... same lock ...                                                                                            deployed='# one'

Every command exits 0. apm audit --ci after the frozen replay reports content-integrity hash drift on the deployed skill, which is correct: the lock says 1.1.0 and the file is the 1.0.0 one.

Two defects, probably one cause

  1. Frozen replay deploys the wrong release. The lock is right, the file is from the other commit. Since both tags for pkg-a 1.1.0 and the root v1.0.0 tag exist, it looks like the frozen path materialises the subdirectory from a cached checkout of the wrong ref rather than from resolved_commit.
  2. A repeat ordinary install loses the semver provenance: constraint and resolved_tag are dropped and resolved_ref becomes the literal string ^1.0.0. update writes them back. This is the shape #3246 / #3311 were about, from the other direction: the metadata on a replay no longer describes the snapshot that was installed.

Repro

Probe script, run from a checkout with the dev environment (it uses the repo's own test utilities). Pass the apm binary and a scratch directory:

update_probe.py
"""install -> reinstall -> update on a git-semver subdirectory dep, --no-policy; print lock fields per step.
usage: python update_probe.py <apm-binary> <scratch-root>"""
import os, sys, yaml
from pathlib import Path
sys.path.insert(0, "<checkout>")  # harness from the working tree
from tests.utils.apm_lifecycle_runner import ApmLifecycleRunner
from tests.utils.isolated_apm_environment import IsolatedApmEnvironment
from tests.utils.local_git_repository import LocalGitRepositoryFactory
from tests.utils.local_package import LocalPackageFactory
from apm_cli.utils.yaml_io import dump_yaml

binary, root = Path(sys.argv[1]), Path(sys.argv[2])
iso = IsolatedApmEnvironment.create(root / "iso", base_env=dict(os.environ)); env = iso.subprocess_env()
pk = LocalPackageFactory(iso.package_root); b = pk.create("mono", targets=("copilot",))
def sub(r, v, m):
    p = r / "packages" / "pkg-a"; (p/".apm"/"skills"/"s").mkdir(parents=True, exist_ok=True)
    dump_yaml({"name":"pkg-a","version":v,"targets":["copilot"]}, p/"apm.yml"); (p/".apm"/"skills"/"s"/"SKILL.md").write_text(f"---\nname: s\ndescription: d\n---\n# {m}\n")
sub(b.root, "1.0.0", "one")
repos = LocalGitRepositoryFactory(iso.repository_root, env=env); repo = repos.create("mono", source_tree=b.root)
c1 = repos.commit(repo, message="1.0.0"); repos.tag(repo, "v1.0.0", c1); repos.tag(repo, "pkg-a-v1.0.0", c1)
sub(repo.worktree, "1.1.0", "two"); c2 = repos.commit(repo, message="1.1.0"); repos.tag(repo, "pkg-a-v1.1.0", c2); repos.tag(repo, "pkg-a--v1.1.0", c2)
env = repos.url_rewrite_subprocess_env(repo, "https://github.com/acme/mono.git")
proj = LocalPackageFactory(iso.work_root).create("consumer", dependencies=("acme/mono/packages/pkg-a#^1.0.0",), targets=("copilot",)).root
r = ApmLifecycleRunner((str(binary),), timeout_seconds=120, scenario_timeout_seconds=600)
print("  c1(1.0.0)", c1.sha[:7], " c2(1.1.0)", c2.sha[:7])
def lock(tag):
    d = yaml.safe_load(open(proj/"apm.lock.yaml"))["dependencies"][0]
    marker = (proj/'.agents/skills/s/SKILL.md').read_text().strip().splitlines()[-1]
    print(f"  [{tag:15}] constraint={d.get('constraint')!r:9} resolved_tag={d.get('resolved_tag')!r:15} resolved_ref={d.get('resolved_ref')!r:15} version={d.get('version')!r:8} commit={str(d.get('resolved_commit'))[:7]} deployed={marker!r}")
common = ("--target","copilot","--no-policy","--parallel-downloads","0")
for tag, args in (("install", ("install",*common)), ("frozen", ("install",*common,"--frozen")), ("reinstall", ("install",*common)), ("update", ("update","--yes","--target","copilot","--parallel-downloads","0")), ("frozen-again", ("install",*common,"--frozen"))):
    res = r.run(args, scenario_id=tag, cwd=proj, env=env)
    print(f"  {tag} exit {res.returncode}" + ("" if res.returncode == 0 else "  :: " + (res.stdout+res.stderr).strip().splitlines()[-1][:140]))
    lock(tag)

Happy to turn this into an APMLifecycle contract if it's accepted; I kept it out of #3224's PR because it isn't a policy problem.

Kaustubh1235 avatar Oct 24 '26 21:10 Kaustubh1235

Decision: approve Area: project Scope: Make install --frozen of a Git-semver virtual subdirectory dependency materialize and deploy content from the locked resolved_commit, and make a repeated ordinary install preserve the locked constraint, resolved_tag and resolved_ref instead of writing the raw range, preserving the frozen replay contract and the lockfile semver provenance fields. Done when: A real-Git APMLifecycle regression with the #3382 monorepo fixture (root v1.0.0 tag plus pkg-a-v1.1.0 tags) runs install, --frozen, install, update and --frozen again and every step deploys the 1.1.0 content, keeps constraint, resolved_tag and resolved_ref equal to the first install and passes apm audit --ci; existing positional git-semver tests still pass. Out of scope: Semver tag-selection policy changes; non-subdirectory semver dependencies unless the same defect reproduces; policy behavior from #3224. Review contact: @danielmeppiel

danielmeppiel avatar Nov 10 '26 16:11 danielmeppiel

The apm-scope:v1 record above was approved by @danielmeppiel at Gate B on 2026-11-10 in the coordinator session of the issue-reduction program. It is the scope a fix for this issue will be reviewed against.

Review contact: @danielmeppiel.


Generated by autopilot-issue-triage-worker. This comment is AI-generated and may contain errors.

danielmeppiel avatar Nov 10 '26 16:11 danielmeppiel