Skip to content

Commit 15c86d2

Browse files
t3dotggclaude
andcommitted
fix(connect): address review findings on reachability causes and status
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 15758da commit 15c86d2

6 files changed

Lines changed: 48 additions & 13 deletions

File tree

‎apps/server/src/cli/connect.ts‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ interface CloudCliStatus {
148148
readonly relayUrl: string | null;
149149
readonly publishAgentActivity: boolean;
150150
readonly relayClient: RelayClient.RelayClientStatus;
151-
/** `null` when no server answered the live check, or none ran because T3 Connect is off. */
151+
readonly linkMode: CliState.CliDesiredLinkMode;
152+
/** `null` when no server answered the live check, or none ran because no tunnel is wanted. */
152153
readonly reachability: EnvironmentConnectReachability | null;
153154
}
154155

@@ -207,7 +208,7 @@ function formatCloudStatus(status: CloudCliStatus, options?: { readonly json?: b
207208
` Relay: ${status.relayUrl ?? "not provisioned"}`,
208209
` Publish agent activity: ${status.publishAgentActivity ? "enabled" : "disabled"}`,
209210
...formatRelayClientStatus(status.relayClient),
210-
...(!status.desired
211+
...(!status.desired || status.linkMode !== "managed"
211212
? []
212213
: status.reachability === null
213214
? [
@@ -656,7 +657,7 @@ const connectStatusCommand = Command.make("status", {
656657
publishAgentActivity,
657658
revoked,
658659
executable,
659-
reachability,
660+
linkMode,
660661
] = yield* Effect.all(
661662
[
662663
CliState.readCliDesiredCloudLink,
@@ -666,14 +667,13 @@ const connectStatusCommand = Command.make("status", {
666667
secrets.get(PUBLISH_AGENT_ACTIVITY_SECRET),
667668
secrets.get(CLOUD_LINK_REVOKED),
668669
relayClient.resolve,
669-
CliState.readCliDesiredCloudLink.pipe(
670-
Effect.flatMap((desired) =>
671-
desired ? checkLiveReachability() : Effect.succeed(null),
672-
),
673-
),
670+
CliState.readCliDesiredLinkMode,
674671
],
675672
{ concurrency: "unbounded" },
676673
);
674+
// A publish-only link has no tunnel for other devices to reach.
675+
const reachability =
676+
desired && linkMode === "managed" ? yield* checkLiveReachability() : null;
677677
const status: CloudCliStatus = {
678678
desired,
679679
authenticated,
@@ -685,6 +685,7 @@ const connectStatusCommand = Command.make("status", {
685685
Option.isSome(publishAgentActivity) ? bytesToString(publishAgentActivity.value) : null,
686686
),
687687
relayClient: executable,
688+
linkMode,
688689
reachability,
689690
};
690691
yield* Console.log(formatCloudStatus(status, { json: flags.json }));

‎apps/server/src/cloud/ConnectReachability.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,27 @@ describe("classifyReachability", () => {
6363
);
6464
});
6565

66+
it("keeps the endpoint cause when the TCP edge test cannot explain it", () => {
67+
// QUIC (UDP) can connect while TCP 7844 is blocked.
68+
expect(
69+
classifyReachability(
70+
facts({ endpoint: { kind: "status", status: 502 }, edgeReachable: false }),
71+
checkedAt,
72+
),
73+
).toMatchObject({ cause: "origin_unreachable" });
74+
// Failed DNS also fails the edge lookups.
75+
expect(
76+
classifyReachability(
77+
facts({
78+
connector: { readyConnections: null, hostname: "env.example.test", protocol: null },
79+
endpoint: { kind: "dns_failed" },
80+
edgeReachable: false,
81+
}),
82+
checkedAt,
83+
),
84+
).toMatchObject({ cause: "dns_failed" });
85+
});
86+
6687
it("waits on a connector that has not connected while the edge answers", () => {
6788
expect(
6889
classifyReachability(facts({ connector: notConnected, edgeReachable: true }), checkedAt),

‎apps/server/src/cloud/ConnectReachability.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,13 @@ export function classifyReachability(
8484
protocol: connector.protocol,
8585
};
8686
}
87-
if (facts.edgeReachable === false) {
87+
// The edge test is TCP only. With QUIC connections up, or with DNS already failing, a
88+
// failed TCP test would hide the real cause.
89+
if (
90+
facts.edgeReachable === false &&
91+
!(connector.readyConnections && connector.readyConnections > 0) &&
92+
endpoint?.kind !== "dns_failed"
93+
) {
8894
return fail(
8995
"edge_unreachable",
9096
`Cloudflare's tunnel port (${TUNNEL_EDGE_PORT}) times out from this machine.`,

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1907,7 +1907,9 @@ function ConfiguredCloudLinkRow({ canManageRelay }: { readonly canManageRelay: b
19071907
: managedTunnelActive
19081908
? reachability?.status === "unreachable"
19091909
? "T3 Connect is on, but other devices cannot reach this environment."
1910-
: "This environment is available to your other devices through T3 Connect."
1910+
: reachability?.status === "reachable"
1911+
? "This environment is available to your other devices through T3 Connect."
1912+
: "T3 Connect is on. Reachability has not been checked yet."
19111913
: managedTunnelOutOfSync
19121914
? "T3 Connect is out of sync. This environment is linked only to publish agent activity, so other devices cannot connect. Turn T3 Connect on to repair it."
19131915
: "Make this environment available to your other devices through T3 Connect."

‎packages/tailscale/src/tailscale.test.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,11 @@ describe("tailscale", () => {
155155
ExitNodeStatus: { ID: "nX", Online: true, TailscaleIPs: ["100.101.102.103/32"] },
156156
Peer: {
157157
"nodekey:a": { HostName: "laptop", DNSName: "laptop.tail.ts.net.", ExitNode: false },
158-
"nodekey:b": { HostName: "home-pi", DNSName: "home-pi.tail.ts.net.", ExitNode: true },
158+
"nodekey:b": {
159+
HostName: "raspberrypi",
160+
DNSName: "home-pi.tail.ts.net.",
161+
ExitNode: true,
162+
},
159163
},
160164
}),
161165
);

‎packages/tailscale/src/tailscale.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,11 @@ export const parseTailscaleExitNode = (
323323
const peer = Object.values(parsed.Peer ?? {}).find(
324324
(candidate) => candidate.ExitNode === true,
325325
);
326-
const hostName = typeof peer?.HostName === "string" ? peer.HostName.trim() : "";
326+
// The DNS label is the tailnet machine name; HostName is the OS name and ignores renames.
327327
const dnsLabel = typeof peer?.DNSName === "string" ? (peer.DNSName.split(".")[0] ?? "") : "";
328+
const hostName = typeof peer?.HostName === "string" ? peer.HostName.trim() : "";
328329
return {
329-
name: hostName || dnsLabel || null,
330+
name: dnsLabel || hostName || null,
330331
online: parsed.ExitNodeStatus.Online === true,
331332
};
332333
}),

0 commit comments

Comments
 (0)