Skip to content

fix(mac): auto-start runner with the env it actually needs#783

Merged
buremba merged 1 commit into
mainfrom
fix/mac-no-auth-runner-env
May 17, 2026
Merged

fix(mac): auto-start runner with the env it actually needs#783
buremba merged 1 commit into
mainfrom
fix/mac-no-auth-runner-env

Conversation

@buremba
Copy link
Copy Markdown
Member

@buremba buremba commented May 17, 2026

Summary

PR #779 introduced no-auth mode but left three rough edges in the Mac app side of the spawn — each of which made the "Start" path silently fail end-to-end:

  1. `HOST=127.0.0.1` wasn't set — `start-local.ts` defaults `HOST=0.0.0.0` and the no-auth bind guard refuses non-loopback. Without this, the runner crashes on boot.
  2. No `LOBU_ALLOW_EPHEMERAL_ENCRYPTION_KEY=1` — the embedded gateway refuses to start without `ENCRYPTION_KEY` or this opt-in flag. For a personal install, the ephemeral key is the only sensible default.
  3. PATH didn't prefer Node 22 — Homebrew users with `node` = 25+ would crash the runner (isolated-vm only supports Node 22–24). Now `LocalLobuRunner.preferredPath` prepends well-known Node 22 install paths (Homebrew keg-only `node@22`, mise, fnm) to PATH for the spawn.

Plus two UX cleanups:

  • `AppState.connect()` now auto-fires on launch when credentials are nil and the URL targets the managed runner. No Start button click required for the 99% case. The connection card only surfaces on actual failure.
  • `startLocalLobu()`'s failure handler no longer echoes the runner error into `state.status`. The connection card's `connectStatusLine` already shows it in orange; echoing into `state.status` duplicated the message at the top of the popover (visible in the user's earlier screenshot).

Test plan

  • Fresh install with `node@22` keg-only present → click Lobu icon → popover transitions to signed-in within ~2s. No Start click, no browser, no error.
  • System has only Node 25+ → `brew install node@22` → relaunch → succeeds.
  • Move `/opt/homebrew/opt/node@22` aside → relaunch → connection card shows `Unsupported Node.js runtime` error inline (no duplicate in header).
  • Kill the runner mid-session → menu bar shows the failure inline; no header echo.

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Refined auto-connect behavior to activate only with the embedded local runner
    • Improved error message display when local service startup fails
  • Improvements

    • Enhanced local runner compatibility with better Node.js detection across common installation locations
    • Simplified embedded gateway configuration to reduce manual setup requirements

Review Change Stack

PR #779 introduced no-auth mode but left three rough edges in the Mac
app side of the spawn:

- HOST=127.0.0.1 wasn't set in the runner env. start-local.ts defaults
  HOST=0.0.0.0, and the no-auth bind guard refuses non-loopback, so
  Start would silently crash the runner on boot.

- ENCRYPTION_KEY isn't set on personal installs and the embedded gateway
  refuses to boot without it (or LOBU_ALLOW_EPHEMERAL_ENCRYPTION_KEY=1).
  For a personal install the ephemeral key is the only sensible default
  — opt in here so the user doesn't manage a secret manually.

- The bundled lobu CLI requires Node 22.x–24.x (isolated-vm constraint)
  but a user on Node 25+ via Homebrew's `node` formula would crash the
  runner. Prefer well-known Node 22 install paths (Homebrew keg-only
  `node@22`, mise, fnm) by prepending them to PATH for the spawn.

Also cleans up two related UX issues:

- AppState.connect() now auto-fires on launch when credentials are nil
  and the URL targets the managed runner — no Start button click needed
  for the 99% case. The connection card only surfaces on actual failure
  (CLI missing, port conflict, etc).

- startLocalLobu()'s failure handler no longer echoes the runner error
  into state.status. The connection card's connectStatusLine already
  shows it in orange under the button; echoing into state.status
  duplicates the message at the top of the popover.
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 17, 2026

📝 Walkthrough

Walkthrough

The PR refines the local runner startup flow on macOS: auto-connect at launch is now conditional on the server URL matching the embedded managed runner, the spawned process is configured with ephemeral encryption support and preferred Node discovery paths, and error handling is adjusted to avoid redundant status messages.

Changes

Local runner startup improvements

Layer / File(s) Summary
Auto-connect conditional at launch
apps/mac/Lobu/AppState.swift
A new shouldAutoConnectAtLaunch() helper parses the custom server URL and gates the auto-connect logic to only trigger when the URL matches the embedded managed runner.
Process environment and Node discovery
apps/mac/Lobu/LocalLobuRunner.swift
The start() method now configures the spawned process with an ephemeral encryption key environment variable and a custom PATH built by preferredPath() that prioritizes known Node 22/24 locations (Homebrew, keg-only, version managers) to ensure the embedded gateway finds a compatible Node interpreter.
Error handling UI alignment
apps/mac/Lobu/AppState.swift
The startLocalLobu() error handler now clears the header status field for both CLI-not-found and other errors, so failure information is surfaced only through localLobuStatus rather than duplicated status messages.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • lobu-ai/lobu#779: Both PRs modify the local runner startup path in AppState and LocalLobuRunner, including managed-runner matching logic and process environment setup.

Poem

🐰 A rabbit hops through node paths with glee,
Encryption blooming wild and free,
Auto-connect now knows its place,
Status messages keep their grace.
Launch and run without a care,
The local lobu's nestled there! 🎯

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main changes: fixing environment configuration for the Mac runner startup with required variables and auto-connection improvements.
Description check ✅ Passed The PR description is comprehensive with clear summary of the three environment fixes and two UX improvements, along with detailed test plan steps, though test plan items are unchecked.
Docstring Coverage ✅ Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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/mac-no-auth-runner-env

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

@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
apps/mac/Lobu/LocalLobuRunner.swift (1)

166-187: 💤 Low value

Consider adding nvm and asdf paths for broader coverage.

The current candidates cover Homebrew keg-only, mise, and fnm. Two other popular version managers (nvm and asdf) have different path structures that aren't covered:

  • nvm: ~/.nvm/versions/node/v22.*/bin
  • asdf: ~/.asdf/installs/nodejs/22.*/bin

These require glob expansion, which adds complexity. The current approach is pragmatic since Homebrew and mise/fnm cover the most common macOS setups, and users of nvm/asdf typically have their shell already configured to put the right Node on PATH. This is a nice-to-have for future consideration.

🤖 Prompt for 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.

In `@apps/mac/Lobu/LocalLobuRunner.swift` around lines 166 - 187, preferredPath
currently checks a fixed list of candidate prefixes (variable candidates) and
only covers Homebrew, mise and fnm; add expansion for nvm and asdf installs by
globbing their versioned directories and inserting any matching bin paths ahead
of currentPath. Modify preferredPath to: (1) construct the existing candidates,
(2) expand globs for "~/.nvm/versions/node/v22*/bin" and
"~/.asdf/installs/nodejs/22*/bin" (resolving ~ with NSHomeDirectory()), (3)
filter the resulting prefixes using FileManager.default.isExecutableFile(atPath:
"\(prefix)/node") as done now, and (4) return (prefixes +
[currentPath]).joined(separator: ":") so nvm/asdf matches are considered first
if present.
🤖 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.

Nitpick comments:
In `@apps/mac/Lobu/LocalLobuRunner.swift`:
- Around line 166-187: preferredPath currently checks a fixed list of candidate
prefixes (variable candidates) and only covers Homebrew, mise and fnm; add
expansion for nvm and asdf installs by globbing their versioned directories and
inserting any matching bin paths ahead of currentPath. Modify preferredPath to:
(1) construct the existing candidates, (2) expand globs for
"~/.nvm/versions/node/v22*/bin" and "~/.asdf/installs/nodejs/22*/bin" (resolving
~ with NSHomeDirectory()), (3) filter the resulting prefixes using
FileManager.default.isExecutableFile(atPath: "\(prefix)/node") as done now, and
(4) return (prefixes + [currentPath]).joined(separator: ":") so nvm/asdf matches
are considered first if present.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8dc1f78a-ef2a-47cd-989b-f8be07231a6e

📥 Commits

Reviewing files that changed from the base of the PR and between a3e6f0a and 2db8658.

📒 Files selected for processing (2)
  • apps/mac/Lobu/AppState.swift
  • apps/mac/Lobu/LocalLobuRunner.swift

@buremba buremba merged commit f8013b5 into main May 17, 2026
21 of 24 checks passed
@buremba buremba deleted the fix/mac-no-auth-runner-env branch May 17, 2026 00:34
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.

2 participants