fix(deps): git-semver update idempotency in build_update_plan#2165
Open
srobroek wants to merge 1 commit into
Open
fix(deps): git-semver update idempotency in build_update_plan#2165srobroek wants to merge 1 commit into
srobroek wants to merge 1 commit into
Conversation
`apm update` reported a spurious UPDATE on every run for git-source semver dependencies already at their locked tag, and never converged: the lockfile was rewritten with the identical SHA each time (only timestamps changed). Root cause: the git-semver resolver rewrites `dep.reference` to the concrete tag and computes its SHA, but stashes the result in `ctx.git_semver_resolutions` (and the download result) without attaching it back to `dep.resolved_reference`. At plan time `resolved_reference` is None, so `build_update_plan` compares the locked commit against `None` and classifies every git-semver dep as `update`. Fix mirrors the registry idempotency fix in microsoft#1908, applied to the git-source path: when a dep has no freshly-resolved commit, the locked entry pins an immutable tag (`resolved_tag` set), and the ref is unchanged, borrow the locked commit so the comparison sees `unchanged`. Scoped to tags -- a branch tip can advance under a stable ref name, so branch deps (no `resolved_tag`) still surface real updates. Adds two regression tests: cached git-semver tag stays `unchanged`; branch-tip advance still shows `update`.
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes apm update idempotency for git-source semver dependencies that are already locked to an immutable tag, preventing repeated “update” results when nothing has changed.
Changes:
- Adjusts
build_update_planto treat cached git-semver tag deps as unchanged by borrowing the locked commit when the resolved ref is unchanged and the lockfile pins aresolved_tag. - Adds regression tests covering (1) the cached git-semver tag unchanged case and (2) ensuring branch-tip advances still report updates.
- Adds an Unreleased changelog entry describing the fix.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/apm_cli/install/plan.py |
Adds a locked-commit fallback for cached git-semver tag deps to prevent spurious updates. |
tests/unit/install/test_plan.py |
Adds unit tests to reproduce the bug and guard against masking branch updates. |
CHANGELOG.md |
Documents the fix under Unreleased. |
Comment on lines
+12
to
+19
| - `apm update` no longer reports a spurious update on every run for git-source | ||
| semver dependencies already at their locked tag. The git-semver resolver | ||
| rewrites the dep reference to the concrete tag but does not attach the | ||
| resolved SHA to `resolved_reference`, so the update plan compared the locked | ||
| commit against `None` and never converged. `build_update_plan` now borrows the | ||
| locked commit for cached, immutable-tag deps whose ref is unchanged, mirroring | ||
| the registry fix in #1908 (branch deps are unaffected -- their tips can still | ||
| advance under a stable ref name). (closes microsoft/apm#2163) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
apm update(andapm update -g) reports a spurious UPDATE on every run for git-source semver dependencies that are already at their locked tag, and never converges. Re-running produces the same "N updated" line indefinitely; the lockfile is rewritten with the identical commit SHA each time (onlygenerated_at/resolved_attimestamps change), and no deployed files change on disk.This is the git-source counterpart of the registry idempotency bug fixed for registry deps in #1908 — that fix did not cover git-semver deps.
Root cause
On
apm update, the git-semver resolver (_maybe_resolve_git_semverininstall/phases/resolve.py) rewritesdep.referenceto the concrete tag and computes its SHA (GitSemverResolution.resolved_sha). But the SHA is stashed inctx.git_semver_resolutionsand the download result — it is never attached back todep.resolved_reference.build_update_plan(called frominstall/pipeline.pyright after resolve, before download) readsdep.resolved_reference, which isNoneat that point. So_extract_new_ref_and_commitreturns the correct concrete tag for the ref butNonefor the commit. The classifier then compares:even though
old_ref == new_ref(same concrete tag). Verified by instrumentingbuild_update_planduring a live update:Fix
Mirror #1908's registry approach on the git-source path. In
build_update_plan, when a dep has no freshly-resolved commit, the locked entry pins an immutable tag (resolved_tagis set), and the ref is unchanged, borrow the locked commit so the comparison correctly yieldsunchanged.Scoped deliberately to tags: a branch tip can advance under a stable ref name, so branch deps (no
resolved_tag) must still surface real updates. The existing registry fallback immediately above is left untouched.Tests
test_git_semver_tag_dep_unchanged_when_cached_and_ref_matches— the reproduction; fails before the fix, passes after.test_git_branch_dep_tip_advance_still_shows_update— guards that a real branch-tip advance is not masked.tests/unit/install/andtests/unit/deps/suites green post-rebase onto currentmain.End-to-end verification
Against a real git-semver dep (
srobroek/agentic-packages/packages/eli5#>=2.0.0 <3.0.0), built from this branch:apm update→Updated N APM dependencies(lockfile diff = timestamps only).All dependencies already at their latest matching refs.— converged.Closes #2163