Skip to content

[FEATURE] perf(install): verify warm git cache hits by hash and clone them into apm_modules #4780

Closed as not planned

Description

Proposals are welcome before implementation. For substantive changes, wait
for a responsible human maintainer to approve the scope and identify a review
contact. An automated recommendation, label alone, or silence is not approval.
See Contributing.

Is your feature request related to a problem? Please describe.
A warm apm install (machine cache populated; fresh project or apm_modules deleted) still pays per dependency for materialization out of the persistent git cache (checkouts_v1/<shard>/<sha>/full): one git ls-tree -r HEAD subprocess (the tracked-symlink check, github_downloader.py WS3 hit path) and a per-file clonefile + copystat copy into apm_modules. On the tree-10 perf fixture (tests/fixtures/perf, offline mirror, 30 ms RTT) at main c969aba, warm spawns 12 git processes (2 version + 10 ls-tree); cProfile attributes 5.5% of warm wall to the copy and 4.2% to the ls-tree scans. The cache entry is also never re-verified against its content before it is copied: verify_checkout_sha checks HEAD only.

Describe the solution you'd like
Bounded scope:

  • A seal per full checkout (.git/apm-seal.json): SHA-256, size and exec bit of every file, every directory, and the tracked-symlink verdict for the whole tree.
  • Verify-before-reuse: every read re-hashes the entry against its seal. A mismatch, a malformed seal, or a seal naming a path outside the entry evicts the entry; nothing reaches apm_modules from it.
  • The tracked-symlink check runs once per entry; a passing verdict is recorded and later hits skip the ls-tree. An unknown or failing verdict runs the existing strict check unchanged.
  • Materialization: copy-on-write clone by default where available (macOS dir-level clonefile(2) through the existing utils/reflink.py binding), copy elsewhere (FICLONE where supported). Hard links are opt-in only (APM_MATERIALIZE=link), protected by verify-before-reuse and documented. Cache file modes are untouched.
  • Read-only readers (apm audit --ci replay) never write a seal or a lock.
  • Path security on every seal path and every materialized destination.

Done when:

  • Red-first cells pass: editing a materialized file does not change the cache (clone, copy); an edited hard-linked entry is detected and never reused; a tampered entry is evicted before any byte is materialized; a seal path escaping the entry is rejected; os.link failure falls back to copy (Windows/EXDEV); uninstall and prune never remove content another tree uses; an unknown or failing link verdict still raises the strict diagnostic; read-only readers write nothing.
  • GAINS evidence in the PR: ABAB at exact SHAs, warm and fresh, tree-10 and tree-50 at rtt 30, with CPU incl. children, wall, load, git subprocesses, copies/clones/links, % of the journey removed and the gap to 1 s.

Out of scope: reusing the seal hashes for the lockfile content_hash (follow-up), cold transport (#4776), subdirectory (virtual) package materialization, policy-discovery and credential traffic on warm installs.

Describe alternatives you've considered

  • Hard links by default (pnpm/uv style): an in-place edit in apm_modules mutates the shared inode, and a read-only cache leaks mode 0444 into deployed files through atomic_copy(metadata=True). Kept opt-in.
  • Trusting HEAD only: does not detect content edits.

Additional context
Implementation: #4779 (draft). Part of the PERF workstream toward 1 s warm installs on tree-10.

Activity

  1. added
    performance
    type/feature
    on Nov 22, 2026
  2. danielmeppiel commented on Nov 22, 2026

    @danielmeppiel
    CollaboratorAuthor

    Decision: approve
    Area: project
    Scope: Performance and cache integrity. Each full checkout in the persistent git cache carries a seal (.git/apm-seal.json) with the SHA-256, size and exec bit of every file, every directory, and the tracked-symlink verdict for the tree. Every read re-hashes the entry against its seal before reuse; a mismatch, a malformed seal, or a seal naming a path outside the entry evicts the entry and nothing reaches apm_modules from it. A passing tracked-symlink verdict is recorded so later hits skip ls-tree; an unknown or failing verdict runs the existing strict check unchanged. Materialization uses copy-on-write clone where available (through src/apm_cli/utils/reflink.py) and copy elsewhere; hard links are opt-in only via APM_MATERIALIZE=link, documented in the environment-variable reference and protected by verify-before-reuse. Cache file modes are untouched, read-only readers (apm audit --ci replay) never write a seal or a lock, and path security applies to every seal path and every materialized destination.
    Done when: Red-first cells pass: editing a materialized file does not change the cache (clone and copy); an edited hard-linked entry is detected and never reused; a tampered entry is evicted before any byte is materialized; a seal path escaping the entry is rejected; os.link failure falls back to copy (Windows, EXDEV); uninstall and prune never remove content another tree uses; an unknown or failing link verdict still raises the strict diagnostic; read-only readers write nothing; on Windows, when clone or hard link is unavailable, materialization falls back to copy, proven in the Windows lane; materialization never follows a symlink out of the cache entry or the deploy root, with path_security validation on every materialized path, proven red-first. The PR carries ABAB GAINS evidence at exact SHAs, warm and fresh, tree-10 and tree-50 at 30 ms RTT. QL's security lane reviews at head as part of H8, CI is green, and a CHANGELOG line is added.
    Out of scope: Reusing seal hashes for the lockfile content_hash; cold transport (#4776); subdirectory (virtual) package materialization; hard links by default; policy-discovery and credential traffic on warm installs.
    Review contact: Daniel Meppiel (@danielmeppiel)

  3. added
    status/accepted
    and removed on Nov 22, 2026
  4. added a commit that references this issue on Nov 22, 2026
    484f229
  5. danielmeppiel commented on Nov 23, 2026

    @danielmeppiel
    CollaboratorAuthor

    Measured below the performance bar. Cached-checkout verification continues in #4891.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    performancestatus/acceptedtype/feature

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions