Skip to content

[client] launch macOS GUI as the logged-in user after install/update - #6962

Open
riccardomanfrin wants to merge 6 commits into
mainfrom
fix-macos-update-inherits-root-home
Open

[client] launch macOS GUI as the logged-in user after install/update#6962
riccardomanfrin wants to merge 6 commits into
mainfrom
fix-macos-update-inherits-root-home

Conversation

@riccardomanfrin

@riccardomanfrin riccardomanfrin commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Describe your changes

In unattended installs/updates there may be no logged-in user, so there's no context to start the GUI (nor anyone to see it).

The bug is the GUI being started in the wrong user context / inheriting the wrong $HOME (OS mechanics aside).

Today the GUI is started by a per-user LaunchAgent, i.e. on behalf of the user who logs in — no login ⇒ no GUI.

The patch aligns to this: it launches the GUI on behalf of the logged-in console user if one exists, otherwise it delegates the launch to the per-user LaunchAgent at next login.

Additionally it logs when default UI settings are applied.

Note (small caveat): the LaunchAgent auto-starts the GUI at login only once it's been registered — which happens on the first GUI launch in the user's context. On an MDM/unattended fresh install done with no user logged in (where the user has never run the GUI before), they may need to start it manually once; it self-registers from then on.

Issue ticket number and link

No public issue — reported internally (community report on Slack: macOS advanced-view + onboarding reset on every update, esp. via MDM/Munki). Buggy line on main:

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)

Internal macOS installer / GUI-launch behavior. No public API, CLI, or configuration change: the fix only changes the user context the desktop GUI is launched in after a pkg install/update.

Docs PR URL (required if "docs added" is checked)

Paste the PR link from https://github.com/netbirdio/docs here:

N/A


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Summary by CodeRabbit

  • Bug Fixes

    • Improved macOS installation and updater UI launching to occur only when an active, valid GUI console session is detected.
    • Prevented UI launches during unattended/system, root, or login-window-related installs.
    • Ensured the app is launched in the correct console-user context, and skips cleanly when username/UID resolution fails.
  • Improvements

    • Added clearer informational logging when the UI preferences file is not found and default preferences are used.

Wails already does this: the GUI is started by a per-user LaunchAgent.
So starting the GUI assumes there is a user that is logging in to refer to.

We are aligning the auto-update to this model here.

IF there is a user, restart the GUI otherwise wait for a login.

WHY it didn't happen before 0.75: cause the Fyne GUI never wrote any ui_preferences.json file
or any other in users $HOME folder.

So it's a problem related to the new GUI and has nothing to do with MDM.
@riccardomanfrin
riccardomanfrin requested a review from pappz July 29, 2026 13:33
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: c621ce13-bede-4dda-90a3-64ad2a798078

📥 Commits

Reviewing files that changed from the base of the PR and between 4b5a8c3 and b09c808.

📒 Files selected for processing (1)
  • client/internal/updater/installer/installer_run_darwin.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • client/internal/updater/installer/installer_run_darwin.go

📝 Walkthrough

Walkthrough

The changes log missing UI preferences and make macOS GUI startup validate the active console user before launching under that user’s context.

Changes

Preferences and macOS GUI launch

Layer / File(s) Summary
Missing preferences logging
client/ui/preferences/store.go
Store.load logs the preferences path when the file does not exist before applying defaults.
Console-user-aware GUI launch
client/internal/updater/installer/installer_run_darwin.go, release_files/darwin_pkg/postinstall
The Go installer and post-install script reject non-interactive console users, resolve the active user context, and launch the GUI through launchctl asuser and sudo; launch failures are logged without aborting installation.

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

Possibly related PRs

Suggested reviewers: pappz

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: launching the macOS GUI as the logged-in user after install/update.
Description check ✅ Passed The description covers the change, issue context, stack, checklist, and documentation notes with enough detail for review.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-macos-update-inherits-root-home

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@release_files/darwin_pkg/postinstall`:
- Around line 43-45: Update the console-user launch flow around uid and
launchctl asuser to validate that the id -u lookup succeeds and returns a
non-empty UID before attempting launch. When lookup fails, handle it explicitly
instead of invoking launchctl with an empty UID; preserve the existing launch
behavior for valid users and avoid masking this failure with || true.
- Line 45: Update the GUI launch command in the postinstall flow to resolve and
validate the target user’s UID before calling launchctl, failing visibly when
lookup fails instead of swallowing errors with || true. Set HOME to the resolved
user’s HomeDir, consistent with the installer’s existing user-path handling,
when invoking launchctl asuser to open APP.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 525b87c4-c0c1-425a-8f70-7e400630476d

📥 Commits

Reviewing files that changed from the base of the PR and between f2c1070 and a5e71db.

📒 Files selected for processing (2)
  • client/ui/preferences/store.go
  • release_files/darwin_pkg/postinstall

Comment thread release_files/darwin_pkg/postinstall Outdated
Comment thread release_files/darwin_pkg/postinstall Outdated
@github-actions

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown

Release artifacts

Built for PR head b09c808 in workflow run #17249.

Artifact Link
All release artifacts Download
Linux packages Download
Windows packages Download
macOS packages Download
UI artifacts Download
UI macOS artifacts Download

GHCR images (amd64)

This comment is updated by the Release workflow. Artifact links expire according to the workflow retention policy.

Address CodeRabbit review on the pkg postinstall: resolve and validate the
console user's uid and home dir before launching, skip visibly instead of
masking with `|| true`, and set HOME to the resolved home so the GUI reads
the user's real ui-preferences.json.
…LOGNAME)

Both launch paths (pkg postinstall and the updater's startUIAsUser) run as
root, so launchctl asuser alone moves the launch into the user's GUI domain
but leaves root's HOME/USER/LOGNAME. Use sudo -u <user> -H to drop to the
console user with their environment, fixing os.UserConfigDir() resolution.
Drops the space-fragile dscl/awk home lookup and the duplicate-HOME append;
extracts consoleUser() and aligns the skip list across both paths.

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@client/internal/updater/installer/installer_run_darwin.go`:
- Line 113: Update the launch command execution in Start() to wait for launchctl
to finish and propagate its exit error, replacing Process.Release() with Run()
or an equivalent Start()/Wait() flow. Preserve the existing command arguments
and return the failure from launchctl, sudo, or open to the caller.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: da71b953-aa0d-4302-913a-3102ad67ad8f

📥 Commits

Reviewing files that changed from the base of the PR and between 4bba5b5 and 4b5a8c3.

📒 Files selected for processing (2)
  • client/internal/updater/installer/installer_run_darwin.go
  • release_files/darwin_pkg/postinstall
🚧 Files skipped from review as they are similar to previous changes (1)
  • release_files/darwin_pkg/postinstall

Comment thread client/internal/updater/installer/installer_run_darwin.go
Replace Start()+Process.Release() with Run() in startUIAsUser: the
launchctl/sudo/open chain is short-lived (open returns once LaunchServices
accepts the request), so waiting surfaces a launch failure to the caller
instead of swallowing it. Addresses CodeRabbit review.
@sonarqubecloud

Copy link
Copy Markdown

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.

1 participant