Repository navigation
perf(install): fetch cold github.com deps as one verified archive - #4774
Daniel Meppiel (danielmeppiel) wants to merge 1 commit into
Conversation
3d478a0 to
1b7e8cf
Compare
1b7e8cf to
8a5d02d
Compare
8a5d02d to
7ed8bd6
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved archive byte-parity, permission, and size-limit issues remain, alongside cache and transport-selection regressions and broken or nonportable tests.
8 open issues
Account for ambient Git attributes to preserve checkout-byte parity · New Update retry tests to mock the keep-alive session · New Move subprocess-backed tests to integration and add taxonomy markers · New Write fixture bytes directly and set the Git index executable bit · New Warm-cache validation fails for archive shards without Git objects · New Honor Git URL rewrites when selecting archive transport · New Normalize extracted file permissions to verified Git modes · New Count directory member sizes toward the uncompressed limit · New
What changed in this PR
This PR adds an archive-based fast path for cold, anonymous GitHub dependency installs, integrating verified repository contents into the existing Git cache while preserving Git fallback.
Changes:
- Fetch and verify archives against commit and tree identities before cache landing.
- Reuse a credential-scoped HTTP session across dependency requests.
- Add transport-parity and rejection tests, architecture registration, and opt-out documentation.
| File | Description |
|---|---|
tests/unit/deps/test_archive_transport.py |
Tests archive verification, rejection, cache landing, and eligibility. |
tests/lifecycle/world/services.py |
Adds simulated codeload and Git tree endpoints. |
tests/lifecycle/scenarios/test_transport_parity.py |
Compares archive, Git, and tampered-archive installs. |
src/apm_cli/utils/archive.py |
Adds bounded in-memory tar reading and extraction. |
src/apm_cli/deps/github_downloader.py |
Integrates archive fetching and shared cached-package handling. |
src/apm_cli/deps/download_strategies.py |
Introduces pooled, credential-scoped HTTP requests. |
src/apm_cli/deps/archive_transport.py |
Implements archive fetching, tree verification, and staging. |
src/apm_cli/deps/archive_checkout.py |
Gates archive eligibility and handles fallback. |
src/apm_cli/cache/git_cache.py |
Adds verified-tree cache landing and metadata. |
scripts/architecture_linter/checks/transport_sparse_and_updates.py |
Updates the materialization-pin usage guard. |
docs/src/content/docs/reference/environment-variables.md |
Documents APM_ARCHIVE_TRANSPORT. |
changelog.d/4774.changed.md |
Records the cold-install transport change. |
.apm/architecture/owners/transport-auth-platform.json |
Registers archive transport ownership and extraction consumers. |
Review effort: Balanced
ac06859 to
295709a
Compare
295709a to
27bcdc8
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Archive extraction limits can be bypassed by PAX/GNU metadata, risking memory exhaustion, while checkout also misses configured URL rewrites and adds unnecessary Git subprocess costs to warm restores.
3 open issues
8 resolved since last review
Write fixture bytes directly and set the Git index executable bit Move subprocess-backed tests to integration and add taxonomy markers Update retry tests to mock the keep-alive session Account for ambient Git attributes to preserve checkout-byte parity Count directory member sizes toward the uncompressed limit Normalize extracted file permissions to verified Git modes Honor Git URL rewrites when selecting archive transport Warm-cache validation fails for archive shards without Git objects
Review effort: Balanced
27bcdc8 to
3402342
Compare
3402342 to
41f575f
Compare
41f575f to
c54e07d
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Critical archive-handling gaps let PAX/GNU metadata bypass decompression limits during verification and extraction, risking memory exhaustion, and allow unverified directories to alter package detection.
5 open issues
1 resolved since last review
Review effort: Balanced
c54e07d to
62e0060
Compare
deff5d2 to
b0d4c90
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Relative Git attribute paths can bypass required content transformations and break hash parity, while streamed connection failures leave the failing archive transport enabled for subsequent fetches.
2 open issues
1 resolved since last review
Review effort: Balanced
b0d4c90 to
53633fb
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
The default-on transport and cache-trust changes require maintainer security/runtime review and exact-SHA tree-10/tree-50 ABAB GAINS validation, as the benchmark tables remain blank.
No open issues 🎉
2 resolved since last review
Review effort: Balanced
53633fb to
8f43e82
Compare
8f43e82 to
37f4c0f
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The archive path can bypass Git’s explicit protocol allow-list by sending an HTTPS codeload request when HTTPS is prohibited, requiring an allow-list check and a routing regression test.
1 open issue
1 resolved since last review
Review effort: Balanced
37f4c0f to
094577e
Compare
A cold whole-repository dependency on github.com is fetched as one codeload tar.gz (by commit SHA), with the GitHub git/trees API call in parallel, instead of a git clone (about 14 git subprocesses and 3 git HTTP requests per dependency). The archive is accepted only when the git tree hash recomputed from its members (path, exec bit, blob bytes) equals the commit's tree and its pax comment names the commit. Links, special files, .gitattributes, submodules, non-canonical paths, the size cap and any HTTP failure fall back to git, and nothing lands. The verified tree lands in the GitCache full-tree shard through GitCache.land_tree_checkout (minimal .git: detached HEAD + materialization pins), so warm and frozen hits are unchanged and the lockfile content hash is the same whichever transport ran. Only the anonymous first attempt the git transport itself makes for github.com is used; auth-first, other hosts, SSH, registry-only mode and APM_ARCHIVE_TRANSPORT=0 keep git. The archive is bounded (64 MiB compressed, 256 MiB uncompressed, 10000 members); hitting a bound falls back to git. apm-spec-waiver: transport-only change; lockfile bytes and content hashes are identical whichever transport fetched the package Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
094577e to
d3370f8
Compare
|
Closed by [PERF] VP v2: lane D KILLED on evidence, per the regent's kill condition (cold bench). CI bench at head-equivalent 094577e vs base 0a31fd7, 3 runners x 3 interleaved pairs, paired CPU:
|
| extended += size | ||
| if extended > _MAX_EXTENDED_HEADER_BYTES: | ||
| _raise(error_type, "Archive extended metadata exceeds its limit") | ||
| offset += block + -(-size // block) * block |


Description
A fresh
apm install(empty cache) is bound by round trips and git subprocesses, not by the network. On the tree-10 perf fixture (offline mirror, 30 ms RTT), main makes 40 requests / 80 round trips / 20 TLS connects and runs ~14 git subprocesses per dependency. Per dependency that is: 1 commits-API GET on its own TLS connection (L1 ref resolution), then a git clone (info/refs + 2 upload-pack POSTs on a second connection), then a local checkout. The resolver is level-parallel, so about 9 round trips sit on the critical path per dependency level.This PR replaces the cold clone with one verified archive:
github.comdependency is downloaded as onecodeload.github.com/<owner>/<repo>/tar.gz/<sha>response. Thegit/trees/<sha>API call runs in parallel, so it adds no round trip. Both requests go throughorigin_bounded_requestwith zero redirect hops andambient_credentials=False: no credential, netrc entry or redirect is ever followed.ArchiveUnavailable: links, special files,.gitattributes, submodules (missing gitlinks change the tree hash), export-ignored paths, non-canonical or non-portable paths (one check on the raw name of every member: empty/./.. segments, backslash, NUL,:NTFS streams, trailing dot/space, DOS device names such asCON/nul.txt/COM1, and.git/git~1in any case; the same rules on every OS), the decompression bounds (ArchiveLimits: 64 MiB compressed, 256 MiB uncompressed counting directory members, 10000 members), any HTTP status other than 200, and any network error. When that happens nothing lands and the git transport runs exactly as before. An unreachable codeload disables archives for the rest of the run. Landed file modes come from the verified tree, never from the archive.checkouts_v1/<shard>/<sha>/fullthrough a new GitCache-owned miss-side method,land_tree_checkout. It writes a minimal.git: detached HEAD, every materialization pin,apm.materialization=verified-treeandapm.tree=<sha>. Warm and--frozenhits treat it like a cloned shard. The link validator's owner (utils/git_sparse.validate_materialized_symlinks) returns early only for these link-free shards, so a warm restore reaches no network (lifecycle-tested).download_packagegains a two-line hook:_cached = try_archive_tree(...) or self._persistent_cache_checkout(...); the existing copy, validate and fallback path is unchanged. There is no second cache. An existing git shard for the SHA is always preferred.Routing (gate in
deps/archive_checkout.py, ownergit-transport-selection). The archive is used only when all of these hold:github.comover HTTPS (no port, not--insecure, not virtual/subdirectory, not Artifactory/ADO);AuthResolver.uses_public_github_anonymous_firstis true, so auth-first keeps git;TransportSelectoranonymous plan starts with plain HTTPS to the unrewritten URL. AnyinsteadOfrewrite (e.g. https->ssh) orAPM_GIT_PROTOCOL=sshkeeps git; this was a security finding, with a red-first test;git var GIT_ATTR_SYSTEM/GIT_ATTR_GLOBALin the git transport's own env), because those could make a checkout differ from the blobs;includeIfanywhere (unscopedgit config --includes --get-regexp ^includeif\.from a neutral directory, in both the user's and the transport's environment). This follows nestedinclude.pathand env-provided config, because a conditional include can activate a rewrite or an attributes file only inside the clone;GIT_ALLOW_PROTOCOLincludeshttps;protocol.allow/protocol.https.allowunset oralways), in both environments;APM_ARCHIVE_TRANSPORTis not0.Tar members are read and extracted only through the archive owner (
utils/archive.py: newread_tar_gz_members,safe_extract_tar_gz_bytes).Integrity. Accepted bytes are proven to be the commit's git tree. The git path, pinned by
core.autocrlf=false,core.eol=lfand no attributes, writes the same blob bytes, socontent_hashand the deployed file hashes are byte-identical whichever transport ran. The lifecycle scenario covers archive, then cold git, then a tampered archive.Floor (tree-10, 5 levels). Level k's dependencies are known only after level k-1 is read, so the floor is (5 levels + 2 connect) RT = 7 x 30 ms = 210 ms. This PR keeps L1 ahead of the archive round (~2 RT per level). Follow-ups, out of scope per #4776: fold L1 into the archive round (1 RT per level), the keep-alive session for L1 (branch
danielmeppiel-perf-keepalive-session), authenticated/private archives, GHE, and the synchronous update check (3 RT before the command).Evidence (GAINS STANDARD)
Journey:
apm install, empty cache (install-cold), offline mirror, RTT 30 ms. ABAB from exact-SHA worktrees on the PERF host slot. basec969aba99a6f(main) -> newd3370f8f628b. Cell: wall s / CPU s (user+sys incl. children) [1-min load].Gain: _ x CPU, _ x wall; _ % of the cold journey removed. North Star: tree-10 cold now _ s wall / _ s CPU, gap to 1 s _ s.
Issue and approved scope
Fixes #4776
Fixes #4819
Human scope-approval comment: scope record posted on #4776 (regent-ruled, accepted).
Does this PR complete the issue, or what remains? It completes #4776's scope. Follow-ups are listed above as out of scope.
Type of change
Testing
New and changed tests:
tests/integration/test_archive_transport.py(component). A verified archive lands an ordinary cache hit whosecompute_package_hashequals a git clone's (real repo with nested dirs, exec bit, CRLF blob and git'sa.b<a/order). Every rejection below asserts that nothing lands in the cache:test_archive_digest_mismatch_rejected_before_deployment, tar traversal / absolute path / dot segment, symlink and hardlink members, decompression bounds (bytes, members, compressed size) and directory members counting toward the bound;.gitattributes, unreachable codeload;insteadOfhttps->ssh rewrite (realGIT_CONFIG_GLOBAL), ambient attributes, GHE Cloud, GHES, ADO, SSH, custom port, insecure, virtual, auth-first andAPM_GIT_PROTOCOL=sshsend no archive request; a codeload 3xx is refused.tests/lifecycle/scenarios/test_transport_parity.py(real CLI, policy on, I1-I9 per step) runs four installs. All four end with the identical lock row (resolved_commit,content_hash,deployed_file_hashes), and the tampered bytes are never deployed or cached:~/.netrcfor both hosts, where every codeload andgit/treesrequest carries noAuthorizationheader and no secret;APM_ARCHIVE_TRANSPORT=0);tests/lifecycle/world/test_world.py: the git-transport cell is pinned toAPM_ARCHIVE_TRANSPORT=0and keeps its git assertion unchanged. A new siblingtest_cold_github_source_installs_through_the_verified_archiveasserts the exact egress (tar.gz/<sha>+git/trees/<sha>) and lock rows identical to git.codeload.github.comas its archive host. So the existing secret-absence evidence now also covers codeload.codeload.github.comwas added to the world host sets oftest_m_sourceandtest_explicit_host_identity.Inherited reds (not from this PR):
tests/unit/install/test_architecture_invariants.py::test_no_install_module_exceeds_loc_budget(exec_gate.py1007 > 1000): main-red, owned by MAIN-RED FIX: move withheld-executable wording out of install/exec_gate.py (LOC budget) #4777/revert: #4729 to clear main red (exec_gate.py LOC budget) #4781.tests/unit/test_outdated_command.py::TestOutdatedCommand::test_long_package_name_folds_instead_of_clipping: an outdated-table width assertion; this PR does not touch that path.Lint mirror (local, at head): ruff 0.15.12 check/format, pylint R0801,
scripts/lint-auth-signals.sh, the complexity ratchet,scripts/lint_architecture_boundaries.py,tests.quality.taxonomy --changedandscripts/check_test_assertions.pyare all clean. The architecture changes: new modules registered under thegit-transport-selectionowner, a new consumer listed onarchive-extraction-limits, and the_checkout_materialization_pins()count guard set to 4 (the verified-tree shard writer).Changelog
changelog.d/<pr>.<section>.md(changelog.d/4774.changed.md).Spec conformance (OpenAPM v0.1)
apm-spec-waiver.