@devries-cameron20 / t3code-1 / commits / 202d5b5616
Fork 0

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

fix(devices): keep devices listed when simulator discovery fails (#25971)

Co-authored-by: PR Batch Tester <agent@local.test> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

shivam committed Nov 6, 2026 at 14:39 UTC 202d5b5616e3edf65706371e2b8a9c4f486d0a96
13 files changed +379 -85
apps/server/src/device/DeviceHost.ts
+2
@@ -110,6 +110,8 @@ export interface DeviceOperations {
110 readonly detail: string | undefined;
111 /** Some Android virtual devices could not be listed; the rest are. */
112 readonly androidDiscoveryIncomplete?: boolean;
113 + /** Platforms that could not be listed; their last known devices stay listed. */
114 + readonly incompletePlatforms?: ReadonlyArray<DevicePlatform>;
115 },
116 DeviceOperationError
117 >;
apps/server/src/device/DeviceHubOperations.ts
+44 -15
@@ -6,6 +6,7 @@ import {
6 } from "@t3tools/contracts";
7 import * as Duration from "effect/Duration";
8 import * as Effect from "effect/Effect";
9 +import * as Option from "effect/Option";
10 import * as Schema from "effect/Schema";
11 import { HttpClient, HttpClientError, HttpClientRequest, HttpClientResponse } from "effect/http";
12
@@ -13,6 +14,11 @@ import type { DeviceHostReady, DeviceOperations, HostDevice } from "./DeviceHost
14
15 const BOOT_TIMEOUT = Duration.minutes(3);
16 const SCREENSHOT_TIMEOUT = Duration.seconds(20);
17 +// Let the hub's 30 s simctl timeout report its cause first.
18 +const LIST_TIMEOUT_SECONDS = 40;
19 +// expo-device-hub 0.19.1 reports a failed simulator listing only as text; its error ids are hashes.
20 +const SIMULATOR_LIST_FAILED =
21 + /^\[apple-utils\] (?:Failed to (?:run `xcrun simctl list devices|parse JSON output:|list devices:)|`xcrun simctl list devices --json` did not respond within )/;
22
23 const HubDevice = Schema.Struct({
24 id: Schema.String,
@@ -63,30 +69,35 @@ export const makeDeviceHubOperations = (options: {
69 readonly origin: string;
70 readonly http: HttpClient.HttpClient;
71 readonly run: DeviceHostReady["run"];
66 - /** Whether to list AVDs, which the hub does not report until they boot. */
67 - readonly androidAvailable: Effect.Effect<boolean>;
72 + /** Android gates listing AVDs, which the hub does not report until they boot. */
73 + readonly platformAvailable: (platform: DevicePlatform) => Effect.Effect<boolean>;
74 }): DeviceOperations => {
75 const { hostId, origin, run } = options;
76 const httpClient = options.http.pipe(HttpClient.withScope);
77
78 + const fetchJson = Effect.fn("DeviceHubOperations.fetchJson")(function* <A, I>(
79 + request: HttpClientRequest.HttpClientRequest,
80 + schema: Schema.Codec<A, I>,
81 + ) {
82 + return yield* httpClient
83 + .execute(request)
84 + .pipe(
85 + Effect.flatMap(HttpClientResponse.filterStatusOk),
86 + Effect.flatMap(HttpClientResponse.schemaBodyJson(schema)),
87 + Effect.scoped,
88 + );
89 + });
90 +
91 const hubJson = <A, I>(
92 request: HttpClientRequest.HttpClientRequest,
93 schema: Schema.Codec<A, I>,
94 operation: string,
95 timeout: Duration.Input = Duration.seconds(15),
96 ) =>
78 - httpClient.execute(request).pipe(
79 - Effect.flatMap(HttpClientResponse.filterStatusOk),
80 - Effect.flatMap(HttpClientResponse.schemaBodyJson(schema)),
81 - Effect.scoped,
97 + fetchJson(request, schema).pipe(
98 Effect.timeout(timeout),
99 Effect.mapError(
84 - (cause) =>
85 - new DeviceOperationError({
86 - operation,
87 - reason: "request_failed",
88 - cause,
89 - }),
100 + (cause) => new DeviceOperationError({ operation, reason: "request_failed", cause }),
101 ),
102 );
103
@@ -106,13 +117,27 @@ export const makeDeviceHubOperations = (options: {
117 );
118
119 const list: DeviceOperations["list"] = Effect.gen(function* () {
109 - const hubList = yield* hubJson(
120 + const listed = yield* fetchJson(
121 HttpClientRequest.get(`${origin}/api/devices`),
122 HubDeviceList,
112 - "list",
123 + ).pipe(
124 + Effect.mapError(
125 + (cause) => new DeviceOperationError({ operation: "list", reason: "request_failed", cause }),
126 + ),
127 + Effect.timeoutOption(Duration.seconds(LIST_TIMEOUT_SECONDS)),
128 );
129 + if (Option.isNone(listed)) {
130 + return {
131 + devices: [],
132 + detail: `The device hub did not answer within ${LIST_TIMEOUT_SECONDS} seconds.`,
133 + incompletePlatforms: yield* Effect.filter(["ios", "android"] as const, (platform) =>
134 + options.platformAvailable(platform),
135 + ),
136 + };
137 + }
138 + const hubList = listed.value;
139 const devices: Array<HostDevice> = [...hubList.simulators, ...hubList.emulators];
115 - const androidAvailable = yield* options.androidAvailable;
140 + const androidAvailable = yield* options.platformAvailable("android");
141 const warnings = hubList.errors?.filter(
142 (error) =>
143 // The host summary already explains a missing Android SDK; the hub's failed probes are noise.
@@ -155,10 +180,14 @@ export const makeDeviceHubOperations = (options: {
180 }
181 }
182 }
183 + const simulatorsUnlisted =
184 + hubList.simulators.length === 0 &&
185 + (hubList.errors ?? []).some((error) => SIMULATOR_LIST_FAILED.test(error.message));
186 return {
187 devices,
188 detail: details.join("\n") || undefined,
189 androidDiscoveryIncomplete,
190 + ...(simulatorsUnlisted ? { incompletePlatforms: ["ios"] as const } : {}),
191 };
192 }).pipe(Effect.withSpan("DeviceHubOperations.list"));
193
apps/server/src/device/DeviceMultiHost.test.ts
+1 -1
@@ -52,7 +52,7 @@ it.effect("keeps hosts independent when serials collide and another host fails",
52 origin: `http://${id}`,
53 http,
54 run,
55 - androidAvailable: Effect.succeed(true),
55 + platformAvailable: () => Effect.succeed(true),
56 }),
57 agentDevice: { baseUrl: `http://${id}`, token: "test", entryPath: "/agent-device" },
58 releaseAgentSession: releaseAgentDeviceSession(http, {
apps/server/src/device/DeviceService.test.ts
+112 -6
@@ -29,6 +29,7 @@ import * as Ref from "effect/Ref";
29 import * as Schema from "effect/Schema";
30 import * as Sink from "effect/Sink";
31 import * as Stream from "effect/Stream";
32 +import * as TestClock from "effect/testing/TestClock";
33 import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
34 import { HttpClient, HttpClientResponse } from "effect/http";
35 import * as ServerConfig from "../config.ts";
@@ -59,7 +60,7 @@ it.effect.each([400, 500])(
60 ),
61 ),
62 run: () => Effect.die("Screenshot does not run a command"),
62 - androidAvailable: Effect.succeed(false),
63 + platformAvailable: () => Effect.succeed(false),
64 });
65 const result = yield* operations
66 .screenshot({
@@ -103,7 +104,9 @@ const fixture = Effect.fn("fixture")(function* (
104 const devices: Array<Omit<DeviceSummary, "hostId">> = [];
105 const discoveryErrors = yield* Ref.make<Array<{ message: string; error?: string }>>([]);
106 const androidAvailable = yield* Ref.make(true);
107 + const iosAvailable = yield* Ref.make(true);
108 const encoderResult = yield* Ref.make({ code: 0, stdout: " V....D libx264", stderr: "" });
109 + const listing = { hangs: false, requested: yield* Deferred.make<void>() };
110 let booted = false;
111 let shutDown = false;
112 const connection = { online: true, kind: "local" as "local" | "ssh", failShutdown: false };
@@ -168,6 +171,11 @@ const fixture = Effect.fn("fixture")(function* (
171 if (request.url.endsWith("/grid/api/start")) {
172 return HttpClientResponse.fromWeb(request, Response.json({ ok: true }));
173 }
174 + if (listing.hangs) {
175 + return yield* Deferred.succeed(listing.requested, undefined).pipe(
176 + Effect.andThen(Effect.never),
177 + );
178 + }
179 return HttpClientResponse.fromWeb(
180 request,
181 Response.json({
@@ -205,7 +213,8 @@ const fixture = Effect.fn("fixture")(function* (
213 origin: "http://device.test",
214 http,
215 run,
208 - androidAvailable: Ref.get(androidAvailable),
216 + platformAvailable: (platform) =>
217 + Ref.get(platform === "ios" ? iosAvailable : androidAvailable),
218 }),
219 ...(options.endsDevices ? { endsDevices: true } : {}),
220 },
@@ -330,6 +339,8 @@ const fixture = Effect.fn("fixture")(function* (
339 encoderResult,
340 discoveryErrors,
341 androidAvailable,
342 + iosAvailable,
343 + listing,
344 endDevice,
345 };
346 });
@@ -829,6 +840,101 @@ it.effect("keeps the cause from the hub's error in discovery warnings, without t
840 }).pipe(Effect.scoped),
841 );
842
843 +it.effect(
844 + "keeps the last simulators while simctl cannot list them, and drops them once it can",
845 + () =>
846 + Effect.gen(function* () {
847 + const { service, devices, discoveryErrors } = yield* fixture();
848 + const simulator = {
849 + id: DeviceId.make("iphone"),
850 + name: "iPhone",
851 + platform: "ios",
852 + version: "iOS 26",
853 + booted: true,
854 + physical: false,
855 + } as const;
856 + devices.push(simulator, { ...simulator, id: DeviceId.make("pixel"), platform: "android" });
857 + yield* service.configure({ enabled: true, agentAccessEnabled: true });
858 + yield* service.agentReadinessIfSupported();
859 + devices.length = 0;
860 + yield* Ref.set(discoveryErrors, [{ message: simctlMessage }]);
861 + const failed = yield* service.list;
862 + expect(failed.devices.map((device) => device.id)).toEqual(["iphone", "Pixel_API_35"]);
863 + expect(failed.hostStatuses.local).toEqual({
864 + status: "ready",
865 + detail: simctlMessage,
866 + incompletePlatforms: ["ios"],
867 + });
868 + yield* service.agentReadinessIfSupported();
869 + expect((yield* service.state).hostStatuses.local).toEqual(failed.hostStatuses.local);
870 + yield* Ref.set(discoveryErrors, []);
871 + const recovered = yield* service.list;
872 + expect(recovered.devices.map((device) => device.id)).toEqual(["Pixel_API_35"]);
873 + expect(recovered.hostStatuses.local).toEqual({ status: "ready" });
874 + }).pipe(Effect.scoped),
875 +);
876 +
877 +it.effect.each([
878 + {
879 + ios: true,
880 + android: true,
881 + incompletePlatforms: ["ios", "android"],
882 + kept: ["iphone", "Pixel_API_35"],
883 + },
884 + { ios: true, android: false, incompletePlatforms: ["ios"], kept: ["iphone"] },
885 + { ios: false, android: true, incompletePlatforms: ["android"], kept: ["Pixel_API_35"] },
886 +] as const)(
887 + "keeps the devices of listable platforms when the hub does not answer within 40 seconds (iOS: $ios, Android SDK: $android)",
888 + ({ ios, android, incompletePlatforms, kept }) =>
889 + Effect.gen(function* () {
890 + const { service, devices, listing, androidAvailable, iosAvailable } = yield* fixture();
891 + yield* Ref.set(androidAvailable, android);
892 + yield* Ref.set(iosAvailable, ios);
893 + devices.push({
894 + id: DeviceId.make("iphone"),
895 + name: "iPhone",
896 + platform: "ios",
897 + version: "iOS 26",
898 + booted: true,
899 + physical: false,
900 + });
901 + yield* service.configure({ enabled: true });
902 + listing.hangs = true;
903 + const listed = yield* service.list.pipe(Effect.forkScoped);
904 + yield* Deferred.await(listing.requested);
905 + yield* TestClock.adjust("40 seconds");
906 + const timedOut = yield* Fiber.join(listed);
907 + expect(timedOut.devices.map((device) => device.id)).toEqual(kept);
908 + expect(timedOut.hostStatuses.local).toEqual({
909 + status: "ready",
910 + detail: "The device hub did not answer within 40 seconds.",
911 + incompletePlatforms,
912 + });
913 + }).pipe(Effect.scoped),
914 +);
915 +
916 +it.effect("does not open a retained pre-boot entry when the post-boot listing is incomplete", () =>
917 + Effect.gen(function* () {
918 + const afterBoot = { run: Effect.void as Effect.Effect<void> };
919 + const android = yield* fixture(Effect.suspend(() => afterBoot.run));
920 + afterBoot.run = Effect.sync(() => {
921 + android.listing.hangs = true;
922 + });
923 + yield* android.service.configure({ enabled: true });
924 + const opening = yield* android.service
925 + .open({
926 + threadId: ThreadId.make("boot-timeout"),
927 + deviceId: "Pixel_API_35",
928 + platform: "android",
929 + })
930 + .pipe(Effect.flip, Effect.forkScoped);
931 + yield* Deferred.await(android.listing.requested);
932 + yield* TestClock.adjust("40 seconds");
933 + expect((yield* Fiber.join(opening))._tag).toBe("DeviceNotFoundError");
934 + expect((yield* android.service.state).sessions).toEqual([]);
935 + }).pipe(Effect.scoped),
936 +);
937 +
938 it.effect.each([
939 {
940 diagnostic: "Insufficient disk space at /private/user/path",
@@ -964,7 +1070,7 @@ it.effect.each(["shutdown", "close"] as const)(
1070 origin: "http://device.test",
1071 http,
1072 run,
967 - androidAvailable: Effect.succeed(true),
1073 + platformAvailable: () => Effect.succeed(true),
1074 }),
1075 helpers: { serveSimAxSettings: null, serveSimCli: null },
1076 run,
@@ -1126,7 +1232,7 @@ it.effect("leaves a session its host leases to every thread open when one thread
1232 origin: "http://device.test",
1233 http,
1234 run,
1129 - androidAvailable: Effect.succeed(true),
1235 + platformAvailable: () => Effect.succeed(true),
1236 }),
1237 agentEndpoint: () =>
1238 Effect.succeed({
@@ -1248,7 +1354,7 @@ it.effect.each([
1354 origin: "http://device.test",
1355 http,
1356 run,
1251 - androidAvailable: Effect.succeed(true),
1357 + platformAvailable: () => Effect.succeed(true),
1358 }),
1359 helpers: { serveSimAxSettings: null, serveSimCli: null },
1360 run,
@@ -1320,7 +1426,7 @@ it.effect.each([LOCAL_DEVICE_HOST_ID, "ssh-fixture"])(
1426 origin: "http://device.test",
1427 http,
1428 run,
1323 - androidAvailable: Effect.succeed(true),
1429 + platformAvailable: () => Effect.succeed(true),
1430 }),
1431 helpers: { serveSimAxSettings: null, serveSimCli: null },
1432 run,
apps/server/src/device/DeviceService.ts
+48 -19
@@ -390,6 +390,9 @@ export const makeWithHosts = Effect.fn("DeviceService.makeWithHosts")(function*
390 return host;
391 });
392
393 + // Readiness phases replace the shown detail; this restores an incomplete listing's cause once ready.
394 + const discoveryDetails = new Map<DeviceHostId, string>();
395 +
396 const setHostStatus = (
397 hostId: DeviceHostId,
398 status: DeviceServiceState["hostStatuses"][string],
@@ -397,21 +400,34 @@ export const makeWithHosts = Effect.fn("DeviceService.makeWithHosts")(function*
400 Effect.suspend(() =>
401 !hosts.has(hostId)
402 ? SynchronizedRef.get(stateRef).pipe(Effect.map(({ state }) => state))
400 - : publish((state) => ({
401 - ...state,
402 - ...(hostId === LOCAL_DEVICE_HOST_ID
403 - ? { hostStatus: status.status, hostStatusDetail: status.detail }
404 - : {}),
405 - hostStatuses: {
406 - ...state.hostStatuses,
407 - [hostId]: {
408 - ...(state.hostStatuses[hostId]?.androidDiscoveryIncomplete
409 - ? { androidDiscoveryIncomplete: true }
410 - : {}),
411 - ...status,
403 + : publish((state) => {
404 + const previous = state.hostStatuses[hostId];
405 + const detail =
406 + status.detail ??
407 + (status.status === "ready" &&
408 + (previous?.incompletePlatforms || previous?.androidDiscoveryIncomplete)
409 + ? discoveryDetails.get(hostId)
410 + : undefined);
411 + return {
412 + ...state,
413 + ...(hostId === LOCAL_DEVICE_HOST_ID
414 + ? { hostStatus: status.status, hostStatusDetail: detail }
415 + : {}),
416 + hostStatuses: {
417 + ...state.hostStatuses,
418 + [hostId]: {
419 + ...(previous?.androidDiscoveryIncomplete
420 + ? { androidDiscoveryIncomplete: true }
421 + : {}),
422 + ...(previous?.incompletePlatforms
423 + ? { incompletePlatforms: previous.incompletePlatforms }
424 + : {}),
425 + ...status,
426 + ...(detail ? { detail } : {}),
427 + },
428 },
413 - },
414 - })),
429 + };
430 + }),
431 );
432
433 const readiness: DeviceService["Service"]["readiness"] = Effect.fn("DeviceService.readiness")(
@@ -536,11 +552,13 @@ export const makeWithHosts = Effect.fn("DeviceService.makeWithHosts")(function*
552 );
553
554 const fetchDevices = Effect.fn("DeviceService.fetchDevices")(function* (ready: DeviceReadiness) {
539 - const { devices, detail, androidDiscoveryIncomplete } = yield* ready.devices.list;
555 + const { devices, detail, androidDiscoveryIncomplete, incompletePlatforms } =
556 + yield* ready.devices.list;
557 return {
558 devices: devices.map((device): DeviceSummary => ({ ...device, hostId: ready.hostId })),
559 detail,
560 androidDiscoveryIncomplete,
561 + incompletePlatforms: incompletePlatforms ?? [],
562 };
563 });
564
@@ -551,19 +569,26 @@ export const makeWithHosts = Effect.fn("DeviceService.makeWithHosts")(function*
569 const sessionKey = (session: DeviceSession) =>
570 `${session.hostId}\u0000${session.deviceId}\u0000${session.threadId}\u0000${session.openedAt}`;
571 const before = new Set((yield* SynchronizedRef.get(stateRef)).state.sessions.map(sessionKey));
554 - const { devices, detail, androidDiscoveryIncomplete } = yield* fetchDevices(ready);
572 + const { devices, detail, androidDiscoveryIncomplete, incompletePlatforms } =
573 + yield* fetchDevices(ready);
574 const hostSummaries = yield* Effect.forEach(hosts.values(), (host) => host.summary);
575 return yield* lifecycleLock.withPermit(
576 Effect.gen(function* () {
577 if (!(yield* readDeviceSettings).enabled || !host || hosts.get(ready.hostId) !== host)
578 return (yield* SynchronizedRef.get(stateRef)).state;
579 + if (detail && (incompletePlatforms.length > 0 || androidDiscoveryIncomplete))
580 + discoveryDetails.set(ready.hostId, detail);
581 + else discoveryDetails.delete(ready.hostId);
582 return yield* publish((state) => ({
583 ...state,
584 hosts: hostSummaries,
585 ...(ready.hostId === LOCAL_DEVICE_HOST_ID ? { hostStatusDetail: detail } : {}),
586 devices: [
565 - ...state.devices.filter((device) => device.hostId !== ready.hostId),
566 - ...devices,
587 + ...state.devices.filter(
588 + (device) =>
589 + device.hostId !== ready.hostId || incompletePlatforms.includes(device.platform),
590 + ),
591 + ...devices.filter((device) => !incompletePlatforms.includes(device.platform)),
592 ],
593 // A host that ends devices itself (EAS stops sessions at their limits)
594 // leaves sessions on devices it no longer lists with nothing to stream.
@@ -582,6 +607,7 @@ export const makeWithHosts = Effect.fn("DeviceService.makeWithHosts")(function*
607 status: "ready",
608 ...(detail ? { detail } : {}),
609 ...(androidDiscoveryIncomplete ? { androidDiscoveryIncomplete } : {}),
610 + ...(incompletePlatforms.length > 0 ? { incompletePlatforms } : {}),
611 },
612 },
613 }));
@@ -795,7 +821,10 @@ export const makeWithHosts = Effect.fn("DeviceService.makeWithHosts")(function*
821 ),
822 );
823 state = yield* refresh(ready);
798 - device = findDevice(state, host.id, bootedId) ?? findDevice(state, host.id, device.id);
824 + // Retained entries predate the boot, so only a complete listing confirms the booted device.
825 + device = state.hostStatuses[host.id]?.incompletePlatforms?.includes(device.platform)
826 + ? undefined
827 + : (findDevice(state, host.id, bootedId) ?? findDevice(state, host.id, device.id));
828 if (!device) {
829 return yield* new DeviceNotFoundError({ hostId: host.id, deviceId: bootedId });
830 }
apps/server/src/device/LocalDeviceHost.ts
+2 -3
@@ -823,9 +823,8 @@ export const make = Effect.fn("LocalDeviceHost.make")(function* () {
823 origin: running.hub.origin,
824 http: httpClient,
825 run,
826 - androidAvailable: platformAvailability("android").pipe(
827 - Effect.map((availability) => availability.available),
828 - ),
826 + platformAvailable: (platform) =>
827 + platformAvailability(platform).pipe(Effect.map((availability) => availability.available)),
828 }),
829 nodePath: running.hub.nodePath,
830 run,
apps/server/src/device/SshDeviceHost.ts
+9 -8
@@ -379,14 +379,15 @@ export const make = Effect.fn("SshDeviceHost.make")(function* (
379 origin: hubOrigin,
380 http,
381 run,
382 - // Keep probing negative reports so an SDK installed after connecting is still found.
383 - androidAvailable: Effect.suspend(() =>
384 - summary.platforms.some((p) => p.platform === "android" && p.available)
385 - ? Effect.succeed(true)
386 - : platformAvailability("android").pipe(
387 - Effect.map((availability) => availability.available),
388 - ),
389 - ),
382 + // Keep probing negative reports so tooling installed after connecting is still found.
383 + platformAvailable: (platform) =>
384 + Effect.suspend(() =>
385 + summary.platforms.some((p) => p.platform === platform && p.available)
386 + ? Effect.succeed(true)
387 + : platformAvailability(platform).pipe(
388 + Effect.map((availability) => availability.available),
389 + ),
390 + ),
391 }),
392 ...(remote.daemonPort !== undefined &&
393 remote.token !== undefined &&
apps/web/src/components/device/DevicePanel.browser.test.tsx
+21
@@ -213,3 +213,24 @@ describe("DevicePanel host probe", () => {
213 ]);
214 });
215 });
216 +
217 +describe("DevicePanel discovery warning", () => {
218 + it("a dismissal hides only the cause it was made for", async () => {
219 + setup();
220 + const withCause = (detail: string): DeviceServiceState => ({
221 + ...deviceState,
222 + hostStatuses: { local: { status: "ready", detail, incompletePlatforms: ["ios"] } },
223 + });
224 + const warning = "iOS list on This Mac may be incomplete.";
225 + currentState = withCause("first cause");
226 + await using screen = await render(devicePanel(threadA), { container });
227 +
228 + await screen.getByRole("button", { name: "Dismiss device warning for This Mac" }).click();
229 + await screen.rerender(devicePanel(threadA));
230 + await expect.element(screen.getByText(warning)).not.toBeInTheDocument();
231 +
232 + currentState = withCause("second cause");
233 + await screen.rerender(devicePanel(threadA));
234 + await expect.element(screen.getByText(warning)).toBeVisible();
235 + });
236 +});
apps/web/src/components/device/DevicePanel.tsx
+91 -25
@@ -18,6 +18,7 @@ import {
18 import { Button } from "~/components/ui/button";
19 import { DiscoveryList } from "~/components/ui/discovery-list";
20 import { Dialog } from "~/components/ui/dialog";
21 +import { Popover, PopoverPopup, PopoverTrigger } from "~/components/ui/popover";
22 import { WizardPopup } from "~/components/ui/wizard";
23 import { Spinner } from "~/components/ui/spinner";
24 import { cn } from "~/lib/utils";
@@ -31,7 +32,12 @@ import {
32 import { formatEnvironmentQueryError } from "~/state/query";
33 import { useAtomCommand } from "~/state/use-atom-command";
34 import { DeviceLoadingView } from "./DeviceLoadingView";
34 -import { DeviceSetup, deviceHubReadiness, isAndroidDiscoveryUncertain } from "./DeviceSetup";
35 +import {
36 + DeviceSetup,
37 + deviceHubReadiness,
38 + incompleteListings,
39 + isAndroidDiscoveryUncertain,
40 +} from "./DeviceSetup";
41 import { DeviceWorkspace } from "./DeviceWorkspace";
42 import { PreviewPanelShell, type PreviewPanelMode } from "../preview/PreviewPanelShell";
43
@@ -178,7 +184,14 @@ export function DevicePanel(props: {
184 const status = state.hostStatuses[host.id];
185 const detail = status?.detail ?? (host.kind === "local" ? state.hostStatusDetail : undefined);
186 return detail && (status?.status ?? state.hostStatus) === "ready"
181 - ? [{ hostId: host.id, label: host.label, detail }]
187 + ? [
188 + {
189 + hostId: host.id,
190 + label: host.label,
191 + detail,
192 + incompletePlatforms: incompleteListings(status),
193 + },
194 + ]
195 : [];
196 });
197 const unavailablePlatforms = state.hosts.flatMap((host) =>
@@ -214,9 +227,11 @@ export function DevicePanel(props: {
227 <div hidden={!!activeDevice}>
228 {diagnostics.map((diagnostic) => (
229 <DeviceDiscoveryWarning
217 - key={`${environmentId}\u0000${diagnostic.hostId}\u0000${diagnostic.detail}`}
230 + key={`${environmentId}\u0000${diagnostic.hostId}`}
231 label={diagnostic.label}
232 detail={diagnostic.detail}
233 + incompletePlatforms={diagnostic.incompletePlatforms}
234 + onRetry={() => list({ environmentId, input: {} })}
235 />
236 ))}
237 </div>
@@ -228,9 +243,7 @@ export function DevicePanel(props: {
243 </div>
244 ) : null}
245 {operationError ? (
231 - <DeviceNotice tone="error" onDismiss={() => setOperation(null)}>
232 - {operationError}
233 - </DeviceNotice>
246 + <DeviceNotice onDismiss={() => setOperation(null)}>{operationError}</DeviceNotice>
247 ) : null}
248 </div>
249 <div className="@container relative flex min-h-0 flex-1">
@@ -373,20 +386,11 @@ export function DevicePanel(props: {
386 );
387 }
388
376 -function DeviceNotice(props: {
377 - readonly tone: "warning" | "error";
378 - readonly onDismiss: () => void;
379 - readonly children: ReactNode;
380 -}) {
389 +function DeviceNotice(props: { readonly onDismiss: () => void; readonly children: ReactNode }) {
390 return (
391 <div
392 role="alert"
384 - className={cn(
385 - "flex items-start gap-2 border-b px-3 py-2 text-xs",
386 - props.tone === "warning"
387 - ? "bg-warning-surface text-warning-foreground"
388 - : "bg-destructive/5 text-destructive",
389 - )}
393 + className="flex items-start gap-2 border-b bg-destructive/5 px-3 py-2 text-xs text-destructive"
394 >
395 <CircleAlert className="mt-1 size-3.5 shrink-0" />
396 <div
@@ -398,7 +402,7 @@ function DeviceNotice(props: {
402 <Button
403 size="icon-xs"
404 variant="ghost"
401 - aria-label={props.tone === "warning" ? "Dismiss device warning" : "Dismiss device error"}
405 + aria-label="Dismiss device error"
406 onClick={props.onDismiss}
407 >
408 <X />
@@ -407,14 +411,76 @@ function DeviceNotice(props: {
411 );
412 }
413
410 -function DeviceDiscoveryWarning(props: { readonly label: string; readonly detail: string }) {
411 - const [dismissed, setDismissed] = useState(false);
412 - if (dismissed) return null;
414 +function DeviceDiscoveryWarning(props: {
415 + readonly label: string;
416 + readonly detail: string;
417 + readonly incompletePlatforms: readonly DevicePlatform[];
418 + readonly onRetry: () => Promise<unknown>;
419 +}) {
420 + const [open, setOpen] = useState(false);
421 + const [retrying, setRetrying] = useState(false);
422 + const [dismissedCause, setDismissedCause] = useState<string | null>(null);
423 + const cause = `${props.incompletePlatforms.join()}\u0000${props.detail}`;
424 + // A dismissal hides one occurrence; a cause that returns later shows again.
425 + if (dismissedCause !== null && dismissedCause !== cause) setDismissedCause(null);
426 + if (dismissedCause === cause) return null;
427 + const platforms = props.incompletePlatforms.map((platform) =>
428 + platform === "ios" ? "iOS" : "Android",
429 + );
430 return (
414 - <DeviceNotice tone="warning" onDismiss={() => setDismissed(true)}>
415 - <p className="font-medium">Device discovery warning · {props.label}</p>
416 - {props.detail}
417 - </DeviceNotice>
431 + <div
432 + role="status"
433 + className="flex flex-wrap items-center gap-x-2 gap-y-0.5 border-b px-3 py-1 text-xs text-muted-foreground"
434 + >
435 + <span className="flex min-w-0 flex-1 basis-56 items-start gap-2">
436 + <CircleAlert className="mt-px size-3.5 shrink-0 text-warning-foreground" />
437 + <span className="min-w-0">
438 + {platforms.length > 0
439 + ? `${platforms.join(" and ")} ${platforms.length > 1 ? "lists" : "list"} on ${props.label} may be incomplete.`
440 + : `Device discovery on ${props.label} reported a warning.`}
441 + </span>
442 + </span>
443 + <span className="ml-auto flex shrink-0 items-center gap-0.5">
444 + {platforms.length > 0 ? (
445 + <Button
446 + size="micro"
447 + variant="ghost"
448 + disabled={retrying}
449 + aria-label={`Retry device discovery on ${props.label}`}
450 + onClick={() => {
451 + setRetrying(true);
452 + void props.onRetry().finally(() => setRetrying(false));
453 + }}
454 + >
455 + {retrying ? "Retrying…" : "Retry"}
456 + </Button>
457 + ) : null}
458 + <Popover open={open} onOpenChange={setOpen}>
459 + <PopoverTrigger
460 + aria-label={`Details for ${props.label}`}
461 + render={<Button size="micro" variant="ghost" />}
462 + >
463 + Details
464 + </PopoverTrigger>
465 + <PopoverPopup side="bottom" align="end" width="lg" padding="compact">
466 + <p className="whitespace-pre-wrap break-words font-mono text-xs text-muted-foreground">
467 + {props.detail}
468 + </p>
469 + </PopoverPopup>
470 + </Popover>
471 + <Button
472 + size="icon-micro"
473 + variant="ghost"
474 + aria-label={`Dismiss device warning for ${props.label}`}
475 + onClick={() => {
476 + setOpen(false);
477 + setDismissedCause(cause);
478 + }}
479 + >
480 + <X />
481 + </Button>
482 + </span>
483 + </div>
484 );
485 }
486
apps/web/src/components/device/DeviceSetup.test.ts
+7 -1
@@ -29,7 +29,7 @@ const deviceState = (overrides: Partial<DeviceServiceState> = {}): DeviceService
29 });
30
31 describe("device setup guidance", () => {
32 - it("waits for complete Android discovery before advising creation of an AVD", () => {
32 + it("waits for complete discovery before advising device setup", () => {
33 const state = deviceState({
34 hostStatus: "idle",
35 hosts: [{ ...deviceState().hosts[0]!, id: "remote", kind: "ssh" }],
@@ -41,6 +41,12 @@ describe("device setup guidance", () => {
41 platformSetupStatus({ ...state, hostStatuses: { remote: { status: "ready" } } }, "android")
42 .message,
43 ).toContain("Device Manager");
44 + expect(
45 + platformSetupStatus(
46 + { ...state, hostStatuses: { remote: { status: "ready", incompletePlatforms: ["ios"] } } },
47 + "ios",
48 + ).message,
49 + ).toContain("discovery reported a problem");
50 });
51
52 it("counts a remote device host when this machine has no simulator tooling", () => {
apps/web/src/components/device/DeviceSetup.tsx
+23 -2
@@ -24,9 +24,20 @@ const deviceHubDescription =
24 const agentDeviceDescription =
25 "Allow new agent sessions in this environment to start and control local and remote devices, with required tools set up automatically.";
26
27 +/** Platforms whose latest listing on a ready host may be missing devices. */
28 +export const incompleteListings = (
29 + status: DeviceServiceState["hostStatuses"][string] | undefined,
30 +) =>
31 + (["ios", "android"] as const).filter(
32 + (platform) =>
33 + status?.status === "ready" &&
34 + (status.incompletePlatforms?.includes(platform) ||
35 + (platform === "android" && status.androidDiscoveryIncomplete === true)),
36 + );
37 +
38 export const isAndroidDiscoveryUncertain = (state: DeviceServiceState) =>
28 - Object.values(state.hostStatuses).some(
29 - (status) => status.status === "ready" && status.androidDiscoveryIncomplete,
39 + Object.values(state.hostStatuses).some((status) =>
40 + incompleteListings(status).includes("android"),
41 );
42
43 /**
@@ -103,6 +114,16 @@ export function platformSetupStatus(state: DeviceServiceState, platform: DeviceP
114 (host.kind === "local" && state.hostStatus === "ready"),
115 );
116 if (readyHosts.length > 0 && !hasDevices) {
117 + if (
118 + readyHosts.some((host) =>
119 + state.hostStatuses[host.id]?.incompletePlatforms?.includes(platform),
120 + )
121 + ) {
122 + return {
123 + ready: false,
124 + message: `No ${platformName(platform)} devices were listed because device discovery reported a problem.`,
125 + };
126 + }
127 return {
128 ready: false,
129 message:
apps/web/src/components/settings/DeviceSourcesSettings.tsx
+18 -5
@@ -28,6 +28,7 @@ import { Menu, MenuItem, MenuPopup, MenuTrigger } from "../ui/menu";
28 import { Popover, PopoverPopup, PopoverTrigger } from "../ui/popover";
29 import { Spinner } from "../ui/spinner";
30 import { toastManager } from "../ui/toast";
31 +import { incompleteListings } from "../device/DeviceSetup";
32 import { DeviceHostEditor } from "./DeviceHostEditor";
33 import { updateDeviceHosts, groupDeviceHosts } from "./deviceHostsSettings.logic";
34 import { EasDeviceHostEditor } from "./EasDeviceHostEditor";
@@ -115,10 +116,12 @@ function hostStatus(
116 if (!state) return { tone: "pending", label: "Loading" };
117 const status = state.hostStatuses[hostId];
118 switch (status?.status) {
118 - case "ready":
119 - return status.androidDiscoveryIncomplete
120 - ? { tone: "warning", label: "Android list may be incomplete", detail: status.detail }
121 - : undefined;
119 + case "ready": {
120 + const incomplete = incompleteListings(status);
121 + if (incomplete.length === 0) return undefined;
122 + const list = incomplete.length > 1 ? "Device" : incomplete[0] === "ios" ? "iOS" : "Android";
123 + return { tone: "warning", label: `${list} list may be incomplete`, detail: status.detail };
124 + }
125 case "installing":
126 case "starting":
127 return { tone: "pending", label: "Starting", detail: status.detail };
@@ -771,10 +774,20 @@ function DeviceSourceRow(props: { row: SourceRow }) {
774 >
775 <span className="min-w-0 break-words">
776 {several ? `${environment.label}: ` : ""}
774 - {!several && environment.status.detail
777 + {environment.status.tone === "error" && !several && environment.status.detail
778 ? environment.status.detail
779 : environment.status.label}
780 </span>
781 + {environment.status.tone === "warning" && environment.status.detail ? (
782 + <Popover>
783 + <PopoverTrigger render={<InlineButton />}>Details</PopoverTrigger>
784 + <PopoverPopup side="bottom" align="start" width="lg" padding="compact">
785 + <p className="whitespace-pre-wrap break-words font-mono text-xs text-muted-foreground">
786 + {environment.status.detail}
787 + </p>
788 + </PopoverPopup>
789 + </Popover>
790 + ) : null}
791 {environment.status.action ? (
792 <InlineButton onClick={environment.status.action.run}>
793 {environment.status.action.label}
packages/contracts/src/device.ts
+1
@@ -256,6 +256,7 @@ export const DeviceHostStatuses = Schema.Record(
256 status: DeviceHostStatus,
257 detail: Schema.optional(Schema.String),
258 androidDiscoveryIncomplete: Schema.optional(Schema.Boolean),
259 + incompletePlatforms: Schema.optional(Schema.Array(DevicePlatform)),
260 }),
261 );
262