Skip to content

Commit 74ce4e6

Browse files
fix(connection): a host replaced by a newer T3 Connect link says so
When the account still lists a host's old identity next to a newer link under the same label, as a reinstall leaves it, a not-linked failure now says the old entry was replaced and to remove it from this device instead of asking to relink it. AI-assisted; verified with the tests and tools listed above.
1 parent 62b6c59 commit 74ce4e6

6 files changed

Lines changed: 62 additions & 8 deletions

File tree

‎apps/mobile/src/features/connection/ConnectionDiagnosisDetails.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export function useConnectionDiagnosis(
4444
state,
4545
via: relayOnly ? "relay" : "direct",
4646
relayRegistration: hasRelayRoute(presentation.entry)
47-
? Discovery.relayEnvironmentRegistration(discovery, environmentId)
47+
? Discovery.relayEnvironmentStanding(discovery, environmentId)
4848
: "unknown",
4949
clientVersion: Constants.expoConfig?.version,
5050
serverVersion: presentation.serverConfig?.environment.serverVersion,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export function useConnectionDiagnosis(environment: EnvironmentPresentation) {
4747
// With a direct route as well, the relay's health says nothing about the route in use.
4848
relayStatus: relayOnly ? Option.getOrNull(relayStatus ?? Option.none()) : null,
4949
relayRegistration: hasRelayRoute(environment.entry)
50-
? Discovery.relayEnvironmentRegistration(discovery, environmentId)
50+
? Discovery.relayEnvironmentStanding(discovery, environmentId)
5151
: "unknown",
5252
clientVersion: APP_VERSION,
5353
serverVersion: environment.serverConfig?.environment.serverVersion,

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ describe("presentConnectionDiagnosis", () => {
139139
traceId: "trace-1",
140140
}),
141141
);
142-
const withRegistration = (relayRegistration: "registered" | "unregistered") =>
142+
const withRegistration = (relayRegistration: "registered" | "unregistered" | "superseded") =>
143143
presentConnectionDiagnosis({
144144
hostLabel: "Mac mini",
145145
state: backoff(failure),
@@ -153,6 +153,9 @@ describe("presentConnectionDiagnosis", () => {
153153
expect(diagnosis?.headline).toContain("no longer on your T3 Connect account");
154154
expect(diagnosis?.steps[0]).toContain("turn T3 Connect on");
155155
expect(diagnosis?.steps[1]).toContain("remove it from this device");
156+
const superseded = withRegistration("superseded");
157+
expect(superseded?.headline).toContain("A newer link to Mac mini replaced this one");
158+
expect(superseded?.steps.join(" ")).not.toContain("turn T3 Connect on");
156159
});
157160

158161
it("blames this device, not the host, while its own T3 Connect sign-in loads", () => {

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
import type { RelayEnvironmentStatusResponse } from "@t3tools/contracts/relay";
66
import * as DateTime from "effect/DateTime";
77

8-
import type { RelayEnvironmentRegistration } from "../relay/discovery.ts";
8+
import type { RelayEnvironmentStanding } from "../relay/discovery.ts";
99

1010
import type {
1111
ConnectionAttemptError,
@@ -42,8 +42,8 @@ export interface ConnectionDiagnosisInput {
4242
RelayEnvironmentStatusResponse,
4343
"status" | "endpointFailure" | "endpointStatus" | "offlineReason"
4444
> | null;
45-
/** Whether the account's environment list still has this host. */
46-
readonly relayRegistration?: RelayEnvironmentRegistration;
45+
/** Whether the account's environment list still has this host, or a newer link replaced it. */
46+
readonly relayRegistration?: RelayEnvironmentStanding;
4747
readonly clientVersion?: string | undefined;
4848
readonly serverVersion?: string | null | undefined;
4949
}
@@ -57,6 +57,7 @@ interface Located {
5757
| "released"
5858
| "session_pending"
5959
| "unregistered"
60+
| "superseded"
6061
| null;
6162
/** The failure named no hop, so the hops before this one were never probed. */
6263
readonly guessed?: true;
@@ -83,8 +84,9 @@ function locate(input: ConnectionDiagnosisInput): Located | null {
8384
return {
8485
hop: failure.hop,
8586
cause:
86-
cause === "not_linked" && input.relayRegistration === "unregistered"
87-
? "unregistered"
87+
cause === "not_linked" &&
88+
(input.relayRegistration === "unregistered" || input.relayRegistration === "superseded")
89+
? input.relayRegistration
8890
: cause,
8991
};
9092
}
@@ -121,6 +123,8 @@ function headline(host: string, located: Located, failure: ConnectionAttemptErro
121123
return `${host} is not linked to your T3 Connect account`;
122124
case "unregistered":
123125
return `${host} is no longer on your T3 Connect account`;
126+
case "superseded":
127+
return `A newer link to ${host} replaced this one on your T3 Connect account`;
124128
case "relay_error":
125129
return "T3 Connect returned an error";
126130
case "tunnel_pending":
@@ -191,6 +195,10 @@ function steps(host: string, located: Located, failure: ConnectionAttemptError |
191195
`If you still use ${host}, turn T3 Connect on there in Settings > Sharing & access, check that this device uses the same T3 Connect account, then retry.`,
192196
`If T3 Code was reinstalled on ${host}, or you no longer use it, remove it from this device.`,
193197
];
198+
case "superseded":
199+
return [
200+
`T3 Code on ${host} now links under a new identity, usually after a reinstall. Remove this old entry from this device.`,
201+
];
194202
case "tunnel_pending":
195203
return ["Wait a minute. T3 Code retries on its own.", checkHost];
196204
case "relay_error":
@@ -264,6 +272,7 @@ function helpSection(
264272
case "session_pending":
265273
case "not_linked":
266274
case "unregistered":
275+
case "superseded":
267276
case "tunnel_not_enabled":
268277
return "sign-in-account-or-link-problems";
269278
case "relay_error":

‎packages/client-runtime/src/relay/discovery.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,30 @@ describe("RelayEnvironmentDiscovery", () => {
310310
}),
311311
);
312312

313+
it("reports a listed environment as superseded by a newer link under the same label", () => {
314+
const reinstalled = {
315+
...environments[0]!,
316+
environmentId: EnvironmentId.make("environment-1-reinstalled"),
317+
linkedAt: "2026-07-01T00:00:00.000Z",
318+
};
319+
const state = {
320+
...RelayEnvironmentDiscovery.EMPTY_RELAY_ENVIRONMENT_DISCOVERY_STATE,
321+
listed: true,
322+
environments: new Map(
323+
[...environments, reinstalled].map((environment) => [
324+
environment.environmentId,
325+
{ environment, availability: "online", status: Option.none(), error: Option.none() },
326+
]),
327+
),
328+
} satisfies RelayEnvironmentDiscovery.RelayEnvironmentDiscoveryState;
329+
const standing = (environmentId: string) =>
330+
RelayEnvironmentDiscovery.relayEnvironmentStanding(state, environmentId);
331+
expect(standing(environments[0]!.environmentId)).toBe("superseded");
332+
expect(standing(reinstalled.environmentId)).toBe("registered");
333+
expect(standing(environments[1]!.environmentId)).toBe("registered");
334+
expect(standing("deregistered-environment")).toBe("unregistered");
335+
});
336+
313337
it.effect(
314338
"preserves discovered rows while offline and refreshes after connectivity returns",
315339
() =>

‎packages/client-runtime/src/relay/discovery.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,24 @@ export function relayEnvironmentRegistration(
6767
return state.listed ? "unregistered" : "unknown";
6868
}
6969

70+
export type RelayEnvironmentStanding = RelayEnvironmentRegistration | "superseded";
71+
72+
/** "superseded" when the account lists a newer link under the same label, as a reinstalled host leaves. */
73+
export function relayEnvironmentStanding(
74+
state: RelayEnvironmentDiscoveryState,
75+
environmentId: string,
76+
): RelayEnvironmentStanding {
77+
const own = state.environments.get(environmentId)?.environment;
78+
if (own === undefined) return relayEnvironmentRegistration(state, environmentId);
79+
const linkedAt = Date.parse(own.linkedAt);
80+
for (const { environment } of state.environments.values()) {
81+
if (environment.label === own.label && Date.parse(environment.linkedAt) > linkedAt) {
82+
return "superseded";
83+
}
84+
}
85+
return "registered";
86+
}
87+
7088
function validateStatus(
7189
environment: RelayClientEnvironmentRecord,
7290
status: RelayEnvironmentStatusResponse,

0 commit comments

Comments
 (0)