@devries-cameron20 / t3code Mirror · read-only / commits / 8f0d66de5f
Fork 0

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 22, 09:30 UTC

fix(web): servers still restarting after an app update no longer offer the update again (#26109)

Tristan Knight committed Oct 31, 2026 at 08:42 UTC 8f0d66de5fa6e8ed94120ae92f86eb22107bb70b
2 files changed +85
apps/web/src/components/sidebar/updateEverythingRun.test.ts new
+70
@@ -0,0 +1,70 @@
1 +import { EnvironmentId } from "@t3tools/contracts";
2 +import { afterEach, describe, expect, it, vi } from "vite-plus/test";
3 +
4 +import { appAtomRegistry } from "~/rpc/atomRegistry";
5 +import { serverEnvironment } from "~/state/server";
6 +import { startDesktopUpdateLaunchNotice } from "./updateEverythingRun";
7 +
8 +function relaunchWhileRestarting(environmentId: EnvironmentId) {
9 + const now = 1_800_000_000_000;
10 + vi.useFakeTimers({ now });
11 + const store = new Map([
12 + [
13 + "t3code:update-everything-result:v1",
14 + JSON.stringify({
15 + savedAt: now,
16 + localVersion: null,
17 + updatedServers: 0,
18 + updatedProviders: 0,
19 + failures: [],
20 + handedOff: [{ environmentId, label: "Slow", targetVersion: "9.9.9", startedAt: now }],
21 + }),
22 + ],
23 + ]);
24 + vi.stubGlobal("window", {
25 + localStorage: {
26 + getItem: (key: string) => store.get(key) ?? null,
27 + removeItem: (key: string) => store.delete(key),
28 + },
29 + });
30 + return startDesktopUpdateLaunchNotice();
31 +}
32 +
33 +describe("startDesktopUpdateLaunchNotice", () => {
34 + afterEach(() => {
35 + vi.useRealTimers();
36 + vi.unstubAllGlobals();
37 + });
38 +
39 + it("keeps a server that is still restarting from looking idle after the app relaunches", async () => {
40 + const environmentId = EnvironmentId.make("slow-machine");
41 + const stop = relaunchWhileRestarting(environmentId);
42 + try {
43 + // Lets the registry run its cleanup of unobserved atoms before the UI mounts.
44 + await vi.advanceTimersByTimeAsync(1_000);
45 + expect(appAtomRegistry.get(serverEnvironment.updateStateAtom(environmentId))).toMatchObject({
46 + status: "running",
47 + stage: "resuming",
48 + targetVersion: "9.9.9",
49 + });
50 + } finally {
51 + await vi.advanceTimersByTimeAsync(32 * 60 * 1000);
52 + stop();
53 + }
54 + });
55 +
56 + it("clears the restored state when the server never comes back", async () => {
57 + const environmentId = EnvironmentId.make("lost-machine");
58 + const stateAtom = serverEnvironment.updateStateAtom(environmentId);
59 + const stop = relaunchWhileRestarting(environmentId);
60 + // Observed like the UI does, so the registry cannot reset it by dropping the atom.
61 + const release = appAtomRegistry.mount(stateAtom);
62 + try {
63 + await vi.advanceTimersByTimeAsync(32 * 60 * 1000);
64 + expect(appAtomRegistry.get(stateAtom)).toEqual({ status: "idle" });
65 + } finally {
66 + release();
67 + stop();
68 + }
69 + });
70 +});
apps/web/src/components/sidebar/updateEverythingRun.tsx
+15
@@ -1,4 +1,5 @@
1 import { useAtomValue } from "@effect/atom-react";
2 +import { serverUpdateStateAtom } from "@t3tools/client-runtime/state/server";
3 import { EnvironmentId } from "@t3tools/contracts";
4 import * as Option from "effect/Option";
5 import * as Schema from "effect/Schema";
@@ -267,12 +268,26 @@ function followHandedOffServers(servers: ReadonlyArray<HandedOffServer>): void {
268 let updatedServers = 0;
269 const failures: string[] = [];
270 for (const server of servers) {
271 + // Update state is in memory, so restore it or the relaunched app offers this server's update again.
272 + const stateAtom = serverUpdateStateAtom(server.environmentId);
273 + appAtomRegistry.set(stateAtom, {
274 + status: "running",
275 + stage: "resuming",
276 + fromVersion:
277 + appAtomRegistry.get(serverEnvironment.configValueAtom(server.environmentId))?.environment
278 + .serverVersion ?? server.targetVersion,
279 + targetVersion: server.targetVersion,
280 + });
281 + // Nothing observes the atom until the UI mounts, and the registry drops unobserved atoms.
282 + const releaseState = appAtomRegistry.mount(stateAtom);
283 let settled = false;
284 const settle = (failure: string | null) => {
285 if (settled) return;
286 settled = true;
287 clearTimeout(timer);
288 queueMicrotask(() => unsubscribe());
289 + appAtomRegistry.set(stateAtom, { status: "idle" });
290 + releaseState();
291 settleUpdateRunMachine(server.environmentId, failure);
292 if (failure === null) updatedServers += 1;
293 else failures.push(`${server.label}: ${failure}`);