Skip to content

Commit 47e0f56

Browse files
fix(server): a launchctl print that times out no longer ends the launch agent wait
Only a print that runs and exits non-zero confirms the label is gone; a probe that fails to run or times out keeps the wait polling. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 993cfc5 commit 47e0f56

2 files changed

Lines changed: 37 additions & 4 deletions

File tree

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ const makeHarness = Effect.fn("test.make_boot_service_harness")(function* (
138138
enabled: boolean;
139139
active: boolean;
140140
launchd: LaunchdJob | undefined;
141-
onCommand?: (command: string) => Effect.Effect<void>;
141+
onCommand?: (command: string) => Effect.Effect<void, ProcessRunner.ProcessRunError>;
142142
} = {
143143
failCommand: undefined,
144144
linger: "yes",
@@ -939,6 +939,35 @@ it.layer(NodeServices.layer)("boot service install", (it) => {
939939
}),
940940
);
941941

942+
it.effect("keeps waiting for a draining launch agent when a print times out", () =>
943+
Effect.gen(function* () {
944+
const { service, control } = yield* makeHarness("darwin");
945+
yield* service.install();
946+
control.launchd = { loaded: true, exitPrints: 1 };
947+
const afterBootout = yield* Deferred.make<void>();
948+
// The first print times out; a premature bootstrap also releases the clock.
949+
control.onCommand = (command) =>
950+
Effect.gen(function* () {
951+
if (!/^launchctl (print|bootstrap) /.test(command)) return;
952+
const first = yield* Deferred.succeed(afterBootout, undefined);
953+
if (first && command.startsWith("launchctl print ")) {
954+
return yield* new ProcessRunner.ProcessTimeoutError({
955+
command: "launchctl",
956+
argumentCount: 2,
957+
timeoutMs: 5000,
958+
});
959+
}
960+
});
961+
962+
const reinstall = yield* service.install().pipe(Effect.forkChild);
963+
yield* Deferred.await(afterBootout);
964+
yield* TestClock.adjust("1 second");
965+
yield* Fiber.join(reinstall);
966+
967+
expect(control.launchd.loaded).toBe(true);
968+
}),
969+
);
970+
942971
it.effect("keeps failed launch agent installs pending until activation succeeds", () =>
943972
Effect.gen(function* () {
944973
const { service, fs, statePath, commands, control } = yield* makeHarness("darwin");

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ export interface BootServiceStep {
187187
readonly optional?: boolean;
188188
readonly timeout?: Duration.Input;
189189
/**
190-
* Then rerun the command with these args until they fail, within `timeout`. The step succeeds
191-
* once they fail, whatever the first command exited with.
190+
* Then rerun the command with these args until it runs and exits non-zero, within `timeout`.
191+
* The step succeeds then, whatever the first command exited with.
192192
*/
193193
readonly waitWhile?: ReadonlyArray<string>;
194194
}
@@ -637,7 +637,11 @@ export const make = Effect.fn("cloud.boot_service.make")(function* (input: {
637637

638638
const waitWhile = (entry: BootServiceStep, args: ReadonlyArray<string>) =>
639639
probe(entry.command, args).pipe(
640-
Effect.repeat({ while: succeeded, schedule: Schedule.spaced(WAIT_WHILE_INTERVAL) }),
640+
// A probe that fails to run or times out proves nothing about the job; keep waiting.
641+
Effect.repeat({
642+
while: (result) => Option.isNone(result) || result.value.code === 0,
643+
schedule: Schedule.spaced(WAIT_WHILE_INTERVAL),
644+
}),
641645
Effect.timeoutOrElse({
642646
duration: entry.timeout ?? STOP_STEP_TIMEOUT,
643647
orElse: () => Effect.fail(new BootServiceCommandError({ step: entry.step })),

0 commit comments

Comments
 (0)