Skip to content

Commit 9eab482

Browse files
fix(server): a launch agent still loaded at the stop deadline fails the stop
The launchd stop is no longer optional: an unloaded job passes the wait, and one still loaded after 120s now stops install, restart and uninstall instead of letting them bootstrap over it or remove its plist. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 47e0f56 commit 9eab482

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

‎apps/server/src/cloud/bootService.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as ConfigProvider from "effect/ConfigProvider";
55
import * as Duration from "effect/Duration";
66
import * as Deferred from "effect/Deferred";
77
import * as Effect from "effect/Effect";
8+
import * as Exit from "effect/Exit";
89
import * as Fiber from "effect/Fiber";
910
import * as FileSystem from "effect/FileSystem";
1011
import * as Layer from "effect/Layer";
@@ -968,6 +969,26 @@ it.layer(NodeServices.layer)("boot service install", (it) => {
968969
}),
969970
);
970971

972+
it.effect("keeps the launch agent installed when it is still loaded at the stop deadline", () =>
973+
Effect.gen(function* () {
974+
const { service, control, fs } = yield* makeHarness("darwin");
975+
const plan = yield* service.install();
976+
control.launchd = { loaded: true, exitPrints: Number.POSITIVE_INFINITY };
977+
const polling = yield* Deferred.make<void>();
978+
control.onCommand = (command) =>
979+
command.startsWith("launchctl print ")
980+
? Deferred.succeed(polling, undefined).pipe(Effect.asVoid)
981+
: Effect.void;
982+
983+
const uninstall = yield* service.uninstall.pipe(Effect.exit, Effect.forkChild);
984+
yield* Deferred.await(polling);
985+
yield* TestClock.adjust("121 seconds");
986+
987+
expect(Exit.isFailure(yield* Fiber.join(uninstall))).toBe(true);
988+
expect(yield* fs.exists(plan.unitPath)).toBe(true);
989+
}),
990+
);
991+
971992
it.effect("keeps failed launch agent installs pending until activation succeeds", () =>
972993
Effect.gen(function* () {
973994
const { service, fs, statePath, commands, control } = yield* makeHarness("darwin");

‎apps/server/src/cloud/bootService.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,11 @@ function launchdManager(input: {
303303
// Unloaded jobs may reject bootout/enable. Bootstrap starts RunAtLoad/KeepAlive jobs; kickstart would restart them.
304304
// bootout can return (0, or 36 EINPROGRESS) while the job drains through ExitTimeOut, and a bootstrap
305305
// then fails EIO, so wait until `print` no longer finds the label. macOS 15 rejects `bootout --wait`.
306+
// Not optional: an unloaded job passes the wait, and one still loaded at the deadline must stop the caller.
306307
const bootout = {
307308
command: "launchctl",
308309
args: ["bootout", serviceTarget],
309310
waitWhile: ["print", serviceTarget],
310-
optional: true,
311311
timeout: STOP_STEP_TIMEOUT,
312312
};
313313
return {

0 commit comments

Comments
 (0)