Skip to content

Prune the package cache before updating - #6734

Merged
dhh merged 1 commit into
quattrofrom
trim-package-cache-during-update
Aug 12, 2026
Merged

Prune the package cache before updating#6734
dhh merged 1 commit into
quattrofrom
trim-package-cache-during-update

Conversation

@dhh

@dhh dhh commented Aug 12, 2026

Copy link
Copy Markdown
Member

The pacman cache grows without bound across updates and nothing in the update flow ever reclaimed it. On this machine it had reached 7.4G across 732 archives, ~3.75 GiB of which are superseded versions nothing will install again.

Adds omarchy-update-pkg-prune, running paccache -rk2 as the first step of an update.

Why that placement

Both halves of it are load-bearing.

Before the packages update. The cache is Arch's only offline downgrade path — when an update breaks one package, reinstalling its predecessor from here is the surgical fix, where a snapshot rollback reverts every other package too. Pruning beforehand means the installed version is still the newest cached, so it survives along with a spare. Pruning after would make the newest cached version the freshly installed one, and cutting down to a single copy would delete exactly what a broken update needs.

Before the snapshot. The cache sits on the snapshotted root subvolume, so a prune taken after omarchy-snapshot create leaves the fresh snapshot holding those extents and reclaims nothing until it ages out of the number cleanup. Ordering it first is what makes the space actually come back.

-k2 reclaims 3.75 GiB here, against 4.95 for -k1 (which leaves no rollback candidate) and 3.11 for -k3.

Failure handling

A failed prune warns and continues rather than aborting. Cache housekeeping shouldn't trip the update's ERR trap and tell the user their update went wrong. This got exercised for real: an early test run hit the unstubbed command with no sudo password available, and it warned and carried on with the cache untouched.

Known limitations

Two things this deliberately does not do, both worth a second opinion:

  • It runs after omarchy-update-requires-free-space, so it reclaims space during healthy updates but does not rescue a machine already under the 10 GiB gate — the case where the cache itself is what's blocking the update. Folding the prune into that gate and rechecking would fix it, at the cost of mutating the system before the user confirms.
  • paccache retains by version order and never consults what is installed. The rollback guarantee therefore holds only while the installed version is among the two newest cached. A deliberate downgrade held with IgnorePkg, or repeated failed transactions, can stack newer archives on top of the installed one, and its copy becomes prunable like any other. Exempting installed versions is possible but needs real filename parsing.

Not included: paccache -ruk0 for uninstalled packages, which is strictly safe and pairs naturally with omarchy-update-orphan-pkgs.

Testing

New test/shell.d/update-pkg-prune-test.sh covers the keep count, the non-fatal failure path, and both ordering invariants by asserting line order in omarchy-update.

Also stubs the new command in update-disk-space-test.sh and update-lock-test.sh, both of which execute the real updater. Without that, ./test/shell reaches a real sudo paccache -rk2 and would prune the developer's own cache on a box with passwordless sudo. update-lock-test.sh was caught by a Codex review pass, not by me.

./test/shell (160 files) and ./test/cli both green.

🤖 Generated with Claude Code

Copilot AI balanced review requested due to automatic review settings August 12, 2026 08:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds safe pacman cache pruning before snapshots and package updates.

Changes:

  • Keeps two cached package versions via paccache -rk2.
  • Treats pruning failures as non-fatal.
  • Tests retention, failure handling, ordering, and updater isolation.

Tip

If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

Reviewed changes

Copilot reviewed 3 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
bin/omarchy-update Runs cache pruning before snapshot creation.
bin/omarchy-update-pkg-cache Implements non-fatal cache pruning.
test/shell.d/update-pkg-cache-test.sh Tests pruning arguments, failure, and ordering.
test/shell.d/update-disk-space-test.sh Stubs pruning during updater tests.
test/shell.d/update-lock-test.sh Stubs pruning during lock tests.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI review requested due to automatic review settings August 12, 2026 09:44
@dhh
dhh force-pushed the trim-package-cache-during-update branch from 9e48d45 to 54e92aa Compare August 12, 2026 09:44
@dhh dhh changed the title Trim the package cache before updating Prune the package cache before updating Aug 12, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 5 changed files in this pull request and generated no new comments.

Suppressed comments (1)

test/shell.d/update-pkg-prune-test.sh:34

  • This regex also accepts values such as -rk20, so a regression that retains far more than the intended two versions could still pass while defeating the pruning goal. Compare the recorded invocation exactly with paccache -rk2 so the retention contract is pinned.
grep -qE 'paccache .*-rk2' "$test_tmp/args" ||

@dhh
dhh force-pushed the trim-package-cache-during-update branch from 54e92aa to 1de9186 Compare August 12, 2026 09:51
The pacman cache grows without bound across updates, and nothing in the
update flow ever reclaimed it. On a machine that has been updating for a
while it reaches several gigabytes of superseded versions that nothing
will ever install again.

Prune it with paccache -rk2 as the first step of an update. Both halves
of that placement are load-bearing.

Keeping two versions rather than one preserves the rollback path. The
cache is Arch's only offline downgrade: when an update breaks a single
package, reinstalling its predecessor from here is the surgical fix,
where a snapshot rollback would revert every other package too. Pruning
before the packages update means the installed version is still the
newest cached, so it survives along with a spare. Retention is by
version order and never consults what is installed, so that holds while
the installed version is among the two newest cached; a deliberate
downgrade or repeated failed transactions can stack newer archives on
top of it.

Running before the snapshot is what actually frees the space. The cache
sits on the snapshotted root subvolume, so a prune taken afterwards
leaves the fresh snapshot holding those extents and reclaims nothing
until it ages out of the number cleanup.

A failed prune warns and continues. Cache housekeeping should not trip
the update's ERR trap and tell the user their update went wrong.

This runs after omarchy-update-requires-free-space, so it reclaims space
during healthy updates but does not rescue a machine already under the
10 GiB gate.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings August 12, 2026 09:55
@dhh
dhh force-pushed the trim-package-cache-during-update branch from 1de9186 to dc936d8 Compare August 12, 2026 09:55
@dhh
dhh merged commit fd23ca0 into quattro Aug 12, 2026
3 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 5 changed files in this pull request and generated no new comments.

@dhh
dhh deleted the trim-package-cache-during-update branch August 12, 2026 10:00
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.

2 participants