@devries-cameron20 / t3code-1 / commits / 02b794c782
Fork 0

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

fix(client-runtime): incompatible hosts no longer switch environments off for good (#15052)

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Vitaly Iegorov committed Oct 20, 2026 at 00:31 UTC 02b794c78211a4cc35ec230a21f042698109b5ef
9 files changed +154 -59
apps/mobile/src/features/threads/NewTaskRouteScreen.tsx
+6 -2
@@ -70,11 +70,15 @@ function deriveProjectEmptyState(catalogState: WorkspaceState): {
70 if (
71 (catalogState.connectionState === "available" ||
72 catalogState.connectionState === "offline" ||
73 - catalogState.connectionState === "error") &&
73 + catalogState.connectionState === "error" ||
74 + catalogState.connectionState === "unsupported") &&
75 !catalogState.hasLoadedShellSnapshot
76 ) {
77 return {
77 - title: "Environment unavailable",
78 + title:
79 + catalogState.connectionState === "unsupported"
80 + ? "Client not supported"
81 + : "Environment unavailable",
82 detail:
83 catalogState.connectionError ??
84 "The saved environment is offline. Check the URL or start the environment, then retry.",
apps/web/src/components/settings/ConnectionsSettings.tsx
+1 -1
@@ -2075,7 +2075,7 @@ export function ConnectionsSettings() {
2075 const loadBalancingEnvironments = [
2076 ...(primaryEnvironment ? [primaryEnvironment] : []),
2077 ...savedEnvironments.filter((environment) => environment.entry.enabled),
2078 - ];
2078 + ].filter((environment) => environment.connection.phase !== "unsupported");
2079 const savedDesktopSshEnvironmentKeys = (() => {
2080 const keys = new Set<string>();
2081 for (const environment of savedEnvironments) {
packages/client-runtime/src/connection/onboarding.test.ts
+4 -1
@@ -368,7 +368,10 @@ describe("connection onboarding", () => {
368 );
369 yield* registry.setCompatibility(PAIRED_ENVIRONMENT_ID, UNSUPPORTED_ERROR);
370 const before = yield* SubscriptionRef.get(registry.entries);
371 - expect(before.get(PAIRED_ENVIRONMENT_ID)?.enabled).toBe(false);
371 + expect(before.get(PAIRED_ENVIRONMENT_ID)).toMatchObject({
372 + enabled: true,
373 + unsupportedReason: UNSUPPORTED_ERROR.message,
374 + });
375
376 const environmentId = yield* onboarding.registerPairing(PAIRING_INPUT);
377
packages/client-runtime/src/connection/registry.test.ts
+71 -19
@@ -987,7 +987,7 @@ describe("EnvironmentRegistry", () => {
987 yield* Deferred.await(relayChecked);
988
989 const entries = yield* SubscriptionRef.get(registry.entries);
990 - expect(entries.get(RELAY_TARGET.environmentId)).toMatchObject({ enabled: false });
990 + expect(entries.get(RELAY_TARGET.environmentId)?.unsupportedReason).toBeDefined();
991 expect(entries.get(TARGET.environmentId)).toMatchObject({ enabled: true });
992 expect(entries.get(TARGET.environmentId)?.unsupportedReason).toBeUndefined();
993 expect((yield* registry.state(TARGET.environmentId)).phase).toBe("connected");
@@ -996,7 +996,7 @@ describe("EnvironmentRegistry", () => {
996 );
997
998 it.effect.each([false, true])(
999 - "discovery keeps unsupported environments off (learned route: %s)",
999 + "a switched-off environment stays off after compatibility clears (learned route: %s)",
1000 (learned) =>
1001 Effect.gen(function* () {
1002 const environmentId = BEARER_TARGET.environmentId;
@@ -1030,6 +1030,9 @@ describe("EnvironmentRegistry", () => {
1030 expect((yield* SubscriptionRef.get(registry.entries)).get(environmentId)?.enabled).toBe(
1031 false,
1032 );
1033 + expect(yield* registry.state(environmentId)).toMatchObject({ desired: false });
1034 + expect(yield* Ref.get(harness.storedDisabled)).toEqual(new Set([environmentId]));
1035 + expect(yield* Ref.get(harness.sessions)).toHaveLength(0);
1036 yield* registry.setEnabled(environmentId, true);
1037 yield* awaitConnectionState(
1038 registry,
@@ -1040,28 +1043,68 @@ describe("EnvironmentRegistry", () => {
1043 }),
1044 );
1045
1043 - it.effect("a socket preflight rejection persists the connection as switched off", () =>
1046 + it.effect("protocol rejection preserves enablement through recovery and relaunch", () =>
1047 Effect.gen(function* () {
1048 const error = new ConnectionBlockedError({
1049 reason: "unsupported",
1050 detail: "Use a compatible client.",
1051 });
1049 - const harness = yield* makeHarness([RELAY_TARGET], [], [], { prepareError: error });
1052 + const rejection = yield* Ref.make<ConnectionBlockedError | undefined>(error);
1053 + const harness = yield* makeHarness([RELAY_TARGET], [], [], {
1054 + beforePrepareRoute: () => Ref.get(rejection),
1055 + });
1056 yield* Effect.gen(function* () {
1057 const registry = yield* EnvironmentRegistry.EnvironmentRegistry;
1058 yield* registry.start;
1059 yield* SubscriptionRef.changes(registry.entries).pipe(
1054 - Stream.filter((entries) => entries.get(RELAY_TARGET.environmentId)?.enabled === false),
1060 + Stream.filter(
1061 + (entries) => entries.get(RELAY_TARGET.environmentId)?.unsupportedReason !== undefined,
1062 + ),
1063 Stream.take(1),
1064 Stream.runDrain,
1065 );
1058 - expect((yield* Ref.get(harness.storedDisabled)).has(RELAY_TARGET.environmentId)).toBe(true);
1066 + expect(yield* Ref.get(harness.storedDisabled)).toEqual(new Set());
1067 expect(
1060 - (yield* SubscriptionRef.get(registry.entries)).get(RELAY_TARGET.environmentId)
1061 - ?.unsupportedReason,
1062 - ).toBe(error.message);
1068 + (yield* SubscriptionRef.get(registry.entries)).get(RELAY_TARGET.environmentId),
1069 + ).toMatchObject({ enabled: true, unsupportedReason: error.message });
1070 + yield* awaitConnectionState(
1071 + registry,
1072 + RELAY_TARGET.environmentId,
1073 + (state) => !state.desired && state.phase === "available",
1074 + );
1075 expect(yield* Ref.get(harness.sessions)).toHaveLength(0);
1064 - }).pipe(Effect.provide(harness.layer));
1076 +
1077 + yield* Ref.set(rejection, undefined);
1078 + yield* registry.setCompatibility(RELAY_TARGET.environmentId, null);
1079 + yield* awaitConnectionState(
1080 + registry,
1081 + RELAY_TARGET.environmentId,
1082 + (state) => state.phase === "connected",
1083 + );
1084 + expect(yield* Ref.get(harness.sessions)).toHaveLength(1);
1085 + yield* registry.setCompatibility(RELAY_TARGET.environmentId, error);
1086 + yield* awaitConnectionState(
1087 + registry,
1088 + RELAY_TARGET.environmentId,
1089 + (state) => !state.desired && state.phase === "available",
1090 + );
1091 + expect(yield* Ref.get(harness.releasedSessions)).toBe(1);
1092 + }).pipe(Effect.provide(harness.layer), Effect.scoped);
1093 +
1094 + yield* Effect.gen(function* () {
1095 + const registry = yield* EnvironmentRegistry.EnvironmentRegistry;
1096 + const entry = (yield* SubscriptionRef.get(registry.entries)).get(
1097 + RELAY_TARGET.environmentId,
1098 + );
1099 + expect(entry?.enabled).toBe(true);
1100 + expect(entry?.unsupportedReason).toBeUndefined();
1101 + yield* registry.start;
1102 + yield* awaitConnectionState(
1103 + registry,
1104 + RELAY_TARGET.environmentId,
1105 + (state) => state.phase === "connected",
1106 + );
1107 + }).pipe(Effect.provide(harness.layer), Effect.scoped);
1108 }),
1109 );
1110
@@ -1100,16 +1143,16 @@ describe("EnvironmentRegistry", () => {
1143 yield* Effect.gen(function* () {
1144 const registry = yield* EnvironmentRegistry.EnvironmentRegistry;
1145 yield* registry.start;
1103 - const awaitDisabled = SubscriptionRef.changes(registry.entries).pipe(
1104 - Stream.filter((entries) => entries.get(environmentId)?.enabled === false),
1146 + const awaitUnsupported = SubscriptionRef.changes(registry.entries).pipe(
1147 + Stream.filter((entries) => entries.get(environmentId)?.unsupportedReason !== undefined),
1148 Stream.take(1),
1149 Stream.runDrain,
1150 );
1108 - yield* awaitDisabled;
1109 - expect((yield* Ref.get(harness.storedDisabled)).has(environmentId)).toBe(true);
1151 + yield* awaitUnsupported;
1152 + expect((yield* Ref.get(harness.storedDisabled)).has(environmentId)).toBe(false);
1153 expect((yield* SubscriptionRef.get(registry.entries)).get(environmentId)).toMatchObject({
1154 target: relayFirst ? relay : BEARER_TARGET,
1112 - enabled: false,
1155 + enabled: true,
1156 unsupportedReason: error.message,
1157 serverUpdateRequired: true,
1158 });
@@ -1132,13 +1175,13 @@ describe("EnvironmentRegistry", () => {
1175 );
1176 expect(yield* Ref.get(harness.sessions)).toHaveLength(1);
1177 } else {
1135 - yield* awaitDisabled;
1178 + yield* awaitUnsupported;
1179 expect((yield* SubscriptionRef.get(registry.entries)).get(environmentId)).toMatchObject({
1137 - enabled: false,
1180 + enabled: true,
1181 unsupportedReason: error.message,
1182 serverUpdateRequired: true,
1183 });
1141 - expect((yield* Ref.get(harness.storedDisabled)).has(environmentId)).toBe(true);
1184 + expect((yield* Ref.get(harness.storedDisabled)).has(environmentId)).toBe(false);
1185 expect(yield* Ref.get(harness.sessions)).toHaveLength(0);
1186 }
1187 expect(yield* Ref.get(attempts)).toBe(2);
@@ -1808,7 +1851,16 @@ describe("EnvironmentRegistry", () => {
1851 yield* registry.reconcilePlatform([registration]);
1852 expect(
1853 (yield* SubscriptionRef.get(registry.entries)).get(TARGET.environmentId),
1811 - ).toMatchObject({ enabled: false, unsupportedReason: error.message });
1854 + ).toMatchObject({ enabled: true, unsupportedReason: error.message });
1855 + yield* registry.registerPlatform(
1856 + new PrimaryConnectionRegistration({
1857 + target: new PrimaryConnectionTarget({ ...TARGET, label: "Renamed" }),
1858 + }),
1859 + );
1860 + expect(yield* registry.state(TARGET.environmentId)).toMatchObject({
1861 + desired: false,
1862 + phase: "available",
1863 + });
1864 expect(yield* Ref.get(harness.sessions)).toHaveLength(1);
1865 yield* registry.registerPlatform(
1866 new PrimaryConnectionRegistration({
packages/client-runtime/src/connection/registry.ts
+7 -21
@@ -357,10 +357,9 @@ export const make = Effect.gen(function* () {
357 const environmentId = entry.target.environmentId;
358 const scope = yield* Scope.fork(registryScope);
359 const supervisor = yield* EnvironmentSupervisor.make(entry, {
360 - // An enabled environment starts out connecting. Starting it idle and
361 - // then asking it to connect would first publish the state of an
362 - // environment the user switched off.
363 - initiallyDesired: entry.enabled,
360 + // Seed the intent to avoid publishing a false switched-off state
361 + // before an enabled, compatible environment starts connecting.
362 + initiallyDesired: entry.enabled && entry.unsupportedReason === undefined,
363 learnRoutes: (input) => learnRoutes({ environmentId, ...input }),
364 }).pipe(
365 Effect.provideService(Connectivity.Connectivity, connectivity),
@@ -377,14 +376,7 @@ export const make = Effect.gen(function* () {
376 yield* SubscriptionRef.changes(supervisor.state).pipe(
377 Stream.runForEach((state) =>
378 state.phase === "blocked" && state.lastFailure?.reason === "unsupported"
380 - ? setCompatibility(environmentId, state.lastFailure).pipe(
381 - Effect.catch((error) =>
382 - Effect.logWarning("Could not disable an unsupported environment.", {
383 - environmentId,
384 - error,
385 - }),
386 - ),
387 - )
379 + ? setCompatibility(environmentId, state.lastFailure)
380 : Effect.void,
381 ),
382 Effect.forkIn(scope),
@@ -613,7 +605,7 @@ export const make = Effect.gen(function* () {
605 const entry: ConnectionCatalogEntry =
606 previous?.unsupportedReason !== undefined &&
607 gitHubRoutingConnectionKey(previous) === gitHubRoutingConnectionKey(registered)
616 - ? { ...registered, enabled: false, ...unsupportedState(previous) }
608 + ? { ...registered, ...unsupportedState(previous) }
609 : registered;
610 const persisted = (yield* Ref.get(persistedEnvironmentIds)).has(target.environmentId);
611 if (
@@ -1118,28 +1110,22 @@ export const make = Effect.gen(function* () {
1110 serverUpdateRequired: _previousUpdateRequired,
1111 ...rest
1112 } = entry;
1113 + // Compatibility pauses connections without changing the user's saved on/off choice.
1114 const next: ConnectionCatalogEntry =
1115 error === null
1116 ? rest
1117 : {
1118 ...rest,
1126 - enabled: false,
1119 unsupportedReason: error.message,
1120 ...(error.serverUpdateRequired === true ? { serverUpdateRequired: true } : {}),
1121 };
1130 - if (
1131 - error !== null &&
1132 - entry.enabled &&
1133 - !(yield* Ref.get(platformEnvironmentIds)).has(environmentId)
1134 - ) {
1135 - yield* registrations.setEnabled(environmentId, false);
1136 - }
1122 const lease = (yield* SubscriptionRef.get(serviceScopes)).get(environmentId);
1123 if (lease !== undefined) {
1124 yield* SubscriptionRef.update(serviceScopes, (current) =>
1125 new Map(current).set(environmentId, { ...lease, entry: next }),
1126 );
1127 if (error !== null) yield* lease.supervisor.disconnect;
1128 + else if (next.enabled) yield* lease.supervisor.connect;
1129 }
1130 yield* SubscriptionRef.update(entries, (current) =>
1131 new Map(current).set(environmentId, next),
packages/client-runtime/src/state/connections.ts
+1 -1
@@ -29,7 +29,7 @@ export function* enabledEnvironmentIds(
29 catalog: EnvironmentCatalogState,
30 ): Generator<EnvironmentIdType> {
31 for (const [environmentId, entry] of catalog.entries) {
32 - if (entry.enabled) {
32 + if (entry.enabled && entry.unsupportedReason === undefined) {
33 yield environmentId;
34 }
35 }
packages/client-runtime/src/state/pullRequestRouting.ts
+7 -1
@@ -161,7 +161,13 @@ const routingAllowed = Effect.fn("PullRequestRouting.allowed")(function* (
161 const entries = yield* SubscriptionRef.get(registry.entries);
162 const origin = entries.get(originId);
163 const destination = entries.get(destinationId);
164 - if (!origin?.enabled || !destination?.enabled) return false;
164 + if (
165 + !origin?.enabled ||
166 + !destination?.enabled ||
167 + origin.unsupportedReason !== undefined ||
168 + destination.unsupportedReason !== undefined
169 + )
170 + return false;
171 const permissions = yield* GitHubRoutingPermissions;
172 const source = yield* permissions.get(origin);
173 const target = yield* permissions.get(destination);
packages/client-runtime/src/state/pullRequests.test.ts
+43 -8
@@ -754,8 +754,15 @@ const makeTestRuntime = Effect.fn("makeTestRuntime")(function* (
754 return { runtime, atoms, registry, environmentRegistry, supervisor, localSupervisor };
755 });
756
757 -it.effect.each(["default", "origin-off", "destination-off", "read-only"] as const)(
758 - "does not probe another environment with %s routing permission",
757 +it.effect.each([
758 + "default",
759 + "origin-off",
760 + "destination-off",
761 + "read-only",
762 + "destination-disabled",
763 + "destination-unsupported",
764 +] as const)(
765 + "preserves source requests when routing to another environment is blocked by %s",
766 (permission) =>
767 Effect.scoped(
768 Effect.gen(function* () {
@@ -765,9 +772,10 @@ it.effect.each(["default", "origin-off", "destination-off", "read-only"] as cons
772 detail: "source failed",
773 });
774 const client = {
768 - [WS_METHODS.pullRequestsSummary]: () =>
775 + [WS_METHODS.pullRequestsSummary]: (input: { allowStale?: boolean }) =>
776 Effect.suspend(() => {
777 calls.push("source-read");
778 + expect(input.allowStale).toBeUndefined();
779 return Effect.fail(failure);
780 }),
781 [WS_METHODS.pullRequestsRunAction]: () =>
@@ -779,7 +787,31 @@ it.effect.each(["default", "origin-off", "destination-off", "read-only"] as cons
787 [WS_METHODS.pullRequestsRoutingIdentity]: () =>
788 Effect.die("untrusted environment was contacted"),
789 } as unknown as WsRpcProtocolClient;
782 - const { environmentRegistry, supervisor } = yield* makeTestRuntime(client, alternate);
790 + const { environmentRegistry, supervisor, localSupervisor } = yield* makeTestRuntime(
791 + client,
792 + alternate,
793 + );
794 + if (permission === "destination-disabled" || permission === "destination-unsupported") {
795 + yield* SubscriptionRef.update(
796 + environmentRegistry.entries,
797 + (entries) =>
798 + new Map(
799 + [...entries].map(([id, entry]) => [
800 + id,
801 + id === TARGET.environmentId
802 + ? entry
803 + : {
804 + ...entry,
805 + enabled: permission !== "destination-disabled",
806 + ...(permission === "destination-unsupported"
807 + ? { unsupportedReason: "Protocol version mismatch" }
808 + : {}),
809 + },
810 + ]),
811 + ),
812 + );
813 + yield* SubscriptionRef.set(localSupervisor.session, Option.none());
814 + }
815 const ref = {
816 projectId: ProjectId.make("project-1"),
817 repository: "private/repo",
@@ -805,10 +837,13 @@ it.effect.each(["default", "origin-off", "destination-off", "read-only"] as cons
837 Effect.succeed(
838 permission === "read-only"
839 ? "read"
808 - : (entry.target.environmentId === TARGET.environmentId) ===
809 - (permission === "origin-off")
810 - ? "off"
811 - : "read-write",
840 + : permission === "destination-disabled" ||
841 + permission === "destination-unsupported"
842 + ? "read-write"
843 + : (entry.target.environmentId === TARGET.environmentId) ===
844 + (permission === "origin-off")
845 + ? "off"
846 + : "read-write",
847 ),
848 }),
849 );
packages/client-runtime/src/state/threadShell.test.ts
+14 -5
@@ -215,7 +215,13 @@ describe("v2 thread shell lists", () => {
215 registry.dispose();
216 });
217
218 - it("leaves switched-off environments out of navigation", () => {
218 + it.each([
219 + { reason: "switched-off", state: { enabled: false } },
220 + {
221 + reason: "unsupported",
222 + state: { enabled: true, unsupportedReason: "Use a compatible client." },
223 + },
224 + ])("leaves $reason environments out of navigation until restored", ({ state }) => {
225 const { registry, threads, catalogValueAtom } = makeHarness([
226 environmentId,
227 remoteEnvironmentId,
@@ -225,15 +231,18 @@ describe("v2 thread shell lists", () => {
231 new Set(registry.get(threads.navigationThreadShellsAtom).map((t) => t.environmentId));
232 expect(environmentsOf()).toEqual(new Set([environmentId, remoteEnvironmentId]));
233
228 - const setRemoteEnabled = (enabled: boolean) => {
234 + const setRemotePaused = (paused: boolean) => {
235 const catalog = registry.get(catalogValueAtom);
236 const entries = new Map(catalog.entries);
231 - entries.set(remoteEnvironmentId, { ...entries.get(remoteEnvironmentId)!, enabled });
237 + entries.set(remoteEnvironmentId, {
238 + ...entries.get(remoteEnvironmentId)!,
239 + ...(paused ? state : { enabled: true, unsupportedReason: undefined }),
240 + });
241 registry.set(catalogValueAtom, { ...catalog, entries });
242 };
234 - setRemoteEnabled(false);
243 + setRemotePaused(true);
244 expect(environmentsOf()).toEqual(new Set([environmentId]));
236 - setRemoteEnabled(true);
245 + setRemotePaused(false);
246 expect(environmentsOf()).toEqual(new Set([environmentId, remoteEnvironmentId]));
247 dispose();
248 registry.dispose();