fix(desktop): derive v2 workspace locality from workspace.hostId, not joined v2Hosts
Merged
SA
6mo ago+70+70+01234567890123456789-116-116-012345678901234567890123456789
Summary
- Workspaces that loaded while Electric was still syncing
v2Hostswere routed through the cloud relay instead of the local host service. The locality check inv2-workspace/layout.tsx(and 5 sibling sites) leftJoinedv2Workspaces → v2Hostsand comparedjoined.hostMachineId === machineId— when Electric hadn't synced the host row, the joined value wasnull, the equality failed, and the entireWorkspaceTrpcProvidergot pointed at${RELAY_URL}/hosts/.... v2Workspaces.hostIdisnotNulland FKs tov2Hosts.machineId, so the workspace already carries the value the join was producing. Switched locality toworkspace.hostId === machineIdeverywhere. Routing-only paths drop thev2Hostsjoin entirely; metadata-display paths (sidebar / list) keep aninnerJoinfor host name +isOnline.- Side-fixes for the same root cause:
useAccessibleV2Workspacesnow stays innerJoin (cleaner; rows briefly hide while Electric catches up but workspaces remain routable via direct URL);DashboardSidebarPortsListsynthesizes a local-host port-query target so local ports show without a syncedv2Hostsrow;DevicePickersynthesizes "this device" so the picker never loses the local entry.
Test plan
-
bun run lint:fix— clean -
bun run typecheck— clean -
bun test(desktop) — 1870 pass - Manually clear
v2Hostsin tanstack-db inspector, navigate to/v2-workspace/$workspaceId, confirmWorkspaceTrpcProviderconnects tohttp://127.0.0.1:<port>(not the relay) and the workspace loads - DevicePicker: with
v2Hostscleared, "this device" still appears as default - Sidebar ports: with
v2Hostscleared, local ports still render - Don't regress remote routing: open a workspace whose
hostIdis a different machine; confirm it still routes via${RELAY_URL}/hosts/<key>
Summary by cubic
Fixes v2 workspace routing by deriving locality from v2Workspaces.hostId === machineId, avoiding relay misrouting when v2Hosts hasn’t synced. Also keeps local ports and “this device” visible even if the local host row is missing.
-
Bug Fixes
- Route workspace TRPC, notifications, terminal, and “Open in” via local host when
hostId === machineId; otherwise use the relay URL. - Prevent local ports from disappearing by synthesizing a local host target from
machineId+activeHostUrl. - Ensure DevicePicker always shows “this device” using
machineIdwhen the localv2Hostsrow is missing.
- Route workspace TRPC, notifications, terminal, and “Open in” via local host when
-
Refactors
- Removed
v2HostsleftJoin from routing-only queries; comparehostIddirectly. - Kept
innerJointov2Hostsonly where host metadata (name,isOnline) is displayed. - Simplified
hostTypederivation tohostId === machineId ? "local-device" : "remote-device".
- Removed
Summary by CodeRabbit
- Refactor
- Simplified workspace-to-host relationship handling across the application.
- Streamlined local and remote device classification logic.
- Optimized database queries for improved performance.