@devries-cameron20 / t3code-1 / commits / 55f4c70256
Fork 0

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

fix(web): reopening Connections picks up new network addresses (#15840)

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

Lars Nieuwenhuis committed Oct 19, 2026 at 20:06 UTC 55f4c70256426032a6de0569dae54d6ba7f91c09
2 files changed +99 -13
apps/desktop/src/backend/DesktopServerExposure.test.ts
+64 -2
@@ -40,7 +40,7 @@ const tailnetNetworkInterfaces: DesktopNetworkInterfaces.NetworkInterfaces = {
40 ],
41 };
42
43 -function layerMockSpawner(statusJson = "{}", onSpawn?: () => void) {
43 +function layerMockSpawner(statusJson: string | (() => string) = "{}", onSpawn?: () => void) {
44 return Layer.succeed(
45 ChildProcessSpawner.ChildProcessSpawner,
46 ChildProcessSpawner.make(() =>
@@ -53,7 +53,9 @@ function layerMockSpawner(statusJson = "{}", onSpawn?: () => void) {
53 kill: () => Effect.void,
54 unref: Effect.succeed(Effect.void),
55 stdin: Sink.drain,
56 - stdout: Stream.make(encoder.encode(statusJson)),
56 + stdout: Stream.make(
57 + encoder.encode(typeof statusJson === "string" ? statusJson : statusJson()),
58 + ),
59 stderr: Stream.empty,
60 all: Stream.empty,
61 getInputFd: () => Sink.drain,
@@ -460,6 +462,66 @@ describe("DesktopServerExposure", () => {
462 ),
463 );
464
465 + it.effect(
466 + "refreshes Tailscale status when addresses change and caches unchanged addresses",
467 + () => {
468 + const networkInterfaces: Record<
469 + string,
470 + readonly DesktopNetworkInterfaces.DesktopNetworkInterfaceInfo[] | undefined
471 + > = { ...lanNetworkInterfaces };
472 + let statusJson = "{}";
473 + let statusReads = 0;
474 +
475 + return withHarness(
476 + networkInterfaces,
477 + Effect.gen(function* () {
478 + const serverExposure = yield* DesktopServerExposure.DesktopServerExposure;
479 + yield* serverExposure.configureFromSettings({ port: 4173 });
480 + yield* serverExposure.setMode("network-accessible");
481 +
482 + const initial = yield* serverExposure.getAdvertisedEndpoints;
483 + assert.deepEqual(
484 + initial.map((endpoint) => endpoint.httpBaseUrl),
485 + ["http://127.0.0.1:4173/", "http://192.168.1.20:4173/"],
486 + );
487 + assert.equal(statusReads, 1);
488 +
489 + for (const [address, dnsName] of [
490 + ["100.90.1.2", "desktop.tail.ts.net"],
491 + ["100.90.1.3", "desktop.other-tail.ts.net"],
492 + ] as const) {
493 + networkInterfaces.vpn0 = [{ address, family: "IPv4", internal: false }];
494 + statusJson = JSON.stringify({
495 + Self: { DNSName: `${dnsName}.`, TailscaleIPs: [address] },
496 + });
497 + const previousReads = statusReads;
498 +
499 + const endpoints = yield* serverExposure.getAdvertisedEndpoints;
500 + assert.deepEqual(
501 + endpoints.map((endpoint) => endpoint.httpBaseUrl),
502 + [
503 + "http://127.0.0.1:4173/",
504 + "http://192.168.1.20:4173/",
505 + `http://${address}:4173/`,
506 + `https://${dnsName}/`,
507 + ],
508 + );
509 + assert.equal(statusReads, previousReads + 1);
510 + assert.deepEqual(yield* serverExposure.getAdvertisedEndpoints, endpoints);
511 + assert.equal(statusReads, previousReads + 1);
512 + }
513 + }),
514 + {},
515 + layerMockSpawner(
516 + () => statusJson,
517 + () => {
518 + statusReads += 1;
519 + },
520 + ),
521 + );
522 + },
523 + );
524 +
525 it.effect("does not spawn the tailscale CLI while server exposure is local-only", () =>
526 withHarness(
527 lanNetworkInterfaces,
apps/desktop/src/backend/DesktopServerExposure.ts
+35 -11
@@ -10,6 +10,7 @@ import {
10 type DesktopServerExposureState,
11 } from "@t3tools/contracts";
12 import { isTailscaleIpv4Address, readTailscaleStatus } from "@t3tools/tailscale";
13 +import * as Cache from "effect/Cache";
14 import * as Context from "effect/Context";
15 import * as Duration from "effect/Duration";
16 import * as Effect from "effect/Effect";
@@ -416,6 +417,25 @@ function resolveRuntimeState(input: {
417 };
418 }
419
420 +const tailscaleIpv4AddressKey = (
421 + networkInterfaces: DesktopNetworkInterfaces.NetworkInterfaces,
422 +): string =>
423 + [
424 + ...new Set(
425 + Object.values(networkInterfaces)
426 + .flatMap((addresses) => addresses ?? [])
427 + .filter(
428 + (address) =>
429 + !address.internal &&
430 + address.family === "IPv4" &&
431 + isTailscaleIpv4Address(address.address),
432 + )
433 + .map((address) => address.address),
434 + ),
435 + ]
436 + .toSorted()
437 + .join(",");
438 +
439 const requiresBackendRelaunch = (previous: RuntimeState, next: RuntimeState): boolean =>
440 previous.port !== next.port ||
441 previous.bindHost !== next.bindHost ||
@@ -434,16 +454,17 @@ export const make = Effect.gen(function* () {
454 // with values it read before that change persisted.
455 const changePermit = yield* Semaphore.make(1);
456
437 - // Cache the `tailscale status` spawn for the TTL. On macOS, the Mac App
438 - // Store Tailscale CLI lives inside Tailscale's sandbox container, so each
439 - // spawn re-triggers the "Other apps" TCC prompt.
440 - const cachedReadTailscaleStatus = yield* Effect.cachedWithTTL(
441 - readTailscaleStatus.pipe(
442 - Effect.orElseSucceed(() => null),
443 - Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, childProcessSpawner),
444 - ),
445 - TAILSCALE_STATUS_CACHE_TTL,
446 - );
457 + // Key status by interface addresses so network changes bypass stale DNS and
458 + // identity. Cache unchanged addresses to avoid repeated macOS TCC prompts.
459 + const tailscaleStatusCache = yield* Cache.make({
460 + capacity: 1,
461 + timeToLive: TAILSCALE_STATUS_CACHE_TTL,
462 + lookup: (_addresses: string) =>
463 + readTailscaleStatus.pipe(
464 + Effect.orElseSucceed(() => null),
465 + Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, childProcessSpawner),
466 + ),
467 + });
468
469 const readNetworkInterfaces = networkInterfaces.read;
470
@@ -564,7 +585,10 @@ export const make = Effect.gen(function* () {
585 serveEnabled: state.tailscaleServeEnabled,
586 servePort: state.tailscaleServePort,
587 networkInterfaces: currentNetworkInterfaces,
567 - readStatus: cachedReadTailscaleStatus,
588 + readStatus: Cache.get(
589 + tailscaleStatusCache,
590 + tailscaleIpv4AddressKey(currentNetworkInterfaces),
591 + ),
592 }).pipe(
593 Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, childProcessSpawner),
594 Effect.provideService(HttpClient.HttpClient, httpClient),