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

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

fix(web): a server updated with the app reconnects as soon as it is ready (#35327)

Co-authored-by: shivam <91240327+shivamhwp@users.noreply.github.com>

Bilal Bakr committed Nov 13, 2026 at 13:32 UTC fa9d85fad55bf42c807e46e6a9a2e7ca44f4c161
2 files changed +48 -3
apps/web/src/components/sidebar/updateEverythingRun.test.ts
+25 -1
@@ -1,7 +1,9 @@
1 +import { AVAILABLE_CONNECTION_STATE } from "@t3tools/client-runtime/connection";
2 import { EnvironmentId, type ServerConfig } from "@t3tools/contracts";
2 -import { Atom } from "effect/reactivity";
3 +import { AsyncResult, Atom } from "effect/reactivity";
4 import { afterEach, describe, expect, it, vi } from "vite-plus/test";
5
6 +import { environmentCatalog } from "~/connection/catalog";
7 import { appAtomRegistry } from "~/rpc/atomRegistry";
8 import { serverEnvironment } from "~/state/server";
9 import type { ServerUpdateOutcome, ServerUpdateTarget } from "../ServerUpdateAction";
@@ -60,6 +62,28 @@ describe("startDesktopUpdateLaunchNotice", () => {
62 }
63 });
64
65 + it("retries the connection to a restarting server instead of waiting out its backoff", async () => {
66 + const environmentId = EnvironmentId.make("backing-off-machine");
67 + using _connection = vi
68 + .spyOn(environmentCatalog, "stateAtom")
69 + .mockReturnValue(
70 + Atom.make(
71 + AsyncResult.success({ ...AVAILABLE_CONNECTION_STATE, phase: "backoff" as const }),
72 + ) as unknown as ReturnType<typeof environmentCatalog.stateAtom>,
73 + );
74 + using retryNow = vi
75 + .spyOn(environmentCatalog.retryNow, "run")
76 + .mockResolvedValue(AsyncResult.success(undefined));
77 + const stop = relaunchWhileRestarting(environmentId);
78 + try {
79 + await vi.advanceTimersByTimeAsync(1_000);
80 + expect(retryNow).toHaveBeenCalledWith(appAtomRegistry, environmentId);
81 + } finally {
82 + await vi.advanceTimersByTimeAsync(32 * 60 * 1000);
83 + stop();
84 + }
85 + });
86 +
87 it("clears the restored state when the server never comes back", async () => {
88 const environmentId = EnvironmentId.make("lost-machine");
89 const stateAtom = serverEnvironment.updateStateAtom(environmentId);
apps/web/src/components/sidebar/updateEverythingRun.tsx
+23 -2
@@ -1,11 +1,18 @@
1 import { useAtomValue } from "@effect/atom-react";
2 -import { serverUpdateStateAtom } from "@t3tools/client-runtime/state/server";
2 +import { AVAILABLE_CONNECTION_STATE } from "@t3tools/client-runtime/connection";
3 +import {
4 + nudgeReconnectDuringUpdateRestart,
5 + serverUpdateStateAtom,
6 +} from "@t3tools/client-runtime/state/server";
7 import { EnvironmentId, type ServerConfig } from "@t3tools/contracts";
8 +import * as Effect from "effect/Effect";
9 import * as Option from "effect/Option";
10 import * as Schema from "effect/Schema";
6 -import { AsyncResult, Atom } from "effect/reactivity";
11 +import * as Stream from "effect/Stream";
12 +import { AsyncResult, Atom, AtomRegistry } from "effect/reactivity";
13
14 import { APP_VERSION } from "~/branding";
15 +import { environmentCatalog } from "~/connection/catalog";
16 import { appAtomRegistry } from "~/rpc/atomRegistry";
17 import { desktopUpdateStateAtom } from "~/state/desktopUpdate";
18 import { serverEnvironment } from "~/state/server";
@@ -308,6 +315,7 @@ function followHandedOffServers(servers: ReadonlyArray<HandedOffServer>): void {
315 if (settled) return;
316 settled = true;
317 clearTimeout(timer);
318 + stopReconnectNudge();
319 queueMicrotask(() => unsubscribe());
320 appAtomRegistry.set(stateAtom, { status: "idle" });
321 releaseState();
@@ -329,6 +337,19 @@ function followHandedOffServers(servers: ReadonlyArray<HandedOffServer>): void {
337 () => settle(`Not back after ${HANDOFF_TIMEOUT_MS / 60_000} minutes`),
338 server.startedAt + HANDOFF_TIMEOUT_MS - Date.now(),
339 );
340 + const stopReconnectNudge = Effect.runCallback(
341 + nudgeReconnectDuringUpdateRestart({
342 + stateChanges: AtomRegistry.toStream(
343 + appAtomRegistry,
344 + environmentCatalog.stateAtom(server.environmentId),
345 + ).pipe(
346 + Stream.map((state) => AsyncResult.getOrElse(state, () => AVAILABLE_CONNECTION_STATE)),
347 + ),
348 + retryNow: Effect.promise(() =>
349 + environmentCatalog.retryNow.run(appAtomRegistry, server.environmentId),
350 + ).pipe(Effect.asVoid),
351 + }),
352 + );
353 const unsubscribe = appAtomRegistry.subscribe(
354 serverEnvironment.configValueAtom(server.environmentId),
355 (config) => {