Skip to content

Commit da2d6ec

Browse files
fix(server): remote updates no longer fail when the staged preflight is slow on a loaded host (pingdotgg#28201)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 1973e0a commit da2d6ec

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { expect, it } from "@effect/vitest";
33
import type { ManagedPolicyDocument } from "@t3tools/contracts";
44
import * as HostProcess from "@t3tools/shared/HostProcess";
55
import * as Deferred from "effect/Deferred";
6+
import * as Duration from "effect/Duration";
67
import * as Effect from "effect/Effect";
78
import * as FileSystem from "effect/FileSystem";
89
import * as Fiber from "effect/Fiber";
@@ -26,6 +27,8 @@ interface HarnessOptions {
2627
readonly mode?: "web" | "desktop";
2728
readonly managed?: boolean;
2829
readonly preflight?: "ready" | "blocked";
30+
readonly preflightDuration?: Duration.Input;
31+
readonly preflightStarted?: Deferred.Deferred<void>;
2932
readonly beforeDownload?: Effect.Effect<void>;
3033
readonly requestUpdate?: ServiceLauncherClient.ServiceLauncherClient["Service"]["requestUpdate"];
3134
readonly desktopAppUpdate?: DesktopAppUpdate.DesktopAppUpdate["Service"];
@@ -78,6 +81,21 @@ const makeHarness = Effect.fn("test.make_self_update_harness")(function* (
7881
stderrInvalidUtf8: false,
7982
};
8083
}
84+
if (options.preflightStarted) yield* Deferred.succeed(options.preflightStarted, undefined);
85+
if (options.preflightDuration !== undefined) {
86+
// Like the real runner, fail once the caller's timeout elapses.
87+
const timeout = Duration.fromInputUnsafe(input.timeout ?? "60 seconds");
88+
const finished = yield* Effect.sleep(options.preflightDuration).pipe(
89+
Effect.timeoutOption(timeout),
90+
);
91+
if (finished._tag === "None") {
92+
return yield* new ProcessRunner.ProcessTimeoutError({
93+
command: input.command,
94+
argumentCount: input.args.length,
95+
timeoutMs: Duration.toMillis(timeout),
96+
});
97+
}
98+
}
8199
order.push("preflight");
82100
const result =
83101
options.preflight === "blocked"
@@ -240,6 +258,27 @@ it.layer(NodeServices.layer)("server self update", (it) => {
240258
}),
241259
);
242260

261+
// regression: #28198 a slow staged preflight on a loaded host no longer fails the update
262+
it.effect("waits for a staged preflight that takes a minute on a loaded host", () =>
263+
Effect.gen(function* () {
264+
const preflightStarted = yield* Deferred.make<void>();
265+
const { selfUpdate, order } = yield* makeHarness({
266+
preflightDuration: "60 seconds",
267+
preflightStarted,
268+
});
269+
const update = yield* Effect.forkChild(selfUpdate.update({ targetVersion: "1.1.0" }), {
270+
startImmediately: true,
271+
});
272+
yield* Deferred.await(preflightStarted);
273+
yield* TestClock.adjust("60 seconds");
274+
const exit = yield* Fiber.await(update);
275+
expect(exit._tag === "Failure" ? String(exit.cause) : "launcher handoff").toBe(
276+
"launcher handoff",
277+
);
278+
expect(order).toEqual(["download", "extract", "preflight", "accept"]);
279+
}),
280+
);
281+
243282
it.effect("keeps preparing after the progress stream closes", () =>
244283
Effect.gen(function* () {
245284
const releaseDownload = yield* Deferred.make<void>();

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ import { decodeServicePreflightResult } from "./servicePreflight.ts";
4545
import * as ServiceLauncherClient from "./serviceLauncherClient.ts";
4646
import { isExactServiceVersion, SERVICE_LAUNCHER_PROTOCOL } from "./serviceProtocol.ts";
4747

48-
const PREFLIGHT_TIMEOUT = Duration.seconds(30);
48+
// A staged runtime's cold start can take over a minute on a loaded, swapping host.
49+
const PREFLIGHT_TIMEOUT = Duration.minutes(3);
4950

5051
export function resolveServerSelfUpdateCapability(input: {
5152
readonly desktopManaged: boolean;

0 commit comments

Comments
 (0)