Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(pairing): offer Tailscale pairing when hosted capacity is full

Saim Shafique7dd9749ea2f3
diff --git a/src/components/PhoneSetupFlow.onDemand.test.ts b/src/components/PhoneSetupFlow.onDemand.test.ts
index 41418500d1..905e74dba3 100644
--- a/src/components/PhoneSetupFlow.onDemand.test.ts
+++ b/src/components/PhoneSetupFlow.onDemand.test.ts
@@ -78,6 +78,17 @@ function desktop() {
stopRetrying() {
account = { available: true, status: "ready", email: "[email protected]" };
},
+ withTailscaleRoute() {
+ companion = {
+ ...companion,
+ routes: {
+ wifi: { on: true, since: null },
+ relay: { on: false, since: null },
+ tailscale: { on: true, since: Date.now(), name: "ada-mac.tail1234.ts.net" },
+ https: { on: false, since: null },
+ },
+ };
+ },
};
}
@@ -138,6 +149,7 @@ describe("pairing on a computer that holds no HTTPS address yet", () => {
expect(text()).toContain("Secure access needs attention");
expect(button("Try secure access again")).not.toBeNull();
expect(button("Pair on this Wi-Fi instead")).not.toBeNull();
+ expect(button("Pair using Tailscale")).toBeNull();
expect(fake.bridge.companion.pairing).not.toHaveBeenCalled();
flushSync(() => button("Pair on this Wi-Fi instead")!.click());
@@ -146,6 +158,25 @@ describe("pairing on a computer that holds no HTTPS address yet", () => {
expect(fake.bridge.companionAccount.prepare).toHaveBeenCalledOnce();
});
+ it("offers Tailscale when the route is ready but hosted capacity is full, and opens its QR", async () => {
+ const fake = desktop();
+ fake.withTailscaleRoute();
+ await startPairing(fake);
+ await vi.waitFor(() => expect(fake.bridge.companionAccount.prepare).toHaveBeenCalledOnce());
+
+ fake.finishPrepare("full");
+ await vi.waitFor(() => expect(text()).toContain(FULL));
+ expect(button("Pair using Tailscale")).not.toBeNull();
+
+ flushSync(() => button("Pair using Tailscale")!.click());
+ await vi.waitFor(() => expect(host.querySelector('[aria-label="Device pairing QR code"]')).not.toBeNull());
+ expect(fake.bridge.companion.pairing).toHaveBeenCalledWith(true);
+ expect(fake.bridge.companionAccount.prepare).toHaveBeenCalledOnce();
+ expect(text()).toContain("123456");
+ flushSync(() => button("Reveal")!.click());
+ expect(text()).toContain("ada-mac.tail1234.ts.net:8810");
+ });
+
it("asks again when the desktop stopped retrying while pairing still waits", async () => {
const fake = desktop();
await startPairing(fake);
diff --git a/src/components/PhoneSetupFlow.tsx b/src/components/PhoneSetupFlow.tsx
index bf1d868d71..9e038a0979 100644
--- a/src/components/PhoneSetupFlow.tsx
+++ b/src/components/PhoneSetupFlow.tsx
@@ -990,6 +990,20 @@ export function PhoneSetupFlowView({ controller }: { controller: PhoneSetupContr
<p className="mt-2 text-center text-[11px] leading-relaxed text-ink-secondary">
{t("phone.signIn.wifiNote")}
</p>
+ {c.tailscaleAvailable && (
+ <button
+ disabled={c.busy || c.accountBusy}
+ onClick={c.useTailscale}
+ className="mt-2 flex items-center justify-center gap-2 rounded-lg border border-hairline/50 py-2.5 text-[13px] text-ink hover:bg-control disabled:opacity-40"
+ >
+ {t("phone.signIn.tailscaleInstead")}
+ </button>
+ )}
+ {c.tailscaleAvailable && (
+ <p className="mt-2 text-center text-[11px] leading-relaxed text-ink-secondary">
+ {t("phone.signIn.tailnetNote")}
+ </p>
+ )}
</div>
);
}
diff --git a/src/lib/companion-pairing.test.ts b/src/lib/companion-pairing.test.ts
index 8f3262cc91..c903d217c6 100644
--- a/src/lib/companion-pairing.test.ts
+++ b/src/lib/companion-pairing.test.ts
@@ -200,6 +200,62 @@ describe("companionPairingRoute", () => {
}, "tailscale")).toBeNull();
});
+ it("uses the enabled Tailscale route name when the sidecar reports no tailnet endpoint or legacy name", () => {
+ const source = {
+ port: 8810,
+ routes: { tailscale: { on: true, since: 1, name: "mac.tail1234.ts.net" } },
+ lan: "192.168.1.42",
+ endpoints: [
+ { url: "http://192.168.1.42:8810", kind: "lan" as const, priority: 200 },
+ ],
+ };
+ const route = companionPairingRoute(source, "tailscale");
+ expect(route?.address).toBe("mac.tail1234.ts.net");
+ expect(route?.port).toBe(8810);
+ expect(route?.hosts).toEqual(["mac.tail1234.ts.net"]);
+ const pin = companionPairingRoutePin(source, "tailscale");
+ expect(pin?.protectedEndpoint).toEqual({
+ url: "http://mac.tail1234.ts.net:8810",
+ kind: "tailnet",
+ priority: 0,
+ });
+ expect(companionPairingRoutePinAvailable(source, pin!)).toBe(true);
+ });
+
+ it("ignores a Tailscale route name that is switched off", () => {
+ expect(companionPairingRoute({
+ port: 8810,
+ routes: { tailscale: { on: false, since: null, name: "mac.tail1234.ts.net" } },
+ endpoints: [],
+ }, "tailscale")).toBeNull();
+ });
+
+ it("ignores a non-MagicDNS name from the enabled Tailscale route", () => {
+ expect(companionPairingRoute({
+ port: 8810,
+ routes: { tailscale: { on: true, since: 1, name: "attacker.example" } },
+ endpoints: [],
+ }, "tailscale")).toBeNull();
+ });
+
+ it("does not keep a Tailscale pin when the enabled route name changes", () => {
+ const source = {
+ port: 8810,
+ routes: { tailscale: { on: true, since: 1, name: "mac.tail1234.ts.net" } },
+ endpoints: [],
+ };
+ const pin = companionPairingRoutePin(source, "tailscale");
+ expect(pin).not.toBeNull();
+ expect(companionPairingRoutePinAvailable({
+ ...source,
+ routes: { tailscale: { on: true, since: 1, name: "other.tail9999.ts.net" } },
+ }, pin!)).toBe(false);
+ expect(companionPairingRoutePinAvailable({
+ ...source,
+ routes: { tailscale: { on: false, since: null, name: "mac.tail1234.ts.net" } },
+ }, pin!)).toBe(false);
+ });
+
it("refuses explicit local pairing when no LAN or Bonjour route exists", () => {
expect(companionPairingRoute({
port: 8810,
diff --git a/src/lib/companion-pairing.ts b/src/lib/companion-pairing.ts
index 9bbf755f3e..99f4f45037 100644
--- a/src/lib/companion-pairing.ts
+++ b/src/lib/companion-pairing.ts
@@ -9,6 +9,8 @@ export interface CompanionPairingRouteSource {
addresses?: string[];
tailscale?: string;
tailnetName?: string;
+ /** The per-route switches from Settings; the sidecar's tailnetName can lag them. */
+ routes?: { tailscale?: { on: boolean; name?: string | null } };
lan?: string | null;
hosts?: string[];
endpoints?: CompanionEndpoint[];
@@ -93,6 +95,16 @@ export function companionPairingRoute(
priority: 0,
}])[0] ?? null;
}
+ if (!preferred && source.routes?.tailscale?.on) {
+ const routeName = source.routes.tailscale.name?.trim();
+ if (routeName) {
+ preferred = qrEndpoints([{
+ url: directHTTPOrigin(routeName, source.port),
+ kind: "tailnet",
+ priority: 0,
+ }])[0] ?? null;
+ }
+ }
if (!preferred) return null;
const parsed = new URL(preferred.url);
@@ -192,12 +204,22 @@ export function companionPairingRoutePin(
/** No silent substitution of another protected endpoint: a new transport needs a fresh pairing credential. */
export function companionPairingRoutePinAvailable(
- source: Pick<CompanionPairingRouteSource, "endpoints">,
+ source: Pick<CompanionPairingRouteSource, "endpoints" | "routes">,
pin: CompanionPairingRoutePin,
): boolean {
if (!pin.protectedEndpoint) return true;
- return qrEndpoints(source.endpoints).some(
+ if (qrEndpoints(source.endpoints).some(
(endpoint) => endpoint.kind === pin.protectedEndpoint?.kind
&& endpoint.url === pin.protectedEndpoint.url,
- );
+ )) return true;
+ if (pin.protectedEndpoint.kind !== "tailnet") return false;
+ const routeName = source.routes?.tailscale?.on
+ ? source.routes.tailscale.name?.trim().toLowerCase().replace(/\.$/, "")
+ : undefined;
+ if (!routeName) return false;
+ try {
+ return new URL(pin.protectedEndpoint.url).hostname.toLowerCase().replace(/\.$/, "") === routeName;
+ } catch {
+ return false;
+ }
}
diff --git a/src/locales/en.json b/src/locales/en.json
index 775f073a84..aab960a767 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -4556,6 +4556,7 @@
"phone.signIn.tailnetNote": "The other device must be signed in to the same tailnet.",
"phone.signIn.wifiInstead": "Pair on this Wi-Fi instead",
"phone.signIn.wifiNote": "Both devices must be on a network that lets them see each other.",
+ "phone.signIn.tailscaleInstead": "Pair using Tailscale",
"phone.verifying.local": "Preparing your pairing code",
"phone.verifying.tailscale": "Preparing Tailscale pairing",
"phone.verifying.secure": "Creating secure remote access",
diff --git a/src/locales/pt-br.json b/src/locales/pt-br.json
index 821130470c..1b5314cf32 100644
--- a/src/locales/pt-br.json
+++ b/src/locales/pt-br.json
@@ -4306,6 +4306,7 @@
"phone.signIn.tailnetNote": "O outro dispositivo precisa estar na mesma tailnet.",
"phone.signIn.wifiInstead": "Parear nesta rede Wi-Fi",
"phone.signIn.wifiNote": "Os dois dispositivos precisam estar em uma rede que permita que eles se enxerguem.",
+ "phone.signIn.tailscaleInstead": "Parear usando o Tailscale",
"phone.verifying.local": "Preparando seu código de pareamento",
"phone.verifying.tailscale": "Preparando o pareamento por Tailscale",
"phone.verifying.secure": "Criando o acesso remoto seguro",