Skip to content

Commit 55c7b44

Browse files
fix(clients): address review findings on connection routes
- A failed unchecked route (signed-out T3 Connect) no longer stops a silent LAN route from being tried; silent routes are tried last. - When any route failed transiently, report that instead of a blocked error, so the supervisor keeps retrying a route that may come back. - Removing an environment's last route happens under the same lease lock, so a route registered meanwhile is not deleted with it. - Bearer route ids use the full origin, so http and https pairings of one host are separate routes. - Tailscale IPv6 addresses (fd7a:115c:a1e0::/48) rank as tailnet. - Web reports a network change only when the connection type changes, not on every bandwidth estimate; mobile seeds the current type so the first Wi-Fi to cellular move is noticed. - After updating an outdated host, the resume poll checks every direct route, not only the one that carried the update. - Onboarding no longer offers a T3 Connect checkbox for a machine already saved over another route. - Mobile route rows announce the route, address, in-use state and position to screen readers; the user doc describes silent-route fallback accurately. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent fe7078a commit 55c7b44

13 files changed

Lines changed: 203 additions & 91 deletions

File tree

‎apps/mobile/src/connection/platform.ts‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,31 @@ const connectivityLayer = Connectivity.layer({
9191
const networkPathChanges = Stream.callback<"network-changed">((queue) =>
9292
Effect.acquireRelease(
9393
Effect.sync(() => {
94+
let active = true;
9495
let previous: Network.NetworkStateType | undefined;
95-
return Network.addNetworkStateListener((state) => {
96+
const record = (state: Network.NetworkState) => {
9697
const type = state.isConnected === true ? state.type : undefined;
9798
if (previous !== undefined && type !== undefined && type !== previous) {
9899
Queue.offerUnsafe(queue, "network-changed");
99100
}
100101
previous = type ?? previous;
101-
});
102+
};
103+
// The listener reports changes only, so seed the current type; without
104+
// it the first Wi-Fi to cellular move would go unnoticed.
105+
void Network.getNetworkStateAsync()
106+
.then((state) => {
107+
if (active && previous === undefined && state.isConnected === true) {
108+
previous = state.type;
109+
}
110+
})
111+
.catch(() => undefined);
112+
const subscription = Network.addNetworkStateListener(record);
113+
return {
114+
remove: () => {
115+
active = false;
116+
subscription.remove();
117+
},
118+
};
102119
}),
103120
(subscription) => Effect.sync(() => subscription.remove()),
104121
).pipe(Effect.asVoid),

‎apps/mobile/src/features/settings/EnvironmentRoutesSection.tsx‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ export function EnvironmentRoutesSection({
7474
<Pressable
7575
key={id}
7676
accessibilityRole="button"
77+
accessibilityLabel={[
78+
connectionRouteLabel(route),
79+
address,
80+
id === activeRouteId ? "In use" : null,
81+
`Route ${index + 1} of ${routes.length}`,
82+
]
83+
.filter((part) => part !== null)
84+
.join(", ")}
7785
accessibilityHint="Shows options for this route"
7886
onPress={() => openActions(index)}
7987
className="flex-row items-center gap-3 p-4 active:opacity-70"

‎apps/web/src/components/cloud/CloudEnvironmentConnectList.tsx‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,14 @@ export function CloudEnvironmentConnectRows({
196196
return false;
197197
};
198198

199+
// During onboarding selection a machine saved over another route already
200+
// has its own row elsewhere, and selecting it must not add a T3 Connect
201+
// route as a side effect, so it is left out here.
199202
const visibleEnvironments = [...environmentsState.environments.values()].filter(
200203
({ environment }) =>
201204
environment.environmentId !== primaryEnvironmentId &&
202-
(showSavedEnvironments || !savedById.has(environment.environmentId)),
205+
(showSavedEnvironments || !savedById.has(environment.environmentId)) &&
206+
!(selection && savedWithoutRelay.has(environment.environmentId)),
203207
);
204208
const selectNewComputers = useEffectEvent(() => {
205209
const seen = selection?.autoSelectedComputers;
@@ -218,9 +222,7 @@ export function CloudEnvironmentConnectRows({
218222
if (seen.has(id)) continue;
219223
seen.add(id);
220224
selection.onChange(id, true);
221-
// A machine saved over another route already connects; adding T3 Connect
222-
// as its fallback is the user's call, from Settings.
223-
if (!savedById.has(id) && !savedWithoutRelay.has(id)) {
225+
if (!savedById.has(id)) {
224226
void connectEnvironment(environment).then((connected) => {
225227
if (!connected) selection.onChange(id, false);
226228
});

‎apps/web/src/connection/platform.ts‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,11 @@ interface NetworkInformationLike extends EventTarget {
9292
}
9393

9494
/**
95-
* Wakes connections when the browser reports a different network path, such
96-
* as a laptop moving from Wi-Fi to a phone hotspot. Only some browsers expose
97-
* `navigator.connection`; elsewhere the periodic route check covers it.
95+
* Wakes connections when the browser reports a different network type, such
96+
* as a laptop moving from Wi-Fi to a phone hotspot. `change` also fires for
97+
* bandwidth and latency estimates on the same network, so only a type change
98+
* counts. Browsers without `navigator.connection.type` rely on the periodic
99+
* route check instead.
98100
*/
99101
const networkPathChanges = Stream.callback<"network-changed">((queue) =>
100102
Effect.acquireRelease(
@@ -103,8 +105,14 @@ const networkPathChanges = Stream.callback<"network-changed">((queue) =>
103105
typeof navigator === "undefined"
104106
? undefined
105107
: (navigator as Navigator & { readonly connection?: NetworkInformationLike }).connection;
106-
if (connection === undefined) return undefined;
107-
const listener = () => Queue.offerUnsafe(queue, "network-changed");
108+
if (connection?.type === undefined) return undefined;
109+
let previous = connection.type;
110+
const listener = () => {
111+
const type = connection.type;
112+
if (type === undefined || type === previous) return;
113+
previous = type;
114+
Queue.offerUnsafe(queue, "network-changed");
115+
};
108116
connection.addEventListener("change", listener);
109117
return { connection, listener };
110118
}),

‎docs/user/remote-access.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ T3 Connect list, and the new route joins the existing one instead of adding a
7070
second machine. Faster routes go first: LAN, then Tailscale, then T3 Connect.
7171

7272
T3 Code connects over the first route that answers. Away from home, a LAN
73-
address that does not answer costs one short check before the next route is
74-
used. While connected over a later route, T3 Code checks the earlier ones when
73+
address that does not answer is checked briefly and skipped. It is only tried
74+
again, after the other routes, if none of them connect. While connected over a later route, T3 Code checks the earlier ones when
7575
your network changes, when you return to the app, and every minute, and moves
7676
back as soon as one works.
7777

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

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,15 @@ export class ConnectionDriver extends Context.Service<
6969
* Connects over the first route, in preference order, that is worth trying.
7070
* Every route is checked at once, but a route only waits for its own check,
7171
* so a reachable LAN address connects without waiting on a silent tailnet
72-
* one. A silent route is skipped so a LAN address from another network costs
73-
* one short check, not a connection timeout. A route that fails to connect
74-
* moves on to the next: a signed-out T3 Connect must not hide a working LAN.
75-
* If every route was silent, each is tried anyway, since a check is not proof.
72+
* one. A silent route is skipped on the first pass so a LAN address from
73+
* another network costs one short check, not a connection timeout. A route
74+
* that fails to connect moves on to the next: a signed-out T3 Connect must
75+
* not hide a working LAN. Silent routes are tried last, since a check is not
76+
* proof.
77+
*
78+
* The reported error is a transient one when any route failed transiently,
79+
* so the supervisor keeps retrying a route that may come back; a blocked
80+
* error is reported only when every attempted route was blocked.
7681
*/
7782
export const connectOverRoutes = Effect.fn("ConnectionDriver.connectOverRoutes")(function* <R>(
7883
entry: ConnectionCatalogEntry,
@@ -87,38 +92,47 @@ export const connectOverRoutes = Effect.fn("ConnectionDriver.connectOverRoutes")
8792
? []
8893
: yield* Effect.forEach(routes, (route) => Effect.forkChild(checkRoute(route)));
8994
const attemptScope = yield* Scope.Scope;
90-
let lastError: ConnectionAttemptError = new ConnectionTransientError({
91-
reason: "endpoint-unavailable",
92-
detail: `${entry.target.label} did not answer on any saved route.`,
93-
});
95+
let transient: ConnectionAttemptError | undefined;
96+
let blocked: ConnectionAttemptError | undefined;
9497
// Each route gets its own scope so a half-open session closes before the next try.
9598
const attempt = Effect.fnUntraced(function* (route: ConnectionRoute) {
9699
const routeScope = yield* Scope.fork(attemptScope);
97-
return yield* connectRoute(route).pipe(
100+
const result = yield* connectRoute(route).pipe(
98101
Scope.provide(routeScope),
99102
Effect.onExit((exit) => (Exit.isSuccess(exit) ? Effect.void : Scope.close(routeScope, exit))),
100103
Effect.result,
101104
);
105+
if (result._tag === "Failure") {
106+
if (result.failure._tag === "ConnectionTransientError") transient ??= result.failure;
107+
else blocked ??= result.failure;
108+
}
109+
return result;
102110
});
103-
let tried = 0;
111+
const silent: Array<ConnectionRoute> = [];
104112
for (const [index, route] of routes.entries()) {
105113
const check = checks.length === 0 ? "unchecked" : yield* Fiber.join(checks[index]!);
106-
if (check === "silent") continue;
107-
tried += 1;
114+
if (check === "silent") {
115+
silent.push(route);
116+
continue;
117+
}
108118
const result = yield* attempt(route);
109119
if (result._tag === "Success") return result.success;
110-
lastError = result.failure;
111120
// An incompatible server is the same server on every route.
112-
if (lastError.reason === "unsupported") return yield* lastError;
121+
if (result.failure.reason === "unsupported") return yield* result.failure;
113122
}
114-
if (tried > 0) return yield* lastError;
115-
for (const route of routes) {
123+
for (const route of silent) {
116124
const result = yield* attempt(route);
117125
if (result._tag === "Success") return result.success;
118-
lastError = result.failure;
119-
if (lastError.reason === "unsupported") break;
126+
if (result.failure.reason === "unsupported") return yield* result.failure;
120127
}
121-
return yield* lastError;
128+
return yield* (
129+
transient ??
130+
blocked ??
131+
new ConnectionTransientError({
132+
reason: "endpoint-unavailable",
133+
detail: `${entry.target.label} did not answer on any saved route.`,
134+
})
135+
);
122136
});
123137

124138
/** @public Service construction is part of the canonical Effect module API. */

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ describe("connection onboarding", () => {
9898
target: {
9999
environmentId: "environment-paired",
100100
label: "Paired environment",
101-
connectionId: "bearer:environment-paired:remote.example.test",
101+
connectionId: "bearer:environment-paired:https://remote.example.test",
102102
},
103103
profile: {
104104
environmentId: "environment-paired",
105105
label: "Paired environment",
106-
connectionId: "bearer:environment-paired:remote.example.test",
106+
connectionId: "bearer:environment-paired:https://remote.example.test",
107107
httpBaseUrl: "https://remote.example.test/",
108108
wsBaseUrl: "wss://remote.example.test/",
109109
},

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ const resolvePairingTarget = Effect.fn("clientRuntime.connection.onboarding.reso
9191
* reuses the id and replaces that route.
9292
*/
9393
function bearerConnectionId(environmentId: EnvironmentId, httpBaseUrl: string): string {
94-
return `bearer:${environmentId}:${new URL(httpBaseUrl).host}`;
94+
return `bearer:${environmentId}:${new URL(httpBaseUrl).origin}`;
9595
}
9696

9797
export const preparePairingRegistration = Effect.fn(

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { isLegacyUpdateHandoffLoss, resolveServerUpdateProgressResult } from "..
2626
import * as RelayEnvironmentDiscovery from "../relay/discovery.ts";
2727
import * as ConnectionResolver from "./resolver.ts";
2828
import * as EnvironmentRegistry from "./registry.ts";
29-
import { connectionRoutes, hasRelayRoute, routeEntry } from "./routes.ts";
29+
import { connectionRoutes, hasRelayRoute, routeEntry, routeHttpBaseUrl } from "./routes.ts";
3030

3131
// A v1 host restarting into v2 runs migrations before its descriptor answers again.
3232
const OUTDATED_HOST_RESTART_TIMEOUT = Duration.minutes(4);
@@ -159,9 +159,23 @@ export const updateOutdatedHost = Effect.fn("clientRuntime.connection.updateOutd
159159
);
160160

161161
yield* onStage("resuming");
162-
const resumed = yield* fetchRemoteEnvironmentDescriptor({
163-
httpBaseUrl: prepared.httpBaseUrl,
164-
}).pipe(
162+
// The restarted host may answer on another saved route, so each poll asks
163+
// every direct address, the one that carried the update first.
164+
const pollUrls = [
165+
prepared.httpBaseUrl,
166+
...connectionRoutes(entry).flatMap((route) => routeHttpBaseUrl(route) ?? []),
167+
].filter((url, index, all) => all.indexOf(url) === index);
168+
const resumed = yield* Effect.firstSuccessOf(
169+
pollUrls.map((httpBaseUrl) =>
170+
fetchRemoteEnvironmentDescriptor({ httpBaseUrl }).pipe(
171+
Effect.filterOrFail(
172+
(descriptor) =>
173+
descriptor.environmentId === environmentId && isCompatibleDescriptor(descriptor),
174+
() => "not-ready" as const,
175+
),
176+
),
177+
),
178+
).pipe(
165179
Effect.provideService(HttpClient.HttpClient, httpClient),
166180
Effect.option,
167181
Effect.repeat({

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

Lines changed: 52 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -768,53 +768,55 @@ export const make = Effect.gen(function* () {
768768
yield* Effect.forEach(platformRegistrations, installPlatformRegistration, { discard: true });
769769
});
770770

771-
const remove = Effect.fn("EnvironmentRegistry.remove")(function* (environmentId: EnvironmentId) {
772-
return yield* withLeaseLock(
773-
environmentId,
774-
Effect.gen(function* () {
775-
if ((yield* Ref.get(platformEnvironmentIds)).has(environmentId)) {
776-
return yield* new PlatformEnvironmentRemovalError({
777-
environmentId,
778-
});
779-
}
780-
const entry = yield* getEntry(environmentId);
781-
782-
yield* githubRoutingPermissions.forget(environmentId);
783-
yield* registrations.remove(environmentId);
784-
yield* Ref.update(persistedEnvironmentIds, (current) => {
785-
const next = new Set(current);
786-
next.delete(environmentId);
787-
return next;
788-
});
789-
yield* closeServiceScope(environmentId);
790-
yield* SubscriptionRef.update(entries, (current) => {
791-
const next = new Map(current);
792-
next.delete(environmentId);
793-
return next;
794-
});
795-
yield* Effect.all(
796-
[
797-
cache.clear(environmentId).pipe(
798-
Effect.catch((error) =>
799-
Effect.logWarning("Could not clear cached environment data after removal.", {
800-
environmentId,
801-
error,
802-
}),
803-
),
804-
),
805-
ownedDataCleanup.clear(environmentId),
806-
],
807-
{ concurrency: "unbounded", discard: true },
808-
);
771+
/** Forgets a user-saved environment. Callers hold its lease lock. */
772+
const removeLocked = Effect.fn("EnvironmentRegistry.removeLocked")(function* (
773+
environmentId: EnvironmentId,
774+
) {
775+
if ((yield* Ref.get(platformEnvironmentIds)).has(environmentId)) {
776+
return yield* new PlatformEnvironmentRemovalError({
777+
environmentId,
778+
});
779+
}
780+
const entry = yield* getEntry(environmentId);
809781

810-
for (const route of connectionRoutes(entry)) {
811-
const profile = Option.getOrNull(route.profile);
812-
if (profile !== null && isSshConnectionProfile(profile)) {
813-
yield* disconnectSsh(environmentId, profile);
814-
}
815-
}
816-
}),
782+
yield* githubRoutingPermissions.forget(environmentId);
783+
yield* registrations.remove(environmentId);
784+
yield* Ref.update(persistedEnvironmentIds, (current) => {
785+
const next = new Set(current);
786+
next.delete(environmentId);
787+
return next;
788+
});
789+
yield* closeServiceScope(environmentId);
790+
yield* SubscriptionRef.update(entries, (current) => {
791+
const next = new Map(current);
792+
next.delete(environmentId);
793+
return next;
794+
});
795+
yield* Effect.all(
796+
[
797+
cache.clear(environmentId).pipe(
798+
Effect.catch((error) =>
799+
Effect.logWarning("Could not clear cached environment data after removal.", {
800+
environmentId,
801+
error,
802+
}),
803+
),
804+
),
805+
ownedDataCleanup.clear(environmentId),
806+
],
807+
{ concurrency: "unbounded", discard: true },
817808
);
809+
810+
for (const route of connectionRoutes(entry)) {
811+
const profile = Option.getOrNull(route.profile);
812+
if (profile !== null && isSshConnectionProfile(profile)) {
813+
yield* disconnectSsh(environmentId, profile);
814+
}
815+
}
816+
});
817+
818+
const remove = Effect.fn("EnvironmentRegistry.remove")(function* (environmentId: EnvironmentId) {
819+
return yield* withLeaseLock(environmentId, removeLocked(environmentId));
818820
});
819821

820822
const disconnectSsh = (environmentId: EnvironmentId, profile: SshConnectionProfile) =>
@@ -832,24 +834,24 @@ export const make = Effect.gen(function* () {
832834
environmentId: EnvironmentId,
833835
routeId: string,
834836
) {
835-
const removed = yield* withLeaseLock(
837+
// One lock for the whole decision: a route registered between "this was
838+
// the last route" and the removal must not be deleted with it.
839+
yield* withLeaseLock(
836840
environmentId,
837841
Effect.gen(function* () {
838842
const entry = yield* userEntry(environmentId);
839843
const routes = connectionRoutes(entry);
840844
const route = routes.find((candidate) => connectionRouteId(candidate.target) === routeId);
841-
if (route === undefined) return "kept" as const;
845+
if (route === undefined) return;
842846
const remaining = routes.filter((candidate) => candidate !== route);
843-
if (remaining.length === 0) return "last" as const;
847+
if (remaining.length === 0) return yield* removeLocked(environmentId);
844848
yield* replaceRoutesLocked(entry, remaining);
845849
const profile = Option.getOrNull(route.profile);
846850
if (profile !== null && isSshConnectionProfile(profile)) {
847851
yield* disconnectSsh(environmentId, profile);
848852
}
849-
return "kept" as const;
850853
}),
851854
);
852-
if (removed === "last") yield* remove(environmentId);
853855
});
854856

855857
const reorderRoutes = Effect.fn("EnvironmentRegistry.reorderRoutes")(function* (

0 commit comments

Comments
 (0)