The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 16:00 UTC
perf(web): Update everything downloads a server's update while providers install (#35346)
Co-authored-by: shivam <91240327+shivamhwp@users.noreply.github.com>
Bilal Bakr committed
Nov 14, 2026 at 13:27 UTC
5958d00ede91d3bd6f1f85c26bd162100e51ac91
10 files changed
+111
-6
apps/server/src/cloud/selfUpdate.test.ts
+13
@@ -346,6 +346,19 @@ it.layer(NodeServices.layer)("server self update", (it) => {
346
}),
347
);
348
349
+ it.effect("stages the runtime without asking the launcher to restart", () =>
350
+ Effect.gen(function* () {
351
+ const { selfUpdate, order } = yield* makeHarness();
352
+ expect(yield* selfUpdate.update({ targetVersion: "1.1.0", stageOnly: true })).toEqual({
353
+ targetVersion: "1.1.0",
354
+ method: "boot-service",
355
+ });
356
+ expect(order).toEqual(["download", "extract", "preflight"]);
357
+ expect((yield* selfUpdate.update({ targetVersion: "1.1.0" })).updateId).toBe("launcher-id");
358
+ expect(order).toEqual(["download", "extract", "preflight", "preflight", "accept"]);
359
+ }),
360
+ );
361
+
362
// regression: #28198 a slow staged preflight on a loaded host no longer fails the update
363
it.effect("waits for a staged preflight that takes a minute on a loaded host", () =>
364
Effect.gen(function* () {
apps/server/src/cloud/selfUpdate.ts
+4
@@ -323,6 +323,10 @@ export const make = Effect.fn("cloud.server_self_update.make")(function* () {
323
}),
324
);
325
326
+ if (input.stageOnly === true) {
327
+ yield* Ref.set(inFlight, false);
328
+ return { targetVersion, method: "boot-service" as const };
329
+ }
330
yield* reportProgress("installing");
331
const updateId = yield* Effect.uninterruptible(
332
launcher.requestUpdate({ targetVersion, dbPath: serverConfig.dbPath }).pipe(
apps/server/src/environment/ServerEnvironment.ts
+1
@@ -287,6 +287,7 @@ export const make = Effect.gen(function* () {
287
...(serverSelfUpdate === "boot-service" || desktopAppUpdate
288
? { serverSelfUpdateProgress: true }
289
: {}),
290
+ ...(serverSelfUpdate === "boot-service" ? { serverUpdateStaging: true } : {}),
291
...(desktopAppUpdate ? { desktopAppUpdate: true, desktopAppChannelSwitch: true } : {}),
292
serverBrowser: true,
293
peerLinks: true,
apps/web/src/components/sidebar/updateEverything.logic.test.ts
+44
@@ -331,6 +331,50 @@ describe("runUpdateEverything", () => {
331
expect(calls).toEqual(["providers", "servers"]);
332
expect(result.localReady).toBe(false);
333
});
334
+
335
+ it("stages servers while providers install and updates each once its own stage settles", async () => {
336
+ const calls: string[] = [];
337
+ const [slow, fast] = [EnvironmentId.make("slow"), EnvironmentId.make("fast")];
338
+ let finishProviders = () => {};
339
+ let failSlowStage = () => {};
340
+ const providers = new Promise<void>((resolve) => (finishProviders = resolve));
341
+ const run = runUpdateEverything({
342
+ updateProviders: () => {
343
+ calls.push("providers");
344
+ return providers.then(() => {
345
+ calls.push("providers done");
346
+ });
347
+ },
348
+ stageServers: () => {
349
+ calls.push("stage");
350
+ return new Map([
351
+ [slow, new Promise((_, reject) => (failSlowStage = () => reject(new Error("failed"))))],
352
+ [fast, Promise.resolve()],
353
+ ]);
354
+ },
355
+ updateServers: (staged) => {
356
+ calls.push("servers");
357
+ return Promise.all(
358
+ [slow, fast].map(async (id) => {
359
+ await staged.get(id);
360
+ calls.push(`server ${id}`);
361
+ if (id === fast) failSlowStage();
362
+ }),
363
+ );
364
+ },
365
+ });
366
+ finishProviders();
367
+ await run;
368
+
369
+ expect(calls).toEqual([
370
+ "stage",
371
+ "providers",
372
+ "providers done",
373
+ "servers",
374
+ "server fast",
375
+ "server slow",
376
+ ]);
377
+ });
378
});
379
380
describe("describeUpdateEverything", () => {
apps/web/src/components/sidebar/updateEverything.logic.ts
+11
-4
@@ -348,11 +348,15 @@ function trackSwitchMove(
348
export interface UpdateEverythingSteps<Providers, Servers> {
349
readonly downloadLocal?: () => Promise<boolean>;
350
readonly updateProviders: () => Promise<Providers>;
351
- readonly updateServers: () => Promise<Servers>;
351
+ readonly stageServers?: () => ReadonlyMap<EnvironmentId, Promise<unknown>>;
352
+ readonly updateServers: (
353
+ staged: ReadonlyMap<EnvironmentId, Promise<unknown>>,
354
+ ) => Promise<Servers>;
355
}
356
354
-/** Finish provider installs before server restarts. Install this app last when localReady; failed
355
- * downloads skip only that install. */
357
+/** Finish provider installs before server restarts; servers stage meanwhile and each server's
358
+ * update waits only on its own stage. Install this app last when localReady; failed downloads skip
359
+ * only that install. */
360
export async function runUpdateEverything<Providers, Servers>(
361
steps: UpdateEverythingSteps<Providers, Servers>,
362
): Promise<{
@@ -360,11 +364,14 @@ export async function runUpdateEverything<Providers, Servers>(
364
readonly providers: Providers;
365
readonly servers: Servers;
366
}> {
367
+ const staged = new Map(
368
+ Array.from(steps.stageServers?.() ?? [], ([id, stage]) => [id, stage.catch(() => undefined)]),
369
+ );
370
const [localReady, remote] = await Promise.all([
371
steps.downloadLocal?.() ?? Promise.resolve(true),
372
steps
373
.updateProviders()
367
- .then(async (providers) => ({ providers, servers: await steps.updateServers() })),
374
+ .then(async (providers) => ({ providers, servers: await steps.updateServers(staged) })),
375
]);
376
return { localReady, ...remote };
377
}
apps/web/src/components/sidebar/useUpdateEverything.ts
+27
-2
@@ -6,8 +6,9 @@ import { isDesktopLocalConnectionTarget } from "~/connection/desktopLocal";
6
import { isElectron } from "~/env";
7
import { useEnvironments } from "~/state/environments";
8
import { environmentIdsKey } from "~/state/environmentAtomList";
9
-import { environmentUpdateStatesAtom } from "~/state/server";
9
+import { environmentUpdateStatesAtom, serverEnvironment } from "~/state/server";
10
import { environmentSessionStatesAtom } from "~/state/session";
11
+import { useAtomCommand } from "~/state/use-atom-command";
12
import { getProviderUpdateRunOutcome } from "../ProviderUpdateLaunchNotification.logic";
13
import { useProviderUpdates } from "../ProviderUpdatesAction";
14
import { canUpdateServer, type ServerUpdateOutcome, useServerUpdate } from "../ServerUpdateAction";
@@ -76,6 +77,9 @@ export function useUpdateEverything(
77
// A track switch moves app and servers only; provider updates stay a separate choice.
78
const providers = channelSwitch ? { machines: [], updateAll: async () => [] } : providerUpdates;
79
const updateServer = useServerUpdate();
80
+ const stageServerUpdate = useAtomCommand(serverEnvironment.stageServerUpdate, {
81
+ reportFailure: false,
82
+ });
83
84
const view = describeUpdateEverything({
85
localVersion: localUpdateVersion,
@@ -181,8 +185,29 @@ export function useUpdateEverything(
185
);
186
return outcomes;
187
},
184
- updateServers: async () => {
188
+ ...(providers.machines.length > 0
189
+ ? {
190
+ stageServers: () =>
191
+ new Map(
192
+ servers
193
+ .filter(
194
+ (server) =>
195
+ machines.find((machine) => machine.environmentId === server.environmentId)
196
+ ?.serverConfig?.environment.capabilities.serverUpdateStaging === true,
197
+ )
198
+ .map((server) => [
199
+ server.environmentId,
200
+ stageServerUpdate({
201
+ environmentId: server.environmentId,
202
+ input: { targetVersion: server.targetVersion, stageOnly: true },
203
+ }),
204
+ ]),
205
+ ),
206
+ }
207
+ : {}),
208
+ updateServers: async (staged) => {
209
const runs = servers.map(async (server) => {
210
+ await staged.get(server.environmentId);
211
const serverOutcome = await updateServer(server, { quiet: true });
212
settleUpdateRunMachine(
213
server.environmentId,
docs/internals/server-updates.md
+5
@@ -27,6 +27,11 @@ Protocol 4 changed the launcher alone, so its runtime still runs under protocol
27
The server names its launcher's protocol to preflight, not its own, since the two differ
28
after the first such update.
29
30
+A client can stage the target early with `stageOnly`, which installs and preflights the
31
+runtime and restarts nothing. "Update everything" does this while provider installs run,
32
+because a restart would kill them. A server without the `serverUpdateStaging` capability
33
+ignores the flag and runs the whole update, so send it only to a server that advertises it.
34
+
35
After a commit or rollback the launcher points the unit at the selected runtime and
36
reloads the manager, so the next service start runs that version's launcher; the
37
protocol check is what makes that safe. Each start after a finished update retries this, because
packages/client-runtime/src/state/server.ts
+4
@@ -1649,6 +1649,10 @@ export function createServerEnvironmentAtoms<R, E>(
1649
tag: WS_METHODS.serverUpdateProvider,
1650
}),
1651
updateServer,
1652
+ stageServerUpdate: createEnvironmentRpcCommand(runtime, {
1653
+ label: "environment-data:server:stage-update",
1654
+ tag: WS_METHODS.serverUpdateServer,
1655
+ }),
1656
upsertKeybinding: createEnvironmentRpcCommand(runtime, {
1657
label: "environment-data:server:upsert-keybinding",
1658
tag: WS_METHODS.serverUpsertKeybinding,
packages/contracts/src/environment.ts
+1
@@ -152,6 +152,7 @@ export const ExecutionEnvironmentCapabilities = Schema.Struct({
152
/** Manual commands must update this install, not the host's default global prefix. */
153
serverInstallation: ForwardCompatibleOptional(ServerInstallation),
154
serverSelfUpdateProgress: Schema.optionalKey(Schema.Boolean),
155
+ serverUpdateStaging: Schema.optionalKey(Schema.Boolean),
156
serverUpdateThreadContinuation: Schema.optionalKey(Schema.Boolean),
157
/** Only explicit false skips Live Activity seeding; older servers may still publish. */
158
agentActivityPublishing: Schema.optionalKey(Schema.Boolean),
packages/contracts/src/server.ts
+1
@@ -1013,6 +1013,7 @@ export const ServerSelfUpdateInput = Schema.Struct({
1013
channel: Schema.optionalKey(DesktopUpdateChannelSchema),
1014
/** The target release's highest migration; the host refuses to leave Nightly without it. */
1015
targetDatabaseMigration: Schema.optionalKey(Schema.Int),
1016
+ stageOnly: Schema.optionalKey(Schema.Boolean),
1017
});
1018
export type ServerSelfUpdateInput = typeof ServerSelfUpdateInput.Type;
1019