Skip to content

fix(install): keep the locked commit as the cached source pin - #3407

Merged
Daniel Meppiel (danielmeppiel) merged 6 commits into
microsoft:mainfrom
abhishekacharya200:fix/cached-source-pin
Nov 10, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 6 commits into
microsoft:mainfrom
abhishekacharya200:fix/cached-source-pin

Conversation

@abhishekacharya200

Copy link
Copy Markdown
Contributor

Fixes #3388

Problem

A cache hit with no live resolved reference built its fallback ResolvedReference with the literal resolved_commit="cached". Codex native admission reads package_info.resolved_reference.resolved_commit as the source pin, so a warm-cache apm install --global --frozen on a dependency whose lockfile and .apm-pin both record a Git SHA fails with:

Failed to install APM dependencies: Invalid original Codex source pin for example/demo/skills/demo; restore the pinned dependency before retrying.

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 (40 or 64 lowercase hex). Branch names and short SHAs keep the cached sentinel, 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_reference now asserts the locked SHA survives on the fallback reference. It fails on main and passes with the change.
  • New test_resolved_ref_none_keeps_cached_sentinel_without_a_full_sha pins the branch-name case to the sentinel.
  • tests/unit/install plus the Codex registrar/admission suites: failure set identical to main apart from the new test (74 vs 75 failures, all pre-existing in this Windows checkout — symlink tests and fixtures outside the sparse clone).
  • ruff check and ruff format --check clean on the touched files.

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.

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.

🟡 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 cached sentinel 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

Comment thread src/apm_cli/install/sources.py Outdated

# 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})")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.
@sergio-sisternes-epam

Copy link
Copy Markdown
Collaborator

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.

@sergio-sisternes-epam Sergio Sisternes (sergio-sisternes-epam) added area/distribution Installers (curl/PowerShell/Brew/Scoop), self-update, devcontainer, codespaces. status/deferred Not invited for implementation now; no release commitment. triage/recommended Automated advice completed; not human scope approval. type/bug Something does not work as documented. labels Nov 3, 2026
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]>
@danielmeppiel Daniel Meppiel (danielmeppiel) removed the status/deferred Not invited for implementation now; no release commitment. label Nov 10, 2026
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]>
@danielmeppiel

Copy link
Copy Markdown
Collaborator

APM Review Panel: ship_now

Community P0 fix: a warm-cache Codex install now keeps the locked commit as its source pin instead of the cached sentinel, and still fails closed when the cache cannot vouch for that commit.

panel-mode=lean then delta; personas=supply-chain-security-expert,test-coverage-expert,python-architect,apm-ceo

cc Abhishek Acharya (@abhishekacharya200) Sergio Sisternes (@sergio-sisternes-epam) -- a fresh advisory pass is ready for your review.

The scope approved on #3388 is the governing scope for this pass. Thank you Abhishek Acharya (@abhishekacharya200) for the fix and for extracting the shared predicate quickly after the Copilot note.

Lean pass on 3d8652f: supply-chain security, test coverage and architecture returned zero findings. They confirmed fail-closed behavior on every degraded path, one owner for the source-pin predicate, and coverage for all five Done-when items. The terminal delta (3d8652f..d146d77) only shortens a docstring and comment so sources.py stays within its 1000-line install-module budget. It changes no behavior, so the earlier persona returns still apply.

Aligned with: secure by default (only a full commit backed by a matching .apm-pin replaces the sentinel), governed by policy (the architecture guard pins both checks in sources.py, with mutation cases), community driven (an accepted scope, delivered by a community contributor).

Panel summary

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-pin keeps the cached sentinel through the canonical cache_pin.verify_marker, so those caches still fail with the existing source-pin error. Branch names and short SHAs behave the same way. Resolved in edd85ba.
  • (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 --frozen with 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 in edd85ba.
  • (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.py within its 1000-line budget, resolved in d146d77.

Copilot signals reviewed

  • src/apm_cli/install/sources.py -- LEGIT: the source-pin predicate was duplicated outside its registrar owner. It is now shared through is_codex_source_pin with a guard and mutation case (resolved in 049a7e9). No new Copilot comments appeared after the push.

Regression-trap evidence (mutation-break gate)

  • test_cached_codex_source_pin.py[locked-sha] -- restored main's sources.py; the test failed as expected; the fix was restored.
  • test_cached_codex_source_pin.py[missing-pin,inconsistent-pin] -- deleted the verify_marker(...) check; the tests failed as expected; the guard was restored.
  • test_cached_codex_source_pin.py[short-sha,branch-name] -- weakened is_codex_source_pin(cached_commit) to bool(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.

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 8b2c323 into microsoft:main Nov 10, 2026
25 checks passed
Daniel Meppiel (danielmeppiel) added a commit to yahavi/apm that referenced this pull request Nov 12, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/distribution Installers (curl/PowerShell/Brew/Scoop), self-update, devcontainer, codespaces. triage/recommended Automated advice completed; not human scope approval. type/bug Something does not work as documented.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Cached Codex plugin installation fails with an invalid source-pin error

4 participants