diff --git a/apps/server/src/cloud/bootService.test.ts b/apps/server/src/cloud/bootService.test.ts
index 2547b0811b..57a11b85c8 100644
--- a/apps/server/src/cloud/bootService.test.ts
+++ b/apps/server/src/cloud/bootService.test.ts
@@ -67,8 +67,8 @@ it("keeps launchd pinned to the stable launcher rather than a versioned server",
it("restarts the launch agent on the systemd cadence", () => {
const plist = BootService.renderBootServicePlist(macPlan, { homeDir: "/Users/theo" });
- expect(plist).toContain("RunAtLoad");
- expect(plist).toContain("KeepAlive");
+ expect(plist).toContain("RunAtLoad\n ");
+ expect(plist).toContain("KeepAlive\n ");
expect(plist).toContain("ThrottleInterval\n 5");
});
@@ -276,7 +276,7 @@ it.layer(NodeServices.layer)("boot service install", (it) => {
yield* service.install;
const plistPath = (yield* service.status).unitPath;
commands.length = 0;
- control.failCommand = "launchctl kickstart -k gui/501/com.t3tools.t3code.service";
+ control.failCommand = `launchctl bootstrap gui/501 ${plistPath}`;
const error = yield* service.install.pipe(Effect.flip);
expect(error._tag).toBe("BootServiceCommandError");
@@ -284,9 +284,7 @@ it.layer(NodeServices.layer)("boot service install", (it) => {
"launchctl bootout gui/501/com.t3tools.t3code.service",
"launchctl enable gui/501/com.t3tools.t3code.service",
`launchctl bootstrap gui/501 ${plistPath}`,
- "launchctl kickstart -k gui/501/com.t3tools.t3code.service",
`launchctl bootstrap gui/501 ${plistPath}`,
- "launchctl kickstart -k gui/501/com.t3tools.t3code.service",
]);
}),
);
@@ -326,7 +324,6 @@ it.layer(NodeServices.layer)("boot service install", (it) => {
expect(commands.filter((command) => command.startsWith("launchctl "))).toEqual([
"launchctl bootout gui/501/com.t3tools.t3code.service",
`launchctl bootstrap gui/501 ${plistPath}`,
- "launchctl kickstart -k gui/501/com.t3tools.t3code.service",
]);
}),
);
diff --git a/apps/server/src/cloud/bootService.ts b/apps/server/src/cloud/bootService.ts
index 939963ecba..e0266c1996 100644
--- a/apps/server/src/cloud/bootService.ts
+++ b/apps/server/src/cloud/bootService.ts
@@ -103,8 +103,11 @@ export function renderBootServicePlist(
): string {
// KeepAlive + ThrottleInterval mirror Restart=always + RestartSec=5. launchd
// has no StartLimitBurst analog; a hard crash loop respawns every 5s forever.
- // ExitTimeOut must exceed the server's graceful shutdown plus the launcher's
- // 5s child SIGKILL grace, or launchd (default 20s) SIGKILLs mid-shutdown.
+ // ExitTimeOut 90 matches systemd's default TimeoutStopSec. A plain stop
+ // completes within the launcher's 5s child grace, but a stop that queues
+ // behind an in-flight update transition can take much longer; launchd's
+ // default 20s would SIGKILL the launcher (and, with it, the process group)
+ // mid-handoff.
// ProcessType Interactive opts out of background-job resource throttling.
// AbandonProcessGroup stays at its default (false): launchd reaps leftover
// process-group members only when the launcher itself exits — the analog of
@@ -138,7 +141,7 @@ export function renderBootServicePlist(
` ThrottleInterval`,
` 5`,
` ExitTimeOut`,
- ` 30`,
+ ` 90`,
` ProcessType`,
` Interactive`,
` StandardOutPath`,
@@ -258,10 +261,13 @@ export function launchdManager(input: {
);
const domainTarget = `gui/${input.uid}`;
const serviceTarget = `${domainTarget}/${BOOT_SERVICE_LAUNCHD_LABEL}`;
- // bootout/enable/bootstrap are optional: they fail on not-loaded /
- // already-loaded states that are fine to proceed from. The strict
- // `kickstart -k` runs last, so a genuinely broken gui domain (e.g. an SSH
- // session with nobody logged in at the screen) still fails the flow loudly.
+ // bootout/enable are optional: they fail on not-loaded states that are fine
+ // to proceed from. The strict `bootstrap` runs last and is also the start:
+ // loading a RunAtLoad/KeepAlive plist starts the job, so a separate
+ // kickstart would kill and restart a server it just booted. A lingering job
+ // that survived bootout, or a gui domain with nobody logged in at the
+ // screen (SSH install), makes bootstrap fail the flow loudly rather than
+ // silently keeping a stale server.
return {
kind: "launchd",
unitPath,
@@ -282,30 +288,18 @@ export function launchdManager(input: {
args: ["enable", serviceTarget],
optional: true,
},
- {
- step: "loading the launch agent",
- command: "launchctl",
- args: ["bootstrap", domainTarget, unitPath],
- optional: true,
- },
// Start last. No administrative state write occurs after this succeeds.
{
step: "starting the service",
command: "launchctl",
- args: ["kickstart", "-k", serviceTarget],
+ args: ["bootstrap", domainTarget, unitPath],
},
],
restart: [
- {
- step: "reloading the launch agent after a failed update",
- command: "launchctl",
- args: ["bootstrap", domainTarget, unitPath],
- optional: true,
- },
{
step: "restarting the service after a failed update",
command: "launchctl",
- args: ["kickstart", "-k", serviceTarget],
+ args: ["bootstrap", domainTarget, unitPath],
},
],
// No `launchctl disable` here: a persisted override would sabotage a
diff --git a/docs/user/background-service.md b/docs/user/background-service.md
index 218b30d340..f0632cba99 100644
--- a/docs/user/background-service.md
+++ b/docs/user/background-service.md
@@ -46,15 +46,18 @@ when the machine boots and keeps running after you log out (lingering is enabled
**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) and keep the Mac from sleeping.
+turn on automatic login (System Settings → Users & Groups; unavailable while FileVault is on) and
+keep the Mac from sleeping.
Two more macOS notes:
-- Installing over SSH only starts the agent immediately when someone is also logged in at the
- Mac's screen. Otherwise the install completes and the agent starts at the next login.
-- A background agent cannot answer macOS privacy prompts. If agent work fails to read protected
- folders such as Desktop, Documents, or Downloads, grant Full Disk Access to the node binary
- listed in the launch agent's `ProgramArguments`.
+- 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`.
**Windows** is not supported yet.