Skip to content
TypeScript

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

shivam202d5b5616e3
diff --git a/apps/server/src/device/DeviceHost.ts b/apps/server/src/device/DeviceHost.ts
index 7a0962e06f1..ef0b48eefc8 100644
--- a/apps/server/src/device/DeviceHost.ts
+++ b/apps/server/src/device/DeviceHost.ts
@@ -110,6 +110,8 @@ export interface DeviceOperations {
readonly detail: string | undefined;
/** Some Android virtual devices could not be listed; the rest are. */
readonly androidDiscoveryIncomplete?: boolean;
+ /** Platforms that could not be listed; their last known devices stay listed. */
+ readonly incompletePlatforms?: ReadonlyArray<DevicePlatform>;
},
DeviceOperationError
>;
diff --git a/apps/server/src/device/DeviceHubOperations.ts b/apps/server/src/device/DeviceHubOperations.ts
index 772b6266194..2725e7ac4fe 100644
--- a/apps/server/src/device/DeviceHubOperations.ts
+++ b/apps/server/src/device/DeviceHubOperations.ts
@@ -6,6 +6,7 @@ import {
} from "@t3tools/contracts";
import * as Duration from "effect/Duration";
import * as Effect from "effect/Effect";
+import * as Option from "effect/Option";
import * as Schema from "effect/Schema";
import { HttpClient, HttpClientError, HttpClientRequest, HttpClientResponse } from "effect/http";
@@ -13,6 +14,11 @@ import type { DeviceHostReady, DeviceOperations, HostDevice } from "./DeviceHost
const BOOT_TIMEOUT = Duration.minutes(3);
const SCREENSHOT_TIMEOUT = Duration.seconds(20);
+// Let the hub's 30 s simctl timeout report its cause first.
+const LIST_TIMEOUT_SECONDS = 40;
+// expo-device-hub 0.19.1 reports a failed simulator listing only as text; its error ids are hashes.
+const SIMULATOR_LIST_FAILED =
+ /^\[apple-utils\] (?:Failed to (?:run `xcrun simctl list devices|parse JSON output:|list devices:)|`xcrun simctl list devices --json` did not respond within )/;
const HubDevice = Schema.Struct({
id: Schema.String,
@@ -63,30 +69,35 @@ export const makeDeviceHubOperations = (options: {
readonly origin: string;
readonly http: HttpClient.HttpClient;
readonly run: DeviceHostReady["run"];
- /** Whether to list AVDs, which the hub does not report until they boot. */
- readonly androidAvailable: Effect.Effect<boolean>;
+ /** Android gates listing AVDs, which the hub does not report until they boot. */
+ readonly platformAvailable: (platform: DevicePlatform) => Effect.Effect<boolean>;
}): DeviceOperations => {
const { hostId, origin, run } = options;
const httpClient = options.http.pipe(HttpClient.withScope);
+ const fetchJson = Effect.fn("DeviceHubOperations.fetchJson")(function* <A, I>(
+ request: HttpClientRequest.HttpClientRequest,
+ schema: Schema.Codec<A, I>,
+ ) {
+ return yield* httpClient
+ .execute(request)
+ .pipe(
+ Effect.flatMap(HttpClientResponse.filterStatusOk),
+ Effect.flatMap(HttpClientResponse.schemaBodyJson(schema)),
+ Effect.scoped,
+ );
+ });
+
const hubJson = <A, I>(
request: HttpClientRequest.HttpClientRequest,
schema: Schema.Codec<A, I>,
operation: string,
timeout: Duration.Input = Duration.seconds(15),
) =>
- httpClient.execute(request).pipe(
- Effect.flatMap(HttpClientResponse.filterStatusOk),
- Effect.flatMap(HttpClientResponse.schemaBodyJson(schema)),
- Effect.scoped,
+ fetchJson(request, schema).pipe(
Effect.timeout(timeout),
Effect.mapError(
- (cause) =>
- new DeviceOperationError({
- operation,
- reason: "request_failed",
- cause,
- }),
+ (cause) => new DeviceOperationError({ operation, reason: "request_failed", cause }),
),
);
@@ -106,13 +117,27 @@ export const makeDeviceHubOperations = (options: {
);
const list: DeviceOperations["list"] = Effect.gen(function* () {
- const hubList = yield* hubJson(
+ const listed = yield* fetchJson(
HttpClientRequest.get(`${origin}/api/devices`),
HubDeviceList,
- "list",
+ ).pipe(
+ Effect.mapError(
+ (cause) => new DeviceOperationError({ operation: "list", reason: "request_failed", cause }),
+ ),
+ Effect.timeoutOption(Duration.seconds(LIST_TIMEOUT_SECONDS)),
);
+ if (Option.isNone(listed)) {
+ return {
+ devices: [],
+ detail: `The device hub did not answer within ${LIST_TIMEOUT_SECONDS} seconds.`,
+ incompletePlatforms: yield* Effect.filter(["ios", "android"] as const, (platform) =>
+ options.platformAvailable(platform),
+ ),
+ };
+ }
+ const hubList = listed.value;
const devices: Array<HostDevice> = [...hubList.simulators, ...hubList.emulators];
- const androidAvailable = yield* options.androidAvailable;
+ const androidAvailable = yield* options.platformAvailable("android");
const warnings = hubList.errors?.filter(
(error) =>
// The host summary already explains a missing Android SDK; the hub's failed probes are noise.
@@ -155,10 +180,14 @@ export const makeDeviceHubOperations = (options: {
}
}
}
+ const simulatorsUnlisted =
+ hubList.simulators.length === 0 &&
+ (hubList.errors ?? []).some((error) => SIMULATOR_LIST_FAILED.test(error.message));
return {
devices,
detail: details.join("\n") || undefined,
androidDiscoveryIncomplete,
+ ...(simulatorsUnlisted ? { incompletePlatforms: ["ios"] as const } : {}),
};
}).pipe(Effect.withSpan("DeviceHubOperations.list"));
diff --git a/apps/server/src/device/DeviceMultiHost.test.ts b/apps/server/src/device/DeviceMultiHost.test.ts
index 44115303e7b..adf01a5cda5 100644
--- a/apps/server/src/device/DeviceMultiHost.test.ts
+++ b/apps/server/src/device/DeviceMultiHost.test.ts
@@ -52,7 +52,7 @@ it.effect("keeps hosts independent when serials collide and another host fails",
origin: `http://${id}`,
http,
run,
- androidAvailable: Effect.succeed(true),
+ platformAvailable: () => Effect.succeed(true),
}),
agentDevice: { baseUrl: `http://${id}`, token: "test", entryPath: "/agent-device" },
releaseAgentSession: releaseAgentDeviceSession(http, {
diff --git a/apps/server/src/device/DeviceService.test.ts b/apps/server/src/device/DeviceService.test.ts
index 9f972cd87bd..64054630f0d 100644
--- a/apps/server/src/device/DeviceService.test.ts
+++ b/apps/server/src/device/DeviceService.test.ts
@@ -29,6 +29,7 @@ import * as Ref from "effect/Ref";
import * as Schema from "effect/Schema";
import * as Sink from "effect/Sink";
import * as Stream from "effect/Stream";
+import * as TestClock from "effect/testing/TestClock";
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
import { HttpClient, HttpClientResponse } from "effect/http";
import * as ServerConfig from "../config.ts";
@@ -59,7 +60,7 @@ it.effect.each([400, 500])(
),
),
run: () => Effect.die("Screenshot does not run a command"),
- androidAvailable: Effect.succeed(false),
+ platformAvailable: () => Effect.succeed(false),
});
const result = yield* operations
.screenshot({
@@ -103,7 +104,9 @@ const fixture = Effect.fn("fixture")(function* (
const devices: Array<Omit<DeviceSummary, "hostId">> = [];
const discoveryErrors = yield* Ref.make<Array<{ message: string; error?: string }>>([]);
const androidAvailable = yield* Ref.make(true);
+ const iosAvailable = yield* Ref.make(true);
const encoderResult = yield* Ref.make({ code: 0, stdout: " V....D libx264", stderr: "" });
+ const listing = { hangs: false, requested: yield* Deferred.make<void>() };
let booted = false;
let shutDown = false;
const connection = { online: true, kind: "local" as "local" | "ssh", failShutdown: false };
@@ -168,6 +171,11 @@ const fixture = Effect.fn("fixture")(function* (
if (request.url.endsWith("/grid/api/start")) {
return HttpClientResponse.fromWeb(request, Response.json({ ok: true }));
}
+ if (listing.hangs) {
+ return yield* Deferred.succeed(listing.requested, undefined).pipe(
+ Effect.andThen(Effect.never),
+ );
+ }
return HttpClientResponse.fromWeb(
request,
Response.json({
@@ -205,7 +213,8 @@ const fixture = Effect.fn("fixture")(function* (
origin: "http://device.test",
http,
run,
- androidAvailable: Ref.get(androidAvailable),
+ platformAvailable: (platform) =>
+ Ref.get(platform === "ios" ? iosAvailable : androidAvailable),
}),
...(options.endsDevices ? { endsDevices: true } : {}),
},
@@ -330,6 +339,8 @@ const fixture = Effect.fn("fixture")(function* (
encoderResult,
discoveryErrors,
androidAvailable,
+ iosAvailable,
+ listing,
endDevice,
};
});
@@ -829,6 +840,101 @@ it.effect("keeps the cause from the hub's error in discovery warnings, without t
}).pipe(Effect.scoped),
);
+it.effect(
+ "keeps the last simulators while simctl cannot list them, and drops them once it can",
+ () =>
+ Effect.gen(function* () {
+ const { service, devices, discoveryErrors } = yield* fixture();
+ const simulator = {
+ id: DeviceId.make("iphone"),
+ name: "iPhone",
+ platform: "ios",
+ version: "iOS 26",
+ booted: true,
+ physical: false,
+ } as const;
+ devices.push(simulator, { ...simulator, id: DeviceId.make("pixel"), platform: "android" });
+ yield* service.configure({ enabled: true, agentAccessEnabled: true });
+ yield* service.agentReadinessIfSupported();
+ devices.length = 0;
+ yield* Ref.set(discoveryErrors, [{ message: simctlMessage }]);
+ const failed = yield* service.list;
+ expect(failed.devices.map((device) => device.id)).toEqual(["iphone", "Pixel_API_35"]);
+ expect(failed.hostStatuses.local).toEqual({
+ status: "ready",
+ detail: simctlMessage,
+ incompletePlatforms: ["ios"],
+ });
+ yield* service.agentReadinessIfSupported();
+ expect((yield* service.state).hostStatuses.local).toEqual(failed.hostStatuses.local);
+ yield* Ref.set(discoveryErrors, []);
+ const recovered = yield* service.list;
+ expect(recovered.devices.map((device) => device.id)).toEqual(["Pixel_API_35"]);
+ expect(recovered.hostStatuses.local).toEqual({ status: "ready" });
+ }).pipe(Effect.scoped),
+);
+
+it.effect.each([
+ {
+ ios: true,
+ android: true,
+ incompletePlatforms: ["ios", "android"],
+ kept: ["iphone", "Pixel_API_35"],
+ },
+ { ios: true, android: false, incompletePlatforms: ["ios"], kept: ["iphone"] },
+ { ios: false, android: true, incompletePlatforms: ["android"], kept: ["Pixel_API_35"] },
+] as const)(
+ "keeps the devices of listable platforms when the hub does not answer within 40 seconds (iOS: $ios, Android SDK: $android)",
+ ({ ios, android, incompletePlatforms, kept }) =>
+ Effect.gen(function* () {
+ const { service, devices, listing, androidAvailable, iosAvailable } = yield* fixture();
+ yield* Ref.set(androidAvailable, android);
+ yield* Ref.set(iosAvailable, ios);
+ devices.push({
+ id: DeviceId.make("iphone"),
+ name: "iPhone",
+ platform: "ios",
+ version: "iOS 26",
+ booted: true,
+ physical: false,
+ });
+ yield* service.configure({ enabled: true });
+ listing.hangs = true;
+ const listed = yield* service.list.pipe(Effect.forkScoped);
+ yield* Deferred.await(listing.requested);
+ yield* TestClock.adjust("40 seconds");
+ const timedOut = yield* Fiber.join(listed);
+ expect(timedOut.devices.map((device) => device.id)).toEqual(kept);
+ expect(timedOut.hostStatuses.local).toEqual({
+ status: "ready",
+ detail: "The device hub did not answer within 40 seconds.",
+ incompletePlatforms,
+ });
+ }).pipe(Effect.scoped),
+);
+
+it.effect("does not open a retained pre-boot entry when the post-boot listing is incomplete", () =>
+ Effect.gen(function* () {
+ const afterBoot = { run: Effect.void as Effect.Effect<void> };
+ const android = yield* fixture(Effect.suspend(() => afterBoot.run));
+ afterBoot.run = Effect.sync(() => {
+ android.listing.hangs = true;
+ });
+ yield* android.service.configure({ enabled: true });
+ const opening = yield* android.service
+ .open({
+ threadId: ThreadId.make("boot-timeout"),
+ deviceId: "Pixel_API_35",
+ platform: "android",
+ })
+ .pipe(Effect.flip, Effect.forkScoped);
+ yield* Deferred.await(android.listing.requested);
+ yield* TestClock.adjust("40 seconds");
+ expect((yield* Fiber.join(opening))._tag).toBe("DeviceNotFoundError");
+ expect((yield* android.service.state).sessions).toEqual([]);
+ }).pipe(Effect.scoped),
+);
+
it.effect.each([
{
diagnostic: "Insufficient disk space at /private/user/path",
@@ -964,7 +1070,7 @@ it.effect.each(["shutdown", "close"] as const)(
origin: "http://device.test",
http,
run,
- androidAvailable: Effect.succeed(true),
+ platformAvailable: () => Effect.succeed(true),
}),
helpers: { serveSimAxSettings: null, serveSimCli: null },
run,
@@ -1126,7 +1232,7 @@ it.effect("leaves a session its host leases to every thread open when one thread
origin: "http://device.test",
http,
run,
- androidAvailable: Effect.succeed(true),
+ platformAvailable: () => Effect.succeed(true),
}),
agentEndpoint: () =>
Effect.succeed({
@@ -1248,7 +1354,7 @@ it.effect.each([
origin: "http://device.test",
http,
run,
- androidAvailable: Effect.succeed(true),
+ platformAvailable: () => Effect.succeed(true),
}),
helpers: { serveSimAxSettings: null, serveSimCli: null },
run,
@@ -1320,7 +1426,7 @@ it.effect.each([LOCAL_DEVICE_HOST_ID, "ssh-fixture"])(
origin: "http://device.test",
http,
run,
- androidAvailable: Effect.succeed(true),
+ platformAvailable: () => Effect.succeed(true),
}),
helpers: { serveSimAxSettings: null, serveSimCli: null },
run,
diff --git a/apps/server/src/device/DeviceService.ts b/apps/server/src/device/DeviceService.ts
index ffe652b6a77..790daabe7a4 100644
--- a/apps/server/src/device/DeviceService.ts
+++ b/apps/server/src/device/DeviceService.ts
@@ -390,6 +390,9 @@ export const makeWithHosts = Effect.fn("DeviceService.makeWithHosts")(function*
return host;
});
+ // Readiness phases replace the shown detail; this restores an incomplete listing's cause once ready.
+ const discoveryDetails = new Map<DeviceHostId, string>();
+
const setHostStatus = (
hostId: DeviceHostId,
status: DeviceServiceState["hostStatuses"][string],
@@ -397,21 +400,34 @@ export const makeWithHosts = Effect.fn("DeviceService.makeWithHosts")(function*
Effect.suspend(() =>
!hosts.has(hostId)
? SynchronizedRef.get(stateRef).pipe(Effect.map(({ state }) => state))
- : publish((state) => ({
- ...state,
- ...(hostId === LOCAL_DEVICE_HOST_ID
- ? { hostStatus: status.status, hostStatusDetail: status.detail }
- : {}),
- hostStatuses: {
- ...state.hostStatuses,
- [hostId]: {
- ...(state.hostStatuses[hostId]?.androidDiscoveryIncomplete
- ? { androidDiscoveryIncomplete: true }
- : {}),
- ...status,
+ : publish((state) => {
+ const previous = state.hostStatuses[hostId];
+ const detail =
+ status.detail ??
+ (status.status === "ready" &&
+ (previous?.incompletePlatforms || previous?.androidDiscoveryIncomplete)
+ ? discoveryDetails.get(hostId)
+ : undefined);
+ return {
+ ...state,
+ ...(hostId === LOCAL_DEVICE_HOST_ID
+ ? { hostStatus: status.status, hostStatusDetail: detail }
+ : {}),
+ hostStatuses: {
+ ...state.hostStatuses,
+ [hostId]: {
+ ...(previous?.androidDiscoveryIncomplete
+ ? { androidDiscoveryIncomplete: true }
+ : {}),
+ ...(previous?.incompletePlatforms
+ ? { incompletePlatforms: previous.incompletePlatforms }
+ : {}),
+ ...status,
+ ...(detail ? { detail } : {}),
+ },
},
- },
- })),
+ };
+ }),
);
const readiness: DeviceService["Service"]["readiness"] = Effect.fn("DeviceService.readiness")(
@@ -536,11 +552,13 @@ export const makeWithHosts = Effect.fn("DeviceService.makeWithHosts")(function*
);
const fetchDevices = Effect.fn("DeviceService.fetchDevices")(function* (ready: DeviceReadiness) {
- const { devices, detail, androidDiscoveryIncomplete } = yield* ready.devices.list;
+ const { devices, detail, androidDiscoveryIncomplete, incompletePlatforms } =
+ yield* ready.devices.list;
return {
devices: devices.map((device): DeviceSummary => ({ ...device, hostId: ready.hostId })),
detail,
androidDiscoveryIncomplete,
+ incompletePlatforms: incompletePlatforms ?? [],
};
});
@@ -551,19 +569,26 @@ export const makeWithHosts = Effect.fn("DeviceService.makeWithHosts")(function*
const sessionKey = (session: DeviceSession) =>
`${session.hostId}\u0000${session.deviceId}\u0000${session.threadId}\u0000${session.openedAt}`;
const before = new Set((yield* SynchronizedRef.get(stateRef)).state.sessions.map(sessionKey));
- const { devices, detail, androidDiscoveryIncomplete } = yield* fetchDevices(ready);
+ const { devices, detail, androidDiscoveryIncomplete, incompletePlatforms } =
+ yield* fetchDevices(ready);
const hostSummaries = yield* Effect.forEach(hosts.values(), (host) => host.summary);
return yield* lifecycleLock.withPermit(
Effect.gen(function* () {
if (!(yield* readDeviceSettings).enabled || !host || hosts.get(ready.hostId) !== host)
return (yield* SynchronizedRef.get(stateRef)).state;
+ if (detail && (incompletePlatforms.length > 0 || androidDiscoveryIncomplete))
+ discoveryDetails.set(ready.hostId, detail);
+ else discoveryDetails.delete(ready.hostId);
return yield* publish((state) => ({
...state,
hosts: hostSummaries,
...(ready.hostId === LOCAL_DEVICE_HOST_ID ? { hostStatusDetail: detail } : {}),
devices: [
- ...state.devices.filter((device) => device.hostId !== ready.hostId),
- ...devices,
+ ...state.devices.filter(
+ (device) =>
+ device.hostId !== ready.hostId || incompletePlatforms.includes(device.platform),
+ ),
+ ...devices.filter((device) => !incompletePlatforms.includes(device.platform)),
],
// A host that ends devices itself (EAS stops sessions at their limits)
// leaves sessions on devices it no longer lists with nothing to stream.
@@ -582,6 +607,7 @@ export const makeWithHosts = Effect.fn("DeviceService.makeWithHosts")(function*
status: "ready",
...(detail ? { detail } : {}),
...(androidDiscoveryIncomplete ? { androidDiscoveryIncomplete } : {}),
+ ...(incompletePlatforms.length > 0 ? { incompletePlatforms } : {}),
},
},
}));
@@ -795,7 +821,10 @@ export const makeWithHosts = Effect.fn("DeviceService.makeWithHosts")(function*
),
);
state = yield* refresh(ready);
- device = findDevice(state, host.id, bootedId) ?? findDevice(state, host.id, device.id);
+ // Retained entries predate the boot, so only a complete listing confirms the booted device.
+ device = state.hostStatuses[host.id]?.incompletePlatforms?.includes(device.platform)
+ ? undefined
+ : (findDevice(state, host.id, bootedId) ?? findDevice(state, host.id, device.id));
if (!device) {
return yield* new DeviceNotFoundError({ hostId: host.id, deviceId: bootedId });
}
diff --git a/apps/server/src/device/LocalDeviceHost.ts b/apps/server/src/device/LocalDeviceHost.ts
index 13ad97fcec6..6643e689328 100644
--- a/apps/server/src/device/LocalDeviceHost.ts
+++ b/apps/server/src/device/LocalDeviceHost.ts
@@ -823,9 +823,8 @@ export const make = Effect.fn("LocalDeviceHost.make")(function* () {
origin: running.hub.origin,
http: httpClient,
run,
- androidAvailable: platformAvailability("android").pipe(
- Effect.map((availability) => availability.available),
- ),
+ platformAvailable: (platform) =>
+ platformAvailability(platform).pipe(Effect.map((availability) => availability.available)),
}),
nodePath: running.hub.nodePath,
run,
diff --git a/apps/server/src/device/SshDeviceHost.ts b/apps/server/src/device/SshDeviceHost.ts
index 2dd9b21f290..d769a85ddb0 100644
--- a/apps/server/src/device/SshDeviceHost.ts
+++ b/apps/server/src/device/SshDeviceHost.ts
@@ -379,14 +379,15 @@ export const make = Effect.fn("SshDeviceHost.make")(function* (
origin: hubOrigin,
http,
run,
- // Keep probing negative reports so an SDK installed after connecting is still found.
- androidAvailable: Effect.suspend(() =>
- summary.platforms.some((p) => p.platform === "android" && p.available)
- ? Effect.succeed(true)
- : platformAvailability("android").pipe(
- Effect.map((availability) => availability.available),
- ),
- ),
+ // Keep probing negative reports so tooling installed after connecting is still found.
+ platformAvailable: (platform) =>
+ Effect.suspend(() =>
+ summary.platforms.some((p) => p.platform === platform && p.available)
+ ? Effect.succeed(true)
+ : platformAvailability(platform).pipe(
+ Effect.map((availability) => availability.available),
+ ),
+ ),
}),
...(remote.daemonPort !== undefined &&
remote.token !== undefined &&
diff --git a/apps/web/src/components/device/DevicePanel.browser.test.tsx b/apps/web/src/components/device/DevicePanel.browser.test.tsx
index 8e8e0d27eb9..2212d969272 100644
--- a/apps/web/src/components/device/DevicePanel.browser.test.tsx
+++ b/apps/web/src/components/device/DevicePanel.browser.test.tsx
@@ -213,3 +213,24 @@ describe("DevicePanel host probe", () => {
]);
});
});
+
+describe("DevicePanel discovery warning", () => {
+ it("a dismissal hides only the cause it was made for", async () => {
+ setup();
+ const withCause = (detail: string): DeviceServiceState => ({
+ ...deviceState,
+ hostStatuses: { local: { status: "ready", detail, incompletePlatforms: ["ios"] } },
+ });
+ const warning = "iOS list on This Mac may be incomplete.";
+ currentState = withCause("first cause");
+ await using screen = await render(devicePanel(threadA), { container });
+
+ await screen.getByRole("button", { name: "Dismiss device warning for This Mac" }).click();
+ await screen.rerender(devicePanel(threadA));
+ await expect.element(screen.getByText(warning)).not.toBeInTheDocument();
+
+ currentState = withCause("second cause");
+ await screen.rerender(devicePanel(threadA));
+ await expect.element(screen.getByText(warning)).toBeVisible();
+ });
+});
diff --git a/apps/web/src/components/device/DevicePanel.tsx b/apps/web/src/components/device/DevicePanel.tsx
index cee7a3e4e4b..694528af3ac 100644
--- a/apps/web/src/components/device/DevicePanel.tsx
+++ b/apps/web/src/components/device/DevicePanel.tsx
@@ -18,6 +18,7 @@ import {
import { Button } from "~/components/ui/button";
import { DiscoveryList } from "~/components/ui/discovery-list";
import { Dialog } from "~/components/ui/dialog";
+import { Popover, PopoverPopup, PopoverTrigger } from "~/components/ui/popover";
import { WizardPopup } from "~/components/ui/wizard";
import { Spinner } from "~/components/ui/spinner";
import { cn } from "~/lib/utils";
@@ -31,7 +32,12 @@ import {
import { formatEnvironmentQueryError } from "~/state/query";
import { useAtomCommand } from "~/state/use-atom-command";
import { DeviceLoadingView } from "./DeviceLoadingView";
-import { DeviceSetup, deviceHubReadiness, isAndroidDiscoveryUncertain } from "./DeviceSetup";
+import {
+ DeviceSetup,
+ deviceHubReadiness,
+ incompleteListings,
+ isAndroidDiscoveryUncertain,
+} from "./DeviceSetup";
import { DeviceWorkspace } from "./DeviceWorkspace";
import { PreviewPanelShell, type PreviewPanelMode } from "../preview/PreviewPanelShell";
@@ -178,7 +184,14 @@ export function DevicePanel(props: {
const status = state.hostStatuses[host.id];
const detail = status?.detail ?? (host.kind === "local" ? state.hostStatusDetail : undefined);
return detail && (status?.status ?? state.hostStatus) === "ready"
- ? [{ hostId: host.id, label: host.label, detail }]
+ ? [
+ {
+ hostId: host.id,
+ label: host.label,
+ detail,
+ incompletePlatforms: incompleteListings(status),
+ },
+ ]
: [];
});
const unavailablePlatforms = state.hosts.flatMap((host) =>
@@ -214,9 +227,11 @@ export function DevicePanel(props: {
<div hidden={!!activeDevice}>
{diagnostics.map((diagnostic) => (
<DeviceDiscoveryWarning
- key={`${environmentId}\u0000${diagnostic.hostId}\u0000${diagnostic.detail}`}
+ key={`${environmentId}\u0000${diagnostic.hostId}`}
label={diagnostic.label}
detail={diagnostic.detail}
+ incompletePlatforms={diagnostic.incompletePlatforms}
+ onRetry={() => list({ environmentId, input: {} })}
/>
))}
</div>
@@ -228,9 +243,7 @@ export function DevicePanel(props: {
</div>
) : null}
{operationError ? (
- <DeviceNotice tone="error" onDismiss={() => setOperation(null)}>
- {operationError}
- </DeviceNotice>
+ <DeviceNotice onDismiss={() => setOperation(null)}>{operationError}</DeviceNotice>
) : null}
</div>
<div className="@container relative flex min-h-0 flex-1">
@@ -373,20 +386,11 @@ export function DevicePanel(props: {
);
}
-function DeviceNotice(props: {
- readonly tone: "warning" | "error";
- readonly onDismiss: () => void;
- readonly children: ReactNode;
-}) {
+function DeviceNotice(props: { readonly onDismiss: () => void; readonly children: ReactNode }) {
return (
<div
role="alert"
- className={cn(
- "flex items-start gap-2 border-b px-3 py-2 text-xs",
- props.tone === "warning"
- ? "bg-warning-surface text-warning-foreground"
- : "bg-destructive/5 text-destructive",
- )}
+ className="flex items-start gap-2 border-b bg-destructive/5 px-3 py-2 text-xs text-destructive"
>
<CircleAlert className="mt-1 size-3.5 shrink-0" />
<div
@@ -398,7 +402,7 @@ function DeviceNotice(props: {
<Button
size="icon-xs"
variant="ghost"
- aria-label={props.tone === "warning" ? "Dismiss device warning" : "Dismiss device error"}
+ aria-label="Dismiss device error"
onClick={props.onDismiss}
>
<X />
@@ -407,14 +411,76 @@ function DeviceNotice(props: {
);
}
-function DeviceDiscoveryWarning(props: { readonly label: string; readonly detail: string }) {
- const [dismissed, setDismissed] = useState(false);
- if (dismissed) return null;
+function DeviceDiscoveryWarning(props: {
+ readonly label: string;
+ readonly detail: string;
+ readonly incompletePlatforms: readonly DevicePlatform[];
+ readonly onRetry: () => Promise<unknown>;
+}) {
+ const [open, setOpen] = useState(false);
+ const [retrying, setRetrying] = useState(false);
+ const [dismissedCause, setDismissedCause] = useState<string | null>(null);
+ const cause = `${props.incompletePlatforms.join()}\u0000${props.detail}`;
+ // A dismissal hides one occurrence; a cause that returns later shows again.
+ if (dismissedCause !== null && dismissedCause !== cause) setDismissedCause(null);
+ if (dismissedCause === cause) return null;
+ const platforms = props.incompletePlatforms.map((platform) =>
+ platform === "ios" ? "iOS" : "Android",
+ );
return (
- <DeviceNotice tone="warning" onDismiss={() => setDismissed(true)}>
- <p className="font-medium">Device discovery warning · {props.label}</p>
- {props.detail}
- </DeviceNotice>
+ <div
+ role="status"
+ className="flex flex-wrap items-center gap-x-2 gap-y-0.5 border-b px-3 py-1 text-xs text-muted-foreground"
+ >
+ <span className="flex min-w-0 flex-1 basis-56 items-start gap-2">
+ <CircleAlert className="mt-px size-3.5 shrink-0 text-warning-foreground" />
+ <span className="min-w-0">
+ {platforms.length > 0
+ ? `${platforms.join(" and ")} ${platforms.length > 1 ? "lists" : "list"} on ${props.label} may be incomplete.`
+ : `Device discovery on ${props.label} reported a warning.`}
+ </span>
+ </span>
+ <span className="ml-auto flex shrink-0 items-center gap-0.5">
+ {platforms.length > 0 ? (
+ <Button
+ size="micro"
+ variant="ghost"
+ disabled={retrying}
+ aria-label={`Retry device discovery on ${props.label}`}
+ onClick={() => {
+ setRetrying(true);
+ void props.onRetry().finally(() => setRetrying(false));
+ }}
+ >
+ {retrying ? "Retrying…" : "Retry"}
+ </Button>
+ ) : null}
+ <Popover open={open} onOpenChange={setOpen}>
+ <PopoverTrigger
+ aria-label={`Details for ${props.label}`}
+ render={<Button size="micro" variant="ghost" />}
+ >
+ Details
+ </PopoverTrigger>
+ <PopoverPopup side="bottom" align="end" width="lg" padding="compact">
+ <p className="whitespace-pre-wrap break-words font-mono text-xs text-muted-foreground">
+ {props.detail}
+ </p>
+ </PopoverPopup>
+ </Popover>
+ <Button
+ size="icon-micro"
+ variant="ghost"
+ aria-label={`Dismiss device warning for ${props.label}`}
+ onClick={() => {
+ setOpen(false);
+ setDismissedCause(cause);
+ }}
+ >
+ <X />
+ </Button>
+ </span>
+ </div>
);
}
diff --git a/apps/web/src/components/device/DeviceSetup.test.ts b/apps/web/src/components/device/DeviceSetup.test.ts
index 322354763b8..f0158641e2a 100644
--- a/apps/web/src/components/device/DeviceSetup.test.ts
+++ b/apps/web/src/components/device/DeviceSetup.test.ts
@@ -29,7 +29,7 @@ const deviceState = (overrides: Partial<DeviceServiceState> = {}): DeviceService
});
describe("device setup guidance", () => {
- it("waits for complete Android discovery before advising creation of an AVD", () => {
+ it("waits for complete discovery before advising device setup", () => {
const state = deviceState({
hostStatus: "idle",
hosts: [{ ...deviceState().hosts[0]!, id: "remote", kind: "ssh" }],
@@ -41,6 +41,12 @@ describe("device setup guidance", () => {
platformSetupStatus({ ...state, hostStatuses: { remote: { status: "ready" } } }, "android")
.message,
).toContain("Device Manager");
+ expect(
+ platformSetupStatus(
+ { ...state, hostStatuses: { remote: { status: "ready", incompletePlatforms: ["ios"] } } },
+ "ios",
+ ).message,
+ ).toContain("discovery reported a problem");
});
it("counts a remote device host when this machine has no simulator tooling", () => {
diff --git a/apps/web/src/components/device/DeviceSetup.tsx b/apps/web/src/components/device/DeviceSetup.tsx
index 29b46e99319..e4836a438b2 100644
--- a/apps/web/src/components/device/DeviceSetup.tsx
+++ b/apps/web/src/components/device/DeviceSetup.tsx
@@ -24,9 +24,20 @@ const deviceHubDescription =
const agentDeviceDescription =
"Allow new agent sessions in this environment to start and control local and remote devices, with required tools set up automatically.";
+/** Platforms whose latest listing on a ready host may be missing devices. */
+export const incompleteListings = (
+ status: DeviceServiceState["hostStatuses"][string] | undefined,
+) =>
+ (["ios", "android"] as const).filter(
+ (platform) =>
+ status?.status === "ready" &&
+ (status.incompletePlatforms?.includes(platform) ||
+ (platform === "android" && status.androidDiscoveryIncomplete === true)),
+ );
+
export const isAndroidDiscoveryUncertain = (state: DeviceServiceState) =>
- Object.values(state.hostStatuses).some(
- (status) => status.status === "ready" && status.androidDiscoveryIncomplete,
+ Object.values(state.hostStatuses).some((status) =>
+ incompleteListings(status).includes("android"),
);
/**
@@ -103,6 +114,16 @@ export function platformSetupStatus(state: DeviceServiceState, platform: DeviceP
(host.kind === "local" && state.hostStatus === "ready"),
);
if (readyHosts.length > 0 && !hasDevices) {
+ if (
+ readyHosts.some((host) =>
+ state.hostStatuses[host.id]?.incompletePlatforms?.includes(platform),
+ )
+ ) {
+ return {
+ ready: false,
+ message: `No ${platformName(platform)} devices were listed because device discovery reported a problem.`,
+ };
+ }
return {
ready: false,
message:
diff --git a/apps/web/src/components/settings/DeviceSourcesSettings.tsx b/apps/web/src/components/settings/DeviceSourcesSettings.tsx
index 09ccc32fd61..9d4e07b0fb0 100644
--- a/apps/web/src/components/settings/DeviceSourcesSettings.tsx
+++ b/apps/web/src/components/settings/DeviceSourcesSettings.tsx
@@ -28,6 +28,7 @@ import { Menu, MenuItem, MenuPopup, MenuTrigger } from "../ui/menu";
import { Popover, PopoverPopup, PopoverTrigger } from "../ui/popover";
import { Spinner } from "../ui/spinner";
import { toastManager } from "../ui/toast";
+import { incompleteListings } from "../device/DeviceSetup";
import { DeviceHostEditor } from "./DeviceHostEditor";
import { updateDeviceHosts, groupDeviceHosts } from "./deviceHostsSettings.logic";
import { EasDeviceHostEditor } from "./EasDeviceHostEditor";
@@ -115,10 +116,12 @@ function hostStatus(
if (!state) return { tone: "pending", label: "Loading" };
const status = state.hostStatuses[hostId];
switch (status?.status) {
- case "ready":
- return status.androidDiscoveryIncomplete
- ? { tone: "warning", label: "Android list may be incomplete", detail: status.detail }
- : undefined;
+ case "ready": {
+ const incomplete = incompleteListings(status);
+ if (incomplete.length === 0) return undefined;
+ const list = incomplete.length > 1 ? "Device" : incomplete[0] === "ios" ? "iOS" : "Android";
+ return { tone: "warning", label: `${list} list may be incomplete`, detail: status.detail };
+ }
case "installing":
case "starting":
return { tone: "pending", label: "Starting", detail: status.detail };
@@ -771,10 +774,20 @@ function DeviceSourceRow(props: { row: SourceRow }) {
>
<span className="min-w-0 break-words">
{several ? `${environment.label}: ` : ""}
- {!several && environment.status.detail
+ {environment.status.tone === "error" && !several && environment.status.detail
? environment.status.detail
: environment.status.label}
</span>
+ {environment.status.tone === "warning" && environment.status.detail ? (
+ <Popover>
+ <PopoverTrigger render={<InlineButton />}>Details</PopoverTrigger>
+ <PopoverPopup side="bottom" align="start" width="lg" padding="compact">
+ <p className="whitespace-pre-wrap break-words font-mono text-xs text-muted-foreground">
+ {environment.status.detail}
+ </p>
+ </PopoverPopup>
+ </Popover>
+ ) : null}
{environment.status.action ? (
<InlineButton onClick={environment.status.action.run}>
{environment.status.action.label}
diff --git a/packages/contracts/src/device.ts b/packages/contracts/src/device.ts
index a36f796abfe..ad52b213f10 100644
--- a/packages/contracts/src/device.ts
+++ b/packages/contracts/src/device.ts
@@ -256,6 +256,7 @@ export const DeviceHostStatuses = Schema.Record(
status: DeviceHostStatus,
detail: Schema.optional(Schema.String),
androidDiscoveryIncomplete: Schema.optional(Schema.Boolean),
+ incompletePlatforms: Schema.optional(Schema.Array(DevicePlatform)),
}),
);