@devries-cameron20 / t3code-1 / commits / 02c5270a11
Fork 0

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

fix(web): keep SSH connection checks pending until they finish (#39328)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Wout Stiens committed Nov 19, 2026 at 21:42 UTC 02c5270a116f8317e5c0917a37b17c58c6251461
3 files changed +120 -14
apps/web/src/components/settings/DeviceSourcesSettings.tsx
+18 -10
@@ -33,7 +33,11 @@ import { Spinner } from "../ui/spinner";
33 import { toastManager } from "../ui/toast";
34 import { incompleteListings } from "../device/DeviceSetup";
35 import { DeviceHostEditor } from "./DeviceHostEditor";
36 -import { updateDeviceHosts, groupDeviceHosts } from "./deviceHostsSettings.logic";
36 +import {
37 + updateDeviceHosts,
38 + groupDeviceHosts,
39 + type DeviceHostGroup,
40 +} from "./deviceHostsSettings.logic";
41 import { EasDeviceHostEditor } from "./EasDeviceHostEditor";
42 import {
43 easSessionLimits,
@@ -320,17 +324,20 @@ export function DeviceSourcesSettings(props: {
324 gt("Simlock host not removed everywhere"),
325 );
326
323 - const [testing, setTesting] = useState<ReadonlySet<string>>(new Set());
324 - const testSsh = async (host: SshDeviceHostConfig) => {
325 - setTesting((current) => new Set(current).add(host.id));
326 - const checked = await testConnection(host).finally(() =>
327 - setTesting((current) => {
327 + const [testingHosts, setTestingHosts] = useState<ReadonlySet<string>>(new Set());
328 + const testSsh = async ({ host, members }: DeviceHostGroup) => {
329 + const check = testConnection(host);
330 + if (!check) return;
331 + // Every member's id, so the row that remains after an environment drops out stays pending.
332 + const ids = members.map((member) => member.host.id);
333 + setTestingHosts((current) => new Set([...current, ...ids]));
334 + const checked = await check.finally(() =>
335 + setTestingHosts((current) => {
336 const next = new Set(current);
329 - next.delete(host.id);
337 + for (const id of ids) next.delete(id);
338 return next;
339 }),
340 );
333 - if (!checked) return;
341 const failed = targets.filter((target) => checked[target.environmentId]?.status === "failed");
342 toastManager.add({
343 type: failed.length ? "error" : "success",
@@ -435,6 +442,7 @@ export function DeviceSourcesSettings(props: {
442 for (const group of sshGroups) {
443 const host = group.host;
444 const holders = new Set(group.members.map((member) => member.environmentId));
445 + const testing = group.members.some((member) => testingHosts.has(member.host.id));
446 rows.push({
447 key: `ssh:${host.id}:${group.members.map((member) => member.environmentId).join(",")}`,
448 shared: true,
@@ -447,7 +455,7 @@ export function DeviceSourcesSettings(props: {
455 );
456 if (!held)
457 return { environmentId: member.environmentId, label: member.label, added: false };
450 - const status = testing.has(host.id)
458 + const status = testing
459 ? ({ tone: "pending", label: gt("Testing connection") } as const)
460 : hostStatus(member.state, held.host.id, m);
461 return {
@@ -472,7 +480,7 @@ export function DeviceSourcesSettings(props: {
480 () =>
481 setEditing({ kind: "ssh", host, original: host, ...(grouped ? {} : { only: holders }) }),
482 () => void saveSsh(host, true, host, holders),
475 - <MenuItem onClick={() => void testSsh(host)}>
483 + <MenuItem onClick={() => void testSsh(group)}>
484 <T>Test connection</T>
485 </MenuItem>,
486 ),
apps/web/src/components/settings/useHostConnectionChecks.ts
+5 -4
@@ -18,13 +18,13 @@ export function useHostConnectionChecks(targets: ReadonlyArray<DeviceHostCheckTa
18 const test = useAtomCommand(deviceEnvironment.testHost, { reportFailure: false });
19 const [checks, setChecks] = useState<Record<string, Record<string, DeviceHostCheck>>>({});
20 const running = useRef(new Set<string>());
21 - const testConnection = async (host: SshDeviceHostConfig) => {
21 + const testConnection = (host: SshDeviceHostConfig) => {
22 const key = deviceHostConnectionKey(host);
23 if (running.current.has(key)) return;
24 running.current.add(key);
25 setChecks((current) => ({ ...current, [key]: {} }));
26 const results: Record<string, DeviceHostCheck> = {};
27 - await checkDeviceHostConnections(
27 + return checkDeviceHostConnections(
28 targets,
29 host,
30 async (environmentId, input) => {
@@ -42,8 +42,9 @@ export function useHostConnectionChecks(targets: ReadonlyArray<DeviceHostCheckTa
42 [key]: { ...current[key], [environmentId]: result },
43 }));
44 },
45 - ).finally(() => running.current.delete(key));
46 - return results;
45 + )
46 + .then(() => results)
47 + .finally(() => running.current.delete(key));
48 };
49 return { checks, testConnection };
50 }
scripts/scenarios/device-host-test-keeps-pending-status.e2e.ts new
+97
@@ -0,0 +1,97 @@
1 +/// <reference lib="dom" />
2 +import { expect } from "e2e";
3 +import * as Effect from "effect/Effect";
4 +
5 +import { T3_HOME } from "../e2e.config.ts";
6 +import { environmentId, rpcClient, runPromise, test, WEB } from "./t3.ts";
7 +
8 +declare global {
9 + interface Window {
10 + deviceHostProbeGate?: { readonly started: Promise<void>; readonly release: () => void };
11 + }
12 +}
13 +
14 +test(
15 + "A second SSH connection check keeps the pending status visible",
16 + WEB,
17 + async ({ t3, app, browser, screen }) => {
18 + const origin = app.baseUrl ?? "";
19 + const environment = await runPromise(environmentId(origin));
20 + await t3.project("demo");
21 + await runPromise(
22 + Effect.gen(function* () {
23 + const client = yield* rpcClient(T3_HOME, origin);
24 + yield* client["server.updateSettings"]({
25 + patch: {
26 + enableDeviceSupport: true,
27 + deviceHosts: [
28 + { kind: "ssh", id: "slow-host", label: "Slow host", target: "127.0.0.1", port: 1 },
29 + ],
30 + },
31 + });
32 + }).pipe(Effect.scoped),
33 + );
34 +
35 + // Delay just the explicit probe at the transport boundary until after the UI sample.
36 + await browser.addInitScript(() => {
37 + const held: Array<() => void> = [];
38 + const started = Promise.withResolvers<void>();
39 + let delaying = true;
40 + const send = WebSocket.prototype.send;
41 + WebSocket.prototype.send = function (this: WebSocket, data) {
42 + if (!delaying || typeof data !== "string") return send.call(this, data);
43 + const parsed = JSON.parse(data);
44 + const messages = [parsed].flat();
45 + const isProbe = (message: { _tag?: string; tag?: string }) =>
46 + message?._tag === "Request" && message.tag === "device.testHost";
47 + if (!messages.some(isProbe)) return send.call(this, data);
48 + const probes = messages.filter(isProbe);
49 + const other = messages.filter((message) => !isProbe(message));
50 + if (other.length) send.call(this, JSON.stringify(other));
51 + held.push(() => send.call(this, Array.isArray(parsed) ? JSON.stringify(probes) : data));
52 + started.resolve();
53 + };
54 + window.deviceHostProbeGate = {
55 + started: started.promise,
56 + release: () => {
57 + delaying = false;
58 + for (const release of held.splice(0)) release();
59 + },
60 + };
61 + });
62 +
63 + await t3.open(`/settings/devices?machine=${encodeURIComponent(environment)}#device-sources`);
64 + const more = browser.locator("#device-sources").getByRole("button", "More", { exact: true });
65 + const testConnection = screen.getByRole("menuitem", "Test connection", { exact: true });
66 + const pending = screen.getByText("Testing connection", { exact: true });
67 + try {
68 + await more.tap();
69 + await testConnection.tap();
70 + await pending.waitFor();
71 + await browser.evaluate(async () => {
72 + await window.deviceHostProbeGate!.started;
73 + return null;
74 + });
75 + if (await more.isEnabled()) {
76 + await more.tap();
77 + await screen.getByRole("menu").waitFor();
78 + if ((await testConnection.isVisible()) && (await testConnection.isEnabled())) {
79 + await testConnection.tap();
80 + await testConnection.waitFor({ state: "hidden" });
81 + } else {
82 + await browser.keyboard.press("Escape");
83 + }
84 + }
85 +
86 + await app.screenshot("second-connection-check");
87 + expect(await pending.isVisible(), "The SSH connection check still shows as pending").toBe(
88 + true,
89 + );
90 + } finally {
91 + await browser.evaluate(() => {
92 + window.deviceHostProbeGate?.release();
93 + return null;
94 + });
95 + }
96 + },
97 +);