Skip to content

fix(install): drop the stale .apm-pin after a git -> registry source switch - #4597

Merged
Daniel Meppiel (danielmeppiel) merged 3 commits into
mainfrom
danielmeppiel-p1-4572-stale-apm-pin
Nov 21, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 3 commits into
mainfrom
danielmeppiel-p1-4572-stale-apm-pin

Conversation

@danielmeppiel

@danielmeppiel Daniel Meppiel (danielmeppiel) commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Description

TL;DR — After a dependency switches from a git source to a registry source, the first apm install now removes the stale git .apm-pin from apm_modules/<pkg>/. The fix lives in the single marker owner, src/apm_cli/install/cache_pin.py: its lockfile sync drops a marker whose dependency is no longer markable. A converged project is a byte fixpoint again: a repeat apm install and apm install --update change no bytes.

Problem (WHY)

  • A registry dependency records no resolved_commit, so a git marker left in its copy names a commit the lockfile no longer vouches for.
  • sync_markers_for_lockfile only wrote markers for markable deps and skipped everything else, so repeated installs kept the stale marker.
  • apm install --update re-downloaded and deleted it, so install reported convergence while install --update still changed bytes (lifecycle law I2). Found by M-SOURCE cell X|install|pkg-registry|UPDATE=on in the [TEST] Lifecycle obligations: burn the baseline down to at most 500 cells for 0.38 #4564 burn-down.

Approach / Implementation (HOW)

File Change
src/apm_cli/install/cache_pin.py sync_markers_for_lockfile collects install paths of unmarkable deps (registry, local, unpinned) and removes their .apm-pin after the write pass. A path that a markable dep also claims is never cleared; only copies under apm_modules are touched; OSError is swallowed (best-effort, like write_marker). The registry download path is unchanged and relies on this owner.
tests/lifecycle/machines/test_m_source.py New receipt test_git_to_registry_switch_drops_the_stale_cache_pin on the M-SOURCE bench (real CLI, I1–I9 per step).
tests/integration/test_cache_pin.py Owner-level table test: registry marker dropped, git marker kept and verified, a marker outside apm_modules untouched, an unlink failure never raises.
tests/fixtures/lifecycle_bug_ledger.json Ledger row for #4572 (idempotency.byte_stable, source.ref_cache_coherent).
CHANGELOG.md One Fixed line.

Trade-offs

  • Removal covers every unmarkable dep (registry, local, unpinned git), not only registry rows: the scope record says the sync "removes a marker whose dependency is no longer markable"; no registry-specific marker was added (out of scope).
  • Both sync passes (self-heal over the pre-existing lockfile and the post-build pass) use the same owner, so the old git row may rewrite the marker first and the new registry row then drops it in the same install. No second code path handles markers.
  • Out of scope and untouched: registry download/verification, lockfile fields, cache layout beyond .apm-pin.

Issue and approved scope

Issue: Closes #4572

Dependency order: none (independent of open PRs)

Human scope-approval comment: #4572 (comment)

Does this PR complete the issue, or what remains? It completes the issue: the receipt cell passes, controls hold, one CHANGELOG line.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass (targeted neighbours; full suites run in CI)
  • Added tests for new functionality (if applicable)

Scenario evidence

promise: P-INV-I2 -- repeating a converged command changes no bytes (source: tests/lifecycle/oracles.py)
cell: OP=install SRC=pkg-registry UPDATE=on (X|install|pkg-registry|UPDATE=on, M-SOURCE)   owner: src/apm_cli/install/cache_pin.py
instrument: target machine-bench test -> tests/lifecycle/machines/test_m_source.py::test_git_to_registry_switch_drops_the_stale_cache_pin (extends M-SOURCE module)
oracles: [I1-I9 via check_cross_cutting per step, byte snapshot of apm_modules + lockfile, apm audit exit 0]
decisive: assert not pin.exists() after the first registry install; _cache_bytes unchanged across install and install --update
controls: git install writes a marker verify_marker accepts; registry -> git switch writes a fresh verified marker; unlink failure never raises
failing-before (main code): 1 failed -- AssertionError: the first registry install must drop the stale git .apm-pin
passing-after: 3 passed (whole test_m_source.py module)
guard+mutation: n/a (no new caller; fix is in the owner)     ledger: #4572
hints executed: none printed
Validation commands and results

All runs through the host guard with env -u GIT_EXEC_PATH PATH=/usr/bin:/bin:$PATH APM_BINARY_PATH=$PWD/.venv/bin/apm.

Command Result
pytest tests/lifecycle/machines/test_m_source.py::test_git_to_registry_switch_drops_the_stale_cache_pin (fix reverted) 1 failed — assert not pin.exists()
pytest tests/lifecycle/machines/test_m_source.py (with fix) 3 passed in 660.87s
pytest tests/integration/test_cache_pin.py 20 passed
pytest tests/unit/install/ tests/unit/test_prune_command.py tests/unit/test_content_hash.py tests/integration/test_cache_coverage.py tests/integration/test_drift_detection.py tests/integration/test_drift_check_e2e.py tests/lifecycle/scenarios/test_cache_presence.py tests/quality/test_lifecycle_bug_ledger.py tests/spec_conformance/test_lockfile_reqs.py 3801 passed, 2 skipped
uvx [email protected] check / format --check (CI paths) All checks passed / 2991 files already formatted
python -m pylint --disable=all --enable=R0801 ... src/apm_cli/ ... 10.00/10
bash scripts/lint-auth-signals.sh auth-signal lint clean
python scripts/check_complexity_ratchet.py --base-ref origin/main complexity ratchet clean
python -m tests.quality.taxonomy --changed tm006: 2 changed test modules carry their marker and promise
BASE_REF=<merge-base> bash tests/spec_conformance/mode_b_detector.sh WAIVED (commit carries apm-spec-waiver)

How to test

  1. APM_BINARY_PATH=$PWD/.venv/bin/apm uv run --extra dev pytest "tests/lifecycle/machines/test_m_source.py::test_git_to_registry_switch_drops_the_stale_cache_pin" -n 0 -q
  2. Revert src/apm_cli/install/cache_pin.py and rerun: it fails on the .apm-pin assertion.
  3. uv run --extra dev pytest tests/integration/test_cache_pin.py -q

Changelog

  • One line in one section under ## [Unreleased] in CHANGELOG.md:
    user-visible effect first, 25 words or fewer, ending with (#PR);
    breaking changes only under upgrade notes; no Highlights; see
    .github/instructions/changelog.instructions.md.
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

  • Spec edit
  • Manifest edit
  • Test edit
  • CONFORMANCE.{md,json} regenerated
  • N/A -- this PR does not change OpenAPM-observable behaviour. (.apm-pin is APM cache hygiene; spec gate waived in the fix commit.)

Co-authored-by: Copilot [email protected]

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the stale .apm-pin cleanup change.

No open issues 🎉

What changed in this PR

Fixes #4572 by clearing stale git .apm-pin markers after a dependency switches to a registry source. Cleanup stays in the existing cache-pin owner, restoring byte-stable repeat installs.

Changes:

  • Removes markers for dependencies that are no longer markable, while protecting shared git paths and paths outside apm_modules.
  • Adds owner-level and real-CLI regression coverage for cleanup, source switching, and repeat-install stability.
  • Records the regression in the lifecycle bug ledger and changelog.
File Description
tests/​lifecycle/​machines/​test_m_source.py Tests source switches, marker validity, and byte-stable repeat installs.
tests/​integration/​test_cache_pin.py Tests stale-marker cleanup, preserved markers, and unlink failures.
tests/​fixtures/​lifecycle_bug_ledger.json Links issue #4572 to regression tests and lifecycle properties.
src/​apm_cli/​install/​cache_pin.py Adds best-effort stale-marker removal during lockfile synchronization.
CHANGELOG.md Documents the source-switch cleanup fix.

Review effort: Balanced

…#4572)

The cache-pin lockfile sync now removes a marker whose dependency is no
longer markable (registry, local, unpinned), so a git -> registry switch
converges on the first apm install.

apm-spec-waiver: .apm-pin is APM cache hygiene, not an OpenAPM v0.1 observable

Co-authored-by: Copilot App <[email protected]>
@danielmeppiel
Daniel Meppiel (danielmeppiel) force-pushed the danielmeppiel-p1-4572-stale-apm-pin branch from 4db0969 to c7ba84a Compare November 21, 2026 11:22
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit c99ec9c into main Nov 21, 2026
82 of 87 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-p1-4572-stale-apm-pin branch November 21, 2026 12:13
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 21, 2026
#4597 fixed the stale .apm-pin after a git -> registry switch but kept the
strict known cell, so test_source_spine_covers_every_form_and_op failed on
main: the bug no longer reproduces. The X|install|pkg-registry|UPDATE=on cell
now earns its oracle receipt like any other.

Co-authored-by: Copilot App <[email protected]>
Mohammed Alkindi (MohammedAlkindi) pushed a commit to MohammedAlkindi/apm that referenced this pull request Nov 21, 2026
…(main red)

microsoft#4597 fixed microsoft#4572 (a git -> registry switch now drops the stale
.apm-pin) but left the strict KnownCell registry-source-switch-stale-pin
in test_m_source.py. The cell no longer fails, so the source spine
(test_source_spine_covers_every_form_and_op, lifecycle_smoke shard 4)
fails strict on every PR. Drop the cell and its KNOWN_CELLS_BY_ID entry;
the regenerated pair X|install|pkg-registry|UPDATE=on moves from
known-failing to required.

Refs microsoft#4572, microsoft#4565

Co-authored-by: Copilot App <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] A git-to-registry source switch leaves the stale git .apm-pin in apm_modules until install --update

2 participants