Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 2, 2025

Currently, Homebrew attempts to remove launchctl services during cask uninstallation, which requires root privileges. When running with sudo, if the launchctl remove command fails, it causes a fatal error that stops the uninstall process. This is problematic for users who:

  • Install Homebrew in "Untar Anywhere" (unsupported) configurations without admin access
  • Prefer not to enter their admin password during routine upgrades
  • Encounter permission issues during service removal

This PR changes the behavior to make launchctl service removal failures non-fatal, allowing the uninstall process to continue gracefully even when these operations fail.

Changes

Core Logic (Library/Homebrew/cask/artifact/abstract_uninstall.rb)

  1. launchctl remove command: Changed from must_succeed: sudo to must_succeed: false

    • Previously, when sudo=true, failures were fatal
    • Now, failures are non-fatal in all cases
  2. Failure handling: Simplified from next if !sudo && !result.success? to next unless result.success?

    • Ensures consistent behavior: skip to next iteration on failure regardless of sudo status
  3. File removal operations: Changed from command.run! to command.run with must_succeed: false for:

    • Removing .plist files from /Library/LaunchAgents/ and /Library/LaunchDaemons/
    • Unloading services via launchctl unload
    • Removing service files directly

Tests (Library/Homebrew/test/cask/artifact/shared_examples/uninstall_zap.rb)

  • Updated existing tests to expect must_succeed: false for sudo operations
  • Added new test case "does not fail when sudo removal fails" to verify non-fatal behavior

Impact

This change ensures that cask uninstallation proceeds even when launchctl service removal operations fail due to permission issues or other errors. The uninstall process will attempt to remove services but won't abort if unsuccessful, improving the user experience for those without admin access or who choose not to provide sudo credentials.

Fixes #<issue_number>

Original prompt

This section details on the original issue you should resolve

<issue_title>Make launchctl service removal sudo failures non-fatal</issue_title>
<issue_description>### Verification

Provide a detailed description of the proposed feature

Currently, Homebrew attempts to remove launchctl services, which requires root privileges. However, users who install Homebrew without root access or prefer not to enter their admin password every time may find this behavior inconvenient.

What is the motivation for the feature?

Right now, Homebrew tries to remove launchctl services, but that needs root access. If you don’t run Homebrew as root (or just don’t wanna type your password every time), this gets annoying fast.

How will the feature be relevant to at least 90% of Homebrew users?

I am not sure

What alternatives to the feature have been considered?

I haven't</issue_description>

Comments on the Issue (you are @copilot in this section)

@MikeMcQuaid @mio-19 Which command(s) specifically are you seeing this behaviour with?

To help us debug this issue can you explain:

  • What you were trying to do (and why)
  • What happened
  • What you expected to happen
  • Step-by-step reproduction instructions (with as minimal input data as possible)</comment_new>
    <comment_new>@MikeMcQuaid

On a normally supported Homebrew installation, I might be too lazy to type my password for sudo, as it is not actually needed to remove launchctl during an upgrade. However, on an “Untar Anywhere” (unsupported) installation on a machine where I don't have access to an administrator account, it is not possible to use sudo to remove launchctl and resulted in failed commands.

What happens if you just hit enter instead of your command in these cases?

We're unlikely to spend much time trying to improve the unsupported case.</comment_new>
<comment_new>@MikeMcQuaid
@mio-19 ok so the request is that if it fails this isn't fatal?

Did you need sudo to install microsoft-edge?</comment_new>
<comment_new>@MikeMcQuaid
@mio-19 Do you have any examples that don't require sudo to install but do to uninstall?</comment_new>
<comment_new>@MikeMcQuaid
Ok, thanks @mio-19. I've updated the issue title here to what I think we should aim for. It shouldn't be an option but just make this operation non-fatal in this situation.</comment_new>

Fixes #19486

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Make launchctl service removal sudo failures non-fatal Make launchctl service removal sudo failures non-fatal Oct 2, 2025
Copilot AI requested a review from MikeMcQuaid October 2, 2025 16:18
Copilot finished work on behalf of MikeMcQuaid October 2, 2025 16:18
@MikeMcQuaid MikeMcQuaid force-pushed the copilot/fix-41f40889-e223-4c24-9687-4f4949cfd718 branch from 4abb160 to 3eb0e5d Compare October 3, 2025 14:28
@MikeMcQuaid MikeMcQuaid marked this pull request as ready for review October 3, 2025 14:29
@MikeMcQuaid MikeMcQuaid enabled auto-merge October 3, 2025 14:30
@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue Oct 6, 2025
Merged via the queue into main with commit c8b5422 Oct 6, 2025
38 checks passed
@MikeMcQuaid MikeMcQuaid deleted the copilot/fix-41f40889-e223-4c24-9687-4f4949cfd718 branch October 6, 2025 08:23
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.

Make launchctl service removal sudo failures non-fatal

3 participants