Skip to content

Commit ba6a667

Browse files
fix(web): outdated servers can be updated even when the client can't connect
A v2 client refuses to open a session with a protocol-1 (v1) server, so the only update path, server.updateServer over that session, was unreachable. Users saw "Client not supported" with no way forward. The self-update RPCs have the same wire shape in both protocols. When the server is the outdated side, the unsupported row in Settings now offers Update: it authorizes the socket without the protocol gate, calls only the update RPCs, waits for the host descriptor to report a compatible protocol, then clears the block and switches the environment back on. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 8ed276c commit ba6a667

15 files changed

Lines changed: 696 additions & 18 deletions

File tree

‎apps/web/src/components/ServerUpdateAction.tsx‎

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { type ComponentProps, useRef, useState } from "react";
1010
import { requestConfirmDialog } from "~/confirmDialog";
1111
import { useCopyToClipboard } from "~/hooks/useCopyToClipboard";
1212
import { useEnvironmentSettings } from "~/hooks/useSettings";
13-
import { serverEnvironment } from "~/state/server";
13+
import { serverEnvironment, updateOutdatedServer } from "~/state/server";
1414
import { useAtomCommand } from "~/state/use-atom-command";
1515
import { manualServerUpdateCommand } from "~/versionSkew";
1616
import { Button } from "./ui/button";
@@ -290,3 +290,56 @@ export function ServerUpdateAction({
290290
</Button>
291291
);
292292
}
293+
294+
/**
295+
* Updates a host too old for this client to connect to. Its version comes
296+
* from the host descriptor because the host never delivers a server config.
297+
*/
298+
export function OutdatedServerUpdateAction({
299+
environmentId,
300+
serverLabel,
301+
fromVersion,
302+
targetVersion,
303+
label = "Update",
304+
}: {
305+
readonly environmentId: EnvironmentId;
306+
readonly serverLabel: string;
307+
readonly fromVersion: string | undefined;
308+
readonly targetVersion: string;
309+
readonly label?: string;
310+
}) {
311+
const update = useAtomCommand(updateOutdatedServer, { reportFailure: false });
312+
const handleUpdate = async () => {
313+
if (pendingUpdateEnvironmentIds.has(environmentId)) return;
314+
pendingUpdateEnvironmentIds.add(environmentId);
315+
try {
316+
const result = await update({
317+
environmentId,
318+
input: { targetVersion },
319+
...(fromVersion === undefined ? {} : { fromVersion }),
320+
});
321+
if (result._tag === "Failure") {
322+
if (isAtomCommandInterrupted(result)) return;
323+
throw squashAtomCommandFailure(result);
324+
}
325+
toastManager.add({
326+
type: "success",
327+
title: `${serverLabel} updated`,
328+
description: `Reconnected on t3@${result.value.targetVersion}.`,
329+
});
330+
} catch (error) {
331+
toastManager.add({
332+
type: "error",
333+
title: "Server update failed",
334+
description: updateFailureMessage(error),
335+
});
336+
} finally {
337+
pendingUpdateEnvironmentIds.delete(environmentId);
338+
}
339+
};
340+
return (
341+
<Button size="xs" variant="outline" onClick={() => void handleUpdate()}>
342+
{label}
343+
</Button>
344+
);
345+
}

‎apps/web/src/components/settings/ConnectionsSettings.tsx‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,13 @@ import {
165165
usePrimaryEnvironment,
166166
useRelayEnvironmentDiscovery,
167167
} from "~/state/environments";
168+
import { APP_VERSION } from "~/branding";
168169
import { requestConfirmDialog } from "~/confirmDialog";
169170
import { useAtomCommand } from "../../state/use-atom-command";
170171
import { primaryServerKeybindingsAtom, serverEnvironment } from "~/state/server";
171172
import { ConnectionStatusDot } from "../ConnectionStatusDot";
172173
import {
174+
OutdatedServerUpdateAction,
173175
ServerUpdateAction,
174176
ServerUpdateProgress,
175177
ServerUpdatesAction,
@@ -1598,6 +1600,17 @@ function SavedBackendListRow({
15981600
) : null
15991601
}
16001602
>
1603+
{unsupported &&
1604+
environment.entry.serverUpdateRequired === true &&
1605+
serverUpdateState.status !== "running" ? (
1606+
<OutdatedServerUpdateAction
1607+
environmentId={environmentId}
1608+
serverLabel={`${environment.label} server`}
1609+
fromVersion={lastDescriptor?.serverVersion}
1610+
targetVersion={APP_VERSION}
1611+
label={serverUpdateState.status === "failed" ? "Retry update" : "Update"}
1612+
/>
1613+
) : null}
16011614
{showUpdateAction ? (
16021615
<ServerUpdateAction
16031616
environmentId={environmentId}

‎apps/web/src/state/server.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
type ServerSettings,
1111
} from "@t3tools/contracts";
1212
import { createServerEnvironmentAtoms } from "@t3tools/client-runtime/state/server";
13+
import { createOutdatedServerUpdateCommand } from "@t3tools/client-runtime/state/outdatedServerUpdate";
1314
import { createEnvironmentServerConfigsAtom } from "@t3tools/client-runtime/state/shell";
1415
import { mergeWithDefaultKeybindings } from "@t3tools/shared/keybindings";
1516
import * as Option from "effect/Option";
@@ -32,6 +33,8 @@ export const serverEnvironment = createServerEnvironmentAtoms(connectionAtomRunt
3233
usageLimitSources: true,
3334
usageLimitsCommand: true,
3435
});
36+
/** Updates a host whose protocol is too old for this client to connect to. */
37+
export const updateOutdatedServer = createOutdatedServerUpdateCommand(connectionAtomRuntime);
3538
export const environmentServerConfigsAtom = createEnvironmentServerConfigsAtom({
3639
catalogValueAtom: environmentCatalog.catalogValueAtom,
3740
serverConfigValueAtom: serverEnvironment.configValueAtom,

‎packages/client-runtime/package.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@
219219
"types": "./src/state/server.ts",
220220
"default": "./src/state/server.ts"
221221
},
222+
"./state/outdatedServerUpdate": {
223+
"types": "./src/state/outdatedServerUpdate.ts",
224+
"default": "./src/state/outdatedServerUpdate.ts"
225+
},
222226
"./state/session": {
223227
"types": "./src/state/session.ts",
224228
"default": "./src/state/session.ts"

‎packages/client-runtime/src/connection/catalog.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ export interface ConnectionCatalogEntry {
4343
readonly enabled: boolean;
4444
/** Discovery rejection stays visible while the saved connection is switched off. */
4545
readonly unsupportedReason?: string;
46+
/** The rejection came from an outdated host, which can still be updated remotely. */
47+
readonly serverUpdateRequired?: boolean;
4648
}
4749

4850
export class BearerConnectionCredential extends Schema.TaggedClass<BearerConnectionCredential>()(

‎packages/client-runtime/src/connection/compatibility.ts‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ export function orchestrationProtocolCompatibilityError(
1414
if (serverProtocolVersion === ORCHESTRATION_PROTOCOL_VERSION) {
1515
return null;
1616
}
17-
return new ConnectionBlockedError({
18-
reason: "unsupported",
19-
detail:
20-
serverProtocolVersion > ORCHESTRATION_PROTOCOL_VERSION
21-
? `This client is not supported by this server. Update your app or use a compatible release to connect to ${descriptor.label}.`
22-
: `This client requires a newer server. Update T3 Code on ${descriptor.label} to connect.`,
23-
});
17+
return serverProtocolVersion > ORCHESTRATION_PROTOCOL_VERSION
18+
? new ConnectionBlockedError({
19+
reason: "unsupported",
20+
detail: `This client is not supported by this server. Update your app or use a compatible release to connect to ${descriptor.label}.`,
21+
})
22+
: new ConnectionBlockedError({
23+
reason: "unsupported",
24+
detail: `This client requires a newer server. Update T3 Code on ${descriptor.label} to connect.`,
25+
serverUpdateRequired: true,
26+
});
2427
}
2528

2629
export function appendOrchestrationProtocol(socketUrl: string): string {

‎packages/client-runtime/src/connection/index.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ export * as EnvironmentSupervisor from "./supervisor.ts";
1616
export * as Wakeups from "./wakeups.ts";
1717

1818
export { orchestrationProtocolCompatibilityError } from "./compatibility.ts";
19+
// Flat so consumers' inferred command types can name it.
20+
export { OutdatedHostUpdateError } from "./outdatedHostUpdate.ts";

‎packages/client-runtime/src/connection/layer.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ export function layerWithOptions(options: RpcSession.RpcSessionOptions) {
7575
registryLayer,
7676
RelayEnvironmentDiscovery.layer,
7777
onboardingLayer,
78+
// Exposed for updating hosts too old to connect through the driver.
79+
ConnectionResolver.layer,
7880
);
7981
const connectionStartupLayer = Layer.effectDiscard(
8082
Effect.gen(function* () {

‎packages/client-runtime/src/connection/model.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ export class ConnectionBlockedError extends Schema.TaggedError<ConnectionBlocked
9494
reason: ConnectionBlockedReason,
9595
detail: Schema.String,
9696
traceId: Schema.optionalKey(Schema.String),
97+
/** The host speaks an older orchestration protocol; updating it restores the connection. */
98+
serverUpdateRequired: Schema.optionalKey(Schema.Boolean),
9799
},
98100
) {
99101
override get message(): string {

0 commit comments

Comments
 (0)