Repository navigation
fix(install): keep the locked commit as the cached source pin - #3407
Daniel Meppiel (danielmeppiel) merged 6 commits into
Conversation
A cache hit without a live resolved reference filled its fallback ResolvedReference with the literal resolved_commit="cached". Codex native admission forwards that field as the source pin, so a warm-cache `apm install --frozen` on a dependency with a locked SHA failed with "Invalid original Codex source pin" even though the lockfile and .apm-pin both recorded the commit. Build the fallback with the commit the cache was resolved from when it is a full SHA, and keep the sentinel when no commit identity is available.
There was a problem hiding this comment.
🟡 Changes recommended
Source-pin validation is duplicated outside its designated owner, risking divergence from native admission and requiring a shared predicate backed by a regression test and registered architecture guard.
1 open issue
What changed in this PR
Fixes #3388 by preserving a cached dependency's full locked commit in the fallback reference used by Codex source-pin validation.
Changes:
- Resolves the cached commit once and preserves full 40- or 64-character lowercase hexadecimal identities.
- Keeps the
cachedsentinel for other values and adds regression coverage. - Documents the warm-cache installation fix in the changelog.
| File | Description |
|---|---|
tests/unit/install/test_sources_materialisation.py |
Tests locked-SHA preservation and branch-name fallback. |
src/apm_cli/install/sources.py |
Carries full cached commit identities into fallback references. |
CHANGELOG.md |
Records the cached Codex source-pin fix. |
Review effort: Balanced
|
|
||
| # A full Git commit identity, the only shape a resolved reference may carry as a | ||
| # source pin. Short SHAs and branch names stay on the ``cached`` sentinel. | ||
| _FULL_COMMIT_RE = re.compile(r"(?:[0-9a-f]{40}|[0-9a-f]{64})") |
There was a problem hiding this comment.
Fixed in 049a7e9. is_codex_source_pin now lives in codex_plugins/registrar.py, and the ledger reader, the identity check and cache materialization all use it. The Codex lifecycle guard requires one definition and the call in install/sources.py, with a mutation case, and a new test covers the predicate and the rejection path.
Cache materialization, the ownership ledger and the identity check now use is_codex_source_pin from the registrar, the owner of source pin integrity, and the architecture guard requires it.
|
Thank you for contributing this pull request. The linked issue #3388 is open but has not been accepted by a maintainer. APM starts with an issue, not an implementation (https://github.com/microsoft/apm/blob/main/CONTRIBUTING.md). Please wait for a maintainer to review and accept the scope in #3388 before proceeding. This PR is labelled status/deferred until then. Generated by autopilot-pr-triage-worker. This comment is AI-generated and may contain errors. |
The approved scope for microsoft#3388 requires caches without a full locked commit (branch name, short SHA, missing or inconsistent .apm-pin) to keep failing closed with the existing source-pin error. A true cache hit now carries the locked full commit only when cache_pin.verify_marker confirms the marker records it; fresh bytes keep their callback identity. Lockfile bookkeeping is unchanged. Adds a hermetic regression that replays the issue fixture through an in-process `apm install --global --frozen` (fails on main), extends the cached fallback unit matrix with lockfile-parity assertions, and pins the marker check in the Codex lifecycle architecture guard with a mutation case. Addresses scope record issuecomment-6772274357 (Done when). Co-authored-by: Copilot App <[email protected]>
Moves the entry into its own Fixed section after main's Added block, cites the PR number per changelog.instructions.md and credits the contributor. Co-authored-by: Copilot App <[email protected]>
The cached source-pin fold pushed sources.py to 1005 lines, past the 1000-line install-module budget enforced by test_no_install_module_exceeds_loc_budget. Condense the duplicated microsoft#3388 comment and docstring instead of raising the budget. Co-authored-by: Copilot App <[email protected]>
APM Review Panel:
|
| Persona | B | R | N | Takeaway |
|---|---|---|---|---|
| Supply Chain Security Expert | 0 | 0 | 0 | Fail-closed on every degradation path; lockfile-to-marker verification chain is sound; no new attack surface. |
| Test Coverage Expert | 0 | 0 | 0 | The regression trap covers all five Done-when items: CliRunner issue-fixture test, unit matrix, predicate test and architecture mutations. |
| Python Architect | 0 | 0 | 0 | Single-owner discipline upheld; _cached_source_pin is a bounded consumer of the registrar predicate and cache_pin.verify_marker. |
B = blocking-severity findings, R = recommended, N = nits. Counts show signal strength only; the maintainer decides whether to ship.
Recommendation
The fix stays inside the approved scope, fails closed and is tested against the issue fixture. CI is green. There are no follow-ups to track, and the PR now needs the required maintainer review.
Folded in this run
- (copilot) Share the source-pin predicate between the registrar and cache materialization (author fold), resolved in
049a7e9. - (scope) Missing or inconsistent
.apm-pinkeeps thecachedsentinel through the canonicalcache_pin.verify_marker, so those caches still fail with the existing source-pin error. Branch names and short SHAs behave the same way. Resolved inedd85ba. - (scope) Added a hermetic regression that replays the [BUG] Cached Codex plugin installation fails with an invalid source-pin error #3388 fixture through in-process
apm install --global --frozenwith the Codex client stubbed after source-pin validation. It fails on main. Also added a 7-case unit matrix with lockfile-parity assertions and an architecture-guard entry plus mutation case for the marker check. Resolved inedd85ba. - (changelog) Added the entry under Unreleased > Fixed citing fix(install): keep the locked commit as the cached source pin #3407 with contributor credit. The conflict with main was resolved by keeping both entries. Resolved in
3d8652f. - (ratchet) Kept
sources.pywithin its 1000-line budget, resolved ind146d77.
Copilot signals reviewed
src/apm_cli/install/sources.py-- LEGIT: the source-pin predicate was duplicated outside its registrar owner. It is now shared throughis_codex_source_pinwith a guard and mutation case (resolved in049a7e9). No new Copilot comments appeared after the push.
Regression-trap evidence (mutation-break gate)
test_cached_codex_source_pin.py[locked-sha]-- restored main'ssources.py; the test failed as expected; the fix was restored.test_cached_codex_source_pin.py[missing-pin,inconsistent-pin]-- deleted theverify_marker(...)check; the tests failed as expected; the guard was restored.test_cached_codex_source_pin.py[short-sha,branch-name]-- weakenedis_codex_source_pin(cached_commit)tobool(cached_commit); the tests failed as expected; the guard was restored.
Lint contract
ruff check and ruff format --check are silent. Pylint R0801 scores 10.00/10, and lint-auth-signals.sh and lint-architecture-boundaries.sh are clean.
CI
On d146d77, 21 checks pass and 2 are skipped (CodeQL and advisory PR eligibility). This took one CI fix iteration: the install-module LOC ratchet.
Mergeability status
| PR | head SHA | CEO stance | iters | folds | defers | Copilot rounds | CI | mergeable | mergeStateStatus | notes |
|---|---|---|---|---|---|---|---|---|---|---|
| #3407 | d146d77 |
ship_now | 1 | 5 | 0 | 2 | green | MERGEABLE | BLOCKED | pending required review |
Convergence
1 outer iteration and 2 Copilot rounds. Final panel stance: ship_now. Operational note: a cache created before .apm-pin markers fails closed once with the existing "restore the pinned dependency" error. It passes after the lockfile phase syncs markers, because accepting unverified identities is out of scope. Ready for maintainer review.
This panel is advisory. It does not block merge.
Generated by autopilot-pr-merge-worker. This comment is AI-generated and may contain errors.
8b2c323
into
microsoft:main
Brings the PR current with main. CHANGELOG.md takes main's version; the auto-merge had re-inserted the microsoft#3439 and microsoft#3407 entries a second time under 0.35.1. Co-authored-by: Copilot App <[email protected]>

Fixes #3388
Problem
A cache hit with no live resolved reference built its fallback
ResolvedReferencewith the literalresolved_commit="cached". Codex native admission readspackage_info.resolved_reference.resolved_commitas the source pin, so a warm-cacheapm install --global --frozenon a dependency whose lockfile and.apm-pinboth record a Git SHA fails with:Change
CachedDependencySource.acquire()now resolves the cached commit once, before the fallback reference is built, and uses it when it is a full commit identity (40or64lowercase hex). Branch names and short SHAs keep thecachedsentinel, so nothing downstream that treats the sentinel as "no recorded identity" changes behavior. The later_resolve_cached_commit()call was folded into the earlier one.Validation
test_resolved_ref_none_creates_fallback_resolved_referencenow asserts the locked SHA survives on the fallback reference. It fails onmainand passes with the change.test_resolved_ref_none_keeps_cached_sentinel_without_a_full_shapins the branch-name case to the sentinel.tests/unit/installplus the Codex registrar/admission suites: failure set identical tomainapart from the new test (74 vs 75 failures, all pre-existing in this Windows checkout — symlink tests and fixtures outside the sparse clone).ruff checkandruff format --checkclean on the touched files.