The best way to control Claude Code, Codex and more from any computer or phone
fix(connect): the remove dialog says whether a T3 Connect environment is still on the account (#21706)
Co-authored-by: Rodrigo Brechard <rodrigo@clubtidy.fr> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>
Rodrigo Brechard committed
Oct 30, 2026 at 21:28 UTC
ebd1265ccf9ef6d886b7c8e8f8b017b45bfe78eb
9 files changed
+204
-33
apps/mobile/src/features/cloud/T3ConnectProfilePage.tsx
+5
@@ -14,6 +14,7 @@ import { SymbolView } from "../../components/ui/AppSymbol";
14
import * as Dialog from "../../components/ui/Dialog";
15
import { Menu } from "../../components/ui/Menu";
16
import { copyTextWithHaptic } from "../../lib/copyTextWithHaptic";
17
+import { relayEnvironmentDiscovery } from "../../state/relay";
18
import { useAtomCommand } from "../../state/use-atom-command";
19
import {
20
deregisterManagedRelayEnvironmentCommand,
@@ -46,6 +47,9 @@ export function T3ConnectProfilePage() {
47
const deregisterEnvironment = useAtomCommand(deregisterManagedRelayEnvironmentCommand, {
48
reportFailure: false,
49
});
50
+ const refreshRelayEnvironments = useAtomCommand(relayEnvironmentDiscovery.refreshAfterMutation, {
51
+ reportFailure: false,
52
+ });
53
const [deregisteringEnvironmentId, setDeregisteringEnvironmentId] =
54
useState<EnvironmentId | null>(null);
55
const mutationPendingRef = useRef(false);
@@ -75,6 +79,7 @@ export function T3ConnectProfilePage() {
79
return { accountId, linkedAtById };
80
});
81
environmentsState.refresh();
82
+ void refreshRelayEnvironments();
83
return;
84
}
85
if (isAtomCommandInterrupted(result)) return;
apps/mobile/src/state/use-remote-environment-registry.ts
+22
-14
@@ -1,6 +1,7 @@
1
import * as Dialog from "../components/ui/Dialog";
2
import { useAtomValue } from "@effect/atom-react";
3
import { useNavigation } from "@react-navigation/native";
4
+import { Discovery } from "@t3tools/client-runtime/relay";
5
import type { EnvironmentId } from "@t3tools/contracts";
6
import * as Cause from "effect/Cause";
7
import { AsyncResult, Atom } from "effect/reactivity";
@@ -17,8 +18,17 @@ import { environmentSession } from "./session";
18
import { environmentCatalog } from "../connection/catalog";
19
import { createRemoteEnvironmentProjectionAtoms } from "./remote-environment-projections";
20
import { serverEnvironment } from "./server";
21
+import { relayEnvironmentDiscovery } from "./relay";
22
import { connectPairingUrl as connectPairingUrlCommand } from "../connection/onboarding";
23
24
+const RELAY_REMOVAL_ACCOUNT_NOTE: Record<Discovery.RelayEnvironmentRegistration, string> = {
25
+ registered:
26
+ "It stays on your T3 Connect account and keeps its host space. Deregister it under T3 Account → T3 Connect to free it.",
27
+ unregistered: "It's no longer on your T3 Connect account.",
28
+ unknown:
29
+ "This doesn't change your T3 Connect account. To deregister it there, use T3 Account → T3 Connect.",
30
+};
31
+
32
const connectionPairingUrlAtom = Atom.make("").pipe(
33
Atom.keepAlive,
34
Atom.withLabel("mobile:connection-pairing-url"),
@@ -180,22 +190,20 @@ export function useRemoteConnections() {
190
},
191
} as const;
192
if (environment.isRelayManaged) {
193
+ const registration = Discovery.relayEnvironmentRegistration(
194
+ appAtomRegistry.get(relayEnvironmentDiscovery.stateValueAtom),
195
+ environmentId,
196
+ );
197
+ const openAccount = {
198
+ text: "Open T3 Account",
199
+ onPress: () => navigation.navigate("SettingsAuth"),
200
+ };
201
Dialog.alert(
202
"Remove from this device?",
185
- `Forget ${environment.environmentLabel} and its cached threads on this device.\n\nIt stays on your T3 Connect account and keeps its host space. Deregister it under T3 Account → T3 Connect to free it.`,
186
- [
187
- { text: "Cancel", style: "cancel" },
188
- // SettingsAuth renders nothing in builds without cloud config.
189
- ...(hasCloudPublicConfig()
190
- ? [
191
- {
192
- text: "Open T3 Account",
193
- onPress: () => navigation.navigate("SettingsAuth"),
194
- },
195
- ]
196
- : []),
197
- remove,
198
- ],
203
+ `Forget ${environment.environmentLabel} and its cached threads on this device.\n\n${RELAY_REMOVAL_ACCOUNT_NOTE[registration]}`,
204
+ registration === "unregistered" || !hasCloudPublicConfig()
205
+ ? [{ text: "Cancel", style: "cancel" }, remove]
206
+ : [{ text: "Cancel", style: "cancel" }, openAccount, remove],
207
);
208
return;
209
}
apps/web/src/components/clerk/RemoveT3ConnectEnvironmentDialog.tsx
+41
-16
@@ -1,5 +1,8 @@
1
+import { Discovery } from "@t3tools/client-runtime/relay";
2
+import type { EnvironmentId } from "@t3tools/contracts";
3
import { useState } from "react";
4
5
+import { useRelayEnvironmentDiscovery } from "../../state/environments";
6
import {
7
AlertDialog,
8
AlertDialogClose,
@@ -14,17 +17,40 @@ import { useT3ConnectAccountPage } from "./T3ConnectAccountPages";
17
18
export function RemoveT3ConnectEnvironmentDialog({
19
environmentLabel,
20
+ environmentId,
21
onCancel,
22
onConfirm,
23
}: {
24
readonly environmentLabel: string | null;
25
+ readonly environmentId: EnvironmentId | null;
26
readonly onCancel: () => void;
27
readonly onConfirm: () => void;
28
}) {
29
const accountPage = useT3ConnectAccountPage();
25
- const [shownLabel, setShownLabel] = useState(environmentLabel);
26
- if (environmentLabel !== null && environmentLabel !== shownLabel) setShownLabel(environmentLabel);
30
+ const discovery = useRelayEnvironmentDiscovery();
31
+ const registration = environmentId
32
+ ? Discovery.relayEnvironmentRegistration(discovery, environmentId)
33
+ : "unknown";
34
+ const [shown, setShown] = useState({ label: environmentLabel, registration });
35
+ if (
36
+ environmentLabel !== null &&
37
+ (environmentLabel !== shown.label || registration !== shown.registration)
38
+ ) {
39
+ setShown({ label: environmentLabel, registration });
40
+ }
41
const openAccountPage = accountPage.open;
42
+ const accountPageLink = openAccountPage ? (
43
+ <InlineButton
44
+ onClick={() => {
45
+ onCancel();
46
+ openAccountPage();
47
+ }}
48
+ >
49
+ T3 Connect settings
50
+ </InlineButton>
51
+ ) : (
52
+ "T3 Connect settings"
53
+ );
54
55
return (
56
<>
@@ -36,25 +62,24 @@ export function RemoveT3ConnectEnvironmentDialog({
62
>
63
<AlertDialogPopup>
64
<AlertDialogHeader>
39
- <AlertDialogTitle>Remove {shownLabel} from this device?</AlertDialogTitle>
65
+ <AlertDialogTitle>Remove {shown.label} from this device?</AlertDialogTitle>
66
<AlertDialogDescription>
67
This forgets its pairing, credentials, and cached threads here.
68
</AlertDialogDescription>
69
<AlertDialogDescription>
44
- It stays on your T3 Connect account and keeps its host space. Deregister it in{" "}
45
- {openAccountPage ? (
46
- <InlineButton
47
- onClick={() => {
48
- onCancel();
49
- openAccountPage();
50
- }}
51
- >
52
- T3 Connect settings
53
- </InlineButton>
70
+ {shown.registration === "registered" ? (
71
+ <>
72
+ It stays on your T3 Connect account and keeps its host space. Deregister it in{" "}
73
+ {accountPageLink} to free it.
74
+ </>
75
+ ) : shown.registration === "unregistered" ? (
76
+ "It's no longer on your T3 Connect account."
77
) : (
55
- "T3 Connect settings"
56
- )}{" "}
57
- to free it.
78
+ <>
79
+ This doesn't change your T3 Connect account. To deregister it there, use{" "}
80
+ {accountPageLink}.
81
+ </>
82
+ )}
83
</AlertDialogDescription>
84
</AlertDialogHeader>
85
<AlertDialogFooter>
apps/web/src/components/clerk/T3ConnectUserProfilePage.tsx
+5
@@ -13,6 +13,7 @@ import {
13
useManagedRelayEnvironments,
14
useManagedTunnelUsage,
15
} from "../../cloud/managedRelayState";
16
+import { relayEnvironmentDiscovery } from "../../state/relay";
17
import { useAtomCommand } from "../../state/use-atom-command";
18
import { T3CHAT_SUBSCRIPTION_URL, TunnelUsageMeter, tunnelUpgradeCopy } from "../cloud/TunnelUsage";
19
import { Button, InlineButton } from "../ui/button";
@@ -165,6 +166,9 @@ export function T3ConnectUserProfilePage() {
166
const deregisterEnvironment = useAtomCommand(deregisterManagedRelayEnvironmentCommand, {
167
reportFailure: false,
168
});
169
+ const refreshRelayEnvironments = useAtomCommand(relayEnvironmentDiscovery.refreshAfterMutation, {
170
+ reportFailure: false,
171
+ });
172
const [deregisteringEnvironmentId, setDeregisteringEnvironmentId] =
173
useState<EnvironmentId | null>(null);
174
const [confirmingEnvironmentId, setConfirmingEnvironmentId] = useState<EnvironmentId | null>(
@@ -197,6 +201,7 @@ export function T3ConnectUserProfilePage() {
201
return { accountId, linkedAtById };
202
});
203
environmentsState.refresh();
204
+ void refreshRelayEnvironments();
205
toastManager.add({
206
type: "success",
207
title: "Server deregistered",
apps/web/src/components/settings/ConnectionsSettings.tsx
+1
@@ -1518,6 +1518,7 @@ export function ConnectionsSettings({ view }: { readonly view: "environments" |
1518
{hasCloudPublicConfig() ? (
1519
<RemoveT3ConnectEnvironmentDialog
1520
environmentLabel={pendingT3ConnectRemoval?.label ?? null}
1521
+ environmentId={pendingT3ConnectRemoval?.environmentId ?? null}
1522
onCancel={() => setPendingT3ConnectRemoval(null)}
1523
onConfirm={() => {
1524
if (!pendingT3ConnectRemoval) return;
docs/user/remote-access.md
+2
-1
@@ -374,7 +374,8 @@ shows that it was removed from T3 Connect. To link it again, turn on
374
command-line host that released its tunnel when it last stopped may link itself
375
again on its next start; run `t3 connect unlink` on that host to keep it off.
376
Removing an environment from a device's connection settings only forgets it on
377
-that device; it stays registered to your account.
377
+that device and doesn't change your T3 Connect account. A device keeps a saved
378
+environment after it's deregistered until you remove it from that device.
379
380
When idle tunnel cleanup is enabled, T3 Connect removes a linked environment's
381
tunnel after it stays offline for several minutes. The environment stays linked
packages/client-runtime/src/relay/discovery.test.ts
+103
-2
@@ -12,6 +12,7 @@ import * as Option from "effect/Option";
12
import * as Ref from "effect/Ref";
13
import * as Stream from "effect/Stream";
14
import * as SubscriptionRef from "effect/SubscriptionRef";
15
+import { Atom, AtomRegistry } from "effect/reactivity";
16
17
import * as ManagedRelay from "./managedRelay.ts";
18
import * as ClientCapabilities from "../platform/capabilities.ts";
@@ -20,6 +21,7 @@ import { ConnectionBlockedError, type NetworkStatus } from "../connection/model.
21
import * as ConnectionWakeups from "../connection/wakeups.ts";
22
import * as RelayEnvironmentDiscovery from "./discovery.ts";
23
import { NETWORK_BLOCKING_HINT } from "../errors/network.ts";
24
+import { createRelayEnvironmentDiscoveryAtoms } from "../state/relayDiscovery.ts";
25
26
const environments = [
27
{
@@ -59,6 +61,8 @@ function status(
61
const makeHarness = Effect.fn("RelayDiscoveryTest.makeHarness")(function* () {
62
const networkStatus = yield* SubscriptionRef.make<NetworkStatus>("online");
63
const listCalls = yield* Ref.make(0);
64
+ const listedEnvironments =
65
+ yield* Ref.make<ReadonlyArray<RelayClientEnvironmentRecord>>(environments);
66
const listFailure = yield* Ref.make<ManagedRelay.ManagedRelayClientError | null>(null);
67
const secondListCall = yield* Deferred.make<void>();
68
const clerkToken = yield* Ref.make<string | null>("clerk-token");
@@ -100,7 +104,7 @@ const makeHarness = Effect.fn("RelayDiscoveryTest.makeHarness")(function* () {
104
if (failure) {
105
return yield* failure;
106
}
103
- return environments;
107
+ return yield* Ref.get(listedEnvironments);
108
}),
109
getEnvironmentStatus: ({ environmentId }) =>
110
Ref.get(statusRequests).pipe(
@@ -165,6 +169,7 @@ const makeHarness = Effect.fn("RelayDiscoveryTest.makeHarness")(function* () {
169
return {
170
layer,
171
listCalls,
172
+ listedEnvironments,
173
listFailure,
174
clerkToken,
175
networkStatus,
@@ -179,6 +184,51 @@ const makeHarness = Effect.fn("RelayDiscoveryTest.makeHarness")(function* () {
184
});
185
186
describe("RelayEnvironmentDiscovery", () => {
187
+ it.effect("fetches a fresh list after removal while an older refresh is checking statuses", () =>
188
+ Effect.scoped(
189
+ Effect.gen(function* () {
190
+ const harness = yield* makeHarness();
191
+ yield* Effect.gen(function* () {
192
+ const discovery = yield* RelayEnvironmentDiscovery.RelayEnvironmentDiscovery;
193
+ const atoms = createRelayEnvironmentDiscoveryAtoms(
194
+ Atom.runtime(
195
+ Layer.succeed(RelayEnvironmentDiscovery.RelayEnvironmentDiscovery, discovery),
196
+ ),
197
+ );
198
+ const registry = AtomRegistry.make();
199
+ yield* Effect.addFinalizer(() => Effect.sync(() => registry.dispose()));
200
+
201
+ const refresh = atoms.refresh.run(registry, undefined);
202
+ yield* SubscriptionRef.changes(discovery.state).pipe(
203
+ Stream.filter((state) => state.environments.size === environments.length),
204
+ Stream.runHead,
205
+ );
206
+ const coalescedRefresh = atoms.refresh.run(registry, undefined);
207
+ yield* Ref.set(harness.listedEnvironments, [environments[1]!]);
208
+ const mutationRefresh = atoms.refreshAfterMutation.run(registry, undefined);
209
+
210
+ const requests = yield* Ref.get(harness.statusRequests);
211
+ for (const environment of environments) {
212
+ yield* Deferred.succeed(
213
+ requests.get(environment.environmentId)!,
214
+ status(environment, "online"),
215
+ );
216
+ }
217
+ const results = yield* Effect.promise(() =>
218
+ Promise.all([refresh, coalescedRefresh, mutationRefresh]),
219
+ );
220
+ for (const result of results) {
221
+ expect(result._tag).toBe("Success");
222
+ }
223
+ expect(yield* Ref.get(harness.listCalls)).toBe(2);
224
+ const complete = yield* SubscriptionRef.get(discovery.state);
225
+ expect([...complete.environments.keys()]).toEqual([environments[1]!.environmentId]);
226
+ expect(complete.refreshing).toBe(false);
227
+ }).pipe(Effect.provide(harness.layer));
228
+ }),
229
+ ),
230
+ );
231
+
232
it.effect("publishes each environment status as soon as that lookup completes", () =>
233
Effect.gen(function* () {
234
const harness = yield* makeHarness();
@@ -228,6 +278,38 @@ describe("RelayEnvironmentDiscovery", () => {
278
}),
279
);
280
281
+ it.effect("reports an environment as unregistered only once the relay list has loaded", () =>
282
+ Effect.gen(function* () {
283
+ const harness = yield* makeHarness();
284
+ yield* Effect.gen(function* () {
285
+ const discovery = yield* RelayEnvironmentDiscovery.RelayEnvironmentDiscovery;
286
+ const listed = environments[0]!.environmentId;
287
+ const deregistered = "deregistered-environment";
288
+ const before = yield* SubscriptionRef.get(discovery.state);
289
+ expect(RelayEnvironmentDiscovery.relayEnvironmentRegistration(before, deregistered)).toBe(
290
+ "unknown",
291
+ );
292
+
293
+ const requests = yield* Ref.get(harness.statusRequests);
294
+ for (const environment of environments) {
295
+ yield* Deferred.succeed(
296
+ requests.get(environment.environmentId)!,
297
+ status(environment, "online"),
298
+ );
299
+ }
300
+ yield* discovery.refresh;
301
+
302
+ const after = yield* SubscriptionRef.get(discovery.state);
303
+ expect(RelayEnvironmentDiscovery.relayEnvironmentRegistration(after, listed)).toBe(
304
+ "registered",
305
+ );
306
+ expect(RelayEnvironmentDiscovery.relayEnvironmentRegistration(after, deregistered)).toBe(
307
+ "unregistered",
308
+ );
309
+ }).pipe(Effect.provide(harness.layer));
310
+ }),
311
+ );
312
+
313
it.effect(
314
"preserves discovered rows while offline and refreshes after connectivity returns",
315
() =>
@@ -350,6 +432,12 @@ describe("RelayEnvironmentDiscovery", () => {
432
const failed = yield* SubscriptionRef.get(discovery.state);
433
expect(failed.environments.size).toBe(0);
434
expect(Option.isSome(failed.error)).toBe(true);
435
+ expect(
436
+ RelayEnvironmentDiscovery.relayEnvironmentRegistration(
437
+ failed,
438
+ environments[0]!.environmentId,
439
+ ),
440
+ ).toBe("unknown");
441
}).pipe(Effect.provide(harness.layer));
442
}),
443
);
@@ -397,6 +485,12 @@ describe("RelayEnvironmentDiscovery", () => {
485
expect(state.environments.size).toBe(0);
486
expect(state.refreshing).toBe(false);
487
expect(Option.isNone(state.error)).toBe(true);
488
+ expect(
489
+ RelayEnvironmentDiscovery.relayEnvironmentRegistration(
490
+ state,
491
+ environments[0]!.environmentId,
492
+ ),
493
+ ).toBe("unknown");
494
}).pipe(Effect.provide(harness.layer));
495
}),
496
);
@@ -429,7 +523,14 @@ describe("RelayEnvironmentDiscovery", () => {
523
yield* Fiber.join(refreshFiber);
524
yield* Effect.yieldNow;
525
432
- expect((yield* SubscriptionRef.get(discovery.state)).environments.size).toBe(0);
526
+ const signedOut = yield* SubscriptionRef.get(discovery.state);
527
+ expect(signedOut.environments.size).toBe(0);
528
+ expect(
529
+ RelayEnvironmentDiscovery.relayEnvironmentRegistration(
530
+ signedOut,
531
+ environments[0]!.environmentId,
532
+ ),
533
+ ).toBe("unknown");
534
}).pipe(Effect.provide(harness.layer), Effect.scoped);
535
}),
536
);
packages/client-runtime/src/relay/discovery.ts
+15
@@ -34,6 +34,8 @@ export interface RelayDiscoveredEnvironment {
34
35
export interface RelayEnvironmentDiscoveryState {
36
readonly environments: ReadonlyMap<string, RelayDiscoveredEnvironment>;
37
+ // Only a loaded account list distinguishes a missing registration from an unknown one.
38
+ readonly listed: boolean;
39
readonly refreshing: boolean;
40
readonly offline: boolean;
41
readonly error: Option.Option<ConnectionAttemptError>;
@@ -49,11 +51,22 @@ export class RelayEnvironmentDiscovery extends Context.Service<
51
52
export const EMPTY_RELAY_ENVIRONMENT_DISCOVERY_STATE: RelayEnvironmentDiscoveryState = {
53
environments: new Map(),
54
+ listed: false,
55
refreshing: false,
56
offline: false,
57
error: Option.none(),
58
};
59
60
+export type RelayEnvironmentRegistration = "registered" | "unregistered" | "unknown";
61
+
62
+export function relayEnvironmentRegistration(
63
+ state: RelayEnvironmentDiscoveryState,
64
+ environmentId: string,
65
+): RelayEnvironmentRegistration {
66
+ if (state.environments.has(environmentId)) return "registered";
67
+ return state.listed ? "unregistered" : "unknown";
68
+}
69
+
70
function validateStatus(
71
environment: RelayClientEnvironmentRecord,
72
status: RelayEnvironmentStatusResponse,
@@ -218,6 +231,7 @@ export const make = Effect.fn("RelayEnvironmentDiscovery.make")(function* () {
231
yield* Ref.set(refreshGeneration, generation);
232
yield* SubscriptionRef.set(state, {
233
environments: new Map(),
234
+ listed: false,
235
refreshing: true,
236
offline: false,
237
error: Option.none(),
@@ -273,6 +287,7 @@ export const make = Effect.fn("RelayEnvironmentDiscovery.make")(function* () {
287
yield* SubscriptionRef.update(state, (current) => ({
288
...current,
289
environments: next,
290
+ listed: true,
291
}));
292
293
yield* Effect.forEach(
packages/client-runtime/src/state/relayDiscovery.ts
+10
@@ -32,9 +32,19 @@ export function createRelayEnvironmentDiscoveryAtoms<R, E>(
32
),
33
});
34
35
+ const refreshAfterMutation = createRuntimeCommand(runtime, {
36
+ label: "relay-environment-discovery:refresh-after-mutation",
37
+ concurrency: { mode: "serial", key: () => "refresh-after-mutation" },
38
+ execute: (_input: void) =>
39
+ RelayEnvironmentDiscovery.RelayEnvironmentDiscovery.pipe(
40
+ Effect.flatMap((discovery) => discovery.refresh),
41
+ ),
42
+ });
43
+
44
return {
45
stateAtom,
46
stateValueAtom,
47
refresh,
48
+ refreshAfterMutation,
49
};
50
}