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

Co-authored-by: Claude Fable 5 <[email protected]>
This commit is contained in:
Theo BrowneandClaude Fable 5 authored and GitHub committed 2026-08-19 01:04:51 -07:00
1 parent 7441b36926
commit 2aa5f095fc
11 files changed
+531 -78

No files matched your search

+7 -6
View File
@@ -2,14 +2,15 @@
> For maintainers. Using T3 Code? See [docs/user](../user/).
Remote server updates use one stable systemd launcher. Foreground CLI processes do not self-update,
and a running server never edits its systemd unit or durable service state.
Remote server updates use one stable launcher selected by the platform service manager (systemd on
Linux, launchd on macOS). Foreground CLI processes do not self-update, and a running server never
edits its service definition or durable service state.
## Ownership
The service files under `<baseDir>/runtime` are:
- `service-launcher.mjs`, the stable process selected by systemd;
- `service-launcher.mjs`, the stable process selected by the service manager;
- `service-state.json`, the launcher's durable selection state;
- `versions/<version>`, immutable exact-version npm installs.
@@ -22,7 +23,7 @@ The state contains one active version and, at most, one update record:
- `pending A → B` selects B as a retryable trial;
- `committed A → B` selects B for ordinary restarts;
- `rolled-back A → B` or `failed A → B` selects A;
- invalid state fails closed so systemd cannot guess at a runtime.
- invalid state fails closed so the service manager cannot guess at a runtime.
Every write uses same-directory replacement plus file and directory fsync.
@@ -50,8 +51,8 @@ operations. It only opens prepared gates and publishes prepared lifecycle state.
The launcher serializes child exits, IPC messages, and timers. A trial must report prepared within
120 seconds. If the trial exits or times out before prepared, the launcher stops it, restores the
snapshot, records rollback, and starts A. A durable restore marker makes an interrupted restore
resume before either version can boot. After commit, B is active and normal systemd restart policy
applies.
resume before either version can boot. After commit, B is active and the service manager's normal
restart policy applies.
## Database Rollback
+35 -11
View File
@@ -1,7 +1,7 @@
# Running T3 Code in the Background
On a Linux host, T3 Code can run as a background service for your user. It starts when the machine
boots and keeps running after you log out.
On Linux and macOS, T3 Code can run as a background service for your user, so it is ready without
keeping a terminal open.
## Manage the Service
@@ -32,18 +32,42 @@ npx t3@latest service uninstall
Updating restarts T3 Code briefly. Let active agent work and terminal commands finish first.
If a remote update is already in progress, wait for it to finish before retrying a local update.
The systemd unit runs a small stable launcher. Exact T3 Code versions are installed separately, so
a failed remote candidate can return to the previous version without rewriting the unit. The
launcher snapshots the database before a remote candidate starts, so database updates roll back
with the server version. An older launcher may require one local `service update` before this is
available.
The service runs a small stable launcher. Exact T3 Code versions are installed separately, so a
failed remote candidate can return to the previous version without rewriting the service
definition. The launcher snapshots the database before a remote candidate starts, so database
updates roll back with the server version. An older launcher may require one local
`service update` before this is available.
## Platform Support
**Linux** uses a systemd user unit at `~/.config/systemd/user/t3code.service`. The service starts
when the machine boots and keeps running after you log out (lingering is enabled during install).
**macOS** uses a launch agent at `~/Library/LaunchAgents/com.t3tools.t3code.service.plist`. It
starts when you log in, not when the Mac boots, and it stops when you log out; macOS has no
equivalent of Linux lingering for user agents. For a Mac that should stay reachable unattended,
turn on automatic login (System Settings → Users & Groups; unavailable while FileVault is on) and
keep the Mac from sleeping.
A few more macOS notes:
- Installing over SSH needs someone logged in at the Mac's screen to start the agent right away.
Without that, the install command reports an error at the final start step, but the agent is
fully installed and starts at the next login.
- macOS may show privacy prompts for protected folders such as Desktop, Documents, or Downloads,
attributed to a bare `node` process, or deny access without a prompt. If agent work fails to
read those folders, grant Full Disk Access to the node binary listed in the launch agent's
`ProgramArguments`.
- The agent appears under System Settings → General → Login Items. If it was switched off there,
or disabled with `launchctl disable`, macOS will not start it at login until you switch it back
on.
**Windows** is not supported yet.
## Using It with T3 Connect
T3 Connect may offer to install the service during setup so the host stays reachable after you log
out. This is only an onboarding shortcut: the service and T3 Connect are managed separately.
T3 Connect may offer to install the service during setup so the host stays reachable in the
background. This is only an onboarding shortcut: the service and T3 Connect are managed separately.
Signing out of T3 Connect does not remove the service. Use `t3 service uninstall` when you no longer
want T3 Code to start in the background.
The background service currently requires Linux with systemd.