Skip to content

gates: cache the declared apt packages on hosted Linux, warmed from the default branch - #202

Merged
SSFSKIM merged 8 commits into
mainfrom
setup-apt-cache
Nov 10, 2026
Merged

SSFSKIM merged 8 commits into
mainfrom
setup-apt-cache

Conversation

@SSFSKIM

@SSFSKIM SSFSKIM commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

Why

On GitHub's Linux runners the Azure Ubuntu mirror sometimes serves about 100 kB/s. When it does, arachne's declared TeX and font set (1167 MB; texlive-fonts-extra alone is 669 MB) keeps "Apply CI environment" running until its 20-minute limit. That has happened 34 times since 11-02, and every rerun passed. The mirror's speed varies from runner to runner: during this work one download of the set took 22–48 s, while another download of the same set, started minutes later, was still running after 45 minutes.

What

  • Gate jobs (hosted Linux with apt). Before the setup step, a step adds an apt drop-in that sets Dir::Cache::Archives to $RUNNER_TEMP/ci-kit-apt/ and APT::Sandbox::User root. actions/cache/restore@v6 then restores *.deb there. The key is ci-kit-apt-1-<ImageOS>-<arch>-<apt set hash>-<ImageVersion>. When it misses, the gate falls back first to the same set on an older image, then to any set, then to a partial warm. On a miss apt downloads from the mirror, as it does today. setup@v1, the setup hash and the stale-image check are unchanged. apt still resolves every package against fresh lists and downloads whatever the directory lacks. Self-hosted runners and macOS don't run these steps (runner.environment == 'github-hosted' && runner.os == 'Linux').
  • The package cache job (default branch only). The planner emits apt_cache (a hash of the sorted apt names) and apt_warm, the names to warm. apt_warm is non-empty only when cache_write is true (the build cache's default-branch rule) and some hosted gate uses the shared setup. The job:
    1. looks up the exact key, and stops there on a hit;
    2. otherwise restores the closest entry, and removes any deb the set no longer needs (--print-uris against an empty directory);
    3. runs apt-get install --download-only --no-upgrade;
    4. saves the result.
      It has continue-on-error, and the verdict doesn't wait for it. If the mirror is too slow for the download's 45-minute limit, what was downloaded is saved under a partial key. That includes the file apt was still downloading (from partial/), and the job stops the apt-get that the step timeout leaves running under sudo before saving. The next warm resumes from that entry; gates read it only when no complete entry exists. The step limit sits below the 60-minute job limit on purpose: a job timeout marks the whole run cancelled (run 42825718305), while a step timeout leaves it green.
  • Why only the default branch saves. A cache entry saved on a ci/** ref or a PR is read only by that ref's own later runs, and every ci-gate call pushes a new ref. Saving there would use the 10 GB quota for nothing.
  • Docs. docs/adopting.md gets a "Package cache" section. Callers add push: [main] and a schedule, the same lines as the build cache's seeds.

Measured

On an arachne scratch branch whose caller pointed at a ci-kit e2e branch: this PR plus a planner line that warms on any ref, and, for the partial rows, a separate key prefix and a forced step timeout. Both branches and every cache they saved have since been deleted.

Run Result
Miss, fast mirror 42824758958 (doctest) Apply CI environment: 2m51s. apt update 3 s, download 24 s (48 MB/s), dpkg ~1m38s, setup script ~45 s
Warm, fast mirror 42829993247 download 48 s, save 1.1 GB in 5 s
Warm, slow mirror 42825718305 the first 97 packages took 21 min, then texlive-fonts-extra ran for 37 min until the 60-minute job limit (this commit had no step limit). That cancelled the run
Hit 42830313763 (doctest, tests-py312) restore 12 s / 9 s (~110 MB/s), Need to get 0 B/1167 MB. Apply CI environment: 2m41s / 2m06s. The warm job stopped after its lookup
Partial save 42831935863 the download step hit a forced 2-minute limit, the step's outcome was failure, the partial save ran, and the run stayed green
Resume 42832620398 restored from the partial key, Need to get 0 B, saved the complete key
Cut mid-file 42835893694 throttled download cut short: tar failed with file changed as we read it because apt was still running. Fixed in eb4d09e
Cut mid-file, fixed 42836614608 → 42837175532 the partial save succeeded (41.6 MB on a mirror slow at the time). The next warm restored it (Need to get 1146 MB/1167 MB), finished and saved the complete key

On a hit, the step still unpacks and configures the packages, runs the TeX triggers (~45 s) and the setup script (~41 s). Those take about 2 minutes. The cache removes the download, which is the part a slow mirror stretches past the 20-minute limit.

Before v1 can move

  • arachne's caller needs push: branches: ['ci/**', main] and a schedule. Today nothing in arachne runs on main, so nothing would save the cache.
  • Once v1 moves, the first run on arachne's main saves the entry. Until then, every ref misses, which is today's behavior.

ci-gate: GREEN https://github.com/SSFSKIM/ci-kit/actions/runs/42830999563

Review fixes (91df9b7, dd9464a)

  • Restored packages are checked against the signed index. apt accepts a file already in its archive directory on name and size alone. So after apt-get update and before the install, both jobs check each restored deb's SHA256 against the index entry for its package and version, using a single apt-cache show for all of them. A deb whose hash differs, or that the index doesn't know, is deleted and downloaded again. If the update fails, no restored deb is used. Files in partial/ aren't checked: apt hashes a resumed download as a whole.
    • The first version matched by file name. On Ubuntu 26.04, apt names an amd64v3 build _amd64v3.deb, but the index entry says amd64, so 68 of 98 good debs were dropped (run 42841293986). It now matches by package, version and hash.
    • Cost of the check on a hit: 110 debs checked, 0 dropped, hashing ~1 s; the step takes 6–7 s including the update. Apply then showed Need to get 0 B/1167 MB and took 2m39s / 2m27s (run 42841768617).
  • The cleanup stops only the warm's own apt. The download runs under sudo setsid --wait, and records its process group and, once apt returns, its exit status. The cleanup signals that group, TERM and then KILL, only when no exit status was recorded, which means a timeout or a cancel. Nothing is stopped by name anymore. Tested in e2e: the download hit its limit partway through texlive-fonts-extra, the job stopped that group, the partial save went through cleanly (559 MB, run 42840531108), and the next warm resumed: Need to get 990 MB, Fetched 632 MB (run 42841293986).
  • The warm's last fallback is now the set's partial entry from any image, so a slow mirror across an image change still converges.

…he default branch

On GitHub's Linux runners the Azure mirror can serve about 100 kB/s, and a
large TeX and font set (arachne's: texlive-fonts-extra alone is 669 MB) then
holds "Apply CI environment" past its 20-minute bound.

A hosted Linux gate with apt packages now points apt at a directory the
Actions cache restores, keyed by image, arch and the declared apt set. The
planner names the set (apt_cache) and, on the default branch, the packages a
new package-cache job downloads and saves (apt_warm): only the default
branch's entries are served to every ref. Self-hosted runners are untouched.
…d the next resumes

Measured on arachne: one warm fetched the 1167 MB set in 26 s, the next sat in
the download for over 25 minutes. The download step gets a 45-minute bound;
what it fetched is saved under a partial key that the next warm restores first
and a gate only when no complete entry exists. docs/adopting.md gains the
Package cache section.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T14:24:01.524082Z bbfb44d PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

…umes it

A slow-mirror warm on arachne spent 37 minutes on texlive-fonts-extra (669 MB)
without finishing; a partial save of complete files alone would start it over
every time. The cache paths carry partial/ as well, opened to the cache before
either save, and the warm's pruning covers it.
… its files

A step's timeout ends its bash but not the apt-get under sudo, and its method
went on writing texlive-fonts-extra: tar failed with 'file changed as we read
it' (arachne run 42835893694).
…s own apt; resume across images

Review of #202:
- apt accepts a file in its archive directory on name and size alone
  (acquire-item.cc, pkgAcqArchive). After a fresh update, every restored .deb
  is checked against the index's SHA256 for its version, in both jobs; a
  mismatch or an unknown file is deleted and downloaded again.
- The warm's download runs under setsid, its group recorded; after a timeout
  (no recorded return) the cleanup signals that group alone, never apt by name.
- The warm's last fallback is the set's partial download on any image.
…hash

On Ubuntu 26.04 apt names an amd64v3 build's file _amd64v3.deb while its index
record says Architecture: amd64, so matching by file name dropped 68 of 98
good packages (arachne run 42841293986).
@SSFSKIM
SSFSKIM merged commit dd1d446 into main Nov 10, 2026
4 checks passed
@SSFSKIM
SSFSKIM deleted the setup-apt-cache branch November 10, 2026 15: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.

1 participant