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, 21:00 UTC
fix(web): update Retry stops re-sending servers already on the target version (#32924)
Julius Marminge committed
Nov 11, 2026 at 16:21 UTC
42d645ae9e03a0d9035d5b89eda60d4ab13c497e
2 files changed
+98
-11
apps/web/src/components/sidebar/updateEverythingRun.test.ts
+71
-2
@@ -1,9 +1,16 @@
1
-import { EnvironmentId } from "@t3tools/contracts";
1
+import { EnvironmentId, type ServerConfig } from "@t3tools/contracts";
2
+import { Atom } from "effect/reactivity";
3
import { afterEach, describe, expect, it, vi } from "vite-plus/test";
4
5
import { appAtomRegistry } from "~/rpc/atomRegistry";
6
import { serverEnvironment } from "~/state/server";
6
-import { startDesktopUpdateLaunchNotice } from "./updateEverythingRun";
7
+import type { ServerUpdateOutcome, ServerUpdateTarget } from "../ServerUpdateAction";
8
+import type { UpdateEverythingRun } from "./updateEverything.logic";
9
+import {
10
+ retryFailedUpdateRunServers,
11
+ setUpdateEverythingRun,
12
+ startDesktopUpdateLaunchNotice,
13
+} from "./updateEverythingRun";
14
15
function relaunchWhileRestarting(environmentId: EnvironmentId) {
16
const now = 1_800_000_000_000;
@@ -68,3 +75,65 @@ describe("startDesktopUpdateLaunchNotice", () => {
75
}
76
});
77
});
78
+
79
+describe("retryFailedUpdateRunServers", () => {
80
+ it("settles a failed server that already restarted on the target and retries only the others", () => {
81
+ const targetVersion = "9.9.9";
82
+ const serverVersions = new Map([
83
+ [EnvironmentId.make("already-updated"), targetVersion],
84
+ [EnvironmentId.make("behind"), "9.9.8"],
85
+ ]);
86
+ using _config = vi
87
+ .spyOn(serverEnvironment, "configValueAtom")
88
+ .mockImplementation((environmentId) =>
89
+ Atom.make({
90
+ environment: { serverVersion: serverVersions.get(environmentId!) },
91
+ } as unknown as ServerConfig),
92
+ );
93
+ const rejection = "Remote updates must select a newer server version.";
94
+ const failedMachine = (environmentId: EnvironmentId) => ({
95
+ environmentId,
96
+ label: environmentId,
97
+ updatesProviders: false,
98
+ server: {
99
+ environmentId,
100
+ serverLabel: environmentId,
101
+ selfUpdate: "boot-service" as const,
102
+ targetVersion,
103
+ },
104
+ handedOffVersion: null,
105
+ startedAt: 0,
106
+ result: "failed" as const,
107
+ failure: rejection,
108
+ providerFailure: null,
109
+ });
110
+ setUpdateEverythingRun(() => ({
111
+ localVersion: null,
112
+ phase: "servers",
113
+ restartAt: null,
114
+ machines: [...serverVersions.keys()].map(failedMachine),
115
+ }));
116
+ const update = vi.fn(
117
+ (_target: ServerUpdateTarget) => new Promise<ServerUpdateOutcome>(() => {}),
118
+ );
119
+
120
+ retryFailedUpdateRunServers(update);
121
+
122
+ let run: UpdateEverythingRun | null = null;
123
+ setUpdateEverythingRun((current) => {
124
+ run = current;
125
+ return null;
126
+ });
127
+ expect(update.mock.calls.map(([target]) => target.environmentId)).toEqual(["behind"]);
128
+ expect(
129
+ (run as UpdateEverythingRun | null)?.machines.map(({ environmentId, result, server }) => ({
130
+ environmentId,
131
+ result,
132
+ retryable: server !== null,
133
+ })),
134
+ ).toEqual([
135
+ { environmentId: "already-updated", result: "done", retryable: false },
136
+ { environmentId: "behind", result: null, retryable: true },
137
+ ]);
138
+ });
139
+});
apps/web/src/components/sidebar/updateEverythingRun.tsx
+27
-9
@@ -1,6 +1,6 @@
1
import { useAtomValue } from "@effect/atom-react";
2
import { serverUpdateStateAtom } from "@t3tools/client-runtime/state/server";
3
-import { EnvironmentId } from "@t3tools/contracts";
3
+import { EnvironmentId, type ServerConfig } from "@t3tools/contracts";
4
import * as Option from "effect/Option";
5
import * as Schema from "effect/Schema";
6
import { AsyncResult, Atom } from "effect/reactivity";
@@ -63,6 +63,13 @@ export function settleUpdateRunMachine(
63
);
64
}
65
66
+function runsVersion(config: ServerConfig | null, targetVersion: string): boolean {
67
+ return (
68
+ config !== null &&
69
+ resolveVersionMismatch(config.environment.serverVersion, targetVersion) === null
70
+ );
71
+}
72
+
73
export function retryFailedUpdateRunServers(
74
update: (
75
target: ServerUpdateTarget,
@@ -75,7 +82,23 @@ export function retryFailedUpdateRunServers(
82
? [{ target: machine.server, providerFailure: machine.providerFailure }]
83
: [],
84
);
78
- const targets = failed.map(({ target }) => target);
85
+ const pending: typeof failed = [];
86
+ for (const entry of failed) {
87
+ // The host rejects a same-version update; a server that came back on the target is done.
88
+ if (
89
+ runsVersion(
90
+ appAtomRegistry.get(serverEnvironment.configValueAtom(entry.target.environmentId)),
91
+ entry.target.targetVersion,
92
+ )
93
+ ) {
94
+ settleUpdateRunMachine(entry.target.environmentId, entry.providerFailure, {
95
+ serverUpdated: true,
96
+ });
97
+ } else {
98
+ pending.push(entry);
99
+ }
100
+ }
101
+ const targets = pending.map(({ target }) => target);
102
const retried = new Set(targets.map((target) => target.environmentId));
103
const startedAt = Date.now();
104
updateRunMachines((machine) =>
@@ -83,7 +106,7 @@ export function retryFailedUpdateRunServers(
106
? { ...machine, result: null, failure: null, startedAt }
107
: machine,
108
);
86
- for (const { target, providerFailure } of failed) {
109
+ for (const { target, providerFailure } of pending) {
110
void update(target, { quiet: true }).then((outcome) =>
111
settleUpdateRunMachine(
112
target.environmentId,
@@ -309,12 +332,7 @@ function followHandedOffServers(servers: ReadonlyArray<HandedOffServer>): void {
332
const unsubscribe = appAtomRegistry.subscribe(
333
serverEnvironment.configValueAtom(server.environmentId),
334
(config) => {
312
- if (
313
- config !== null &&
314
- resolveVersionMismatch(config.environment.serverVersion, server.targetVersion) === null
315
- ) {
316
- settle(null);
317
- }
335
+ if (runsVersion(config, server.targetVersion)) settle(null);
336
},
337
{ immediate: true },
338
);