autoremove: cross-check candidates against formula definitions#21725
Open
costajohnt wants to merge 1 commit intoHomebrew:mainfrom
Open
autoremove: cross-check candidates against formula definitions#21725costajohnt wants to merge 1 commit intoHomebrew:mainfrom
costajohnt wants to merge 1 commit intoHomebrew:mainfrom
Conversation
Contributor
Author
5 tasks
The forward dependency check in `removable_formulae` relies on tab data (INSTALL_RECEIPT.json) which becomes stale when homebrew-core adds new dependencies to a formula. Cross-check autoremove candidates against current formula definitions by calling `runtime_formula_dependencies` with `read_from_tab: false` on non-candidate formulae. The check iterates until convergence to handle cascading dependencies and falls back gracefully on error. Fixes Homebrew#21511
3b547b1 to
8696502
Compare
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.


Fixes #21511
Problem
brew autoremovesuggests removing formulae (e.g.libthai) thatbrew uninstallthen refuses to remove because they're still needed by installed formulae (e.g.pango).The root cause:
removable_formulaeusesinstalled_runtime_formula_dependenciesto build its dependency graph, which reads from tab data (INSTALL_RECEIPT.json). When homebrew-core adds a new dependency to a formula (e.g. addinglibthaito pango), the installed bottle's tab doesn't reflect this — the tab is written at install time and never updated.#21519 fixed a name-comparison issue but the stale tab problem remains for users who haven't reinstalled affected bottles.
Approach
The suggested fix was to use the same dependency resolution as
brew uninstall(InstalledDependents.find_some_installed_dependents). I tried this first, but discovered it doesn't work:InstalledDependentsultimately callsruntime_dependencies(read_from_tab: true), which reads from the same stale tab data. The uninstall command only catches the problem becausemissing_dependenciestriggers linkage analysis as a secondary check — not because of the reverse dependency logic itself.Instead, this PR cross-checks autoremove candidates against current formula definitions by calling
runtime_formula_dependencies(read_from_tab: false, undeclared: false)on non-candidate (installed-on-request) formulae. This reads from.rbformula files, which are always current afterbrew update. If any non-candidate's formula definition lists a candidate as a dependency, that candidate is kept.The check iterates until convergence to handle cascading dependencies (e.g. if formula A needs B and B needs C, both B and C are kept). Falls back gracefully on error.
Test plan
brew tests --only=utils/autoremove— all specs passbrew style— no offenses