@devries-cameron20 / t3code-1 / commits / da2d6ec2c8
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): remote updates no longer fail when the staged preflight is slow on a loaded host (#28201)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Nov 1, 2026 at 21:32 UTC da2d6ec2c881aaca225e7219e232e7a07a41b6fd
2 files changed +41 -1
apps/server/src/cloud/selfUpdate.test.ts
+39
@@ -3,6 +3,7 @@ import { expect, it } from "@effect/vitest";
3 import type { ManagedPolicyDocument } from "@t3tools/contracts";
4 import * as HostProcess from "@t3tools/shared/HostProcess";
5 import * as Deferred from "effect/Deferred";
6 +import * as Duration from "effect/Duration";
7 import * as Effect from "effect/Effect";
8 import * as FileSystem from "effect/FileSystem";
9 import * as Fiber from "effect/Fiber";
@@ -26,6 +27,8 @@ interface HarnessOptions {
27 readonly mode?: "web" | "desktop";
28 readonly managed?: boolean;
29 readonly preflight?: "ready" | "blocked";
30 + readonly preflightDuration?: Duration.Input;
31 + readonly preflightStarted?: Deferred.Deferred<void>;
32 readonly beforeDownload?: Effect.Effect<void>;
33 readonly requestUpdate?: ServiceLauncherClient.ServiceLauncherClient["Service"]["requestUpdate"];
34 readonly desktopAppUpdate?: DesktopAppUpdate.DesktopAppUpdate["Service"];
@@ -78,6 +81,21 @@ const makeHarness = Effect.fn("test.make_self_update_harness")(function* (
81 stderrInvalidUtf8: false,
82 };
83 }
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 + }
99 order.push("preflight");
100 const result =
101 options.preflight === "blocked"
@@ -240,6 +258,27 @@ it.layer(NodeServices.layer)("server self update", (it) => {
258 }),
259 );
260
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 +
282 it.effect("keeps preparing after the progress stream closes", () =>
283 Effect.gen(function* () {
284 const releaseDownload = yield* Deferred.make<void>();
apps/server/src/cloud/selfUpdate.ts
+2 -1
@@ -45,7 +45,8 @@ import { decodeServicePreflightResult } from "./servicePreflight.ts";
45 import * as ServiceLauncherClient from "./serviceLauncherClient.ts";
46 import { isExactServiceVersion, SERVICE_LAUNCHER_PROTOCOL } from "./serviceProtocol.ts";
47
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);
50
51 export function resolveServerSelfUpdateCapability(input: {
52 readonly desktopManaged: boolean;