Skip to content

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

Open
Abhishek Acharya (abhishekacharya200) wants to merge 2 commits into
microsoft:mainfrom
abhishekacharya200:fix/cached-source-pin
Open

Abhishek Acharya (abhishekacharya200) wants to merge 2 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

This branch has not been deployed

No deployments
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. 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.

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

3 participants