Skip to content

ci(linux): install cached desktop packages without an apt index refresh - #5021

Merged
thymikee merged 10 commits into
mainfrom
ci/linux-smoke-apt-update
Nov 23, 2026
Merged

thymikee merged 10 commits into
mainfrom
ci/linux-smoke-apt-update

Conversation

@thymikee

@thymikee thymikee commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Summary

Smoke failed in 21 of the last 60 Linux runs. Each sampled failure (45166777462, 45157212041, 45145924854) hit apt-get update did not finish within 30s on 3 attempts. In job 137665639883, a slow archive.ubuntu.com mirror killed each attempt mid-InRelease. Green runs then needed 0 B of archives: the cache already held every package.

The cache holds the Ubuntu lists of the last refresh and the archives apt selected for PACKAGES. A run accepts only InRelease and plain Packages lists. It checks each InRelease with gpgv, each list against its signed digest, and each archive's SHA-256 against the record for the escaped file name apt looks up. It installs with --no-download only when --print-uris plans no download. Any failure recovers dpkg state, discards the set, and refreshes, downloads, installs and saves through one job-private directory. The step budget covers every lock wait and window (410s of 540s).

Before / after

No observable change to the product.

Install step Before After
Restored set 10s, or 90s fail 5s, 7s, 7s
Rejected set – 24–36s, clean fallback

Validation

Head 3eeb9b0: run 45215082154, attempts 1–3 all green (verified 15 lists and 41 archives).
Temporary commits, now dropped, tested rejected sets:

  • extra .lz4 list (45214284821)
  • another package's archive under a selected name (45214737470)
  • tampered archive (45202010948)

Run 45213544759 rejected a stale entry, and run 45192438725 tested dpkg repair.

🤖 Generated with Claude Code

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 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.55 MB 6.55 MB -1.8 kB
Package (unpacked) 6.55 MB 6.55 MB -1.8 kB
Package (download) 2.00 MB 2.00 MB -812 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 29.7 ms 32.0 ms +2.2 ms
CLI --help 64.4 ms 62.3 ms -2.0 ms

…tall

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thymikee
thymikee force-pushed the ci/linux-smoke-apt-update branch from 16ae1db to fba967a Compare November 23, 2026 12:54
@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 1 new finding on 16ae1db. The verdict and the full list are in the summary comment.

Comment thread .github/workflows/linux.yml Resolved
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

The cached-install route in 5564e2c passes in CI, but six defects remain in how it falls back. All 21 checks pass at this commit, including the Linux Smoke Tests job whose route the diff changes. There are no conflicts. The fixes below must land before merge.

A second independent pass found that line 129 installs every restored archive as an explicit root target. The saved set holds every archive in the system archive directory, so an unrelated archive already on the runner at save time is later installed too. The check at lines 119-123 can still pass. The merge base requested only PACKAGES. Request only PACKAGES from APT, with the restored archives as candidates and authenticated local package metadata, and save only the archives selected for that dependency set.

A second independent pass found that line 126 copies restored archives into the system archive directory before the install. If an archive has valid control data but damaged package data, dpkg fails on it. The fallback's download-only step at line 139 then accepts the same file because its name and size match, and the install at line 141 fails on it again. Keep restored archives in an isolated archive directory. When the cached install fails, discard that directory and run the fallback with a clean one, so APT fetches and verifies a replacement.

A second independent pass found that line 139 can fail after the cached install is interrupted. If dpkg is killed with a dirty status journal, APT refuses the download-only step when it opens the package database, so the refreshed package set never reaches the final install. After a cached install fails, check for interrupted dpkg state and recover it before starting the named-package fallback.

A second independent pass found that line 128 skips the all_installed check when the archive directory is empty. A runner image that already has all ten packages, with an absent or empty saved entry, refreshes indexes anyway. If the mirror stalls on both attempts, the job fails although the package set was complete. A successful run can also save an empty entry under a new key at lines 145-156. Check all_installed before probing the archive glob and exit successfully when it passes. Save a replacement entry only when there are archives to save.

A second independent pass found that line 129 lets the cached attempt spend the dpkg lock wait set at line 91 plus the time to install a partial set before all_installed rejects it. With two network phases near 120 seconds each, the fallback can be left with under 50 seconds. It still allows another lock wait at line 141, so the six-minute step at line 83 can end before the fallback dpkg starts. Kill grace at line 112 adds to this. Check the offline package plan before starting dpkg, then budget the cached attempt, both retry windows, the kill grace and the final lock wait together, and reserve time for the final dpkg run and the cache copy.

A second independent pass found that line 141 runs the final install with downloads enabled. If another process changes the package indexes or removes a prefetched archive after line 139, apt-get can contact the mirror outside apt_bounded. A slow but steady transfer then avoids the per-I/O timeouts at lines 88-89 and can use the rest of the step. The call exists on the merge base, but here it breaks the bounded network-phase rule. Use a job-private archive directory for prefetch and install, pass --no-download to the final install, and send any newly missing archives through the bounded download phase.

A second independent pass found that line 139 shortens the download window to 60 seconds per attempt. A transfer that needs 67 seconds with steady progress, on a mirror that restarts partial transfers, fails both attempts. The merge base allowed 75 seconds per attempt and finished that job. Keep at least the former 75-second window for a single transfer, account for it in the step budget, and keep time for dpkg.

Not blocking, and these can be taken or left: the comment at line 140 counts only the apt_bounded windows and omits the kill grace and both dpkg lock waits, so "about two minutes without a dpkg lock wait" is more accurate; the comment at line 125 says apt resolves local .debs only through its archive directory, but the copy matters for the fallback's download-only step and for dependencies not on the command line; the cached install can refuse a downgrade of a library the runner image already upgraded, which falls back to a refresh by design; and the saved .debs are frozen, so mirror security updates arrive only on a scheduled refresh on main if freshness matters.

Not verified here: the "cached install fails, so refresh" route was not observed live, only the miss route (run 45178372896, on a temporary key) and the hit route. That route was read from the code only. The workflow was not run locally, and APT downgrade and archive-reuse behavior comes from reading APT, not from running it. The restore-keys ordering of the cache backend was not checked separately beyond the live log.

The earlier inline thread on the download windows is fixed in 5564e2c, since the windows are now 2x60s and total 240s; it can be resolved: #5021 (comment)

thymikee and others added 2 commits November 23, 2026 15:06
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 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thymikee
thymikee force-pushed the ci/linux-smoke-apt-update branch 3 times, most recently from 26d7279 to 0c429fe Compare November 23, 2026 14:16
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thymikee
thymikee force-pushed the ci/linux-smoke-apt-update branch from 0c429fe to 77b7c0a Compare November 23, 2026 14:18
@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

Addressed in 77b7c0a. Each finding and its fix:

  1. Explicit archive targets. apt now receives only PACKAGES. The cache stores the lists that the refresh authenticated (*Release*, *_Packages*), and the cached attempt resolves against them with Dir::State::Lists. The archive directory holds only what --download-only fetched for PACKAGES into an empty directory, so it is the selected set.
  2. Shared archive directory. Restored archives stay in ~/apt-cache/archives through Dir::Cache::Archives and never enter the system directory. Every fallback deletes the restored set and downloads into an empty directory.
  3. Interrupted dpkg. After a failed cached dpkg run, the step runs dpkg --configure -a. On a broken system apt resolves only around named packages, so the fallback also names what --fix-broken would install (a simulation needs no lock and no network). Verified live: run 45192438725 corrupted a restored libgtk-4-1 archive. dpkg failed, the fallback installed the missing package, and the run was green. The next run (45192864063) healed the partial entry that the repair saved.
  4. Probe order and empty save. all_installed runs first and exits when it passes. The save runs only when archives exist.
  5. Budget. --print-uris checks the plan before dpkg (no lock). The windows are 60s cached lock + 2×65s refresh + 2×80s download + 60s final lock = 410s. The step limit is 9 minutes, which leaves 130s for dpkg (2–5s per run) and the copy.
  6. Final install downloads. Every install uses --no-download. A download attempt passes only when --print-uris then plans nothing, so newly missing archives stay inside the bounded phase.
  7. Download window. The download window is back to 75s per attempt.

Non-blocking notes: I took the comment corrections. A downgrade refusal and frozen archives fall back to a refresh by design. The refresh that healed the entry took 43s, which the old 30s window would have failed.

@thymikee

Copy link
Copy Markdown
Member Author

All seven findings from the earlier review (#5021 (comment)) are fixed at 77b7c0a. A second independent pass found two defects that still need a change.

A second independent pass found that the restored-archive install does not verify contents. A restored archive with the expected filename and byte count but changed contents passes the plan at line 126, because APT treats an existing archive as complete on a size match. Line 130 then hands those bytes to dpkg. Restored package lists have the same gap at lines 83 and 104: APT trusts a source by the presence of InRelease or Release.gpg and does not re-verify a restored Packages list during install. The rule: before the restored install, verify the Release signatures with the configured Ubuntu keyring, verify the restored package lists against those signed digests, and check the SHA-256 of every selected archive against its verified package record. Send any verification failure to the existing clean fallback. Refs: APT archive lookup, APT local source trust check.

A second independent pass also found that the fallback can change package indexes between download and install. Line 163 clears LIST_OPTS, so the bounded download and the plan check at line 169 use the runner's live indexes. If the periodic index update publishes a newer candidate for a missing package after that check, line 171 needs an archive the private directory lacks. APT then exits under --no-download and the step fails even when the mirror is healthy. The earlier review named this route. A refresh after install but before line 177 can also save lists that select different versions from the archives just downloaded. The rule: the fallback download, plan, install and save must all use one job-private refreshed list directory, and the install keeps --no-download. Refs: periodic index update, missing archives under --no-download.

The earlier thread on the 2x60s refresh windows (#5021 (comment)) no longer applies: the windows are unchanged and the 410s of 540s budget is now counted explicitly. It can be resolved.

All 22 checks pass or skip at 77b7c0a, including the Smoke Tests job whose install step this diff rewrites (run 45192864063, attempt 4). The diff touches only .github/workflows/linux.yml. No conflicts. Both findings need a fix before merge, and the Smoke Tests job should then show the restored-install route and the fallback route each succeed, with the integrity checks running on the restored route.

Not verified here: the workflow was not run locally, and the APT behavior above comes from reading APT and the author's live runs. The logs of runs 45190712904, 45192438725 and attempts 1-3 of 45192864063 were not read, so the corrupted-archive recovery and the refresh and cold-path timings are the author's claims. The restore-keys ordering across ref scopes was not checked beyond the author's runs.

thymikee and others added 2 commits November 23, 2026 16:05
…s 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 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thymikee
thymikee force-pushed the ci/linux-smoke-apt-update branch from b6b3ac0 to ad49f00 Compare November 23, 2026 15:11
@thymikee

Copy link
Copy Markdown
Member Author

Both findings are addressed in e48894d. ad49f00 only adds a log line.

  1. Restored lists and archives are verified before the restored install. Each step below sends any failure to the clean fallback (verify_restored).
    • Each restored *_InRelease must pass gpgv with /usr/share/keyrings/ubuntu-archive-keyring.gpg.
    • Each *_Packages list must match the SHA-256 and path in the signed content of its InRelease.
    • Each archive's Package_Version_Architecture and SHA-256 must match a record in those verified lists.
    • The save keeps only InRelease files that verify against that keyring, plus their Packages lists.
    • Evidence:
      • Run 45202404368, attempts 1–3: APT verified 15 lists and 41 archives. The check takes about 1.1s, and the step takes 6–7s.
      • Run 45202010948, a temporary commit now dropped: it overwrote 16 bytes of a restored archive and kept its size. The check printed Unverified: …/libgtk-4-1_4.14.5+ds-0ubuntu0.10_amd64.deb before dpkg ran. The fallback then installed and saved a full set.
      • Run 45201292602: it rejected the earlier entry because that entry held unsigned third-party lists.
  2. The fallback uses one job-private index. Dir::State::Lists now always points at ~/apt-cache/lists. The refresh writes there, and the download, plan check, --no-download install, repair simulation and save all read the same lists. The periodic index update writes only the system lists, so it cannot change the plan. The step no longer copies lists from the system directory.

I resolved the earlier thread on the refresh windows.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 1 new finding on b6b3ac0. The verdict and the full list are in the summary comment.

@thymikee

Copy link
Copy Markdown
Member Author

Both findings from the earlier review (#5021 (comment)) are fixed at ad49f00, but three new defects remain in the restore check. A second independent pass found them, and each lets a restored install skip verification.

A second independent pass found that a restored set can carry a compressed Packages list for another configured pocket with no plain counterpart. The check skips it, APT reads it when resolving the plan, and a record from it can complete the offline install even if its digest differs from the signed Release. The previous save copied compressed lists, so such sets exist. Please reject unexpected list files on restore before calling APT, or point the restored install at a directory that holds only verified list and release files. APT index lookup

A second independent pass found that an archive path expected for a selected dependency can hold a different Ubuntu package of the same byte count. Its own identity and SHA-256 sit in a verified list, so the check passes. APT accepts the file by basename and size and can hand it to dpkg before the fallback runs. The rule: look up the expected SHA-256 by the archive identity and filename APT selects, using APT's filename escaping, and reject a restored file whose digest differs. APT archive lookup

A second independent pass found that if awk hits a write error after it emits the rows the archives need, it exits nonzero but leaves those rows behind. Because verify_restored runs inside an if condition at line 179, Bash ignores errexit there, so the lookups can pass on partial output and the install proceeds. Please return failure explicitly when record extraction fails, and check the exit status of the verifier's other setup and extraction commands the same way. Bash errexit behavior

Checks are green on ad49f00. Earlier cancelled rows came from a newer push superseding the first runs, and the re-run at the same commit passed every job. The diff touches only the Linux workflow, which the Linux Smoke Tests job runs. No conflicts. These three fixes must land before merge.

Of the earlier inline threads, none still apply. The thread at #5021 (comment) targets a temporary debug line from b6b3ac0, which is not in this head. The thread at #5021 (comment) is fixed by the 9-minute timeout and the 410s count in the step comment.

Not verified here: the workflow and script were not run locally, and the findings rest on reading the head script and the logs of the restored-route and tampered-archive runs. Not verified here: the repair route (dpkg --configure -a then --fix-broken -s) at this head, since its last live run was at 77b7c0a. Not verified here: InRelease file names outside the 15 lists the current image produces, which take the fallback and cannot pass. After the fixes, a run that restores a set containing an extra compressed list and a swapped same-size archive should fall back and install from verified downloads.

thymikee and others added 2 commits November 23, 2026 17:08
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 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thymikee
thymikee force-pushed the ci/linux-smoke-apt-update branch 2 times, most recently from 24f8bfa to 3eeb9b0 Compare November 23, 2026 16:18
@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ⛔ Block · review of 24f8bfa

Since the review of b6b3ac0: 0 new · 1 still open · 0 no longer raised

1 finding(s): 1 blocker.

Required fixes

  • Temporary swapped-archive check fails every cold-cache run and disables the cached route

🔴 Blocker (1)

Where Finding
.github/workflows/linux.yml:182 Temporary swapped-archive check fails every cold-cache run and disables the cached route

Reviewed with this repository's own Sentinel configuration (0d38f89b11da).

💬 Talking to Sentinel

In a finding's thread, reply with:

Command What it does
@apex-sentinel-staging note <context> Adds context; Sentinel re-checks the cited code
@apex-sentinel-staging pivot <why> Says the finding is wrong; Sentinel re-checks the cited code
@apex-sentinel-staging like Marks the finding as useful
@apex-sentinel-staging dislike <why> Marks it as not useful, so it is not raised again

On this conversation, comment @apex-sentinel-staging review to run a full review once again.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 1 finding moved to a new line on 24f8bfa. The verdict and the full list are in the summary comment.

Comment thread .github/workflows/linux.yml Resolved
@thymikee

Copy link
Copy Markdown
Member Author

All three are fixed in 29b5e25 and 3eeb9b0:

  1. Unexpected list files. Before apt runs, verify_restored rejects any entry in the restored list directory other than *_InRelease, plain *_Packages, and the empty partial/ directory. The save now deletes everything outside that set, not just regular files. The stricter check also caught a real leftover: apt's auxfiles/ mirror-list link, which earlier saves kept.
  2. Archive identity. The records now map each SHA-256 to the file name apt looks up: Package_Version_Architecture.deb, with % escaped as %25 and : as %3a in the version, as apt's QuoteString does. Each restored archive must match the record for its own file name, so another package's file under a selected name is rejected. The dpkg-deb identity lookup is gone.
  3. Exit statuses. Inside the verifier, mktemp, find, tr, every sha256sum and the awk extraction each end with || return 1. The digests come from ${sha%% *}, not a pipe.

Live evidence:

  • Run 45215082154, attempts 1–3 on 3eeb9b0: restored route with verified 15 lists and 41 archives. The epoch-escaped names pass, and the step takes 5–7s.
  • Run 45214284821 (temporary commit): an extra …noble-proposed_main_binary-amd64_Packages.lz4 printed Unexpected list files. The fallback was green.
  • Run 45214737470 (temporary commit): libgtk-4-1's valid archive copied over libadwaita-1-0_1.5.0-1ubuntu2_amd64.deb printed Unverified: …libadwaita-1-0…deb. The fallback was green. The previous identity check would have accepted that file.

Both temporary commits are dropped. I resolved the two stale threads.

@thymikee

Copy link
Copy Markdown
Member Author

The three defects from the earlier review (ad49f00, #5021 (comment)) are fixed at 3eeb9b0. The Linux Smoke Tests install step now installs the cached desktop packages without an apt index refresh, and the live run passed with epoch-escaped package names (41 archives verified). CI is green at this commit: both Linux Smoke Tests runs, iOS, macOS and Coverage pass; the other non-passing rows come from superseded runs of earlier pushes. There are no conflicts. Nothing remains to fix before merge.

Of the two open inline threads, neither still applies, so the author can resolve both. The temporary swapped-archive line is gone from the workflow at this commit (#5021 (comment)). The timing concern is covered by the 410s of 540s budget in the workflow (#5021 (comment)).

Not verified here: the job logs of the dropped temporary-commit runs, and the exact apt quoting rules in the apt source. The review relied on the author's reported output and the green runs at this commit.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 23, 2026
@thymikee
thymikee merged commit a7440cc into main Nov 23, 2026
33 of 38 checks passed
@thymikee
thymikee deleted the ci/linux-smoke-apt-update branch November 23, 2026 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant