@devries-cameron20 / t3code Mirror · read-only / commits / 23f9c2c99a
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 09:30 UTC

perf(server): skip the per-listing SSH probe once a host reports Android (#23748)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>

Victor Vogel committed Oct 31, 2026 at 03:46 UTC 23f9c2c99af358df64f64b15cba9ff2af45e780c
2 files changed +122 -2
apps/server/src/device/SshDeviceHost.test.ts
+115
@@ -193,3 +193,118 @@ it.effect("preserves installed status after probes and cleans failed agent activ
193 expect(forwards).toBe(0);
194 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
195 );
196 +
197 +it.effect("lists Android devices without probing the host again once it reports Android", () =>
198 + Effect.gen(function* () {
199 + const fs = yield* FileSystem.FileSystem;
200 + const home = yield* fs.makeTempDirectoryScoped();
201 + const modes: string[] = [];
202 + let androidInstalled = false;
203 + const spawner = ChildProcessSpawner.make((command) =>
204 + Effect.gen(function* () {
205 + if (command._tag !== "StandardCommand") return yield* Effect.die("Unexpected command");
206 + const forwarding = command.args.includes("-L");
207 + let output = "";
208 + if (!forwarding) {
209 + const stdin = command.options.stdin;
210 + const script =
211 + stdin && typeof stdin === "object" && "stream" in stdin && Stream.isStream(stdin.stream)
212 + ? yield* stdin.stream.pipe(
213 + Stream.decodeText(),
214 + Stream.runFold(
215 + () => "",
216 + (a, b) => a + b,
217 + ),
218 + )
219 + : "";
220 + const mode = /const mode = "([^"]+)"/.exec(script)?.[1] ?? "";
221 + modes.push(mode);
222 + output =
223 + mode === ""
224 + ? "Pixel_8\n"
225 + : JSON.stringify({
226 + nodePath: "/node",
227 + platforms: [
228 + { platform: "ios", available: true },
229 + { platform: "android", available: androidInstalled },
230 + ],
231 + hubPort: 1234,
232 + helpers: { serveSimAxSettings: null, serveSimCli: null },
233 + });
234 + }
235 + return ChildProcessSpawner.makeHandle({
236 + pid: ChildProcessSpawner.ProcessId(123),
237 + stdout: Stream.make(new TextEncoder().encode(output)),
238 + stderr: Stream.empty,
239 + all: Stream.empty,
240 + exitCode: forwarding ? Effect.never : Effect.succeed(ChildProcessSpawner.ExitCode(0)),
241 + isRunning: Effect.succeed(forwarding),
242 + kill: () => Effect.void,
243 + stdin: Sink.drain,
244 + getInputFd: () => Sink.drain,
245 + getOutputFd: () => Stream.empty,
246 + unref: Effect.succeed(Effect.void),
247 + });
248 + }),
249 + );
250 + const host = yield* SshDeviceHost.make({
251 + kind: "ssh",
252 + id: "test",
253 + label: "Test",
254 + target: "test.example",
255 + }).pipe(
256 + Effect.provide(Layer.mergeAll(ServerConfig.layerTest(home, home), Net.layer)),
257 + Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
258 + Effect.provideService(
259 + HttpClient.HttpClient,
260 + HttpClient.make((request) =>
261 + Effect.succeed(
262 + HttpClientResponse.fromWeb(
263 + request,
264 + new Response(
265 + request.url.endsWith("/api/devices")
266 + ? JSON.stringify({ simulators: [], emulators: [] })
267 + : "ok",
268 + ),
269 + ),
270 + ),
271 + ),
272 + ),
273 + );
274 + const ready = yield* host.ensureReady(() => Effect.void);
275 + const androidNames = ready.devices.list.pipe(
276 + Effect.map((list) =>
277 + list.devices.filter((device) => device.platform === "android").map((device) => device.name),
278 + ),
279 + );
280 +
281 + modes.splice(0);
282 +
283 + expect(yield* androidNames).toEqual([]);
284 + expect(modes.splice(0)).toEqual(["probe"]);
285 + expect(yield* androidNames).toEqual([]);
286 + expect(modes.splice(0)).toEqual(["probe"]);
287 +
288 + // The SDK appears after connecting, so the next listing still probes the host.
289 + androidInstalled = true;
290 + expect(yield* androidNames).toEqual(["Pixel_8"]);
291 + expect(modes.splice(0)).toEqual(["probe", ""]);
292 +
293 + // Android is now known to be available, so listing only runs `emulator -list-avds`.
294 + expect(yield* androidNames).toEqual(["Pixel_8"]);
295 + expect(modes.splice(0)).toEqual([""]);
296 +
297 + androidInstalled = false;
298 + expect((yield* host.platformAvailability("android")).available).toBe(false);
299 + expect(modes.splice(0)).toEqual(["probe"]);
300 + expect(yield* androidNames).toEqual([]);
301 + expect(modes.splice(0)).toEqual(["probe"]);
302 +
303 + androidInstalled = true;
304 + yield* host.inspect;
305 + expect(modes.splice(0)).toEqual(["probe"]);
306 + expect(yield* androidNames).toEqual(["Pixel_8"]);
307 + expect(modes.splice(0)).toEqual([""]);
308 + yield* host.stop;
309 + }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
310 +);
apps/server/src/device/SshDeviceHost.ts
+7 -2
@@ -317,8 +317,13 @@ export const make = Effect.fn("SshDeviceHost.make")(function* (
317 origin: hubOrigin,
318 http,
319 run,
320 - androidAvailable: platformAvailability("android").pipe(
321 - Effect.map((availability) => availability.available),
320 + // Keep probing negative reports so an SDK installed after connecting is still found.
321 + androidAvailable: Effect.suspend(() =>
322 + summary.platforms.some((p) => p.platform === "android" && p.available)
323 + ? Effect.succeed(true)
324 + : platformAvailability("android").pipe(
325 + Effect.map((availability) => availability.available),
326 + ),
327 ),
328 }),
329 ...(remote.daemonPort !== undefined &&