Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion apps/ade-cli/src/services/sync/deviceRegistryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,19 @@ function isTailscaleAddress(ipAddress: string): boolean {
// this computer, so a phone that dials them just burns a connect attempt.
// Other `vEthernet (...)` adapters stay: with a Hyper-V External switch, or WSL
// in bridged mode, Windows moves the real LAN address onto one of them.
const VIRTUAL_ADAPTER_PATTERN = /^vEthernet \((WSL|Default Switch)|docker|^br-|virbr|vmnet|vboxnet/i;
// Windows names its hotspot and Wi-Fi Direct adapters "<localized name>* <n>"
// ("Local Area Connection* 2", "LAN-Verbindung* 10"); they carry the ICS
// gateway 192.168.137.1 and reach only this machine's tethered devices.
const VIRTUAL_ADAPTER_PATTERN = /^vEthernet \((WSL|Default Switch)|docker|^br-|virbr|vmnet|vboxnet|^virtualbox host-only|\* \d+$/i;

// VirtualBox (0a:00:27) and VMware (00:50:56:c0:00) host-only adapters use
// fixed MAC prefixes. Their Windows names are user-renameable ("VirtualBox
// Host-Only Network" is not matched above), so the MAC is the backstop. Linux
// bridges can inherit these MACs, so only Windows is checked.
const WINDOWS_HOST_ADAPTER_MAC = /^(0a:00:27|00:50:56:c0:00):/i;

/** VPN and proxy clients put their tunnels in 198.18.0.0/15 (RFC 2544), which is never a LAN. */
const isVpnTunnelAddress = (address: string): boolean => /^198\.1[89]\./.test(address);

function readLocalNetworkMetadata(): LocalNetworkMetadata {
const interfaces = readNetworkInterfaces();
Expand All @@ -260,6 +272,8 @@ function readLocalNetworkMetadata(): LocalNetworkMetadata {
const isLikelyTailscaleInterface = /tailscale|utun|tun/i.test(interfaceName);
for (const entry of entries ?? []) {
if (!entry || entry.internal || entry.family !== "IPv4") continue;
if (isVpnTunnelAddress(entry.address)) continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Saved tunnel addresses survive

After an upgrade, an address such as 198.19.2.2 previously saved from utun40 remains in tailscaleIp. The new filter skips it, but ensureLocalDevice and touchLocalDevice keep the saved value when the fresh value is null—even when a real LAN address exists. Bonjour and pairing candidates then offer that unusable address to phones again.

Remove excluded addresses from saved values too, and allow upsertDeviceRecord to clear tailscaleIp.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/ade-cli/src/services/sync/deviceRegistryService.ts
Line: 275

Comment:
**Saved tunnel addresses survive**

After an upgrade, an address such as `198.19.2.2` previously saved from `utun40` remains in `tailscaleIp`. The new filter skips it, but `ensureLocalDevice` and `touchLocalDevice` keep the saved value when the fresh value is null—even when a real LAN address exists. Bonjour and pairing candidates then offer that unusable address to phones again.

Remove excluded addresses from saved values too, and allow `upsertDeviceRecord` to clear `tailscaleIp`.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code

if (process.platform === "win32" && WINDOWS_HOST_ADAPTER_MAC.test(entry.mac)) continue;
Comment on lines +275 to +276

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Filtered addresses survive sync upgrades

After an upgrade, ensureLocalDevice keeps the old LAN list or tailnet IP when filtering leaves that field empty. Bonjour and pairing QR codes still advertise those saved addresses.

Learn more

The interface scan now rejects addresses that earlier versions saved in the local device row. ensureLocalDevice restores the stored LAN list when the scan returns an empty list and restores the stored tailnet IP when the scan returns null. touchLocalDevice repeats those fallbacks, and upsertDeviceRecord treats an explicit null tailnet IP as an omitted value. publishLanDiscovery and buildPairingConnectInfo use the resulting device row, so another refresh does not remove the rejected address.

Example: A host on Wi-Fi has an utun proxy at 198.19.2.2 and no real Tailscale adapter. The old version saves the proxy IP as tailscaleIp. After upgrading, the fresh scan returns null for tailscaleIp, but the existing row still carries 198.19.2.2, and the next Bonjour publish includes it.

Recommended fix: Make a successful local interface scan authoritative for the local row's LAN and tailnet fields, including an empty LAN list or explicit null tailnet IP. Preserve the existing merge behavior for peer updates that omit network fields. Extend the registry test to seed an old address and verify that refreshing the local row removes it from the pairing candidates.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

if (isLikelyTailscaleInterface || isTailscaleAddress(entry.address)) {
tailscale.push(entry.address);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,37 @@ function makeProjectRoot(prefix: string): string {
}

describe("deviceRegistryService", () => {
it("advertises real Hyper-V LAN adapters and filters host-only virtual networks", () => {
it("advertises real LAN adapters and filters host-only, hotspot and VPN addresses", () => {
// The MAC backstop is Windows-only, so pin the platform for every host.
const platform = Object.getOwnPropertyDescriptor(process, "platform");
Object.defineProperty(process, "platform", { value: "win32", configurable: true });
const networkInterfaces = vi.spyOn(os, "networkInterfaces").mockReturnValue({
"vEthernet (WSL)": [{ address: "172.25.0.1", family: "IPv4", internal: false, netmask: "255.255.0.0", mac: "00:00:00:00:00:01", cidr: "172.25.0.1/16" }],
"vEthernet (Default Switch)": [{ address: "172.26.0.1", family: "IPv4", internal: false, netmask: "255.255.0.0", mac: "00:00:00:00:00:02", cidr: "172.26.0.1/16" }],
docker0: [{ address: "172.17.0.1", family: "IPv4", internal: false, netmask: "255.255.0.0", mac: "00:00:00:00:00:03", cidr: "172.17.0.1/16" }],
// Windows hotspot / Wi-Fi Direct adapters: ICS gateway, reach tethered devices only.
"Local Area Connection* 2": [{ address: "192.168.137.1", family: "IPv4", internal: false, netmask: "255.255.255.0", mac: "00:00:00:00:00:07", cidr: "192.168.137.1/24" }],
"LAN-Verbindung* 10": [{ address: "192.168.137.2", family: "IPv4", internal: false, netmask: "255.255.255.0", mac: "00:00:00:00:00:08", cidr: "192.168.137.2/24" }],
// RFC 2544 tunnels (Tailscale userspace, Clash/Mihomo Wintun) are never a LAN.
utun40: [{ address: "198.19.2.2", family: "IPv4", internal: false, netmask: "255.255.0.0", mac: "00:00:00:00:00:09", cidr: "198.19.2.2/16" }],
"VirtualBox Host-Only Network": [{ address: "192.168.56.1", family: "IPv4", internal: false, netmask: "255.255.0.0", mac: "0a:00:27:00:00:0a", cidr: "192.168.56.1/24" }],
"VMware Network Adapter VMnet8": [{ address: "192.168.159.1", family: "IPv4", internal: false, netmask: "255.255.255.0", mac: "00:50:56:c0:00:08", cidr: "192.168.159.1/24" }],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 VMware MAC check goes untested

The VMware fixture never exercises WINDOWS_HOST_ADAPTER_MAC: its name contains VMnet8, so the existing name filter skips it first. A broken VMware MAC pattern would still pass this test. Give this fixture an unrelated name, as the test already does for VirtualBox, so it checks the promised renamed-adapter behavior.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/desktop/src/main/services/sync/deviceRegistryService.test.ts
Line: 40

Comment:
**VMware MAC check goes untested**

The VMware fixture never exercises `WINDOWS_HOST_ADAPTER_MAC`: its name contains `VMnet8`, so the existing name filter skips it first. A broken VMware MAC pattern would still pass this test. Give this fixture an unrelated name, as the test already does for VirtualBox, so it checks the promised renamed-adapter behavior.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code

// A user-renamed VirtualBox adapter: only its MAC identifies it.
"Lab Only": [{ address: "192.168.56.2", family: "IPv4", internal: false, netmask: "255.255.0.0", mac: "0a:00:27:00:00:0b", cidr: "192.168.56.2/24" }],
"vEthernet (External)": [{ address: "192.168.1.25", family: "IPv4", internal: false, netmask: "255.255.255.0", mac: "00:00:00:00:00:04", cidr: "192.168.1.25/24" }],
en0: [{ address: "192.168.1.30", family: "IPv4", internal: false, netmask: "255.255.255.0", mac: "00:00:00:00:00:05", cidr: "192.168.1.30/24" }],
tailscale0: [{ address: "100.70.0.4", family: "IPv4", internal: false, netmask: "255.255.255.255", mac: "00:00:00:00:00:06", cidr: "100.70.0.4/32" }],
} as unknown as ReturnType<typeof os.networkInterfaces>);

const defaults = localSyncDeviceDefaults();
networkInterfaces.mockRestore();

expect(defaults.ipAddresses).toEqual(["192.168.1.25", "192.168.1.30"]);
expect(defaults.lastHost).toBe("192.168.1.25");
expect(defaults.tailscaleIp).toBe("100.70.0.4");
try {
const defaults = localSyncDeviceDefaults();
expect(defaults.ipAddresses).toEqual(["192.168.1.25", "192.168.1.30"]);
expect(defaults.lastHost).toBe("192.168.1.25");
expect(defaults.tailscaleIp).toBe("100.70.0.4");
} finally {
networkInterfaces.mockRestore();
if (platform) Object.defineProperty(process, "platform", platform);
}
});

it("keeps a stable local device identity across restarts and bootstraps the cluster brain", async () => {
Expand Down
Loading