emacs: refresh archives and retry when a package install fails - #30
Merged
Conversation
Installing magit on a machine whose archive cache was stale failed with "https://elpa.nongnu.org/nongnu/with-editor-3.4.9.tar: Not found". The cache is not wrong about which packages exist, it is wrong about their versions: GNU and nongnu ELPA keep only the current release of each package, so an index that names a superseded version resolves to a tarball the server has deleted. Nothing in the config recovered from that. The refresh added earlier only runs when package-archive-contents is empty, so after the first successful run on a machine the index is never refreshed again. use-package cannot cover for it either -- use-package-ensure-elpa refreshes only when the package is missing from the cache: (if (assoc package package-archive-contents) (package-install package) ; present: install, no refresh (package-refresh-contents) ; absent: refresh, then install (package-install package)) magit was present in the stale cache, so it took the first branch and failed resolving its dependency. Any newly added package hits this on any machine whose cache has aged, and the only recovery was to run M-x package-refresh-contents by hand. package-install now refreshes and retries once on failure. That costs nothing when the cache is fresh, since it only runs on the error path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The failure
On m5air, adding
magitproduced:The cached archive index isn't wrong about which packages exist — it's wrong about their versions. GNU and nongnu ELPA keep only the current release of each package, so an index naming a superseded version resolves to a tarball the server has deleted. A 404, not a missing-package error.
Why nothing recovered
This is a regression from the startup work in #27. That change added:
which refreshes only when the cache is empty — so after the first successful run on a machine, the index is never refreshed again and quietly rots.
use-package can't cover for it either. From
use-package-ensure-elpa:magitwas present in the stale cache, so it took the first branch and failed while resolvingwith-editor. Any newly added package hits this on any machine whose cache has aged; the only recovery wasM-x package-refresh-contentsby hand.The fix
package-installnow refreshes the archives and retries once on failure. It only runs on the error path, so a fresh cache costs nothing.Verification
The advice was unit-tested across all three paths:
attempts=2 refreshed=tattempts=1 refreshed=nilFull cold start against an empty init-directory: exit 0, no errors, 24 packages,
magit-4.6.0+with-editor-3.5.2.What I could not reproduce end-to-end: I tried to recreate the exact 404 by corrupting a real cached nongnu index to name
with-editor 3.5.999. package.el installed MELPA's date-versioned build (20260701.1252) instead, so it never hit nongnu's dead tarball — a difference in archive selection between that sandbox and m5air I did not chase further. The mechanism above is established by readinguse-package-ensure-elpaand by the unit tests, not by a full reproduction.Immediate unblock
On m5air, before this merges:
M-x package-refresh-contents, thenM-x package-install RET magit RET.