From bec7599845500bc520fd9c67f2742cdf09db6752 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 23 Nov 2026 13:44:21 +0100 Subject: [PATCH 01/10] ci(linux): install cached desktop packages without an apt index refresh The Smoke job failed when a slow Ubuntu mirror could not finish `apt-get update` within 3x30s, although the restored archive cache already held every package the step needs. Install the cached .debs directly, and refresh the index only when they do not cover the package set. The cache key is unique per run attempt so a refreshed set replaces a stale one. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/linux.yml | 56 ++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 0c1bb102df..f7d30e1417 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -58,27 +58,27 @@ jobs: run: node --experimental-strip-types scripts/device-lane-impact.ts replay-linux linux-command-evidence # Unbounded, this step could not fail — it could only stall. On 2026-08-19 a slow mirror - # held apt past the job's 30-minute budget on four main-branch runs and several unrelated - # PRs, which reported as a red check on branches that never ran a line of project code. - # On 2026-10-22 it recurred: the step took 20-60s normally, but 10 of 73 runs hit the - # 6-minute backstop. The Azure mirror appears to be a pull-through cache. A package nobody - # else requested recently (poppler-data, fonts-urw-base35, pulled in by gnome-calculator) - # is fetched from a slow upstream on first request, and the download crawls or stalls. The - # retry that warmed the mirror then succeeded in seconds, which is why re-runs were green. - # Three bounds fix that: the downloaded .debs are cached so most runs never ask the mirror - # for them, a download that does stall is dropped and retried under a per-attempt deadline - # (apt resumes with the files already fetched), and `timeout-minutes` stays as the - # backstop. dpkg itself never runs under a deadline. + # held apt past the job's 30-minute budget. On 2026-10-22 a pull-through mirror crawled on + # packages nobody else had requested recently (poppler-data, fonts-urw-base35, pulled in by + # gnome-calculator). In November 2026 the index refresh itself became the failure: a slow + # archive.ubuntu.com mirror could not serve the ~41 MB of indexes within the deadline. + # The cached .debs already cover the package set, so a run installs them without + # `apt-get update` and never asks a mirror for anything. Only a miss, or an install that the + # cached .debs cannot satisfy (a changed package list or runner image), refreshes the index, + # downloads under a per-attempt deadline (apt resumes with the files already fetched), and + # saves a new cache entry. The key is unique per run attempt, so restore-keys always load + # the most recent entry and a refreshed set replaces a stale one. `timeout-minutes` stays as + # the backstop. dpkg itself never runs under a deadline. - name: Restore Linux desktop package archives - id: apt-archives if: steps.impact.outputs.run != 'false' uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.2.3 with: path: ~/apt-archives - key: apt-archives-${{ runner.os }}-${{ hashFiles('.github/workflows/linux.yml') }} + key: apt-archives-${{ runner.os }}-${{ github.run_id }}-${{ github.run_attempt }} restore-keys: apt-archives-${{ runner.os }}- - name: Install Linux desktop dependencies + id: apt-install if: steps.impact.outputs.run != 'false' timeout-minutes: 6 run: | @@ -105,20 +105,36 @@ jobs: # Retry a network phase under a per-attempt deadline. apt_bounded() { local seconds="$1" - shift - for attempt in 1 2 3; do + local attempts="$2" + shift 2 + for ((attempt = 1; attempt <= attempts; attempt++)); do printf 'APT %s attempt %s start (UTC): %s\n' "$1" "$attempt" "$(date -u +%Y-%m-%dT%H:%M:%SZ)" if sudo timeout --kill-after=5 "$seconds" apt-get "$@" "${APT_OPTS[@]}"; then return 0 fi done - echo "::error::apt-get $1 did not finish within ${seconds}s on 3 attempts" + echo "::error::apt-get $1 did not finish within ${seconds}s on ${attempts} attempts" return 1 } + all_installed() { + local missing + missing="$(dpkg-query -W -f='${db:Status-Status} ${Package}\n' "${PACKAGES[@]}" 2>&1 | grep -v '^installed ' || true)" + [ -z "$missing" ] || { printf 'Not installed:\n%s\n' "$missing"; return 1; } + } mkdir -p ~/apt-archives + printf 'APT cached install start (UTC): %s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" + if compgen -G "$HOME/apt-archives/*.deb" > /dev/null \ + && sudo apt-get install -y --no-install-recommends --no-download "${APT_OPTS[@]}" "$HOME"/apt-archives/*.deb \ + && all_installed; then + printf 'APT cached install complete (UTC): %s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" + exit 0 + fi + echo "::notice::Cached Linux desktop packages do not cover the package set; refreshing the apt index." + echo "refreshed=true" >> "$GITHUB_OUTPUT" sudo cp -n ~/apt-archives/*.deb /var/cache/apt/archives/ 2>/dev/null || true - apt_bounded 30 update - apt_bounded 75 install -y --no-install-recommends --download-only "${PACKAGES[@]}" + # A killed refresh starts over, so a slow mirror needs one window long enough to finish. + apt_bounded 60 2 update + apt_bounded 75 3 install -y --no-install-recommends --download-only "${PACKAGES[@]}" printf 'APT install start (UTC): %s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" sudo apt-get install -y --no-install-recommends "${APT_OPTS[@]}" "${PACKAGES[@]}" printf 'APT install complete (UTC): %s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" @@ -131,11 +147,11 @@ jobs: fi - name: Save Linux desktop package archives - if: steps.impact.outputs.run != 'false' && steps.apt-archives.outputs.cache-hit != 'true' + if: steps.impact.outputs.run != 'false' && steps.apt-install.outputs.refreshed == 'true' uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.2.3 with: path: ~/apt-archives - key: apt-archives-${{ runner.os }}-${{ hashFiles('.github/workflows/linux.yml') }} + key: apt-archives-${{ runner.os }}-${{ github.run_id }}-${{ github.run_attempt }} - name: Start Xvfb and D-Bus if: steps.impact.outputs.run != 'false' From fba967a3b67970b39ea4854720cfbad26a6d5653 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 23 Nov 2026 13:47:35 +0100 Subject: [PATCH 02/10] ci(linux): stage cached debs in the apt archive before the cached install Co-Authored-By: Claude Opus 5.5 --- .github/workflows/linux.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index f7d30e1417..3c697d95db 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -122,6 +122,8 @@ jobs: [ -z "$missing" ] || { printf 'Not installed:\n%s\n' "$missing"; return 1; } } mkdir -p ~/apt-archives + # apt resolves the local .debs only when it also finds them in its own archive directory. + sudo cp -n ~/apt-archives/*.deb /var/cache/apt/archives/ 2>/dev/null || true printf 'APT cached install start (UTC): %s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" if compgen -G "$HOME/apt-archives/*.deb" > /dev/null \ && sudo apt-get install -y --no-install-recommends --no-download "${APT_OPTS[@]}" "$HOME"/apt-archives/*.deb \ @@ -131,7 +133,6 @@ jobs: fi echo "::notice::Cached Linux desktop packages do not cover the package set; refreshing the apt index." echo "refreshed=true" >> "$GITHUB_OUTPUT" - sudo cp -n ~/apt-archives/*.deb /var/cache/apt/archives/ 2>/dev/null || true # A killed refresh starts over, so a slow mirror needs one window long enough to finish. apt_bounded 60 2 update apt_bounded 75 3 install -y --no-install-recommends --download-only "${PACKAGES[@]}" From 5564e2c802622a0628067679d93efbaa2c2e24a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 23 Nov 2026 14:00:53 +0100 Subject: [PATCH 03/10] ci(linux): leave dpkg headroom inside the install step budget Co-Authored-By: Claude Opus 5.5 --- .github/workflows/linux.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 3c697d95db..2ea970134d 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -134,8 +134,9 @@ jobs: echo "::notice::Cached Linux desktop packages do not cover the package set; refreshing the apt index." echo "refreshed=true" >> "$GITHUB_OUTPUT" # A killed refresh starts over, so a slow mirror needs one window long enough to finish. + # The windows total 240s, which leaves dpkg two minutes of the 6-minute step. apt_bounded 60 2 update - apt_bounded 75 3 install -y --no-install-recommends --download-only "${PACKAGES[@]}" + apt_bounded 60 2 install -y --no-install-recommends --download-only "${PACKAGES[@]}" printf 'APT install start (UTC): %s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" sudo apt-get install -y --no-install-recommends "${APT_OPTS[@]}" "${PACKAGES[@]}" printf 'APT install complete (UTC): %s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" From 8325c4bf0da7c472fe2c458b82ad2ba9e4b4e3f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 23 Nov 2026 15:06:43 +0100 Subject: [PATCH 04/10] ci(linux): resolve cached packages against the lists that selected them Cache the authenticated package lists with the archives apt selected for the package set, keep both outside the system directories, and install only when the offline plan needs no download. A failed cached install recovers dpkg state and falls back to a clean archive directory. Every install runs with --no-download, and the step budget covers every lock wait and network window. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/linux.yml | 128 ++++++++++++++++++++++-------------- 1 file changed, 77 insertions(+), 51 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 2ea970134d..077783979a 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -62,34 +62,46 @@ jobs: # packages nobody else had requested recently (poppler-data, fonts-urw-base35, pulled in by # gnome-calculator). In November 2026 the index refresh itself became the failure: a slow # archive.ubuntu.com mirror could not serve the ~41 MB of indexes within the deadline. - # The cached .debs already cover the package set, so a run installs them without - # `apt-get update` and never asks a mirror for anything. Only a miss, or an install that the - # cached .debs cannot satisfy (a changed package list or runner image), refreshes the index, - # downloads under a per-attempt deadline (apt resumes with the files already fetched), and - # saves a new cache entry. The key is unique per run attempt, so restore-keys always load - # the most recent entry and a refreshed set replaces a stale one. `timeout-minutes` stays as - # the backstop. dpkg itself never runs under a deadline. - - name: Restore Linux desktop package archives + # + # The cache holds the package lists that the last refresh authenticated, together with the + # archives that apt selected for PACKAGES from them. A run resolves PACKAGES against those + # lists and installs only when the plan needs no download, so it never asks a mirror for + # anything. Only a miss, a plan that needs a download (a changed package list or runner + # image), or a failed install discards the restored set, refreshes the index, downloads + # into an empty archive directory and saves a new entry. The key is unique per run attempt, + # so restore-keys load the newest entry and a refreshed set replaces a stale one. + # + # Every install runs with --no-download, so the network is reached only inside a bounded + # phase. Worst case: cached install lock wait 60s, refresh 2 x (60s + 5s kill grace), + # download 2 x (75s + 5s), final install lock wait 60s. That is 410s of the 540s step, + # which leaves 130s for dpkg (2-5s per run in CI) and the cache copy. dpkg itself never + # runs under a deadline. + - name: Restore Linux desktop packages if: steps.impact.outputs.run != 'false' uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.2.3 with: - path: ~/apt-archives - key: apt-archives-${{ runner.os }}-${{ github.run_id }}-${{ github.run_attempt }} - restore-keys: apt-archives-${{ runner.os }}- + path: ~/apt-cache + key: apt-cache-${{ runner.os }}-${{ github.run_id }}-${{ github.run_attempt }} + restore-keys: apt-cache-${{ runner.os }}- - name: Install Linux desktop dependencies id: apt-install if: steps.impact.outputs.run != 'false' - timeout-minutes: 6 + timeout-minutes: 9 run: | set -euo pipefail + CACHE="$HOME/apt-cache" APT_OPTS=( -o Acquire::Retries=2 -o Acquire::http::Timeout=15 -o Acquire::https::Timeout=15 # The runner's own unattended-upgrades timer holds the dpkg lock; wait, don't hang. -o DPkg::Lock::Timeout=60 + # A restored archive stays out of the system archive directory, so a fallback never reuses it. + -o "Dir::Cache::Archives=$CACHE/archives/" ) + # The cached attempt resolves against the restored lists; the fallback clears this. + LIST_OPTS=(-o "Dir::State::Lists=$CACHE/lists/") PACKAGES=( xvfb xdotool @@ -102,58 +114,72 @@ jobs: gnome-calculator wmctrl ) - # Retry a network phase under a per-attempt deadline. + stamp() { printf 'APT %s (UTC): %s\n' "$1" "$(date -u +%Y-%m-%dT%H:%M:%SZ)"; } + all_installed() { + local missing + missing="$(dpkg-query -W -f='${db:Status-Status} ${Package}\n' "${PACKAGES[@]}" 2>&1 | grep -v '^installed ' || true)" + [ -z "$missing" ] || { printf 'Not installed:\n%s\n' "$missing"; return 1; } + } + # Succeeds when apt can install PACKAGES from the archive directory without a download. + offline_plan() { + local uris + uris="$(sudo apt-get install -qq --print-uris --no-install-recommends "${APT_OPTS[@]}" "${LIST_OPTS[@]}" "${PACKAGES[@]}")" || return 1 + [ -z "$uris" ] || { printf 'Archives to download:\n%s\n' "$uris"; return 1; } + } + install_offline() { + sudo apt-get install -y --no-install-recommends --no-download "${APT_OPTS[@]}" "${LIST_OPTS[@]}" "${PACKAGES[@]}" + } + # Retry a network phase under a per-attempt deadline. An attempt passes only when its check passes too. apt_bounded() { - local seconds="$1" - local attempts="$2" + local seconds="$1" check="$2" shift 2 - for ((attempt = 1; attempt <= attempts; attempt++)); do - printf 'APT %s attempt %s start (UTC): %s\n' "$1" "$attempt" "$(date -u +%Y-%m-%dT%H:%M:%SZ)" - if sudo timeout --kill-after=5 "$seconds" apt-get "$@" "${APT_OPTS[@]}"; then + for attempt in 1 2; do + stamp "$1 attempt $attempt start" + if sudo timeout --kill-after=5 "$seconds" apt-get "$@" "${APT_OPTS[@]}" && "$check"; then return 0 fi done - echo "::error::apt-get $1 did not finish within ${seconds}s on ${attempts} attempts" + echo "::error::apt-get $1 did not finish within ${seconds}s on 2 attempts" return 1 } - all_installed() { - local missing - missing="$(dpkg-query -W -f='${db:Status-Status} ${Package}\n' "${PACKAGES[@]}" 2>&1 | grep -v '^installed ' || true)" - [ -z "$missing" ] || { printf 'Not installed:\n%s\n' "$missing"; return 1; } - } - mkdir -p ~/apt-archives - # apt resolves the local .debs only when it also finds them in its own archive directory. - sudo cp -n ~/apt-archives/*.deb /var/cache/apt/archives/ 2>/dev/null || true - printf 'APT cached install start (UTC): %s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" - if compgen -G "$HOME/apt-archives/*.deb" > /dev/null \ - && sudo apt-get install -y --no-install-recommends --no-download "${APT_OPTS[@]}" "$HOME"/apt-archives/*.deb \ - && all_installed; then - printf 'APT cached install complete (UTC): %s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" + if all_installed; then exit 0 fi - echo "::notice::Cached Linux desktop packages do not cover the package set; refreshing the apt index." - echo "refreshed=true" >> "$GITHUB_OUTPUT" - # A killed refresh starts over, so a slow mirror needs one window long enough to finish. - # The windows total 240s, which leaves dpkg two minutes of the 6-minute step. - apt_bounded 60 2 update - apt_bounded 60 2 install -y --no-install-recommends --download-only "${PACKAGES[@]}" - printf 'APT install start (UTC): %s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" - sudo apt-get install -y --no-install-recommends "${APT_OPTS[@]}" "${PACKAGES[@]}" - printf 'APT install complete (UTC): %s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" - # Drop archives for versions the index no longer offers so the cache cannot grow. - sudo apt-get autoclean -q - rm -f ~/apt-archives/*.deb - # An unmatched glob stays literal and fails cp under set -e when the runner image already has every package. - if compgen -G "/var/cache/apt/archives/*.deb" > /dev/null; then - cp /var/cache/apt/archives/*.deb ~/apt-archives/ + mkdir -p "$CACHE/lists/partial" "$CACHE/archives/partial" + stamp "cached install start" + cached_dpkg=false + if offline_plan && cached_dpkg=true && install_offline && all_installed; then + stamp "cached install complete" + exit 0 + fi + echo "::notice::The cached Linux desktop packages cannot install the package set; refreshing the apt index." + # A killed or failed dpkg run leaves state that makes apt refuse every later command. + if [ "$cached_dpkg" = true ]; then + sudo dpkg --configure -a + fi + sudo rm -rf "$CACHE" + mkdir -p "$CACHE/lists" "$CACHE/archives/partial" + LIST_OPTS=() + apt_bounded 60 true update + apt_bounded 75 offline_plan install -y --no-install-recommends --download-only "${PACKAGES[@]}" + stamp "install start" + install_offline + all_installed + stamp "install complete" + # Keep the lists that selected these archives; the cached attempt resolves against them. + sudo find /var/lib/apt/lists -maxdepth 1 -type f \( -name '*Release*' -o -name '*_Packages*' \) -exec cp -t "$CACHE/lists/" {} + + sudo rm -rf "$CACHE/archives/partial" "$CACHE/archives/lock" + sudo chown -R "$(id -u):$(id -g)" "$CACHE" + if compgen -G "$CACHE/archives/*.deb" > /dev/null; then + echo "save=true" >> "$GITHUB_OUTPUT" fi - - name: Save Linux desktop package archives - if: steps.impact.outputs.run != 'false' && steps.apt-install.outputs.refreshed == 'true' + - name: Save Linux desktop packages + if: steps.impact.outputs.run != 'false' && steps.apt-install.outputs.save == 'true' uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.2.3 with: - path: ~/apt-archives - key: apt-archives-${{ runner.os }}-${{ github.run_id }}-${{ github.run_attempt }} + path: ~/apt-cache + key: apt-cache-${{ runner.os }}-${{ github.run_id }}-${{ github.run_attempt }} - name: Start Xvfb and D-Bus if: steps.impact.outputs.run != 'false' From b7f917e8fe1f9a320fa5b3ca8d143c6781061023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 23 Nov 2026 15:10:26 +0100 Subject: [PATCH 05/10] ci(linux): keep the preinstalled-package probe quiet Co-Authored-By: Claude Opus 5.5 --- .github/workflows/linux.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 077783979a..342f6a5297 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -142,7 +142,7 @@ jobs: echo "::error::apt-get $1 did not finish within ${seconds}s on 2 attempts" return 1 } - if all_installed; then + if all_installed > /dev/null; then exit 0 fi mkdir -p "$CACHE/lists/partial" "$CACHE/archives/partial" From 77b7c0aa148c347e9947de990ddf1e12a30ccfe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 23 Nov 2026 15:11:43 +0100 Subject: [PATCH 06/10] ci(linux): repair what a failed cached install left before the fallback Co-Authored-By: Claude Opus 5.5 --- .github/workflows/linux.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 342f6a5297..7075925967 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -153,20 +153,27 @@ jobs: exit 0 fi echo "::notice::The cached Linux desktop packages cannot install the package set; refreshing the apt index." - # A killed or failed dpkg run leaves state that makes apt refuse every later command. + # A killed or failed dpkg run leaves a journal that makes apt refuse every later command. + # Packages whose dependency that run never unpacked stay unconfigured, so this exits nonzero. if [ "$cached_dpkg" = true ]; then - sudo dpkg --configure -a + sudo dpkg --configure -a || true fi sudo rm -rf "$CACHE" mkdir -p "$CACHE/lists" "$CACHE/archives/partial" LIST_OPTS=() apt_bounded 60 true update + if [ "$cached_dpkg" = true ]; then + # On a broken system apt resolves only the named packages, so name what --fix-broken would install. + mapfile -t -O "${#PACKAGES[@]}" PACKAGES < <(sudo apt-get install --fix-broken -s -qq "${APT_OPTS[@]}" | awk '/^Inst /{print $2}') + fi apt_bounded 75 offline_plan install -y --no-install-recommends --download-only "${PACKAGES[@]}" stamp "install start" install_offline all_installed stamp "install complete" # Keep the lists that selected these archives; the cached attempt resolves against them. + # After a repair the set holds only what the repair fetched, so the next run's plan needs a + # download and that run saves a complete set. sudo find /var/lib/apt/lists -maxdepth 1 -type f \( -name '*Release*' -o -name '*_Packages*' \) -exec cp -t "$CACHE/lists/" {} + sudo rm -rf "$CACHE/archives/partial" "$CACHE/archives/lock" sudo chown -R "$(id -u):$(id -g)" "$CACHE" From e48894da0e2b647b0589052a6caea3d19d326439 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 23 Nov 2026 16:05:24 +0100 Subject: [PATCH 07/10] ci(linux): verify restored apt lists and archives, keep fallback lists job-private Check each restored InRelease against the Ubuntu keyring, each Packages list against its signed digest, and each archive against the SHA-256 in its package record before the restored install. The fallback refreshes into the job-private list directory, so the download, plan, install and save all use one index. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/linux.yml | 72 +++++++++++++++++++++++++------------ 1 file changed, 50 insertions(+), 22 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 7075925967..0672233b46 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -63,19 +63,20 @@ jobs: # gnome-calculator). In November 2026 the index refresh itself became the failure: a slow # archive.ubuntu.com mirror could not serve the ~41 MB of indexes within the deadline. # - # The cache holds the package lists that the last refresh authenticated, together with the - # archives that apt selected for PACKAGES from them. A run resolves PACKAGES against those - # lists and installs only when the plan needs no download, so it never asks a mirror for - # anything. Only a miss, a plan that needs a download (a changed package list or runner - # image), or a failed install discards the restored set, refreshes the index, downloads - # into an empty archive directory and saves a new entry. The key is unique per run attempt, - # so restore-keys load the newest entry and a refreshed set replaces a stale one. + # The cache holds the Ubuntu package lists of the last refresh and the archives that apt + # selected for PACKAGES from them. A run verifies the signatures, list digests and archive + # hashes, resolves PACKAGES against those lists and installs only when the plan needs no + # download, so it never asks a mirror for anything. A miss, a failed check, a plan that + # needs a download (a changed package list or runner image) or a failed install discards + # the restored set, refreshes into empty job-private directories and saves a new entry. + # The key is unique per run attempt, so restore-keys load the newest entry and a refreshed + # set replaces a stale one. # # Every install runs with --no-download, so the network is reached only inside a bounded # phase. Worst case: cached install lock wait 60s, refresh 2 x (60s + 5s kill grace), # download 2 x (75s + 5s), final install lock wait 60s. That is 410s of the 540s step, - # which leaves 130s for dpkg (2-5s per run in CI) and the cache copy. dpkg itself never - # runs under a deadline. + # which leaves 130s for dpkg (2-5s per run in CI), the checks and the cache copy. dpkg + # itself never runs under a deadline. - name: Restore Linux desktop packages if: steps.impact.outputs.run != 'false' uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.2.3 @@ -91,17 +92,18 @@ jobs: run: | set -euo pipefail CACHE="$HOME/apt-cache" + KEYRING=/usr/share/keyrings/ubuntu-archive-keyring.gpg APT_OPTS=( -o Acquire::Retries=2 -o Acquire::http::Timeout=15 -o Acquire::https::Timeout=15 # The runner's own unattended-upgrades timer holds the dpkg lock; wait, don't hang. -o DPkg::Lock::Timeout=60 - # A restored archive stays out of the system archive directory, so a fallback never reuses it. + # Job-private lists and archives: the runner's periodic index update cannot change the + # plan between download and install, and a fallback never reuses a restored archive. + -o "Dir::State::Lists=$CACHE/lists/" -o "Dir::Cache::Archives=$CACHE/archives/" ) - # The cached attempt resolves against the restored lists; the fallback clears this. - LIST_OPTS=(-o "Dir::State::Lists=$CACHE/lists/") PACKAGES=( xvfb xdotool @@ -120,14 +122,39 @@ jobs: missing="$(dpkg-query -W -f='${db:Status-Status} ${Package}\n' "${PACKAGES[@]}" 2>&1 | grep -v '^installed ' || true)" [ -z "$missing" ] || { printf 'Not installed:\n%s\n' "$missing"; return 1; } } + # apt trusts a list by the presence of InRelease and an archive by its size, so check the + # restored set: each InRelease against the Ubuntu keyring, each Packages list against its + # signed digest, and each archive against the SHA-256 in its verified package record. + verify_restored() { + local signed name suite path sha key + signed="$(mktemp -d)" + compgen -G "$CACHE/lists/*_InRelease" > /dev/null && compgen -G "$CACHE/archives/*.deb" > /dev/null || return 1 + for list in "$CACHE"/lists/*_InRelease; do + gpgv --quiet --keyring "$KEYRING" --output "$signed/${list##*/}" "$list" 2> /dev/null || { echo "Unverified: $list"; return 1; } + done + for list in "$CACHE"/lists/*_Packages; do + name="${list##*/}" + suite="${name#*_dists_}" + suite="${suite%%_*}" + path="$(tr _ / <<< "${name#*_dists_"$suite"_}")" + sha="$(sha256sum "$list" | cut -d' ' -f1)" + grep -qE "^ $sha +[0-9]+ $path\$" "$signed/${name%%_dists_*}_dists_${suite}_InRelease" || { echo "Unverified: $list"; return 1; } + done + awk '/^Package:/{p=$2} /^Architecture:/{a=$2} /^Version:/{v=$2} /^SHA256:/{print $2 " " p "_" v "_" a}' "$CACHE"/lists/*_Packages > "$signed/records" + for deb in "$CACHE"/archives/*.deb; do + key="$(dpkg-deb --show --showformat='${Package}_${Version}_${Architecture}' "$deb")" + sha="$(sha256sum "$deb" | cut -d' ' -f1)" + grep -qxF "$sha $key" "$signed/records" || { echo "Unverified: $deb"; return 1; } + done + } # Succeeds when apt can install PACKAGES from the archive directory without a download. offline_plan() { local uris - uris="$(sudo apt-get install -qq --print-uris --no-install-recommends "${APT_OPTS[@]}" "${LIST_OPTS[@]}" "${PACKAGES[@]}")" || return 1 + uris="$(sudo apt-get install -qq --print-uris --no-install-recommends "${APT_OPTS[@]}" "${PACKAGES[@]}")" || return 1 [ -z "$uris" ] || { printf 'Archives to download:\n%s\n' "$uris"; return 1; } } install_offline() { - sudo apt-get install -y --no-install-recommends --no-download "${APT_OPTS[@]}" "${LIST_OPTS[@]}" "${PACKAGES[@]}" + sudo apt-get install -y --no-install-recommends --no-download "${APT_OPTS[@]}" "${PACKAGES[@]}" } # Retry a network phase under a per-attempt deadline. An attempt passes only when its check passes too. apt_bounded() { @@ -148,7 +175,7 @@ jobs: mkdir -p "$CACHE/lists/partial" "$CACHE/archives/partial" stamp "cached install start" cached_dpkg=false - if offline_plan && cached_dpkg=true && install_offline && all_installed; then + if verify_restored && offline_plan && cached_dpkg=true && install_offline && all_installed; then stamp "cached install complete" exit 0 fi @@ -159,8 +186,7 @@ jobs: sudo dpkg --configure -a || true fi sudo rm -rf "$CACHE" - mkdir -p "$CACHE/lists" "$CACHE/archives/partial" - LIST_OPTS=() + mkdir -p "$CACHE/lists/partial" "$CACHE/archives/partial" apt_bounded 60 true update if [ "$cached_dpkg" = true ]; then # On a broken system apt resolves only the named packages, so name what --fix-broken would install. @@ -171,12 +197,14 @@ jobs: install_offline all_installed stamp "install complete" - # Keep the lists that selected these archives; the cached attempt resolves against them. - # After a repair the set holds only what the repair fetched, so the next run's plan needs a - # download and that run saves a complete set. - sudo find /var/lib/apt/lists -maxdepth 1 -type f \( -name '*Release*' -o -name '*_Packages*' \) -exec cp -t "$CACHE/lists/" {} + - sudo rm -rf "$CACHE/archives/partial" "$CACHE/archives/lock" + sudo rm -rf "$CACHE/lists/partial" "$CACHE/lists/lock" "$CACHE/archives/partial" "$CACHE/archives/lock" sudo chown -R "$(id -u):$(id -g)" "$CACHE" + # Save only Ubuntu lists, the ones verify_restored can check. After a repair the set holds only + # what the repair fetched, so the next run's plan needs a download and that run saves a full set. + for list in "$CACHE"/lists/*_InRelease; do + gpgv --quiet --keyring "$KEYRING" "$list" 2> /dev/null || rm -f "${list%InRelease}"* + done + find "$CACHE/lists" -type f ! -name '*_InRelease' ! -name '*_Packages' -delete if compgen -G "$CACHE/archives/*.deb" > /dev/null; then echo "save=true" >> "$GITHUB_OUTPUT" fi From ad49f00457a000e2dca421543888eb0a46606d32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 23 Nov 2026 16:07:32 +0100 Subject: [PATCH 08/10] ci(linux): log what the restored-set check verified Co-Authored-By: Claude Opus 5.5 --- .github/workflows/linux.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 0672233b46..bfe629f556 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -146,6 +146,7 @@ jobs: sha="$(sha256sum "$deb" | cut -d' ' -f1)" grep -qxF "$sha $key" "$signed/records" || { echo "Unverified: $deb"; return 1; } done + stamp "verified $(compgen -G "$CACHE/lists/*_Packages" | wc -l) lists and $(compgen -G "$CACHE/archives/*.deb" | wc -l) archives" } # Succeeds when apt can install PACKAGES from the archive directory without a download. offline_plan() { From 29b5e254446cb0c76f4030d8ddb814c21d47a761 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 23 Nov 2026 17:08:22 +0100 Subject: [PATCH 09/10] ci(linux): verify restored archives by the file name apt looks up Reject any restored list file other than InRelease and plain Packages, match each archive to the record whose escaped file name apt selects, and check every command's status inside the verifier. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/linux.yml | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index bfe629f556..611de01867 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -122,12 +122,16 @@ jobs: missing="$(dpkg-query -W -f='${db:Status-Status} ${Package}\n' "${PACKAGES[@]}" 2>&1 | grep -v '^installed ' || true)" [ -z "$missing" ] || { printf 'Not installed:\n%s\n' "$missing"; return 1; } } - # apt trusts a list by the presence of InRelease and an archive by its size, so check the - # restored set: each InRelease against the Ubuntu keyring, each Packages list against its - # signed digest, and each archive against the SHA-256 in its verified package record. + # apt trusts a list by the presence of InRelease and an archive by its file name and size, + # so check the restored set: only InRelease and plain Packages lists, each InRelease + # against the Ubuntu keyring, each list against its signed digest, and each archive + # against the SHA-256 of the record whose escaped file name apt looks up. + # This runs in an if condition, where errexit is off, so every command checks its status. verify_restored() { - local signed name suite path sha key - signed="$(mktemp -d)" + local signed extra name suite path sha + signed="$(mktemp -d)" || return 1 + extra="$(find "$CACHE/lists" -mindepth 1 ! -name '*_InRelease' ! -name '*_Packages' ! -path "$CACHE/lists/partial")" || return 1 + [ -z "$extra" ] || { printf 'Unexpected list files:\n%s\n' "$extra"; return 1; } compgen -G "$CACHE/lists/*_InRelease" > /dev/null && compgen -G "$CACHE/archives/*.deb" > /dev/null || return 1 for list in "$CACHE"/lists/*_InRelease; do gpgv --quiet --keyring "$KEYRING" --output "$signed/${list##*/}" "$list" 2> /dev/null || { echo "Unverified: $list"; return 1; } @@ -136,15 +140,16 @@ jobs: name="${list##*/}" suite="${name#*_dists_}" suite="${suite%%_*}" - path="$(tr _ / <<< "${name#*_dists_"$suite"_}")" - sha="$(sha256sum "$list" | cut -d' ' -f1)" - grep -qE "^ $sha +[0-9]+ $path\$" "$signed/${name%%_dists_*}_dists_${suite}_InRelease" || { echo "Unverified: $list"; return 1; } + path="$(tr _ / <<< "${name#*_dists_"$suite"_}")" || return 1 + sha="$(sha256sum "$list")" || return 1 + grep -qE "^ ${sha%% *} +[0-9]+ $path\$" "$signed/${name%%_dists_*}_dists_${suite}_InRelease" || { echo "Unverified: $list"; return 1; } done - awk '/^Package:/{p=$2} /^Architecture:/{a=$2} /^Version:/{v=$2} /^SHA256:/{print $2 " " p "_" v "_" a}' "$CACHE"/lists/*_Packages > "$signed/records" + # apt stores an archive as Package_Version_Architecture.deb, escaping % and : in the version. + awk '/^Package:/{p=$2} /^Architecture:/{a=$2} /^Version:/{v=$2; gsub(/%/, "%25", v); gsub(/:/, "%3a", v)} + /^SHA256:/{print $2 " " p "_" v "_" a ".deb"}' "$CACHE"/lists/*_Packages > "$signed/records" || return 1 for deb in "$CACHE"/archives/*.deb; do - key="$(dpkg-deb --show --showformat='${Package}_${Version}_${Architecture}' "$deb")" - sha="$(sha256sum "$deb" | cut -d' ' -f1)" - grep -qxF "$sha $key" "$signed/records" || { echo "Unverified: $deb"; return 1; } + sha="$(sha256sum "$deb")" || return 1 + grep -qxF "${sha%% *} ${deb##*/}" "$signed/records" || { echo "Unverified: $deb"; return 1; } done stamp "verified $(compgen -G "$CACHE/lists/*_Packages" | wc -l) lists and $(compgen -G "$CACHE/archives/*.deb" | wc -l) archives" } From 3eeb9b065580eab4deae7a942dfd7fa72130b2ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 23 Nov 2026 17:10:38 +0100 Subject: [PATCH 10/10] ci(linux): save only the list files the restore check accepts Co-Authored-By: Claude Opus 5.5 --- .github/workflows/linux.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 611de01867..cce399fab0 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -210,7 +210,7 @@ jobs: for list in "$CACHE"/lists/*_InRelease; do gpgv --quiet --keyring "$KEYRING" "$list" 2> /dev/null || rm -f "${list%InRelease}"* done - find "$CACHE/lists" -type f ! -name '*_InRelease' ! -name '*_Packages' -delete + find "$CACHE/lists" -mindepth 1 ! -name '*_InRelease' ! -name '*_Packages' -delete if compgen -G "$CACHE/archives/*.deb" > /dev/null; then echo "save=true" >> "$GITHUB_OUTPUT" fi