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 24, 09:00 UTC
fix(desktop): separate LAN and Tailscale pairing endpoints (#9882)
maria committed
Sep 5, 2026 at 14:41 UTC
60e1b73948debac845c3dc72aac35c9adbd4cd64
3 files changed
+49
-11
apps/desktop/src/app/DesktopApp.ts
+4
-1
@@ -194,7 +194,10 @@ const bootstrap = Effect.gen(function* () {
194
yield* logBootstrapInfo("bootstrap enabled network access", {
195
endpointUrl: serverExposureState.endpointUrl,
196
});
197
- } else if (settings.serverExposureMode === "network-accessible") {
197
+ } else if (
198
+ settings.serverExposureMode === "network-accessible" &&
199
+ serverExposureState.mode === "local-only"
200
+ ) {
201
yield* logBootstrapWarning(
202
"bootstrap fell back to local-only because no advertised network host was available",
203
);
apps/desktop/src/backend/DesktopServerExposure.test.ts
+33
-7
@@ -304,9 +304,9 @@ describe("DesktopServerExposure", () => {
304
);
305
});
306
307
- it.effect("resolves advertised endpoints from the scoped runtime state", () =>
307
+ it.effect("keeps LAN and Tailscale endpoints distinct when Tailscale is enumerated first", () =>
308
withHarness(
309
- { ...lanNetworkInterfaces, ...tailnetNetworkInterfaces },
309
+ { ...tailnetNetworkInterfaces, ...lanNetworkInterfaces },
310
Effect.gen(function* () {
311
const serverExposure = yield* DesktopServerExposure.DesktopServerExposure;
312
yield* serverExposure.configureFromSettings({ port: 4173 });
@@ -321,6 +321,32 @@ describe("DesktopServerExposure", () => {
321
),
322
);
323
324
+ it.effect("keeps Tailscale-only hosts network-accessible", () =>
325
+ withHarness(
326
+ tailnetNetworkInterfaces,
327
+ Effect.gen(function* () {
328
+ const serverExposure = yield* DesktopServerExposure.DesktopServerExposure;
329
+ const settings = yield* DesktopAppSettings.DesktopAppSettings;
330
+ yield* settings.setServerExposureMode("network-accessible");
331
+
332
+ const state = yield* serverExposure.configureFromSettings({ port: 4173 });
333
+ assert.equal(state.mode, "network-accessible");
334
+ assert.equal(state.advertisedHost, null);
335
+ assert.equal(state.endpointUrl, null);
336
+ assert.equal((yield* serverExposure.backendConfig).bindHost, "0.0.0.0");
337
+
338
+ const endpoints = yield* serverExposure.getAdvertisedEndpoints;
339
+ assert.deepEqual(
340
+ endpoints.map((endpoint) => [endpoint.reachability, endpoint.httpBaseUrl]),
341
+ [
342
+ ["loopback", "http://127.0.0.1:4173/"],
343
+ ["private-network", "http://100.90.1.2:4173/"],
344
+ ],
345
+ );
346
+ }),
347
+ ),
348
+ );
349
+
350
it.effect("does not spawn the tailscale CLI while server exposure is local-only", () =>
351
withHarness(
352
lanNetworkInterfaces,
@@ -342,7 +368,7 @@ describe("DesktopServerExposure", () => {
368
),
369
);
370
345
- it.effect("uses ConfigProvider desktop exposure overrides", () =>
371
+ it.effect("preserves explicit Tailscale exposure overrides", () =>
372
withHarness(
373
lanNetworkInterfaces,
374
Effect.gen(function* () {
@@ -350,17 +376,17 @@ describe("DesktopServerExposure", () => {
376
yield* serverExposure.configureFromSettings({ port: 4173 });
377
const change = yield* serverExposure.setMode("network-accessible");
378
353
- assert.equal(change.state.advertisedHost, "10.0.0.7");
354
- assert.equal(change.state.endpointUrl, "http://10.0.0.7:4173");
379
+ assert.equal(change.state.advertisedHost, "100.90.1.2");
380
+ assert.equal(change.state.endpointUrl, "http://100.90.1.2:4173");
381
382
const endpoints = yield* serverExposure.getAdvertisedEndpoints;
383
assert.deepEqual(
384
endpoints.map((endpoint) => endpoint.httpBaseUrl),
359
- ["http://127.0.0.1:4173/", "http://10.0.0.7:4173/", "https://public.example.test/"],
385
+ ["http://127.0.0.1:4173/", "http://100.90.1.2:4173/", "https://public.example.test/"],
386
);
387
}),
388
{
363
- T3CODE_DESKTOP_LAN_HOST: "10.0.0.7",
389
+ T3CODE_DESKTOP_LAN_HOST: "100.90.1.2",
390
T3CODE_DESKTOP_HTTPS_ENDPOINTS: "https://public.example.test",
391
},
392
),
apps/desktop/src/backend/DesktopServerExposure.ts
+12
-3
@@ -9,7 +9,7 @@ import {
9
type DesktopServerExposureMode,
10
type DesktopServerExposureState,
11
} from "@t3tools/contracts";
12
-import { readTailscaleStatus } from "@t3tools/tailscale";
12
+import { isTailscaleIpv4Address, readTailscaleStatus } from "@t3tools/tailscale";
13
import * as Context from "effect/Context";
14
import * as Duration from "effect/Duration";
15
import * as Effect from "effect/Effect";
@@ -65,7 +65,9 @@ const normalizeOptionalHost = (value: string | undefined): string | undefined =>
65
};
66
67
const isUsableLanIpv4Address = (address: string): boolean =>
68
- !address.startsWith("127.") && !address.startsWith("169.254.");
68
+ !address.startsWith("127.") &&
69
+ !address.startsWith("169.254.") &&
70
+ !isTailscaleIpv4Address(address);
71
72
const isHttpsEndpointUrl = (value: string): boolean => {
73
try {
@@ -376,7 +378,14 @@ function resolveRuntimeState(input: {
378
...(advertisedHostOverride ? { advertisedHostOverride } : {}),
379
});
380
const unavailable =
379
- input.requestedMode === "network-accessible" && requestedExposure.endpointUrl === null;
381
+ input.requestedMode === "network-accessible" &&
382
+ requestedExposure.endpointUrl === null &&
383
+ !Object.values(input.networkInterfaces).some((addresses) =>
384
+ addresses?.some(
385
+ (address) =>
386
+ !address.internal && address.family === "IPv4" && isTailscaleIpv4Address(address.address),
387
+ ),
388
+ );
389
const exposure = unavailable
390
? resolveDesktopServerExposure({
391
mode: "local-only",