@devries-cameron20 / t3code-1 / commits / 9878f487fa
Fork 0

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

fix(connections): retry unsupported saved direct connections (#15107)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Nick Anisimov committed Oct 19, 2026 at 22:09 UTC 9878f487fac567949f366b4cc34d97a252f56bf8
6 files changed +154 -39
apps/mobile/src/features/connection/CloudEnvironmentRows.tsx
+10 -2
@@ -2,7 +2,10 @@ import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator";
2 import { ConnectionTraceId } from "./ConnectionTraceId";
3 import { useAuth } from "@clerk/expo";
4 import { SymbolView } from "../../components/ui/AppSymbol";
5 -import { type EnvironmentConnectionPhase } from "@t3tools/client-runtime/connection";
5 +import {
6 + hasSavedBearerRoute,
7 + type EnvironmentConnectionPhase,
8 +} from "@t3tools/client-runtime/connection";
9 import {
10 type EnvironmentId,
11 type EnvironmentMachineKind,
@@ -20,6 +23,7 @@ import { cn } from "../../lib/cn";
23 import { copyTextWithHaptic } from "../../lib/copyTextWithHaptic";
24 import type { ConnectedEnvironmentSummary } from "../../state/remote-runtime-types";
25 import { serverEnvironment } from "../../state/server";
26 +import { environmentPresentations } from "../../state/presentation";
27 import { availableCloudEnvironmentPresentation } from "../cloud/cloudEnvironmentPresentation";
28 import { hasCloudPublicConfig } from "../cloud/publicConfig";
29 import { ConnectionStatusDot } from "./ConnectionStatusDot";
@@ -185,6 +189,10 @@ function ConnectedCloudEnvironmentRow(props: {
189 serverEnvironment.configValueAtom(props.environment.environmentId),
190 );
191 const unsupported = props.environment.connectionState === "unsupported";
192 + const presentation = useAtomValue(
193 + environmentPresentations.presentationAtom(props.environment.environmentId),
194 + );
195 + const canRetry = presentation !== null && hasSavedBearerRoute(presentation.entry);
196 const enabled = props.environment.isEnabled && !unsupported;
197 const [lastDescriptor, setLastDescriptor] = useState(props.descriptor);
198 if (props.descriptor !== undefined && props.descriptor !== lastDescriptor) {
@@ -205,7 +213,7 @@ function ConnectedCloudEnvironmentRow(props: {
213 )}
214 onValueChange={props.onSetEnabled}
215 onToggleError={props.onToggleError}
208 - disabled={unsupported}
216 + disabled={unsupported && !canRetry}
217 {...(enabled || unsupported ? {} : { statusText: "Off" })}
218 value={enabled}
219 />
apps/mobile/src/features/connection/ConnectionEnvironmentRow.tsx
+7 -1
@@ -1,6 +1,7 @@
1 import * as Dialog from "../../components/ui/Dialog";
2 import { ConnectionTraceId } from "./ConnectionTraceId";
3 import { SymbolView } from "../../components/ui/AppSymbol";
4 +import { hasSavedBearerRoute } from "@t3tools/client-runtime/connection";
5 import type { AtomCommandResult } from "@t3tools/client-runtime/state/runtime";
6 import { type EnvironmentId, resolveEnvironmentMachineKind } from "@t3tools/contracts";
7 import { useAtomValue } from "@effect/atom-react";
@@ -18,6 +19,7 @@ import { ThemedSwitch } from "../../components/ui/ThemedSwitch";
19 import { cn } from "../../lib/cn";
20 import type { ConnectedEnvironmentSummary } from "../../state/remote-runtime-types";
21 import { serverEnvironment } from "../../state/server";
22 +import { environmentPresentations } from "../../state/presentation";
23 import { ConnectionFormField } from "./ConnectionFormField";
24 import { ConnectionStatusDot } from "./ConnectionStatusDot";
25 import { environmentStatusText } from "./environmentStatusText";
@@ -52,6 +54,10 @@ export function ConnectionEnvironmentRow(props: {
54 serverEnvironment.configValueAtom(props.environment.environmentId),
55 );
56 const unsupported = props.environment.connectionState === "unsupported";
57 + const presentation = useAtomValue(
58 + environmentPresentations.presentationAtom(props.environment.environmentId),
59 + );
60 + const canRetry = presentation !== null && hasSavedBearerRoute(presentation.entry);
61 const enabled = props.environment.isEnabled && !unsupported;
62 const statusLabel = connectionStatusLabel(props.environment);
63 const statusTraceId = enabled ? props.environment.connectionErrorTraceId : null;
@@ -136,7 +142,7 @@ export function ConnectionEnvironmentRow(props: {
142 <ThemedSwitch
143 accessibilityLabel={`Enable ${props.environment.environmentLabel}`}
144 style={{ alignSelf: "center" }}
139 - disabled={unsupported}
145 + disabled={unsupported && !canRetry}
146 onValueChange={(next) => props.onSetEnabled(props.environment.environmentId, next)}
147 value={enabled}
148 />
apps/web/src/components/settings/ConnectionsSettings.tsx
+4 -2
@@ -47,6 +47,7 @@ import {
47 RelayConnectionRegistration,
48 RelayConnectionTarget,
49 connectionRoutes,
50 + hasSavedBearerRoute,
51 connectionStatusText,
52 environmentMcpUrl,
53 } from "@t3tools/client-runtime/connection";
@@ -1467,6 +1468,7 @@ function SavedBackendListRow({
1468 const [permissionsOpen, setPermissionsOpen] = useState(false);
1469 const environmentId = environment.environmentId;
1470 const unsupported = environment.connection.phase === "unsupported";
1471 + const blocked = unsupported && !hasSavedBearerRoute(environment.entry);
1472 const enabled = environment.entry.enabled && !unsupported;
1473 const isConnected = environment.connection.phase === "connected";
1474 const isRemoving = removingEnvironmentId === environmentId;
@@ -1704,14 +1706,14 @@ function SavedBackendListRow({
1706 <Switch
1707 size="sm"
1708 checked={enabled}
1707 - disabled={isRemoving || unsupported}
1709 + disabled={isRemoving || blocked}
1710 aria-label={`${enabled ? "Switch off" : "Switch on"} ${environment.label}`}
1711 onCheckedChange={(checked) => onSetEnabled(environmentId, checked)}
1712 />
1713 }
1714 />
1715 <TooltipPopup side="top">
1714 - {unsupported ? "Client not supported" : enabled ? "Switch off" : "Switch on"}
1716 + {blocked ? "Client not supported" : enabled ? "Switch off" : "Switch on"}
1717 </TooltipPopup>
1718 </Tooltip>
1719 <Menu>
packages/client-runtime/src/connection/registry.test.ts
+122 -31
@@ -995,39 +995,49 @@ describe("EnvironmentRegistry", () => {
995 }),
996 );
997
998 - it.effect("discovery keeps unsupported environments off until compatibility changes", () =>
999 - Effect.gen(function* () {
1000 - const harness = yield* makeHarness([RELAY_TARGET], [], [], {
1001 - initialDisabled: [RELAY_TARGET.environmentId],
1002 - });
1003 - yield* Effect.gen(function* () {
1004 - const registry = yield* EnvironmentRegistry.EnvironmentRegistry;
1005 - yield* registry.start;
1006 - const error = new ConnectionBlockedError({
1007 - reason: "unsupported",
1008 - detail: "Use a compatible client.",
998 + it.effect.each([false, true])(
999 + "discovery keeps unsupported environments off (learned route: %s)",
1000 + (learned) =>
1001 + Effect.gen(function* () {
1002 + const environmentId = BEARER_TARGET.environmentId;
1003 + const relay = new RelayConnectionTarget({ ...RELAY_TARGET, environmentId });
1004 + const profile = new BearerConnectionProfile({
1005 + ...BEARER_PROFILE,
1006 + learned: true,
1007 + authorization: "t3-connect",
1008 });
1010 - yield* registry.setCompatibility(RELAY_TARGET.environmentId, error);
1011 - const entry = (yield* SubscriptionRef.get(registry.entries)).get(
1012 - RELAY_TARGET.environmentId,
1009 + const harness = yield* makeHarness(
1010 + learned ? [relay, BEARER_TARGET] : [relay],
1011 + learned ? [profile] : [],
1012 + [],
1013 + { initialDisabled: [environmentId] },
1014 );
1014 - expect(entry).toMatchObject({ enabled: false, unsupportedReason: error.message });
1015 - expect(
1016 - yield* Effect.flip(registry.setEnabled(RELAY_TARGET.environmentId, true)),
1017 - ).toMatchObject({ reason: "unsupported" });
1018 - expect(yield* Ref.get(harness.sessions)).toHaveLength(0);
1019 - yield* registry.setCompatibility(RELAY_TARGET.environmentId, null);
1020 - expect(
1021 - (yield* SubscriptionRef.get(registry.entries)).get(RELAY_TARGET.environmentId)?.enabled,
1022 - ).toBe(false);
1023 - yield* registry.setEnabled(RELAY_TARGET.environmentId, true);
1024 - yield* awaitConnectionState(
1025 - registry,
1026 - RELAY_TARGET.environmentId,
1027 - (state) => state.phase === "connected",
1028 - );
1029 - }).pipe(Effect.provide(harness.layer));
1030 - }),
1015 + yield* Effect.gen(function* () {
1016 + const registry = yield* EnvironmentRegistry.EnvironmentRegistry;
1017 + yield* registry.start;
1018 + const error = new ConnectionBlockedError({
1019 + reason: "unsupported",
1020 + detail: "Use a compatible client.",
1021 + });
1022 + yield* registry.setCompatibility(environmentId, error);
1023 + const entry = (yield* SubscriptionRef.get(registry.entries)).get(environmentId);
1024 + expect(entry).toMatchObject({ enabled: false, unsupportedReason: error.message });
1025 + expect(yield* Effect.flip(registry.setEnabled(environmentId, true))).toMatchObject({
1026 + reason: "unsupported",
1027 + });
1028 + expect(yield* Ref.get(harness.sessions)).toHaveLength(0);
1029 + yield* registry.setCompatibility(environmentId, null);
1030 + expect((yield* SubscriptionRef.get(registry.entries)).get(environmentId)?.enabled).toBe(
1031 + false,
1032 + );
1033 + yield* registry.setEnabled(environmentId, true);
1034 + yield* awaitConnectionState(
1035 + registry,
1036 + environmentId,
1037 + (state) => state.phase === "connected",
1038 + );
1039 + }).pipe(Effect.provide(harness.layer));
1040 + }),
1041 );
1042
1043 it.effect("a socket preflight rejection persists the connection as switched off", () =>
@@ -1055,6 +1065,87 @@ describe("EnvironmentRegistry", () => {
1065 }),
1066 );
1067
1068 + it.effect.each([
1069 + { outcome: "connects after a server update", compatible: true, relayFirst: false },
1070 + { outcome: "connects with a preferred relay route", compatible: true, relayFirst: true },
1071 + { outcome: "blocks again if still incompatible", compatible: false, relayFirst: false },
1072 + ])("retrying an unsupported saved URL $outcome", ({ compatible, relayFirst }) =>
1073 + Effect.gen(function* () {
1074 + const environmentId = BEARER_TARGET.environmentId;
1075 + const error = new ConnectionBlockedError({
1076 + reason: "unsupported",
1077 + detail: "Update the server to use this client.",
1078 + serverUpdateRequired: true,
1079 + });
1080 + const relay = new RelayConnectionTarget({
1081 + environmentId,
1082 + label: "Relay route",
1083 + });
1084 + const attempts = yield* Ref.make(0);
1085 + const retryStarted = yield* Deferred.make<void>();
1086 + const retryResult = yield* Deferred.make<ConnectionBlockedError | undefined>();
1087 + const harness = yield* makeHarness(
1088 + relayFirst ? [relay, BEARER_TARGET] : [BEARER_TARGET],
1089 + [BEARER_PROFILE],
1090 + [[BEARER_TARGET.connectionId, BEARER_CREDENTIAL]],
1091 + {
1092 + beforePrepareRoute: () =>
1093 + Effect.gen(function* () {
1094 + if ((yield* Ref.updateAndGet(attempts, (count) => count + 1)) === 1) return error;
1095 + yield* Deferred.succeed(retryStarted, undefined);
1096 + return yield* Deferred.await(retryResult);
1097 + }),
1098 + },
1099 + );
1100 + yield* Effect.gen(function* () {
1101 + const registry = yield* EnvironmentRegistry.EnvironmentRegistry;
1102 + yield* registry.start;
1103 + const awaitDisabled = SubscriptionRef.changes(registry.entries).pipe(
1104 + Stream.filter((entries) => entries.get(environmentId)?.enabled === false),
1105 + Stream.take(1),
1106 + Stream.runDrain,
1107 + );
1108 + yield* awaitDisabled;
1109 + expect((yield* Ref.get(harness.storedDisabled)).has(environmentId)).toBe(true);
1110 + expect((yield* SubscriptionRef.get(registry.entries)).get(environmentId)).toMatchObject({
1111 + target: relayFirst ? relay : BEARER_TARGET,
1112 + enabled: false,
1113 + unsupportedReason: error.message,
1114 + serverUpdateRequired: true,
1115 + });
1116 + expect(yield* Ref.get(attempts)).toBe(1);
1117 +
1118 + yield* registry.setEnabled(environmentId, true);
1119 + yield* Deferred.await(retryStarted);
1120 + const retrying = (yield* SubscriptionRef.get(registry.entries)).get(environmentId);
1121 + expect(retrying?.enabled).toBe(true);
1122 + expect(retrying?.unsupportedReason).toBeUndefined();
1123 + expect(retrying?.serverUpdateRequired).toBeUndefined();
1124 + expect((yield* Ref.get(harness.storedDisabled)).has(environmentId)).toBe(false);
1125 +
1126 + yield* Deferred.succeed(retryResult, compatible ? undefined : error);
1127 + if (compatible) {
1128 + yield* awaitConnectionState(
1129 + registry,
1130 + environmentId,
1131 + (state) => state.phase === "connected",
1132 + );
1133 + expect(yield* Ref.get(harness.sessions)).toHaveLength(1);
1134 + } else {
1135 + yield* awaitDisabled;
1136 + expect((yield* SubscriptionRef.get(registry.entries)).get(environmentId)).toMatchObject({
1137 + enabled: false,
1138 + unsupportedReason: error.message,
1139 + serverUpdateRequired: true,
1140 + });
1141 + expect((yield* Ref.get(harness.storedDisabled)).has(environmentId)).toBe(true);
1142 + expect(yield* Ref.get(harness.sessions)).toHaveLength(0);
1143 + }
1144 + expect(yield* Ref.get(attempts)).toBe(2);
1145 + }).pipe(Effect.provide(harness.layer));
1146 + }),
1147 + );
1148 +
1149 it.effect("switching an environment off disconnects it and persists the flag", () =>
1150 Effect.gen(function* () {
1151 const harness = yield* makeHarness([RELAY_TARGET]);
packages/client-runtime/src/connection/registry.ts
+7 -3
@@ -50,6 +50,7 @@ import {
50 credentialConnectionId,
51 entryWithRoutes,
52 findRouteToSameAddress,
53 + hasSavedBearerRoute,
54 mergeLearnedRoutes,
55 routesAfterRemoving,
56 upsertRoute,
@@ -1019,19 +1020,22 @@ export const make = Effect.gen(function* () {
1020 environmentId,
1021 Effect.gen(function* () {
1022 const entry = yield* getEntry(environmentId);
1022 - if (enabled && entry.unsupportedReason !== undefined) {
1023 + const retryUnsupported = enabled && entry.unsupportedReason !== undefined;
1024 + if (retryUnsupported && !hasSavedBearerRoute(entry)) {
1025 return yield* new ConnectionBlockedError({
1026 reason: "unsupported",
1027 detail: entry.unsupportedReason,
1028 });
1029 }
1028 - if (entry.enabled === enabled) {
1030 + if (entry.enabled === enabled && !retryUnsupported) {
1031 return;
1032 }
1033 if (!(yield* Ref.get(platformEnvironmentIds)).has(environmentId)) {
1034 yield* registrations.setEnabled(environmentId, enabled);
1035 }
1034 - const next: ConnectionCatalogEntry = { ...entry, enabled };
1036 + // A cached rejection can outlive a server update.
1037 + const { unsupportedReason: _reason, serverUpdateRequired: _update, ...rest } = entry;
1038 + const next: ConnectionCatalogEntry = { ...(retryUnsupported ? rest : entry), enabled };
1039 // Update the lease in place so the supervisor keeps its generation and
1040 // durable streams; `installEntryLocked` would tear it down instead.
1041 const lease = (yield* SubscriptionRef.get(serviceScopes)).get(environmentId);
packages/client-runtime/src/connection/routes.ts
+4
@@ -186,6 +186,10 @@ export function connectionRouteAddress(route: ConnectionRoute): string | null {
186 return routeHttpBaseUrl(route);
187 }
188
189 +/** Learned routes alone must not make relay environments manually retryable. */
190 +export const hasSavedBearerRoute = (entry: ConnectionCatalogEntry) =>
191 + connectionRoutes(entry).some((r) => !isLearned(r) && r.target._tag === "BearerConnectionTarget");
192 +
193 export function hasRelayRoute(
194 entry: Pick<ConnectionCatalogEntry, "target" | "alternateRoutes">,
195 ): boolean {