Skip to content

Commit a96277c

Browse files
vitalyiegorovclaude
andcommitted
fix(client-runtime): incompatible hosts no longer switch environments off for good
A protocol mismatch persisted the environment into the user's switched-off list, and nothing turned it back on once the host was updated. Treat the mismatch as runtime state instead: it pauses the connection without touching the user's on/off choice, and an environment the user left on reconnects when a fresh check finds the host compatible. Fixes #15051 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent a1d9d72 commit a96277c

5 files changed

Lines changed: 114 additions & 30 deletions

File tree

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,14 +1981,17 @@ export function ConnectionsSettings() {
19811981
}),
19821982
[savedServerUpdateStates],
19831983
);
1984-
// Switched-off machines never receive threads, so they stay out of the
1985-
// load balancing and GitHub sharing lists. The WSL backend has no row in
1986-
// the Environments list but does take threads, so it stays in here. This
1987-
// machine leads the list.
1984+
// Switched-off and unsupported machines never receive threads, so they stay
1985+
// out of the load balancing and GitHub sharing lists. The WSL backend has no
1986+
// row in the Environments list but does take threads, so it stays in here.
1987+
// This machine leads the list.
19881988
const loadBalancingEnvironments = useMemo(
19891989
() => [
19901990
...(primaryEnvironment ? [primaryEnvironment] : []),
1991-
...savedEnvironments.filter((environment) => environment.entry.enabled),
1991+
...savedEnvironments.filter(
1992+
(environment) =>
1993+
environment.entry.enabled && environment.connection.phase !== "unsupported",
1994+
),
19921995
],
19931996
[primaryEnvironment, savedEnvironments],
19941997
);

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,12 @@ export interface ConnectionCatalogEntry {
6262
readonly target: ConnectionTarget;
6363
readonly profile: Option.Option<ConnectionProfile>;
6464
readonly alternateRoutes?: ReadonlyArray<ConnectionRoute>;
65-
/** False when the user switched the environment off: saved, but never connects. */
65+
/** The user's persisted choice. False means saved, but never connects. */
6666
readonly enabled: boolean;
67-
/** Discovery rejection stays visible while the saved connection is switched off. */
67+
/**
68+
* Runtime protocol rejection, never persisted. Pauses the connection without
69+
* changing `enabled`, so it reconnects once the host is compatible again.
70+
*/
6871
readonly unsupportedReason?: string;
6972
/** The rejection came from an outdated host, which can still be updated remotely. */
7073
readonly serverUpdateRequired?: boolean;

‎packages/client-runtime/src/connection/registry.test.ts‎

Lines changed: 86 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -951,15 +951,15 @@ describe("EnvironmentRegistry", () => {
951951
yield* Deferred.await(relayChecked);
952952

953953
const entries = yield* SubscriptionRef.get(registry.entries);
954-
expect(entries.get(RELAY_TARGET.environmentId)).toMatchObject({ enabled: false });
954+
expect(entries.get(RELAY_TARGET.environmentId)?.unsupportedReason).toBeDefined();
955955
expect(entries.get(TARGET.environmentId)).toMatchObject({ enabled: true });
956956
expect(entries.get(TARGET.environmentId)?.unsupportedReason).toBeUndefined();
957957
expect((yield* registry.state(TARGET.environmentId)).phase).toBe("connected");
958958
}).pipe(Effect.provide(harness.layer), Effect.scoped);
959959
}),
960960
);
961961

962-
it.effect("discovery keeps unsupported environments off until compatibility changes", () =>
962+
it.effect("a switched-off environment stays off after its compatibility block clears", () =>
963963
Effect.gen(function* () {
964964
const harness = yield* makeHarness([RELAY_TARGET], [], [], {
965965
initialDisabled: [RELAY_TARGET.environmentId],
@@ -994,7 +994,7 @@ describe("EnvironmentRegistry", () => {
994994
}),
995995
);
996996

997-
it.effect("a socket preflight rejection persists the connection as switched off", () =>
997+
it.effect("a socket preflight rejection pauses the connection without switching it off", () =>
998998
Effect.gen(function* () {
999999
const error = new ConnectionBlockedError({
10001000
reason: "unsupported",
@@ -1005,20 +1005,97 @@ describe("EnvironmentRegistry", () => {
10051005
const registry = yield* EnvironmentRegistry.EnvironmentRegistry;
10061006
yield* registry.start;
10071007
yield* SubscriptionRef.changes(registry.entries).pipe(
1008-
Stream.filter((entries) => entries.get(RELAY_TARGET.environmentId)?.enabled === false),
1008+
Stream.filter(
1009+
(entries) => entries.get(RELAY_TARGET.environmentId)?.unsupportedReason !== undefined,
1010+
),
10091011
Stream.take(1),
10101012
Stream.runDrain,
10111013
);
1012-
expect((yield* Ref.get(harness.storedDisabled)).has(RELAY_TARGET.environmentId)).toBe(true);
1014+
expect((yield* Ref.get(harness.storedDisabled)).has(RELAY_TARGET.environmentId)).toBe(
1015+
false,
1016+
);
10131017
expect(
1014-
(yield* SubscriptionRef.get(registry.entries)).get(RELAY_TARGET.environmentId)
1015-
?.unsupportedReason,
1016-
).toBe(error.message);
1018+
(yield* SubscriptionRef.get(registry.entries)).get(RELAY_TARGET.environmentId),
1019+
).toMatchObject({ enabled: true, unsupportedReason: error.message });
1020+
yield* awaitConnectionState(
1021+
registry,
1022+
RELAY_TARGET.environmentId,
1023+
(state) => !state.desired && state.phase === "available",
1024+
);
10171025
expect(yield* Ref.get(harness.sessions)).toHaveLength(0);
10181026
}).pipe(Effect.provide(harness.layer));
10191027
}),
10201028
);
10211029

1030+
it.effect("an enabled environment reconnects once its compatibility block clears", () =>
1031+
Effect.gen(function* () {
1032+
const harness = yield* makeHarness([RELAY_TARGET]);
1033+
const error = new ConnectionBlockedError({
1034+
reason: "unsupported",
1035+
detail: "Use a compatible client.",
1036+
});
1037+
yield* Effect.gen(function* () {
1038+
const registry = yield* EnvironmentRegistry.EnvironmentRegistry;
1039+
yield* registry.start;
1040+
yield* awaitConnectionState(
1041+
registry,
1042+
RELAY_TARGET.environmentId,
1043+
(state) => state.phase === "connected",
1044+
);
1045+
1046+
yield* registry.setCompatibility(RELAY_TARGET.environmentId, error);
1047+
yield* awaitConnectionState(
1048+
registry,
1049+
RELAY_TARGET.environmentId,
1050+
(state) => state.phase === "available",
1051+
);
1052+
expect(
1053+
(yield* SubscriptionRef.get(registry.entries)).get(RELAY_TARGET.environmentId),
1054+
).toMatchObject({ enabled: true, unsupportedReason: error.message });
1055+
expect((yield* Ref.get(harness.storedDisabled)).has(RELAY_TARGET.environmentId)).toBe(
1056+
false,
1057+
);
1058+
1059+
yield* registry.setCompatibility(RELAY_TARGET.environmentId, null);
1060+
yield* awaitConnectionState(
1061+
registry,
1062+
RELAY_TARGET.environmentId,
1063+
(state) => state.phase === "connected",
1064+
);
1065+
expect(yield* Ref.get(harness.sessions)).toHaveLength(2);
1066+
}).pipe(Effect.provide(harness.layer));
1067+
}),
1068+
);
1069+
1070+
it.effect("a blocked environment comes back enabled after a relaunch", () =>
1071+
Effect.gen(function* () {
1072+
const harness = yield* makeHarness([RELAY_TARGET]);
1073+
yield* Effect.gen(function* () {
1074+
const registry = yield* EnvironmentRegistry.EnvironmentRegistry;
1075+
yield* registry.start;
1076+
yield* registry.setCompatibility(
1077+
RELAY_TARGET.environmentId,
1078+
new ConnectionBlockedError({ reason: "unsupported", detail: "Use a compatible client." }),
1079+
);
1080+
}).pipe(Effect.provide(harness.layer), Effect.scoped);
1081+
1082+
yield* Effect.gen(function* () {
1083+
const registry = yield* EnvironmentRegistry.EnvironmentRegistry;
1084+
const entry = (yield* SubscriptionRef.get(registry.entries)).get(
1085+
RELAY_TARGET.environmentId,
1086+
);
1087+
expect(entry?.enabled).toBe(true);
1088+
expect(entry?.unsupportedReason).toBeUndefined();
1089+
yield* registry.start;
1090+
yield* awaitConnectionState(
1091+
registry,
1092+
RELAY_TARGET.environmentId,
1093+
(state) => state.phase === "connected",
1094+
);
1095+
}).pipe(Effect.provide(harness.layer), Effect.scoped);
1096+
}),
1097+
);
1098+
10221099
it.effect("switching an environment off disconnects it and persists the flag", () =>
10231100
Effect.gen(function* () {
10241101
const harness = yield* makeHarness([RELAY_TARGET]);
@@ -1471,7 +1548,7 @@ describe("EnvironmentRegistry", () => {
14711548
yield* registry.reconcilePlatform([registration]);
14721549
expect(
14731550
(yield* SubscriptionRef.get(registry.entries)).get(TARGET.environmentId),
1474-
).toMatchObject({ enabled: false, unsupportedReason: error.message });
1551+
).toMatchObject({ enabled: true, unsupportedReason: error.message });
14751552
expect(yield* Ref.get(harness.sessions)).toHaveLength(1);
14761553
yield* registry.registerPlatform(
14771554
new PrimaryConnectionRegistration({

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ function unsupportedState(
6767
};
6868
}
6969

70+
/** The user wants it on and its host is not known to be incompatible. */
71+
function shouldConnect(entry: ConnectionCatalogEntry): boolean {
72+
return entry.enabled && entry.unsupportedReason === undefined;
73+
}
74+
7075
export class EnvironmentNotRegisteredError extends Schema.TaggedError<EnvironmentNotRegisteredError>()(
7176
"EnvironmentNotRegisteredError",
7277
{
@@ -372,7 +377,7 @@ export const make = Effect.gen(function* () {
372377
Scope.provide(scope),
373378
Effect.onError(() => Scope.close(scope, Exit.void)),
374379
);
375-
if (entry.enabled) {
380+
if (shouldConnect(entry)) {
376381
yield* supervisor.connect;
377382
}
378383
yield* SubscriptionRef.update(serviceScopes, (current) => {
@@ -385,7 +390,7 @@ export const make = Effect.gen(function* () {
385390
state.phase === "blocked" && state.lastFailure?.reason === "unsupported"
386391
? setCompatibility(environmentId, state.lastFailure).pipe(
387392
Effect.catch((error) =>
388-
Effect.logWarning("Could not disable an unsupported environment.", {
393+
Effect.logWarning("Could not mark an environment unsupported.", {
389394
environmentId,
390395
error,
391396
}),
@@ -622,7 +627,7 @@ export const make = Effect.gen(function* () {
622627
const entry: ConnectionCatalogEntry =
623628
previous?.unsupportedReason !== undefined &&
624629
gitHubRoutingConnectionKey(previous) === gitHubRoutingConnectionKey(registered)
625-
? { ...registered, enabled: false, ...unsupportedState(previous) }
630+
? { ...registered, ...unsupportedState(previous) }
626631
: registered;
627632
const persisted = (yield* Ref.get(persistedEnvironmentIds)).has(target.environmentId);
628633
if (
@@ -1087,28 +1092,24 @@ export const make = Effect.gen(function* () {
10871092
serverUpdateRequired: _previousUpdateRequired,
10881093
...rest
10891094
} = entry;
1095+
// Compatibility is runtime state: it pauses the connection without
1096+
// touching the user's persisted on/off choice, so an environment the
1097+
// user left on reconnects once its host speaks our protocol again.
10901098
const next: ConnectionCatalogEntry =
10911099
error === null
10921100
? rest
10931101
: {
10941102
...rest,
1095-
enabled: false,
10961103
unsupportedReason: error.message,
10971104
...(error.serverUpdateRequired === true ? { serverUpdateRequired: true } : {}),
10981105
};
1099-
if (
1100-
error !== null &&
1101-
entry.enabled &&
1102-
!(yield* Ref.get(platformEnvironmentIds)).has(environmentId)
1103-
) {
1104-
yield* registrations.setEnabled(environmentId, false);
1105-
}
11061106
const lease = (yield* SubscriptionRef.get(serviceScopes)).get(environmentId);
11071107
if (lease !== undefined) {
11081108
yield* SubscriptionRef.update(serviceScopes, (current) =>
11091109
new Map(current).set(environmentId, { ...lease, entry: next }),
11101110
);
11111111
if (error !== null) yield* lease.supervisor.disconnect;
1112+
else if (shouldConnect(next)) yield* lease.supervisor.connect;
11121113
}
11131114
yield* SubscriptionRef.update(entries, (current) =>
11141115
new Map(current).set(environmentId, next),

‎packages/client-runtime/src/state/connections.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ export interface EnvironmentCatalogState {
2727

2828
/**
2929
* Environments that take part in the workspace: projects, threads, and shell
30-
* summaries only come from these. Disabled environments stay in `entries` so
31-
* Settings can list them and switch them back on.
30+
* summaries only come from these. Disabled environments, and ones whose host
31+
* this client cannot talk to, stay in `entries` so Settings can list them.
3232
*/
3333
export function* enabledEnvironmentIds(
3434
catalog: EnvironmentCatalogState,
3535
): Generator<EnvironmentIdType> {
3636
for (const [environmentId, entry] of catalog.entries) {
37-
if (entry.enabled) {
37+
if (entry.enabled && entry.unsupportedReason === undefined) {
3838
yield environmentId;
3939
}
4040
}

0 commit comments

Comments
 (0)