Skip to content

Cache the TeX Live apt install: a slow Ubuntu mirror stalls PDF builds for hours #224

Closed

Description

@mmcky

Every lecture build that makes the PDF downloads TeX Live from the Ubuntu archive on every run. For lecture-python-advanced.myst that is 138 packages and 1013 MB. It usually takes a minute or two, but it depends entirely on the speed of the mirror the runner is given, and when that mirror is slow, the build stalls for hours without failing.

What happened

On 2026-10-25 the publish-2026oct25 publish of lecture-python-advanced.myst (run 40234381123) sat in "Install latex dependencies":

  • Attempt 1 downloaded 82 MB in 23 minutes from azure.archive.ubuntu.com, about 60 KB/s. At that rate the full 1013 MB would have taken about 4.5 hours, close to the 6-hour job limit. It was cancelled by hand.
  • Attempt 2 was still in the same step 27 minutes later.
  • The PR's CI run for the same commit, an hour earlier, downloaded the same 1013 MB in about a minute.

Nothing errors, so nothing alerts: the job simply runs on, and someone has to notice.

Who is affected

  • setup-environment with install-latex: 'true' runs an uncached apt-get update and apt-get install.
  • No lecture repo found by code search uses that input. Instead, about 17 repos inline their own sudo apt-get install texlive-… step, usually in ci.yml, cache.yml and publish.yml. They include lecture-python-advanced.myst, lecture-python-intro, lecture-python-programming, lecture-julia.myst, lecture-dle, lecture-dynamics, lecture-eqm, lecture-dps, lecture-tools-techniques, lecture-econometrics-machine-learning, lecture-python-programming.fa, lecture-intro.zh-cn, lecture-python.zh-cn, continuous_time_mcs and dse_2023.

A fix therefore needs to be easy for those inline steps to adopt, not only for repos that already use setup-environment.

Proposal

Cache the downloaded .deb archives with actions/cache, and install from the cache.

  • Key. The runner image (ImageOS and ImageVersion) plus a hash of the package list, with a restore-keys fallback on the image prefix so that a changed list re-downloads only what changed. A cache-version input lets a repo force a fresh cache.
  • Miss. Download into a workspace directory with apt-get install --download-only -o Dir::Cache::archives=<dir>, and hand the directory to the runner user so that actions/cache can save it.
  • Hit. Install from that directory, so that no mirror is contacted for the archives. Whether apt-get update can also be skipped on a hit, for example by installing the cached files directly with apt-get install ./*.deb, needs testing, since update also goes to the mirror.
  • Cache .debs, not installed files. dpkg still runs TeX Live's maintainer scripts (fmtutil, mktexlsr, font maps), so the result is the same as today's install. Actions that cache the installed files instead, such as awalsh128/cache-apt-pkgs-action, skip those scripts, which is fragile for TeX Live.
  • Guard the miss. Add a timeout-minutes on the step and -o Acquire::Retries=3, so that a slow mirror on a cache miss fails loudly in minutes rather than running for hours.

Delivery. I suggest a small standalone setup-latex action, which takes a package list or file plus cache-version. An inline repo can then switch with a one-step change, and setup-environment's install-latex path can call the same action internally.

Cost. About 1 GB of cache per repo, against the default 10 GB per-repository limit. Caches are per repository, so each repo pays one full download after each runner-image update.

Alternative already available

The QuantEcon images (ghcr.io/quantecon/quantecon-build, ghcr.io/quantecon/quantecon) already include TeX Live. They pull about 2.9 GB from GHCR, a different network path from the Ubuntu mirrors. Repos that move to containers sidestep this problem, but that is a larger migration than adopting a cached install step.

🤖 Generated with Claude Code

Activity

  1. added
    infrastructure
    enhancement
    on Oct 25, 2026
  2. mmcky commented on Nov 7, 2026

    @mmcky
    ContributorAuthor

    Checked against main at e40924a on 2026-11-07. The problem is real, and larger than one incident. Since 2026-09-01, 12 of 220 TeX Live install steps across 6 active lecture repos took over 5 minutes, and 10 over 15 minutes: 267, 159, 129 and 40 minutes in lecture-python-advanced.myst; 354 (cancelled near the 6-hour limit), 52, 35, 21 and 20 minutes in lecture-python.zh-cn; and 92 minutes (cancelled) in lecture-intro.zh-cn. That is about 20 hours of runner time. The logs show slow downloads, 64–690 kB/s. The incident's second attempt did finish, after 2 h 09 min ("Fetched 1013 MB in 2h 6min 48s (133 kB/s)"). On a normal day, the 26.04 runner fetches lecture-python-advanced.myst's 141 packages (1077 MB) in 28 s, then spends about 90 s in dpkg and TeX's triggers, which no cache can save.

    Who is affected. 15 repos inline their own apt-get install texlive-…, the 15 named above, and none has moved to a container; six of them are dormant. No repo uses setup-environment's install-latex. Ten install the same nine packages; lecture-python.zh-cn's CI adds latex-cjk-all (1352 MB). The planned container moves cover intro, programming and advanced, but not the two zh-cn repos, which had 7 of the 12 slow steps.

    What changes in the proposal. (1) setup-environment cannot call the new action with uses:. quantecon/actions/setup-latex@v0 would run the released copy, never the pull request's (the skew build-jupyter-cache already has), and ./setup-latex resolves against the caller's workspace. The two actions share a script under scripts/ instead, as they already share workflow-command.sh. (2) No -o Acquire::Retries=3: the 26.04 runner image sets Acquire::Retries "1" and 15 s timeouts on purpose, so that a stalled mirror fails over to archive.ubuntu.com quickly. A higher count delays that, and the failover never trips on a mirror that trickles anyway. (3) A composite action's step cannot take timeout-minutes, so the timeout is a timeout in the script, around apt-get update and the download only, never around dpkg. (4) The key hashes the installed package set (plus the OS release, architecture, cache-version and the package list), not ImageOS/ImageVersion. These exist only on GitHub's images, and an exact hit then means the cache holds every package this host lacks.

    apt-get update on a hit. On an exact hit it is skipped: the cached archives are installed as local ./*.deb files with downloads disabled, so dpkg runs every maintainer script as it does today. A fallback restore or a miss runs update, downloads only what the cache lacks, installs, prunes stale archives and saves. The harness proves the hit by pointing apt's proxy at a local stand-in that records every request, and asserting it recorded none.

    The maintainer's decisions, 2026-11-07 (the timeout default revised from off to 30 minutes the same day, at the maintainer's request). Delivery: both, sharing one script under scripts/, in two pull requests. The first adds a new action, setup-latex, which nothing calls yet. The second moves setup-environment's install-latex onto the same script and cache, and merges only after the scheduled lecture-matrix run of 2026-11-09, which uses main's setup-environment. setup-latex's interface: exactly one of packages (whitespace- or newline-separated, # comments allowed) or requirements-file (the format of latex-requirements-file) must be set, otherwise the action fails before installing anything; no bundled default list. It also takes cache-version (default v1) and download-timeout-minutes, and outputs cache-hit, meaning what conda-cache-hit means. The timeout: download-timeout-minutes defaults to 30, and 0 means no limit. setup-environment: install-latex reuses cache-version, gains a latex-cache-hit output, and uses the same fixed 30-minute download limit, with no input. The CHANGELOG entry is Changed, with no ⚠️ marker, and says that a miss whose download runs past 30 minutes now fails rather than finishing slowly. No QuantEcon repository passes install-latex. Saving: on every miss or fallback restore, except from a tag ref, whose cache no later run could restore. No input.

    Claude Code (on behalf of mmcky), organiser session; the check by the mini:actions-latex session

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

    enhancementinfrastructure

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions