@devries-cameron20 / t3code-1 / commits / e704190e8c
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(devices): Android fold controls work over T3 Connect (#21156)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Theo Browne committed Oct 18, 2026 at 15:28 UTC e704190e8ce0d15f85e42bc844baad525b2110c1
6 files changed +71 -7
apps/server/src/device/DeviceHubProxy.test.ts
+22 -1
@@ -25,9 +25,11 @@ const fixture = (
25 ) => {
26 let finalized = 0;
27 const requests: string[] = [];
28 + const headers: Array<Readonly<Record<string, string>>> = [];
29 const client = HttpClient.make((request, _url, signal) =>
30 Effect.gen(function* () {
31 requests.push(request.url);
32 + headers.push(request.headers);
33 signal.addEventListener("abort", () => {
34 finalized++;
35 });
@@ -61,7 +63,7 @@ const fixture = (
63 { disableLogger: true },
64 );
65 disposers.push(dispose);
64 - return { handler, requests, finalized: () => finalized };
66 + return { handler, requests, headers, finalized: () => finalized };
67 };
68
69 describe("device hub proxy", () => {
@@ -131,6 +133,25 @@ describe("device hub proxy", () => {
133 ]);
134 });
135
136 + it("presents fold changes from an HTTPS client as same-origin hub requests", async () => {
137 + const { handler, headers } = fixture([AuthOrchestrationOperateScope]);
138 + const response = await handler(
139 + new Request(
140 + "https://relay.test/api/device-hub/vendor/serve-emu/api/fold?device=emulator-5554",
141 + {
142 + method: "POST",
143 + headers: { origin: "https://relay.test", "x-forwarded-proto": "https" },
144 + body: '{"posture":"opened"}',
145 + },
146 + ),
147 + );
148 + expect(response.status).toBe(200);
149 + await response.text();
150 + expect(headers).toHaveLength(1);
151 + expect(headers[0]?.origin).toBe("http://hub.test");
152 + expect(headers[0]).not.toHaveProperty("x-forwarded-proto");
153 + });
154 +
155 it("never forwards the vendor shell endpoint", async () => {
156 const { handler, requests } = fixture([AuthOrchestrationOperateScope]);
157 expect(
apps/server/src/device/DeviceHubProxy.ts
+3
@@ -57,6 +57,9 @@ const DROPPED_REQUEST_HEADERS = new Set([
57 "dpop",
58 "content-length",
59 "accept-encoding",
60 + // Describes the client's HTTPS hop to T3. The hub builds its own origin from it and then
61 + // rejects the loopback Origin set below, so every mutation fails over T3 Connect.
62 + "x-forwarded-proto",
63 ]);
64
65 const isWebSocketUpgrade = (request: HttpServerRequest.HttpServerRequest) =>
apps/web/src/components/device/DeviceAndroidFoldControls.tsx
+16 -3
@@ -3,6 +3,7 @@ import { useEffect, useRef, useState } from "react";
3 import { Button } from "~/components/ui/button";
4 import { Tooltip, TooltipPopup, TooltipTrigger } from "~/components/ui/tooltip";
5 import {
6 + AndroidFoldError,
7 readAndroidFold,
8 setAndroidFold,
9 type AndroidFoldPosture,
@@ -18,6 +19,7 @@ export function DeviceAndroidFoldControls(props: {
19 readonly screenWidth: number | undefined;
20 readonly screenHeight: number | undefined;
21 readonly onFoldAngle: (angle: number | null) => void;
22 + readonly renewAccess: () => Promise<DeviceHubAccess | null>;
23 }) {
24 const [fold, setFold] = useState<AndroidFoldState | null>(null);
25 const [pending, setPending] = useState(false);
@@ -47,8 +49,10 @@ export function DeviceAndroidFoldControls(props: {
49 );
50 }
51 })
50 - .catch(() => {
51 - if (!controller.signal.aborted) retry = window.setTimeout(read, 3_000);
52 + .catch((cause: unknown) => {
53 + // Retrying an expired ticket cannot succeed. New access re-runs this effect.
54 + const expired = cause instanceof AndroidFoldError && cause.status === 401;
55 + if (!controller.signal.aborted && !expired) retry = window.setTimeout(read, 3_000);
56 });
57 };
58 read();
@@ -68,7 +72,16 @@ export function DeviceAndroidFoldControls(props: {
72 props.onFoldAngle(posture === "closed" ? 0 : 180);
73 const controller = new AbortController();
74 const timeout = window.setTimeout(() => controller.abort(), 12_000);
71 - void setAndroidFold(props.access, props.deviceId, posture, controller.signal)
75 + const send = (access: DeviceHubAccess) =>
76 + setAndroidFold(access, props.deviceId, posture, controller.signal);
77 + void send(props.access)
78 + .catch(async (cause: unknown) => {
79 + // Hub tickets expire after a few minutes, while the panel stays open much longer.
80 + if (!(cause instanceof AndroidFoldError && cause.status === 401)) throw cause;
81 + const renewed = await props.renewAccess();
82 + if (!renewed || controller.signal.aborted) throw cause;
83 + return send(renewed);
84 + })
85 .then((next) => {
86 if (mounted.current) {
87 setFold(next);
apps/web/src/components/device/DeviceStreamView.tsx
+2 -1
@@ -3,7 +3,7 @@ import { useEffect, useRef, useState, type ReactNode } from "react";
3
4 import { cn } from "~/lib/utils";
5 import { Button } from "~/components/ui/button";
6 -import { refreshDeviceHubAccess, useDeviceHubAccess } from "~/state/device";
6 +import { refreshDeviceHubAccess, renewDeviceHubAccess, useDeviceHubAccess } from "~/state/device";
7 import { createCanvasFrameSink } from "@t3tools/client-runtime/device/frame";
8 import { resolveDeviceShape } from "@t3tools/client-runtime/device/shape-profile";
9 import { deviceKeyboard, deviceModel } from "./deviceModels";
@@ -343,6 +343,7 @@ export function DeviceStreamView(props: {
343 screenWidth={screen?.width}
344 screenHeight={screen?.height}
345 onFoldAngle={setFoldAngle}
346 + renewAccess={() => renewDeviceHubAccess(props.environmentId, props.hostId)}
347 />
348 ) : showPhone && isDuo && screen?.supportsHingeAngle ? (
349 <DeviceDuoControls
apps/web/src/components/device/deviceFold.ts
+11 -1
@@ -9,6 +9,15 @@ export interface AndroidFoldState {
9 readonly hingeAngle: number | null;
10 }
11
12 +export class AndroidFoldError extends Error {
13 + readonly status: number;
14 +
15 + constructor(message: string, status: number) {
16 + super(message);
17 + this.status = status;
18 + }
19 +}
20 +
21 const isRecord = (value: unknown): value is Record<string, unknown> =>
22 typeof value === "object" && value !== null && !Array.isArray(value);
23
@@ -54,8 +63,9 @@ const foldRequest = async (
63 if (!response.ok) {
64 const payload: unknown = await response.json().catch(() => null);
65 const error = isRecord(payload) ? payload.error : null;
57 - throw new Error(
66 + throw new AndroidFoldError(
67 typeof error === "string" ? error : `Fold command failed (${response.status}).`,
68 + response.status,
69 );
70 }
71 return parseFold(await response.json());
apps/web/src/state/device.ts
+17 -1
@@ -7,7 +7,7 @@ import {
7 import type { DeviceServiceState, EnvironmentId } from "@t3tools/contracts";
8 import * as Effect from "effect/Effect";
9 import * as Option from "effect/Option";
10 -import { AsyncResult, Atom } from "effect/reactivity";
10 +import { AsyncResult, Atom, AtomRegistry } from "effect/reactivity";
11
12 import { connectionAtomRuntime } from "../connection/runtime";
13 import { appAtomRegistry } from "../rpc/atomRegistry";
@@ -69,3 +69,19 @@ const EMPTY_ACCESS_ATOM = Atom.make(AsyncResult.initial<DeviceHubAccess, never>(
69 export function refreshDeviceHubAccess(environmentId: EnvironmentId): void {
70 appAtomRegistry.refresh(deviceHubAccessAtom(environmentId));
71 }
72 +
73 +/** Mints a fresh hub ticket for a one-off request that failed with 401. Resolves null on failure. */
74 +export function renewDeviceHubAccess(
75 + environmentId: EnvironmentId,
76 + hostId = "local",
77 +): Promise<DeviceHubAccess | null> {
78 + const atom = deviceHubAccessAtom(environmentId);
79 + appAtomRegistry.refresh(atom);
80 + return Effect.runPromise(
81 + AtomRegistry.getResult(appAtomRegistry, atom, { suspendOnWaiting: true }).pipe(
82 + Effect.map((access) => ({ ...access, query: { ...access.query, hostId } })),
83 + Effect.timeout("10 seconds"),
84 + Effect.orElseSucceed(() => null),
85 + ),
86 + );
87 +}