Skip to content

keg: keep versioned opt aliases that still point at an installed keg - #24113

Merged
MikeMcQuaid merged 3 commits into
Homebrew:mainfrom
erikdw:keg-keep-versioned-opt-aliases
Sep 29, 2026
Merged

MikeMcQuaid merged 3 commits into
Homebrew:mainfrom
erikdw:keg-keep-versioned-opt-aliases

Conversation

@erikdw

@erikdw erikdw commented Sep 28, 2026

Copy link
Copy Markdown

Uninstall deletes a keg's INSTALL_RECEIPT.json before remove_old_aliases reads it. The alias list is then empty, so the versioned opt sweep treats names such as ruby@4.0 as stale and deletes them when they point anywhere in that formula's rack, including the newer keg. MacVim (and anything else linked against Homebrew Ruby's install name) then aborts with Library not loaded: .../opt/ruby@4.0/lib/libruby.4.0.dylib.

uninstall now passes the alias list it read before removing the keg. A versioned opt alias that this keg owns is kept while its target still exists, and removed when that target was the keg just deleted. Stale names that are not aliases of the keg being removed, such as a leftover ffmpeg@8, are still deleted.

Fixes the failure discussed in https://github.com/orgs/Homebrew/discussions/7041 and macvim-dev/macvim#1697.

To reproduce:

brew install ruby macvim
# upgrade or reinstall ruby so cleanup uninstalls the previous keg
brew reinstall ruby
ls -l "$(brew --prefix)/opt/ruby@4.0"
vim --version

opt/ruby@4.0 is missing and vim aborts. brew unlink ruby && brew link ruby brings the alias back until the next Ruby upgrade.


  • Have you followed our Contributing guidelines?
  • Have you checked for other open Pull Requests for the same change?
  • Have you explained what your changes do? Performance claims (e.g. "this is faster") must include brew benchmark results.
  • Have you explained why you'd like these changes included, not just what they do?
  • For bug fixes, have you given step-by-step brew commands to reproduce the bug?
  • Have you written new tests (excluding integration tests)? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) locally?

  • I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; I did not attribute commits to AI and will answer maintainer questions and review comments myself without AI/LLM.

Drafted with Cursor Grok 4.7. I reviewed the diff and verified it with brew lgtm (brew typecheck, brew style --changed, and brew tests --only=keg).


Made with Cursor

Uninstall deleted the install receipt before reading aliases, so cleanup
treated names such as ruby@4.0 as stale and removed them even when they
pointed at the newer keg.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copilot AI lite review requested due to automatic review settings September 28, 2026 20:37

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Comment thread Library/Homebrew/keg.rb Outdated
Comment thread Library/Homebrew/keg.rb Outdated
Comment thread Library/Homebrew/keg.rb Outdated
Comment thread Library/Homebrew/keg.rb Outdated
Comment thread Library/Homebrew/keg.rb Outdated
Comment thread Library/Homebrew/keg.rb Outdated
Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
Comment thread Library/Homebrew/keg.rb Outdated

@MikeMcQuaid MikeMcQuaid left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@MikeMcQuaid
MikeMcQuaid added this pull request to the merge queue Sep 29, 2026
Merged via the queue into Homebrew:main with commit 6363864 Sep 29, 2026
51 checks passed
@erikdw
erikdw deleted the keg-keep-versioned-opt-aliases branch September 29, 2026 22:25
@erikdw

erikdw commented Sep 29, 2026

Copy link
Copy Markdown
Author

Thanks for accepting my suggested fix, and improving it to be mergeable!

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.

3 participants