fix(connect): show which part of a T3 Connect connection failed and how to fix it #22171
Mergedt3dotgg(GitHub profile, opens in a new tab)merged 5 commits into
main fromrefs/pull/22171/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- packages/client-runtime/src/connection/diagnosis.ts lines 228 to 228OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +208,21 @@208+ * Turns a connection state into what failed, in order, and what to try. Returns209+ * null when nothing has failed. Web and mobile render this same model.210+ */211+export function presentConnectionDiagnosis(212+ input: ConnectionDiagnosisInput,213+): ConnectionDiagnosis | null {214+ const located = locate(input);215+ if (located === null) return null;216+ const host = input.hostLabel;217+ const failure = input.state.lastFailure;218+ const relayPath =219+ located.hop === "relay" || located.hop === "tunnel" || (failure?.via ?? input.via) === "relay";220+ const order: ReadonlyArray<ConnectionHop> = HOP_ORDER[relayPath ? "relay" : "direct"];221+ const failedIndex = order.indexOf(located.hop);222+ const hops = order.map((hop, index): ConnectionDiagnosisHop => ({223+ hop,224+ label: hopLabel(hop, host),225+ result: index < failedIndex ? "ok" : index === failedIndex ? "failed" : "unchecked",226+ }));227+228+ const httpStatus = failure?.httpStatus ?? input.relayStatus?.endpointStatus;
- apps/web/src/components/settings/ConnectionDiagnosisDetails.tsx lines 34 to 44OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +24,21 @@24+ * What failed on the way to an environment, or null while it is connected, off,25+ * or has not failed. Reads the supervisor state itself so callers that only need26+ * the headline do not re-render on every attempt.27+ */28+export function useConnectionDiagnosis(environment: EnvironmentPresentation) {29+ const environmentId = environment.environmentId;30+ const state = Option.getOrElse(31+ AsyncResult.value(useAtomValue(environmentCatalog.stateAtom(environmentId))),32+ () => AVAILABLE_CONNECTION_STATE,33+ );34+ const relayStatus = useRelayEnvironmentDiscovery().environments.get(environmentId)?.status;35+ const routes = connectionRoutes(environment.entry);36+ const relayOnly = routes.length === 1 && hasRelayRoute(environment.entry);37+ const phase = environment.connection.phase;38+ const diagnosis =39+ environment.entry.enabled && phase !== "connected" && phase !== "unsupported"40+ ? presentConnectionDiagnosis({41+ hostLabel: environment.label,42+ state,43+ via: relayOnly ? "relay" : "direct",44+ relayStatus: Option.getOrNull(relayStatus ?? Option.none()),
- packages/client-runtime/src/connection/diagnosis.ts line 190Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +153,21 @@153+ checkHost,154+ `A VPN or Tailscale exit node on ${host} can block the tunnel (port 7844). Turn it off or allow the tunnel.`,155+ ];156+ case "origin_unreachable":157+ case "invalid_response":158+ return [`Open or restart T3 Code on ${host}.`, checkHost];159+ default:160+ break;161+ }162+ switch (located.hop) {163+ case "device":164+ return ["Restart T3 Code on this device."];165+ case "relay":166+ return failure?.reason === "authentication"167+ ? ["Sign out of T3 Connect and sign in again."]168+ : [169+ "Check this device's internet connection.",170+ "A VPN, firewall, or ad blocker on this device can block T3 Connect.",171+ ];172+ case "tunnel":173+ return failure?.reason === "network" ||packages/client-runtime/src/connection/diagnosis.ts lines 219 to 220OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +200,21 @@200+ case "tunnel":201+ return `${host} tunnel`;202+ case "server":203+ return `T3 Code on ${host}`;204+ }205+}206+207+/**208+ * Turns a connection state into what failed, in order, and what to try. Returns209+ * null when nothing has failed. Web and mobile render this same model.210+ */211+export function presentConnectionDiagnosis(212+ input: ConnectionDiagnosisInput,213+): ConnectionDiagnosis | null {214+ const located = locate(input);215+ if (located === null) return null;216+ const host = input.hostLabel;217+ const failure = input.state.lastFailure;218+ const relayPath =219+ located.hop === "relay" || located.hop === "tunnel" || (failure?.via ?? input.via) === "relay";220+ const order: ReadonlyArray<ConnectionHop> = HOP_ORDER[relayPath ? "relay" : "direct"];
- apps/web/src/components/settings/ConnectionDiagnosisDetails.tsx lines 44 to 46OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +26,21 @@26+ * the headline do not re-render on every attempt.27+ */28+export function useConnectionDiagnosis(environment: EnvironmentPresentation) {29+ const environmentId = environment.environmentId;30+ const state = Option.getOrElse(31+ AsyncResult.value(useAtomValue(environmentCatalog.stateAtom(environmentId))),32+ () => AVAILABLE_CONNECTION_STATE,33+ );34+ const relayStatus = useRelayEnvironmentDiscovery().environments.get(environmentId)?.status;35+ const routes = connectionRoutes(environment.entry);36+ const relayOnly = routes.length === 1 && hasRelayRoute(environment.entry);37+ const phase = environment.connection.phase;38+ const diagnosis =39+ environment.entry.enabled && phase !== "connected" && phase !== "unsupported"40+ ? presentConnectionDiagnosis({41+ hostLabel: environment.label,42+ state,43+ via: relayOnly ? "relay" : "direct",44+ relayStatus: hasRelayRoute(environment.entry)45+ ? Option.getOrNull(relayStatus ?? Option.none())46+ : null,
- packages/client-runtime/src/connection/diagnosis.ts line 68Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +48,21 @@48+ "invalid_response",49+]);50+51+function locate(input: ConnectionDiagnosisInput): Located | null {52+ const failure = input.state.lastFailure;53+ if (input.state.network === "offline" || input.state.phase === "offline") {54+ return { hop: "device", cause: "offline" };55+ }56+ if (failure?._tag === "ConnectionBlockedError" && failure.serverUpdateRequired) {57+ return { hop: "server", cause: "outdated" };58+ }59+ if (failure?.hop !== undefined) {60+ return { hop: failure.hop, cause: failure.failureCause ?? null };61+ }62+ if (failure !== null) {63+ const unreachable =64+ failure.reason === "network" ||65+ failure.reason === "timeout" ||66+ failure.reason === "transport";67+ const via = failure.via ?? input.via;68+ return { hop: unreachable && via === "relay" ? "tunnel" : "server", cause: null };
- packages/client-runtime/src/connection/diagnosis.ts lines 115 to 118Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +96,21 @@96+ case "invalid_response":97+ return `T3 Code on ${host} sent an unexpected answer`;98+ case "dns":99+ return `${host}'s tunnel address did not resolve`;100+ case "tls":101+ return `Secure connection to ${host}'s tunnel failed`;102+ case "refused":103+ return `${host}'s tunnel refused the connection`;104+ case "timeout":105+ return `${host} did not answer in time`;106+ case "unknown":107+ case null:108+ break;109+ }110+ switch (located.hop) {111+ case "device":112+ return "This device could not prepare the connection";113+ case "relay":114+ return failure?.reason === "authentication"115+ ? "T3 Connect did not accept this device's sign-in"116+ : "This device can't reach T3 Connect";
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.



macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed