Skip to content

fix: fetch every named dependency ref by the commit it was admitted at - #5195

Merged
Daniel Meppiel (danielmeppiel) merged 17 commits into
mainfrom
fix-5138-fetch-named-ref-by-commit
Nov 24, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 17 commits into
mainfrom
fix-5138-fetch-named-ref-by-commit

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

A dependency given as a branch or tag name was admitted at the commit its ref resolved to, but some download paths then fetched it by name (git clone --branch). If the ref moved in between, the fetched commit and the lockfile could differ from the admitted one.

Every declared ref other than a full commit is now fetched by its admitted commit, never by name:

  • The subdirectory path fetches the admitted commit through the existing by-commit paths.
  • The regular path without the persistent cache fetches it shallowly: git init, git fetch --depth=1 --no-tags <url> <commit>, then a detached checkout, using the same validated environment a clone gets (so remote-activated config such as a mirror rewrite applies) and an untranslated git locale. Only when the server refuses a want for an unadvertised commit does it fall back to a full clone and a checkout of the commit, logged at verbose; a commit the server no longer has, or an auth failure, fails at depth-1 cost. When a host answers "not our ref" for a commit, the ref is listed: if it still names the admitted commit, that ref is fetched at depth 1 and the admitted commit is checked out and verified; otherwise the install fails as below.
  • The persistent-cache paths already fetched by commit and are unchanged.

When the admitted commit is no longer on the origin (for example the branch was force-pushed), the install fails closed and the message names both commits and the remedy, for example: 'main' was admitted at commit <a>, which can no longer be fetched from the origin ('main' now points to <b>). Run the install again to admit its current commit, or 'apm update' when the lockfile pins it. A failure that never reached a reachability verdict, or one that is not a git fetch, clone or checkout failure, keeps its original error. Admission and reachability rules are unchanged.

Issue and approved scope

Issue: Fixes #5138

Human scope-approval comment: the apm-scope approval on #5138.

This PR completes the issue.

Type of change

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

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)

Red-first CLI cells in tests/integration/test_install_pinned_commit_reachability.py (real origin; repo or subdirectory, with or without the persistent cache):

  • test_a_branch_that_moves_after_admission_installs_the_admitted_commit: the lockfile records the admitted commit and the deployed content matches it. Failed on main for both no-cache paths.
  • test_an_admitted_commit_force_pushed_away_fails_closed: exit 1 with the named message, nothing installed, no lockfile. Failed on main on all four paths.
  • test_a_named_ref_is_checked_out_at_its_commit_even_when_a_want_by_commit_is_refused: the shallow fetch by commit, and the full-clone fallback when the server refuses the want.

Fixture and expectation changes (classified with QL before editing, assertions unchanged where marked):

  • Cells that asserted clone --branch/depth=1 for a named ref now assert the fetch by commit, or run on the default-branch path they were exercising.
  • Cells whose downloaders had no resolver now use the default-branch path; their assertions are unchanged.

Validation (serial, targeted): tests/unit/deps plus shared_clone_cache, validation_flow, deps_resolver, deps_models, install_pinned and git_cache_sha_reachability: 2624+ passed. Lint mirror (ruff check/format, pylint R0801, lint-auth-signals.sh, complexity ratchet, taxonomy --changed, architecture boundaries) and quality baselines: clean.

Cost: unchanged with the persistent cache (default). Without it, the regular path stays depth 1, now by commit.

Changelog

  • One fragment per section, changelog.d/<pr>.<section>.md, holding
    one line: user-visible effect first, 25 words or fewer, ending with
    (#PR); breaking changes only under upgrade notes; no Highlights; no
    new lines under ## [Unreleased]. See changelog.d/README.md and
    .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.

A branch or tag can move between admission and fetch. Every declared ref
other than a full commit is now fetched by its admitted commit, never by
name: the subdirectory path fetches the commit through the existing
by-commit paths, and the regular path without the persistent cache
fetches it shallowly (init, fetch --depth=1 of the commit, detached
checkout), falling back to a full clone and a checkout of the commit when
the server refuses a want by commit. The lockfile and the deployed
content are always the admitted commit. When the admitted commit is no
longer on the origin, the install fails with a message that names both
commits and the remedy.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 23, 2026 22:54
@danielmeppiel Daniel Meppiel (danielmeppiel) added this to the 0.39.0 milestone Nov 23, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
apm-spec-waiver: fetch mechanics only; which commit a ref admits and resolves to is unchanged.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

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

With tiered resolution disabled, persistent-cache downloads can use a newer commit instead of the admitted SHA, while failure handling can misclassify validation or filesystem errors and suppress lost-commit diagnostics.

4 open issues
What changed in this PR

This PR addresses #5138 by fetching named dependencies at their admitted commit, aiming to keep installed content and lockfile records consistent when a branch or tag moves during installation.

Changes:

  • Fetches named refs by commit, with a shallow-fetch path and full-clone fallback.
  • Adds diagnostics for admitted commits that can no longer be fetched.
  • Adds moving-ref regression coverage and adjusts existing download fixtures.
File Description
tests/​unit/​deps/​test_github_downloader.py Updates named-ref expectations and default-branch fixtures.
tests/​unit/​deps/​test_github_downloader_package_download.py Moves clone-path fixtures to default-branch references.
tests/​integration/​test_shared_clone_cache.py Adjusts shared-cache fixtures to use default refs.
tests/​integration/​test_install_pinned_commit_reachability.py Adds branch-movement, force-push, and fetch-fallback coverage.
tests/​integration/​test_github_downloader_validation_flow.py Uses the default-branch cache path in validation fixtures.
src/​apm_cli/​deps/​github_downloader.py Routes named downloads through commit fetching and diagnostic handling.
src/​apm_cli/​deps/​bare_cache.py Adds shallow commit fetching with full-clone fallback.
src/​apm_cli/​cache/​commit_reachability.py Expands commit-based admission fetching and adds lost-commit diagnostics.
changelog.d/​5195.fixed.md Records the user-visible dependency-fetch fix.

Review effort: Balanced

- Fetch by admitted commit falls back to a full clone only when the
  server refuses a want-by-commit; a commit the server no longer has
  fails without cloning the history.
- The lost-admitted-commit message renders the ref as printable ASCII.
- Only git and clone failures are renamed; validation errors pass through.
- The persistent subdir path and the error check use the admitted commit
  captured at admission instead of resolving the ref again; string refs
  are parsed before the check.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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

Critical issues can bypass configured mirrors and misreport transport failures as lost commits, while direct subdirectory downloads lack admission diagnostics and error tests no longer reliably exercise the intended failure paths.

2 open issues
2 previously missed issues

In code that hasn't changed since last review

Medium severity Open admission context for direct subdirectory downloads

src/​apm_cli/​deps/​github_downloader.py:1804

The admission context is opened only for download_package, but ScriptRunner._auto_install_virtual_package calls download_subdirectory_package directly (core/script_runner.py:919). On that path, _note_admitted discards the admitted ref/commit, so a ref force-pushed away still produces a generic Git failure instead of the named diagnostic. Establish the context at the subdirectory entry point too, preserving its keyword-call interface, and cover the direct-call path.

Medium severity Update tests to mock the named-ref fetch route

src/​apm_cli/​deps/​github_downloader.py:1994

TestGitHubPackageDownloader.test_download_package_git_failure and TestDownloadPackage.test_git_command_error_auth_failure_raises_runtime still stub only the old clone route, which this named-ref branch bypasses. They can reach the real fetch transport and satisfy their broad Failed to clone assertions on an unrelated failure without exercising the scripted Git/authentication error. Update both fixtures to mock the new fetch route (or use an undeclared ref if they specifically test cloning), and assert that the failure mock was called.

4 resolved since last review

Review effort: Balanced

Comment thread src/apm_cli/deps/bare_cache.py Resolved
- The fetch by commit runs untranslated (LC_ALL=C, LANGUAGE=C), so a
  server's refusal is recognized in any locale.
- A host that answers "not our ref" gets the named ref fetched shallowly
  by name, only while it still points at the admitted commit, and the
  checkout is verified against that commit; otherwise the install fails
  naming the lost commit. No full clone either way.
- The fetch by commit uses the validated clone environment, so config a
  clone activates by its remote URL (a mirror rewrite) applies.
- A transport failure before any reachability verdict keeps its original
  error instead of being reported as a lost commit.
- Mkdtemp permission cells use the default branch: a named ref is now
  resolved to its commit before any temp directory exists.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
A named ref, resolved to its commit through a stubbed resolver, reaches
the same temp-directory error handling as the default branch.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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

Active findings identify a prohibited mutable-ref fallback, a false lost-commit diagnosis for reachable commits, and verification failures for packages with valid internal symlinks.

3 open issues
2 resolved since last review

Review effort: Balanced

Comment thread src/apm_cli/deps/bare_cache.py Resolved
Comment thread src/apm_cli/deps/bare_cache.py Resolved
The fetch by name for a host that will not serve a commit by its id
checked the checkout before tracked links were materialized, so a
package with a link failed. The caller already verifies every fetch by
commit against its commit after materializing links.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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.

🔵 Needs a closer look

Human assessment is needed because mirror routing and auto-install diagnostics have unresolved edge cases, while an authentication test may pass on an unrelated network failure.

No open issues 🎉

3 resolved since last review

Review effort: Balanced

Resolve the github_downloader import conflict by keeping both imports.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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

The fallback lookup uses the original transport environment instead of the validated mirror configuration, risking contact with the wrong server and incorrect reports that an available commit is missing.

1 open issue

Review effort: Balanced

Comment thread src/apm_cli/deps/bare_cache.py Resolved
The by-name fallback listed the ref with the transport environment, so a
mirror activated by the remote URL was skipped and the listing went to
the origin. Listing and fetch now both use the validated clone env.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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.

🔵 Needs a closer look

Human assessment is needed to evaluate a critical risk of reusing mirror-derived reachability verdicts at the origin and a dumb-HTTP regression affecting fully qualified refs.

1 open issue

Review effort: Balanced

The probe memo was process-global and held its entries for the process
lifetime. It now lives on the install attempt's verdict stage, keyed by
a digest of the URL and environment, and is dropped when the attempt
commits or is discarded. Without an open stage every listing probes.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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.

🔵 Needs a closer look

Human assessment is needed because conditional mirror rewrites can permit reuse of reachability verdicts without upstream checks and mask lost-commit diagnostics, while dumb-HTTP no-cache installs can regress.

1 open issue

Review effort: Balanced

A ref listing that a remote-activated mirror served recorded its tip
under the transport environment, i.e. as the origin's verdict; once the
rewrite was removed, the origin trusted that marker without a check. The
listing environment is now probed once and used both to list and to
record, so the verdict names the mirror.

The loopback HTTPS cell server wraps its socket with stdlib ssl, as the
repository's HTTPS fixtures do, so an injected truststore cannot break it.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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.

🔵 Needs a closer look

Human assessment is needed to evaluate mirror-transport inconsistencies and dumb-HTTP fallback regressions that can suppress lost-commit diagnostics or reject available commits.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

A tip the resolver read from the origin (a commits API answer or its
legacy clone) was recorded under the transport environment. A clone that
a remote-activated mirror served was then keyed as the origin's verdict.
The tip is now keyed under the same probed listing environment as a
listed tip, and nothing is recorded when that probe cannot run.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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

A critical cache issue can record the origin’s reachability verdict for an unchecked mirror, allowing later SHA admission to skip required verification.

1 open issue

Review effort: Balanced

The reachability check listed and keyed its verdict under the transport
environment, but its persisted repository has an origin remote, so a
remote-activated mirror rewrite could serve its fetch. A commit only the
mirror held was then recorded as the origin's verdict. The check now
probes the clone environment once and uses it for the verdict key, the
listing and the fetch, so each names the server that answered.

The locked-replay cell matches git subcommands by argument, not by
substring of a path.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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.

🔵 Needs a closer look

Human assessment is needed because unpublished critical findings identify stale-cache commit admission without origin verification and dumb-HTTP compatibility regressions.

1 open issue

Review effort: Balanced

- Only an includeIf section can make git config depend on the remote. An
  install attempt checks once whether any config scope has one; without
  one, the transport environment already is the clone environment and
  nothing is probed. When that cannot be told, it probes.
- A tip the resolver read is recorded only when the probed and transport
  environments name the same server: the resolver may have listed the
  origin plainly or cloned it through a remote-activated mirror, so under
  such a rewrite the tip is verified at the destination when next admitted.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Recording a resolved tip probes which server a clone of its contact
reaches. That probe ran under the downloader's environment, so its local
git calls (which name the contact URL) could carry platform tokens and a
translated locale. It only needs the URL git contacts, so it now runs
without credentials and untranslated.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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.

🔵 Needs a closer look

Human assessment is needed because unpublished findings identify Git object-format mismatches and missing commit-pinned fallback support for whole-repository dependencies on dumb-HTTPS hosts.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

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.

🔵 Needs a closer look

Human assessment is needed to evaluate unpublished findings concerning version-range fallback failures and no-cache download regressions on dumb HTTPS origins.

No open issues 🎉

Review effort: Balanced

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit a97d08e into main Nov 24, 2026
77 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the fix-5138-fetch-named-ref-by-commit branch November 24, 2026 06:30
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.

deps: fetch a named branch by its admitted commit

3 participants