The best way to control Claude Code, Codex and more from any computer or phone
fix(mobile): update outdated servers and respect provider permissions (#21402)
maria committed
Oct 21, 2026 at 00:03 UTC
145d73b42e067ecdffacc50af0ccd6fd6e1afcf2
8 files changed
+286
-35
apps/mobile/src/features/settings/OutdatedServerUpdateSection.tsx
new
+129
@@ -0,0 +1,129 @@
1
+import { useAtomValue } from "@effect/atom-react";
2
+import { settlePromise, squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
3
+import type { EnvironmentId } from "@t3tools/contracts";
4
+import { AsyncResult } from "effect/reactivity";
5
+import { useEffect, useRef, useState } from "react";
6
+import { View } from "react-native";
7
+
8
+import { AppText as Text } from "../../components/ui/AppText";
9
+import * as Dialog from "../../components/ui/Dialog";
10
+import {
11
+ describeOutdatedServer,
12
+ serverEnvironment,
13
+ updateOutdatedServer,
14
+} from "../../state/server";
15
+import { useAtomCommand } from "../../state/use-atom-command";
16
+import { SettingsActionRow } from "./components/SettingsActionRow";
17
+import { SettingsSection } from "./components/SettingsSection";
18
+import { findEnvironmentUpdate } from "./environment-maintenance";
19
+
20
+export function OutdatedServerUpdateSection({
21
+ environmentId,
22
+ label,
23
+}: {
24
+ readonly environmentId: EnvironmentId;
25
+ readonly label: string;
26
+}) {
27
+ const describe = useAtomCommand(describeOutdatedServer, { reportFailure: false });
28
+ const update = useAtomCommand(updateOutdatedServer, { reportFailure: false });
29
+ const state = useAtomValue(serverEnvironment.updateStateAtom(environmentId));
30
+ const [release, setRelease] = useState<{
31
+ fromVersion: string;
32
+ targetVersion: string | null;
33
+ } | null>(null);
34
+ const [checking, setChecking] = useState(false);
35
+ const [error, setError] = useState<string | null>(null);
36
+ const controller = useRef<AbortController | null>(null);
37
+ useEffect(() => () => controller.current?.abort(), []);
38
+ const busy = checking || state.status === "running";
39
+
40
+ async function check() {
41
+ if (busy || controller.current !== null) return;
42
+ const request = new AbortController();
43
+ controller.current = request;
44
+ setChecking(true);
45
+ setError(null);
46
+ const timeout = setTimeout(() => request.abort(), 20_000);
47
+ const result = await settlePromise(async () => {
48
+ const description = await describe(environmentId);
49
+ if (AsyncResult.isFailure(description)) throw squashAtomCommandFailure(description);
50
+ const fromVersion = description.value.serverVersion;
51
+ const targetVersion = await findEnvironmentUpdate(fromVersion, request.signal);
52
+ if (!request.signal.aborted) setRelease({ fromVersion, targetVersion });
53
+ });
54
+ clearTimeout(timeout);
55
+ controller.current = null;
56
+ setChecking(false);
57
+ if (AsyncResult.isFailure(result)) {
58
+ const failure = squashAtomCommandFailure(result);
59
+ setError(failure instanceof Error ? failure.message : "Could not check for updates.");
60
+ }
61
+ }
62
+
63
+ function requestUpdate() {
64
+ const targetVersion = release?.targetVersion;
65
+ if (busy || !release || !targetVersion) return;
66
+ Dialog.alert(
67
+ `Update ${label}?`,
68
+ `Install T3 Code ${targetVersion}. T3 Code restarts on that machine and reconnects. Running threads may be interrupted.`,
69
+ [
70
+ { text: "Cancel", style: "cancel" },
71
+ {
72
+ text: "Update",
73
+ onPress: () => {
74
+ setError(null);
75
+ void update({
76
+ environmentId,
77
+ input: { targetVersion },
78
+ fromVersion: release.fromVersion,
79
+ });
80
+ },
81
+ },
82
+ ],
83
+ );
84
+ }
85
+
86
+ return (
87
+ <SettingsSection title="T3 Code">
88
+ <View className="gap-1 p-4">
89
+ <Text className="text-base text-foreground">
90
+ {release ? `Version ${release.fromVersion}` : "Update required"}
91
+ </Text>
92
+ <Text className="text-sm text-foreground-muted">
93
+ {state.status === "running"
94
+ ? state.stage === "resuming"
95
+ ? "Restarting and reconnecting…"
96
+ : state.stage === "installing"
97
+ ? "Installing update…"
98
+ : "Downloading update…"
99
+ : release
100
+ ? release.targetVersion
101
+ ? `Version ${release.targetVersion} is available.`
102
+ : "No newer version is available yet."
103
+ : "This app needs a newer version of T3 Code on this machine."}
104
+ </Text>
105
+ {error || state.status === "failed" ? (
106
+ <Text selectable accessibilityRole="alert" className="text-sm text-danger-foreground">
107
+ {error ?? (state.status === "failed" ? state.message : null)}
108
+ </Text>
109
+ ) : null}
110
+ </View>
111
+ <SettingsActionRow
112
+ icon="arrow.clockwise"
113
+ label="Check for updates"
114
+ disabled={busy}
115
+ loading={checking}
116
+ onPress={() => void check()}
117
+ />
118
+ {release?.targetVersion ? (
119
+ <SettingsActionRow
120
+ icon="arrow.up.circle"
121
+ label={state.status === "failed" ? "Retry update" : `Update to ${release.targetVersion}`}
122
+ disabled={busy}
123
+ loading={state.status === "running"}
124
+ onPress={requestUpdate}
125
+ />
126
+ ) : null}
127
+ </SettingsSection>
128
+ );
129
+}
apps/mobile/src/features/settings/SettingsEnvironmentDetailRouteScreen.tsx
+12
-2
@@ -17,12 +17,14 @@ import { AppText as Text } from "../../components/ui/AppText";
17
import { ProviderIcon } from "../../components/ProviderIcon";
18
import { ScreenScrollView } from "../../components/ui/ScreenScrollView";
19
import { appAtomRegistry } from "../../state/atom-registry";
20
+import { environmentPresentations } from "../../state/presentation";
21
import { serverEnvironment } from "../../state/server";
22
import { environmentSession, useEnvironmentScope, readEnvironmentScope } from "../../state/session";
23
import { useAtomCommand } from "../../state/use-atom-command";
24
import { useRemoteConnections } from "../../state/use-remote-environment-registry";
25
import { ConnectionEnvironmentRow } from "../connection/ConnectionEnvironmentRow";
26
import { EnvironmentRoutesSection } from "./EnvironmentRoutesSection";
27
+import { OutdatedServerUpdateSection } from "./OutdatedServerUpdateSection";
28
import { SettingsActionRow } from "./components/SettingsActionRow";
29
import { SettingsScreen } from "./components/SettingsScreen";
30
import { SettingsSection } from "./components/SettingsSection";
@@ -58,6 +60,9 @@ function EnvironmentDetail({ environmentId }: { readonly environmentId: Environm
60
const session = useAtomValue(environmentSession.sessionStateValueAtom(environmentId));
61
const sessionResult = useAtomValue(environmentSession.sessionStateAtom(environmentId));
62
const updateState = useAtomValue(serverEnvironment.updateStateAtom(environmentId));
63
+ const outdated =
64
+ useAtomValue(environmentPresentations.presentationAtom(environmentId))?.entry
65
+ .serverUpdateRequired === true;
66
const updateServer = useAtomCommand(serverEnvironment.updateServer);
67
const updateProvider = useAtomCommand(serverEnvironment.updateProvider);
68
const refreshProviders = useAtomCommand(serverEnvironment.refreshProviders);
@@ -206,7 +211,12 @@ function EnvironmentDetail({ environmentId }: { readonly environmentId: Environm
211
})
212
}
213
/>
209
- {!connected ? (
214
+ {outdated ? (
215
+ <OutdatedServerUpdateSection
216
+ environmentId={environmentId}
217
+ label={environment.environmentLabel}
218
+ />
219
+ ) : !connected ? (
220
<Text className="px-2 text-sm text-foreground-muted">
221
Connect this environment to manage it.
222
</Text>
@@ -225,7 +235,7 @@ function EnvironmentDetail({ environmentId }: { readonly environmentId: Environm
235
</Text>
236
) : null}
237
{notice ? <Text className="px-2 text-sm text-foreground-muted">{notice}</Text> : null}
228
- {config ? (
238
+ {config && !outdated ? (
239
<>
240
<SettingsSection title="T3 Code">
241
<View className="gap-1 p-4">
apps/mobile/src/features/settings/SettingsProviderAccountsRouteScreen.tsx
+40
-23
@@ -4,7 +4,11 @@ import {
4
squashAtomCommandFailure,
5
type AtomCommandResult,
6
} from "@t3tools/client-runtime/state/runtime";
7
-import type { ProviderAuthResponse, ServerProvider } from "@t3tools/contracts";
7
+import {
8
+ AuthProvidersManageScope,
9
+ type ProviderAuthResponse,
10
+ type ServerProvider,
11
+} from "@t3tools/contracts";
12
import { useAtomValue } from "@effect/atom-react";
13
import { useRef, useState } from "react";
14
import { Linking, Pressable, ScrollView, TextInput, View } from "react-native";
@@ -15,6 +19,7 @@ import { ScreenScrollView } from "../../components/ui/ScreenScrollView";
19
import { environmentPresentations } from "../../state/presentation";
20
import { useEnvironmentQuery } from "../../state/query";
21
import { serverEnvironment } from "../../state/server";
22
+import { useEnvironmentsWithScope } from "../../state/session";
23
import { useAtomCommand } from "../../state/use-atom-command";
24
import { SettingsActionRow } from "./components/SettingsActionRow";
25
import {
@@ -27,6 +32,7 @@ import { useSettingsEnvironmentFilter, type SettingsTarget } from "./settings-en
32
33
export function SettingsProviderAccountsRouteScreen() {
34
const { selectedTargets } = useSettingsEnvironmentFilter();
35
+ const permittedEnvironments = useEnvironmentsWithScope(selectedTargets, AuthProvidersManageScope);
36
const providersByEnvironment = useAtomValue(environmentPresentations.providersByEnvironmentAtom);
37
const insets = useSafeAreaInsets();
38
return (
@@ -44,28 +50,39 @@ export function SettingsProviderAccountsRouteScreen() {
50
) : (
51
selectedTargets.map((environment) => (
52
<SettingsSection key={environment.environmentId} title={environment.label}>
47
- {(providersByEnvironment.get(environment.environmentId) ?? [])
48
- .filter(
49
- (provider) =>
50
- provider.setup?.canAuthenticate ||
51
- (provider.driver === "acpRegistry" && provider.installed),
52
- )
53
- .map((provider) => (
54
- <ProviderAccount
55
- key={provider.instanceId}
56
- environment={environment}
57
- provider={provider}
58
- />
59
- ))}
60
- {!(providersByEnvironment.get(environment.environmentId) ?? []).some(
61
- (provider) =>
62
- provider.setup?.canAuthenticate ||
63
- (provider.driver === "acpRegistry" && provider.installed),
64
- ) ? (
65
- <Text className="p-4 text-foreground-muted">
66
- Configure a provider with in-app sign-in in web or desktop Settings.
67
- </Text>
68
- ) : null}
53
+ {!permittedEnvironments.has(environment.environmentId) ? (
54
+ <View className="gap-1 p-4">
55
+ <Text className="text-base text-foreground">Limited permissions</Text>
56
+ <Text className="text-sm text-foreground-muted">
57
+ {`This session can view ${environment.label}'s providers but can't change their settings.`}
58
+ </Text>
59
+ </View>
60
+ ) : (
61
+ <>
62
+ {(providersByEnvironment.get(environment.environmentId) ?? [])
63
+ .filter(
64
+ (provider) =>
65
+ provider.setup?.canAuthenticate ||
66
+ (provider.driver === "acpRegistry" && provider.installed),
67
+ )
68
+ .map((provider) => (
69
+ <ProviderAccount
70
+ key={provider.instanceId}
71
+ environment={environment}
72
+ provider={provider}
73
+ />
74
+ ))}
75
+ {!(providersByEnvironment.get(environment.environmentId) ?? []).some(
76
+ (provider) =>
77
+ provider.setup?.canAuthenticate ||
78
+ (provider.driver === "acpRegistry" && provider.installed),
79
+ ) ? (
80
+ <Text className="p-4 text-foreground-muted">
81
+ Configure a provider with in-app sign-in in web or desktop Settings.
82
+ </Text>
83
+ ) : null}
84
+ </>
85
+ )}
86
</SettingsSection>
87
))
88
)}
apps/mobile/src/state/server.ts
+6
@@ -1,4 +1,8 @@
1
import { createServerEnvironmentAtoms } from "@t3tools/client-runtime/state/server";
2
+import {
3
+ createOutdatedServerDescriptionCommand,
4
+ createOutdatedServerUpdateCommand,
5
+} from "@t3tools/client-runtime/state/outdatedServerUpdate";
6
import { createEnvironmentServerConfigsAtom } from "@t3tools/client-runtime/state/shell";
7
8
import { environmentCatalog } from "../connection/catalog";
@@ -11,6 +15,8 @@ export const serverEnvironment = createServerEnvironmentAtoms(connectionAtomRunt
15
usageLimitSources: true,
16
usageLimitsCommand: true,
17
});
18
+export const describeOutdatedServer = createOutdatedServerDescriptionCommand(connectionAtomRuntime);
19
+export const updateOutdatedServer = createOutdatedServerUpdateCommand(connectionAtomRuntime);
20
export const environmentServerConfigsAtom = createEnvironmentServerConfigsAtom({
21
catalogValueAtom: environmentCatalog.catalogValueAtom,
22
serverConfigValueAtom: serverEnvironment.configValueAtom,
apps/mobile/src/state/session.test.ts
+23
@@ -1,5 +1,6 @@
1
import {
2
AuthOrchestrationOperateScope,
3
+ AuthProvidersManageScope,
4
EnvironmentId,
5
type AuthSessionState,
6
} from "@t3tools/contracts";
@@ -111,3 +112,25 @@ it("uses exact new-server permissions and keeps old-server grants usable", () =>
112
appAtomRegistry.set(source(primary), AsyncResult.success(session(true)));
113
expect(useEnvironmentScope(primary, AuthOrchestrationOperateScope)).toBe(true);
114
});
115
+
116
+it("limits provider accounts to environments granting provider management", () => {
117
+ const environments = [{ environmentId: primary }, { environmentId: secondary }];
118
+ const permitted = () => useEnvironmentsWithScope(environments, AuthProvidersManageScope);
119
+ appAtomRegistry.set(
120
+ source(primary),
121
+ AsyncResult.success({ ...session(true), permissions: [AuthOrchestrationOperateScope] }),
122
+ );
123
+ expect(permitted()).toEqual(new Set());
124
+ appAtomRegistry.set(
125
+ source(secondary),
126
+ AsyncResult.success({ ...session(false), permissions: [AuthProvidersManageScope] }),
127
+ );
128
+ expect(permitted()).toEqual(new Set([secondary]));
129
+ appAtomRegistry.set(source(primary), AsyncResult.success(session(true)));
130
+ expect(permitted()).toEqual(new Set([primary, secondary]));
131
+ appAtomRegistry.set(
132
+ source(secondary),
133
+ AsyncResult.success({ ...session(true), scopes: [AuthProvidersManageScope], permissions: [] }),
134
+ );
135
+ expect(permitted()).toEqual(new Set([primary]));
136
+});
packages/client-runtime/src/connection/outdatedHostUpdate.test.ts
+42
-1
@@ -17,7 +17,7 @@ import * as Socket from "effect/socket/Socket";
17
import type { ConnectionCatalogEntry } from "./catalog.ts";
18
import { orchestrationProtocolCompatibilityError } from "./compatibility.ts";
19
import { PrimaryConnectionTarget } from "./model.ts";
20
-import { updateOutdatedHost } from "./outdatedHostUpdate.ts";
20
+import { describeOutdatedHost, updateOutdatedHost } from "./outdatedHostUpdate.ts";
21
import * as EnvironmentRegistry from "./registry.ts";
22
import * as ConnectionResolver from "./resolver.ts";
23
import * as RelayEnvironmentDiscovery from "../relay/discovery.ts";
@@ -49,6 +49,47 @@ const decodeJson = Schema.decodeUnknownSync(Schema.fromJsonString(Schema.Unknown
49
const encodeJson = Schema.encodeUnknownSync(Schema.fromJsonString(Schema.Unknown));
50
const encodeDescriptor = Schema.encodeSync(Schema.fromJsonString(ExecutionEnvironmentDescriptor));
51
52
+describe("describeOutdatedHost", () => {
53
+ it.effect("discovers a disabled outdated host without opening a normal session", () =>
54
+ Effect.gen(function* () {
55
+ const expected = descriptor(undefined, "0.0.45");
56
+ const result = yield* describeOutdatedHost(TARGET.environmentId).pipe(
57
+ Effect.provideService(
58
+ EnvironmentRegistry.EnvironmentRegistry,
59
+ EnvironmentRegistry.EnvironmentRegistry.of({
60
+ entries: yield* SubscriptionRef.make<
61
+ ReadonlyMap<EnvironmentId, ConnectionCatalogEntry>
62
+ >(
63
+ new Map([
64
+ [TARGET.environmentId, { target: TARGET, profile: Option.none(), enabled: false }],
65
+ ]),
66
+ ),
67
+ } as unknown as EnvironmentRegistry.EnvironmentRegistry["Service"]),
68
+ ),
69
+ Effect.provideService(
70
+ ConnectionResolver.ConnectionResolver,
71
+ ConnectionResolver.ConnectionResolver.of({
72
+ prepare: () => Effect.die(new Error("normal sessions reject this protocol")),
73
+ prepareForUpdate: (entry) =>
74
+ Effect.succeed({
75
+ descriptor: expected,
76
+ prepared: {
77
+ environmentId: entry.target.environmentId,
78
+ label: entry.target.label,
79
+ httpBaseUrl: TARGET.httpBaseUrl,
80
+ socketUrl: "wss://build.example.test/ws",
81
+ httpAuthorization: null,
82
+ target: TARGET,
83
+ },
84
+ }),
85
+ }),
86
+ ),
87
+ );
88
+ expect(result).toEqual(expected);
89
+ }),
90
+ );
91
+});
92
+
93
type Listener = (event: { readonly type: string; readonly data?: unknown }) => void;
94
95
class OutdatedHostSocket {
packages/client-runtime/src/connection/outdatedHostUpdate.ts
+20
-8
@@ -48,6 +48,25 @@ export class OutdatedHostUpdateError extends Schema.TaggedError<OutdatedHostUpda
48
49
export type OutdatedHostUpdateStage = "downloading" | "installing" | "resuming";
50
51
+const reachOutdatedHost = Effect.fn("clientRuntime.connection.reachOutdatedHost")(function* (
52
+ environmentId: EnvironmentId,
53
+) {
54
+ const registry = yield* EnvironmentRegistry.EnvironmentRegistry;
55
+ const resolver = yield* ConnectionResolver.ConnectionResolver;
56
+ const entry = (yield* SubscriptionRef.get(registry.entries)).get(environmentId);
57
+ if (entry === undefined) {
58
+ return yield* new EnvironmentRegistry.EnvironmentNotRegisteredError({ environmentId });
59
+ }
60
+ const { prepared, descriptor } = yield* Effect.firstSuccessOf(
61
+ usableRoutes(entry).map((route) => resolver.prepareForUpdate(routeEntry(entry, route))),
62
+ );
63
+ return { entry, prepared, descriptor };
64
+});
65
+
66
+// The normal session cannot read config from a host behind the protocol gate.
67
+export const describeOutdatedHost = (environmentId: EnvironmentId) =>
68
+ reachOutdatedHost(environmentId).pipe(Effect.map(({ descriptor }) => descriptor));
69
+
70
/**
71
* The normal session refuses to open against such a host, so this opens a bare
72
* socket and calls only the self-update RPCs, whose wire shape has not changed
@@ -60,16 +79,9 @@ export const updateOutdatedHost = Effect.fn("clientRuntime.connection.updateOutd
79
onStage: (stage: OutdatedHostUpdateStage) => Effect.Effect<void>,
80
) {
81
const registry = yield* EnvironmentRegistry.EnvironmentRegistry;
63
- const resolver = yield* ConnectionResolver.ConnectionResolver;
82
const webSocketConstructor = yield* Socket.WebSocketConstructor;
83
const httpClient = yield* HttpClient.HttpClient;
66
- const entry = (yield* SubscriptionRef.get(registry.entries)).get(environmentId);
67
- if (entry === undefined) {
68
- return yield* new EnvironmentRegistry.EnvironmentNotRegisteredError({ environmentId });
69
- }
70
- const { prepared, descriptor } = yield* Effect.firstSuccessOf(
71
- usableRoutes(entry).map((route) => resolver.prepareForUpdate(routeEntry(entry, route))),
72
- );
84
+ const { entry, prepared, descriptor } = yield* reachOutdatedHost(environmentId);
85
// Discovery still holds the old relay descriptor and would re-block the
86
// environment from it, so replace that before clearing the block.
87
const switchBackOn = Effect.gen(function* () {
packages/client-runtime/src/state/outdatedServerUpdate.ts
+14
-1
@@ -6,7 +6,7 @@ import type * as HttpClient from "effect/http/HttpClient";
6
import type { Atom } from "effect/reactivity";
7
import type * as Socket from "effect/socket/Socket";
8
9
-import { updateOutdatedHost } from "../connection/outdatedHostUpdate.ts";
9
+import { describeOutdatedHost, updateOutdatedHost } from "../connection/outdatedHostUpdate.ts";
10
import type * as ConnectionResolver from "../connection/resolver.ts";
11
import type * as EnvironmentRegistry from "../connection/registry.ts";
12
import type * as RelayEnvironmentDiscovery from "../relay/discovery.ts";
@@ -24,6 +24,19 @@ export interface OutdatedServerUpdateTarget {
24
readonly fromVersion?: string;
25
}
26
27
+export function createOutdatedServerDescriptionCommand<E>(
28
+ runtime: Atom.AtomRuntime<
29
+ EnvironmentRegistry.EnvironmentRegistry | ConnectionResolver.ConnectionResolver,
30
+ E
31
+ >,
32
+) {
33
+ return createRuntimeCommand(runtime, {
34
+ label: "environment-data:server:describe-outdated-server",
35
+ execute: (environmentId: EnvironmentId) =>
36
+ describeOutdatedHost(environmentId).pipe(Effect.timeout("20 seconds")),
37
+ });
38
+}
39
+
40
export function createOutdatedServerUpdateCommand<E>(
41
runtime: Atom.AtomRuntime<
42
| EnvironmentRegistry.EnvironmentRegistry