Skip to content

Commit 02c8028

Browse files
t3dotggclaude
andcommitted
fix(connect): point relay-side tunnel failures at the host and keep relay hops for health-check causes
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 97f989f commit 02c8028

3 files changed

Lines changed: 35 additions & 5 deletions

File tree

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ export function useConnectionDiagnosis(environment: EnvironmentPresentation) {
4141
hostLabel: environment.label,
4242
state,
4343
via: relayOnly ? "relay" : "direct",
44-
relayStatus: hasRelayRoute(environment.entry)
45-
? Option.getOrNull(relayStatus ?? Option.none())
46-
: null,
44+
// With a direct route as well, the relay's health says nothing about the route in use.
45+
relayStatus: relayOnly ? Option.getOrNull(relayStatus ?? Option.none()) : null,
4746
clientVersion: APP_VERSION,
4847
serverVersion: environment.serverConfig?.environment.serverVersion,
4948
})

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
RelayAuthInvalidError,
3+
RelayEnvironmentEndpointTimedOutError,
34
RelayEnvironmentEndpointUnavailableError,
45
type RelayProtectedError,
56
} from "@t3tools/contracts/relay";
@@ -90,6 +91,19 @@ describe("presentConnectionDiagnosis", () => {
9091
expect(diagnosis?.steps.join(" ")).not.toContain("On Mac mini");
9192
});
9293

94+
it("points a relay timeout at the host, not this device", () => {
95+
const failure = fromRelay(
96+
new RelayEnvironmentEndpointTimedOutError({
97+
code: "environment_endpoint_timed_out",
98+
traceId: "trace-3",
99+
}),
100+
);
101+
const diagnosis = diagnose(backoff(failure));
102+
expect(diagnosis?.headline).toBe("Mac mini did not answer in time");
103+
expect(diagnosis?.steps.join(" ")).toContain("On Mac mini");
104+
expect(diagnosis?.steps.join(" ")).not.toContain("on this device");
105+
});
106+
93107
it("stops at T3 Connect when this device cannot reach the relay", () => {
94108
const failure = mapManagedRelayError(
95109
new ManagedRelayRequestFailedError({
@@ -133,6 +147,13 @@ describe("presentConnectionDiagnosis", () => {
133147
relayStatus: { status: "offline", endpointFailure: "tunnel_down", endpointStatus: 530 },
134148
});
135149
expect(diagnosis?.headline).toBe("Mac mini's tunnel is offline");
150+
const origin = presentConnectionDiagnosis({
151+
hostLabel: "Mac mini",
152+
state: AVAILABLE_CONNECTION_STATE,
153+
via: "direct",
154+
relayStatus: { status: "offline", endpointFailure: "origin_unreachable" },
155+
});
156+
expect(origin?.hops.map((hop) => hop.hop)).toEqual(["device", "relay", "tunnel", "server"]);
136157
});
137158

138159
it("keeps the relay health status out of a failure that has its own cause", () => {

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,14 @@ function steps(host: string, located: Located, failure: ConnectionAttemptError |
156156
case "origin_unreachable":
157157
case "invalid_response":
158158
return [`Open or restart T3 Code on ${host}.`, checkHost];
159-
default:
159+
// The relay saw these on its way to the host, so the fix is on the host.
160+
case "dns":
161+
case "tls":
162+
case "refused":
163+
case "timeout":
164+
case "unknown":
165+
return [`Make sure ${host} is awake and online.`, checkHost];
166+
case null:
160167
break;
161168
}
162169
switch (located.hop) {
@@ -216,7 +223,10 @@ export function presentConnectionDiagnosis(
216223
const host = input.hostLabel;
217224
const failure = input.state.lastFailure;
218225
const relayPath =
219-
located.hop === "relay" || located.hop === "tunnel" || (failure?.via ?? input.via) === "relay";
226+
located.hop === "relay" ||
227+
located.hop === "tunnel" ||
228+
(failure === null && input.relayStatus?.status === "offline") ||
229+
(failure?.via ?? input.via) === "relay";
220230
const order: ReadonlyArray<ConnectionHop> = HOP_ORDER[relayPath ? "relay" : "direct"];
221231
const failedIndex = order.indexOf(located.hop);
222232
const hops = order.map((hop, index): ConnectionDiagnosisHop => ({

0 commit comments

Comments
 (0)