Skip to content
Source
Sign inSign up
pingdotgg/t3code

feat(server): run the background service on macOS via launchd #6286

Mergedt3dotgg(GitHub profile, opens in a new tab)merged 5 commits intomain fromrefs/pull/6286/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

Wanted the T3 Connect/serve daemon running in the background on a Mac, the same way it works on Linux. But `t3 service install` was systemd-only and failed closed on darwin.

Now macOS gets a per-user LaunchAgent (`~/Library/LaunchAgents/com.t3tools.t3code.service.plist`). The pinned runtime, stable launcher, and remote-update protocol are reused unchanged; only the service-manager layer is new. The platform split is a small data-driven `BootServiceManager` (paths, pure renderer, command steps), so install/uninstall/status stay single-flow with no platform branches. launchctl steps that fail on already/not-loaded states are tolerated; the final `kickstart -k` stays strict so a broken setup fails loudly.

Honest semantics: a LaunchAgent starts at login and stops at logout (no linger equivalent), so onboarding copy and docs say so instead of promising boot-time behavior.

Verified end to end on an M-series Mac with an isolated `T3CODE_HOME`: install pins `t3@0.0.33` from npm, the job runs, killing the launcher gets respawned by KeepAlive, the child server carries the launcher IPC context (so remote self-update capability is advertised), and uninstall removes the job and plist cleanly. 28 tests pass across the touched files.


Built by Claude Code (Fable 5) with human direction from Theo.


Note

Medium Risk Touches host service installation and long-blocking launchctl/systemctl orchestration; mistakes could leave a broken or stale agent, though behavior is heavily tested and Linux paths are mostly refactored, not rewritten.

Overview macOS can now install the same pinned-launcher background service via a per-user LaunchAgent (~/Library/LaunchAgents/com.t3tools.t3code.service.plist). Linux systemd behavior is unchanged; Windows still fails closed.

bootService is refactored around a BootServiceManager abstraction: each platform supplies paths, a pure unit/plist renderer, and declarative launchctl / systemctl step lists consumed by shared install / uninstall / status flows. macOS uses bootout --wait, optional enable/bootout steps, 120s stop timeouts (above systemd/ExitTimeOut), and plist settings aligned with the existing launcher/update model. HostProcessUserId (process.getuid() on POSIX) drives the gui/<uid> launchd domain.

Onboarding and status copy no longer promise post-logout reachability on Mac: connect and service prompts describe login-scoped availability instead of boot/linger behavior. User and internal docs now document Linux vs macOS differences (SSH install, TCC, Login Items).

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit d3db1408e7449eec3555559a021189e176097e02. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Add macOS launchd support for the background boot service

  • Adds a launchdManager in bootService.ts that installs a launch agent plist, bootstraps it at login, and handles stop/restart/uninstall via launchctl.
  • Adds renderBootServicePlist to generate a launchd plist with RunAtLoad, KeepAlive, ThrottleInterval=5, ExitTimeOut=90, and consolidated stdout/stderr logging.
  • Refactors the boot service factory to select between systemd (Linux) and launchd (macOS) via a new selectBootServiceManager abstraction, using a new HostProcessUserId context for POSIX uid.
  • Updates CLI messaging and onboarding prompts to reflect macOS login-scoped persistence vs. Linux boot-time/linger persistence.
  • Behavioral Change: on macOS the service runs only while the user is logged in (no linger equivalent); Windows remains unsupported.
Macroscope summarized d3db140.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: 3cdab0e2-46d3-4cd5-817a-95c4e2704be1

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      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.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    3. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium

      https://github.com/pingdotgg/t3code/blob/adff784c33390ab3bf888ac76155083b77829c38/apps/server/src/cloud/bootService.ts#L269

      launchdManager.deactivate and launchdManager.stop mark launchctl bootout as optional: true, so runSteps ignores every non-zero exit — not just the intended "not loaded" case. During uninstall, a genuine bootout failure is followed by plist removal and a true return even though the KeepAlive agent is still running. During install/update, a failed bootout means the old job stays loaded; the subsequent bootstrap failure is also swallowed (also optional), and kickstart -k restarts the still-loaded job with the old cached plist definition — yet install returns the new plan and status only compares the plist on disk, so callers are told the update is current while launchd runs the previous configuration. Consider making bootout failures fatal (or narrowing optionality to only the "not loaded" exit case) so genuine unload failures block the flow before rewriting files.

      No longer relevant as of 4fd54ed67b6b2536b28ca2d7b0a596f3542103e8

    4. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire11.3 KiB12.6 KiB+1.3 KiB (+11.3%)15.1 KiB✅
      CodexThread snapshot wire5.5 KiB6.3 KiB+848 B (+15.2%)7.3 KiB✅
      CodexLive turn WebSocket wire5.9 KiB6.3 KiB+468 B (+7.8%)7.8 KiB✅
      CodexLive turn WebSocket decoded49.7 KiB51.8 KiB+2.1 KiB (+4.2%)66.4 KiB✅
      CodexLive turn messages16160 (0.0%)21✅
      ClaudeTotal thread wire11.3 KiB12.6 KiB+1.3 KiB (+11.2%)15.1 KiB✅
      ClaudeThread snapshot wire5.5 KiB6.3 KiB+812 B (+14.5%)7.3 KiB✅
      ClaudeLive turn WebSocket wire5.9 KiB6.3 KiB+490 B (+8.2%)7.8 KiB✅
      ClaudeLive turn WebSocket decoded50.6 KiB52.7 KiB+2.1 KiB (+4.2%)66.4 KiB✅
      ClaudeLive turn messages16160 (0.0%)21✅

      Baseline: 5a84614 · PR result: d3db140 · Source CI: success

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 99.9 KiB
      • Claude decoded thread snapshot: 100.6 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    5. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — This PR introduces new macOS launchd support for the background service—a significant new feature with new platform integration logic. There is also an open Medium-severity finding about potential bootout compatibility issues on older macOS versions.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    6. Note

      🤖 Claude Fable 5 responding on behalf of Theo

      Half of this was fixed before the review posted, the other half is a deliberate bound.

      The install/update half no longer applies: 653a7880c removed kickstart -k entirely. The strict last step is now bootstrap, which fails loudly (EALREADY) when a genuine bootout failure leaves the old job loaded — no silent restart of a stale cached definition, and install errors instead of returning the new plan. The repair-failure test pins this.

      The uninstall half is a known limitation we're accepting: distinguishing "not loaded" from other bootout failures requires exit-code matching that isn't stable across macOS versions. The failure is written to the boot-service log, the running job dies at logout, and removing the plist stops every future login load. Commented at the deactivate table.

    7. github-actions[bot](GitHub profile, opens in a new tab) added labels📱 Native Change

    8. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot). Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit d3db1408e7449eec3555559a021189e176097e02. Configure [here](https://www.cursor.com/dashboard/bugbot).
      @@ -85,0 +279,21 @@
      279+ const serviceTarget = `${domainTarget}/${BOOT_SERVICE_LAUNCHD_LABEL}`;
      280+ // bootout/enable are optional: they fail on not-loaded states that are fine
      281+ // to proceed from. The strict `bootstrap` runs last and is also the start:
      282+ // loading a RunAtLoad/KeepAlive plist starts the job, so a separate
      283+ // kickstart would kill and restart a server it just booted. A lingering job
      284+ // that survived bootout, or a gui domain with nobody logged in at the
      285+ // screen (SSH install), makes bootstrap fail the flow loudly rather than
      286+ // silently keeping a stale server.
      287+ return {
      288+ kind: "launchd",
      289+ unitPath,
      290+ render: (plan) => renderBootServicePlist(plan, { homeDir: input.homeDir }),
      291+ // Without --wait, bootout returns in milliseconds while the job drains
      292+ // for up to ExitTimeOut, and a bootstrap during the drain fails EIO.
      293+ // --wait (present on modern macOS, absent from the man page) blocks until
      294+ // the job is removed from the domain; STOP_STEP_TIMEOUT outlives it.
      295+ stop: [
      296+ {
      297+ step: "stopping the installed launch agent",
      298+ command: "launchctl",
      299+ args: ["bootout", "--wait", serviceTarget],

      Optional bootout skips stop without --wait

      Medium Severity

      launchctl bootout --wait is not available before macOS 26, but stop and uninstall still mark that step optional. An unrecognized flag fails the command without unloading the job, the failure is ignored, and install then rewrites launcher and state under a still-running agent, after which bootstrap fails. Updates and reinstalls on Sequoia-era Macs never stop the existing service.

      Additional Locations (1)
      Fix in Cursor Fix in Web
      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit d3db1408e7449eec3555559a021189e176097e02. Configure [here](https://www.cursor.com/dashboard/bugbot).
    9. @t3dotgg this breaks T3 Connect auth for me on ARM MacOS 26.5.

      Connect was setup and linked and status was green:

      npx t3@0.0.34-nightly.20260819.1133 connect status

      Then, I ran npx t3@0.0.34-nightly.20260819.1133 service install and npx t3@0.0.34-nightly.20260819.1133 service status.

      It started T3 correctly, but Connect couldn't auth with cloudflared:

      <user>@<machine>:~ % ps aux | rg '[c]loudflared'
      <user>@<machine>:~ % tail -n 200 ~/.t3/userdata/logs/boot-service.log | \
        rg -i 'relay|cloudflared|tunnel|warning|error|failed'
          cause: 'RelayAuthInvalidError: Relay authentication failed: not_authorized\n' +
            '    at AgentAwarenessRelay.publishThread (file:///Users/<user>/.t3/runtime/versions/0.0.34-nightly.20260819.1133/node_modules/t3/dist/bin.mjs:175637:6)'
      [10:30:19.883] WARN (#248): agent activity publish failed
          cause: 'RelayAuthInvalidError: Relay authentication failed: not_authorized\n' +
          ...

Sign in to join this conversation.