G
YouTube TikTok Games
Skip to content

Avoid duplicate source upgrades of dependencies - #24209

Merged
MikeMcQuaid merged 1 commit into
mainfrom
avoid-duplicate-source-upgrades
Oct 10, 2026
Merged

MikeMcQuaid merged 1 commit into
mainfrom
avoid-duplicate-source-upgrades

Conversation

@p-linnane

Copy link
Copy Markdown
Contributor

Upgrading a formula that's also a build dependency of another outdated formula could build it from source twice: once as the dependency, then again for its own queued upgrade. The second build reused the same keg, so if it failed it deleted the working installation. The already-attempted check missed the duplicate because the queued installer still held the API-loaded formula while the dependency used the source-loaded one, and Formula#== compares classes.

Compare attempted formulae by full name and spec, as fetch deduplication already does, so the queued upgrade is skipped before its keg is unlinked.

Fixes #24203


  • 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.

GPT-6 Astra drafted the fix and tests and ran brew lgtm --online; Claude Code (Opus 5.5) reviewed it, reproduced the missed duplicate with real API- and source-loaded formulae and confirmed the regression tests fail without the change and pass with it. I reviewed the diff.


Signed-off-by: Patrick Linnane <patrick@linnane.io>
@coderabbitai

coderabbitai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c7177e1c-eeca-4e21-a29f-1efb81ae0c0e

📥 Commits

Reviewing files that changed from the base of the PR and between 7a8f775 and f387f01.


📒 Files selected for processing (3)
  • Library/Homebrew/formula_installer.rb
  • Library/Homebrew/test/formula_installer_spec.rb
  • Library/Homebrew/test/install_spec.rb

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📜 Recent review details
⏰ Context from checks skipped due to timeout. (20)
  • GitHub Check: docker (arm64 Ubuntu 24.04)
  • GitHub Check: docker (x86_64 Ubuntu 26.04)
  • GitHub Check: docker (x86_64 Ubuntu 24.04)
  • GitHub Check: docker (arm64 Ubuntu 26.04)
  • GitHub Check: tests (no Sorbet)
  • GitHub Check: tests (macOS, 1/2)
  • GitHub Check: tests (load-only macOS)
  • GitHub Check: tests (macOS, 2/2)
  • GitHub Check: tests (load-only Linux)
  • GitHub Check: tests (generic OS, 1/2)
  • GitHub Check: tests (Linux, 1/2)
  • GitHub Check: tests (online, 2/2)
  • GitHub Check: tests (generic OS, 2/2)
  • GitHub Check: tests (Linux, 2/2)
  • GitHub Check: tests (online, 1/2)
  • GitHub Check: syntax
  • GitHub Check: check-commit-format
  • GitHub Check: workflow_syntax
  • GitHub Check: Analyze
  • GitHub Check: docs

🔇 Additional comments (3)
Library/Homebrew/formula_installer.rb (1)

411-411: LGTM!

Also applies to: 1508-1508, 1917-1925


Library/Homebrew/test/formula_installer_spec.rb (1)

1248-1258: LGTM!

Also applies to: 1260-1265, 1267-1272, 1274-1285


Library/Homebrew/test/install_spec.rb (1)

124-139: LGTM!





📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Prevented duplicate upgrade attempts when the same formula is represented by different formula types.
    • Preserved a keg’s linked state when an upgrade fails after another formula type has already attempted the upgrade.

Walkthrough

FormulaInstaller now identifies equivalent formula attempts by full_name and active_spec_sym, without requiring matching classes. The same comparison is used to locate previously fetched formulas. Tests cover matching boundaries and linked-keg state after a failed upgrade attempt.

Changes

Formula attempt identity

Layer / File(s) Summary
Formula identity comparison and checks
Library/Homebrew/formula_installer.rb
A private comparison matches formulas by full_name and active_spec_sym, regardless of class. Attempt checks and fetched-formula lookup use this comparison.
Attempt-check and upgrade tests
Library/Homebrew/test/formula_installer_spec.rb, Library/Homebrew/test/install_spec.rb
Tests cover rejection of matching formulas, allowance for different taps and specs, and linked-keg state after a failed upgrade attempt.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: mikemcquaid


Merge Risk

Merge Risk: ⚪ Minimal · up to f387f

This change stops an outdated formula from being built from source twice during an upgrade, which could leave its keg broken. No merge-blocking issues were found.

Security Architecture Review

Security architecture risk: ⚪ Minimal · up to f387f

The change prevents duplicate installation attempts while preserving tap and stable/HEAD identity boundaries. No introduced or worsened security risk was identified in the reviewed installation paths.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The reviewed exposure change is broader duplicate suppression for equivalent Formula representations within an installation operation, not a new execution or authority path. Matching still separates different taps and active specs.

Trust Boundaries and Controls

  • observed — The installer prelude retains forbidden-license, forbidden-tap and forbidden-formula checks before installation sanity checking. The PR changes duplicate identity recognition rather than removing these controls or adding a privileged caller.

Resilience and Maintainability Implications

  • observed — Attempt markers remain recorded before pouring or building, and failed attempts remain subject to operation-local duplicate suppression. Existing dependency restoration, installation locking and exception-time lock release are unchanged; the PR does not introduce a new retry or concurrency mechanism.



🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: preventing duplicate source upgrades of dependencies.
Description check Passed The description directly explains the duplicate-build bug, its cause, the fix, regression tests, and validation results.
Linked Issues check Passed The change satisfies the coding requirement in issue #24203. FormulaInstaller#check_installation_already_attempted now compares full_name and active_spec_sym through same_formula?, so API-load…
Out of Scope Changes check Passed The changes stay within issue #24203. The helper reuse in previously_fetched_formula applies the same formula identity rule to existing fetch deduplication. The added tests directly verify duplicate…


  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@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.

Good catch, thanks!

@MikeMcQuaid
MikeMcQuaid added this pull request to the merge queue Oct 10, 2026
Merged via the queue into main with commit 161e442 Oct 10, 2026
53 checks passed
@MikeMcQuaid
MikeMcQuaid deleted the avoid-duplicate-source-upgrades branch October 10, 2026 08:54
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.

When upgrading packages and some (A) are dependencies for some others (B), A will be upgraded twice and may break it instead because of failed cleanup

2 participants