From c66cb01cf34fb101d4feebf61d01b857115add89 Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 10 Nov 2026 15:28:46 -0800 Subject: [PATCH] fix(cloud): hide Orca Cloud sandbox clones from the sidebar; no Tailscale hint for cloud hosts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Each Orca Cloud workspace is its own sandbox host whose clone is registered as the project there (orca-worktree mode, hosted-sandbox-driver.ts), with the workspace as a worktree beside it. The clone was listed as a primary row, so every cloud workspace added another identical 'master [primary] · Orca Cloud' row under its project. Sidebar lists and the jump palette now hide primary checkouts on Orca Cloud hosts, reusing the VM-create hidden-checkout filter. An unreachable Orca Cloud sandbox (asleep, gone, or another team's) was classified as a network host and got the 'connect both devices to Tailscale' hint; cloud hosts now keep the plain message. --- .../runtime-environment-tailscale-response.ts | 3 +- ...ntime-environment-unreachable-hint.test.ts | 21 +++++++ .../runtime-environment-unreachable-hint.ts | 9 ++- .../listing/use-main-list-model.ts | 9 +-- .../listing/use-visible-worktrees.ts | 11 ++-- .../use-worktree-jump-palette-store-state.ts | 13 ++--- .../use-sidebar-hidden-checkouts.test.ts | 18 ++++++ .../use-sidebar-hidden-checkouts.ts | 33 +++++++++++ .../lib/vm-create-hidden-checkouts.test.ts | 56 +++++++++++++++++- .../src/lib/vm-create-hidden-checkouts.ts | 58 +++++++++++++++---- 10 files changed, 197 insertions(+), 34 deletions(-) create mode 100644 src/main/ipc/runtime-environments/runtime-environment-unreachable-hint.test.ts create mode 100644 src/renderer/src/lib/orca-cloud/use-sidebar-hidden-checkouts.test.ts create mode 100644 src/renderer/src/lib/orca-cloud/use-sidebar-hidden-checkouts.ts diff --git a/src/main/ipc/runtime-environments/runtime-environment-tailscale-response.ts b/src/main/ipc/runtime-environments/runtime-environment-tailscale-response.ts index 0982462832d..27a62db2d57 100644 --- a/src/main/ipc/runtime-environments/runtime-environment-tailscale-response.ts +++ b/src/main/ipc/runtime-environments/runtime-environment-tailscale-response.ts @@ -5,7 +5,8 @@ import { withRuntimeUnreachableHint } from './runtime-environment-unreachable-hi export function withTailscaleHintForResponse( response: RuntimeRpcResponse, endpoint: string, - environment: Pick + environment: Pick & + Partial> ): RuntimeRpcResponse { if (response.ok === true) { return response diff --git a/src/main/ipc/runtime-environments/runtime-environment-unreachable-hint.test.ts b/src/main/ipc/runtime-environments/runtime-environment-unreachable-hint.test.ts new file mode 100644 index 00000000000..73328b930f7 --- /dev/null +++ b/src/main/ipc/runtime-environments/runtime-environment-unreachable-hint.test.ts @@ -0,0 +1,21 @@ +import { describe, expect, it } from 'vitest' +import { withRuntimeUnreachableHint } from './runtime-environment-unreachable-hint' + +const FAILURE = 'Could not connect to the remote Orca runtime: socket closed.' +const ENDPOINT = 'wss://203.0.113.7:6768' + +describe('withRuntimeUnreachableHint', () => { + it('hints Tailscale for a paired server on another network', () => { + expect( + withRuntimeUnreachableHint({ name: 'desk', source: 'manual' }, FAILURE, ENDPOINT) + ).toMatch(/Tailscale/) + }) + + it('leaves an Orca Cloud sandbox failure without a Tailscale hint', () => { + const cloud = { + name: 'orca-sandbox-push-test sandbox 1a2b3c4d', + source: 'ephemeral-vm' as const + } + expect(withRuntimeUnreachableHint(cloud, FAILURE, ENDPOINT)).toBe(FAILURE) + }) +}) diff --git a/src/main/ipc/runtime-environments/runtime-environment-unreachable-hint.ts b/src/main/ipc/runtime-environments/runtime-environment-unreachable-hint.ts index 3b329ba1237..58b27c5aa93 100644 --- a/src/main/ipc/runtime-environments/runtime-environment-unreachable-hint.ts +++ b/src/main/ipc/runtime-environments/runtime-environment-unreachable-hint.ts @@ -1,15 +1,22 @@ import { withRemoteRuntimeTailscaleHint } from '../../../shared/remote-runtime/remote-runtime-tailscale-hint' import { classifyRuntimeEnvironmentHost } from '../../../shared/remote-runtime/host-catalog/runtime-environment-host-kind' import type { KnownRuntimeEnvironment } from '../../../shared/remote-runtime/host-catalog/runtime-environments' +import { isOrcaCloudRuntimeEnvironment } from '../../../shared/remote-runtime/host-catalog/orca-cloud-environment-name' const UNREACHABLE_RE = /could not connect to the remote orca runtime|remote orca runtime closed the connection|timed out (?:waiting for|while connecting to) the remote orca runtime/i export function withRuntimeUnreachableHint( - environment: Pick, + environment: Pick & + Partial>, message: string, endpoint: string | null | undefined ): string { + // Orca Cloud sandboxes are reached through Orca Cloud, not the user's network: one that does not + // answer is asleep, gone, or another team's, and a Tailscale hint sends the user the wrong way. + if (isOrcaCloudRuntimeEnvironment(environment)) { + return message + } const host = classifyRuntimeEnvironmentHost(environment) switch (host.kind) { case 'network': diff --git a/src/renderer/src/components/sidebar/worktree-list/listing/use-main-list-model.ts b/src/renderer/src/components/sidebar/worktree-list/listing/use-main-list-model.ts index 6c9fbe9abd5..df2c3b16de1 100644 --- a/src/renderer/src/components/sidebar/worktree-list/listing/use-main-list-model.ts +++ b/src/renderer/src/components/sidebar/worktree-list/listing/use-main-list-model.ts @@ -9,11 +9,8 @@ import { } from '@/lib/sidebar-pending-layer' import { useSidebarListSession } from '@/lib/sidebar-list-session' import { readEndedCreations, subscribeEndedCreations } from '@/lib/sidebar-ended-creations' -import { - readHiddenVmCheckouts, - subscribeHiddenVmCheckouts, - withoutHiddenVmCheckouts -} from '@/lib/vm-create-hidden-checkouts' +import { withoutHiddenVmCheckouts } from '@/lib/vm-create-hidden-checkouts' +import { useSidebarHiddenCheckouts } from '@/lib/orca-cloud/use-sidebar-hidden-checkouts' import '../../../../../../shared/folder-workspaces/folder-workspace-execution-host' import { getFolderWorkspaceHostId } from '../../../../../../shared/folder-workspaces/folder-workspace-host-id' import type { FolderWorkspace } from '../../../../../../shared/folder-workspaces/folder-workspace-types' @@ -78,7 +75,7 @@ export function useMainSidebarListModel(args: SidebarListModelArgs): SidebarList const feed = useDesktopSidebarFeed() const pending = useSyncExternalStore(subscribeSidebarPendingLayer, readSidebarPendingLayer) const endedCreationIds = useSyncExternalStore(subscribeEndedCreations, readEndedCreations) - const hiddenVmCheckouts = useSyncExternalStore(subscribeHiddenVmCheckouts, readHiddenVmCheckouts) + const hiddenVmCheckouts = useSidebarHiddenCheckouts() const pendingCreationKeys = useAppStore( useShallow((s) => selectPendingWorktreeCreationKeys(s.pendingWorktreeCreations)) ) diff --git a/src/renderer/src/components/sidebar/worktree-list/listing/use-visible-worktrees.ts b/src/renderer/src/components/sidebar/worktree-list/listing/use-visible-worktrees.ts index 9a83fe32d62..c33f953ca27 100644 --- a/src/renderer/src/components/sidebar/worktree-list/listing/use-visible-worktrees.ts +++ b/src/renderer/src/components/sidebar/worktree-list/listing/use-visible-worktrees.ts @@ -1,5 +1,5 @@ import { selectSidebarLineageParentIdentities } from '@/store/slices/worktrees/metadata/cross-store-lineage-parents' -import { useMemo, useState, useSyncExternalStore } from 'react' +import { useMemo, useState } from 'react' import { shallow } from 'zustand/shallow' import type { AppState } from '@/store/types' import { useAppStore } from '@/store' @@ -24,11 +24,8 @@ import type { SidebarWorktreeFilters } from './use-filters' import { useReusedArrayIdentity } from './use-reused-array-identity' import { useSleepingSweepRetention } from './use-sleeping-sweep-retention' import { selectWorktreesByRepo } from '@/store/workspaces/catalog/workspace-record-fields' -import { - readHiddenVmCheckouts, - subscribeHiddenVmCheckouts, - withoutHiddenVmWorktrees -} from '@/lib/vm-create-hidden-checkouts' +import { withoutHiddenVmWorktrees } from '@/lib/vm-create-hidden-checkouts' +import { useSidebarHiddenCheckouts } from '@/lib/orca-cloud/use-sidebar-hidden-checkouts' const EMPTY_WORKTREE_ID_SET: ReadonlySet = new Set() @@ -123,7 +120,7 @@ export function useVisibleSidebarWorktrees(args: { worktreeIdsWithStructuredChat }) - const hiddenVmCheckouts = useSyncExternalStore(subscribeHiddenVmCheckouts, readHiddenVmCheckouts) + const hiddenVmCheckouts = useSidebarHiddenCheckouts() const recomputedVisibleWorktrees = useMemo(() => { const visible = computeVisibleWorktrees(worktreesByRepo, sortedIds, { filterRepoIds, diff --git a/src/renderer/src/components/worktree-jump/use-worktree-jump-palette-store-state.ts b/src/renderer/src/components/worktree-jump/use-worktree-jump-palette-store-state.ts index fb5113b520b..1806af7e8c5 100644 --- a/src/renderer/src/components/worktree-jump/use-worktree-jump-palette-store-state.ts +++ b/src/renderer/src/components/worktree-jump/use-worktree-jump-palette-store-state.ts @@ -1,4 +1,4 @@ -import { useMemo, useSyncExternalStore } from 'react' +import { useMemo } from 'react' import { useTranslation } from 'react-i18next' import { useShallow } from 'zustand/react/shallow' import { useAppStore } from '@/store/index' @@ -6,11 +6,8 @@ import { usePluginCommands } from '@/store/plugins/catalog/plugin-contribution-c import { usePluginNewFiles } from '@/store/plugins/file-creation/plugin-new-files' import { useSettingsNavigationMetadata } from '@/hooks/useSettingsNavigationMetadata' import { dedupePaletteWorktrees } from '@/lib/workspace/search/palette-repo-resolution' -import { - readHiddenVmCheckouts, - subscribeHiddenVmCheckouts, - withoutHiddenVmWorktreesByRepo -} from '@/lib/vm-create-hidden-checkouts' +import { withoutHiddenVmWorktreesByRepo } from '@/lib/vm-create-hidden-checkouts' +import { useSidebarHiddenCheckouts } from '@/lib/orca-cloud/use-sidebar-hidden-checkouts' import { selectPaletteIndexStatusSnapshot, selectPaletteStatusInputs @@ -42,8 +39,8 @@ export function useWorktreeJumpPaletteStoreState({ const recordFeatureInteraction = useAppStore((state) => state.recordFeatureInteraction) const revealSidebarRow = useAppStore((state) => state.revealSidebarRow) const storedWorktreesByRepo = useAppStore((state) => selectWorktreesByRepo(state)) - const hiddenVmCheckouts = useSyncExternalStore(subscribeHiddenVmCheckouts, readHiddenVmCheckouts) - // Why: a VM create's checkout is not a workspace until the create adopts it. + const hiddenVmCheckouts = useSidebarHiddenCheckouts() + // Why: a VM create's checkout is not a workspace until the create adopts it; an Orca Cloud clone never is. const worktreesByRepo = useMemo( () => withoutHiddenVmWorktreesByRepo(storedWorktreesByRepo, hiddenVmCheckouts), [storedWorktreesByRepo, hiddenVmCheckouts] diff --git a/src/renderer/src/lib/orca-cloud/use-sidebar-hidden-checkouts.test.ts b/src/renderer/src/lib/orca-cloud/use-sidebar-hidden-checkouts.test.ts new file mode 100644 index 00000000000..6dc1de652e6 --- /dev/null +++ b/src/renderer/src/lib/orca-cloud/use-sidebar-hidden-checkouts.test.ts @@ -0,0 +1,18 @@ +import { describe, expect, it } from 'vitest' +import type { AppState } from '@/store/types' +import { selectOrcaCloudHostIdsKey } from './use-sidebar-hidden-checkouts' + +describe('selectOrcaCloudHostIdsKey', () => { + it('names only Orca Cloud sandbox servers', () => { + // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the selector reads only id, name and source. + const state = { + runtimeEnvironments: [ + { id: 'a', name: 'orca-sandbox-push-test sandbox 1a2b3c4d', source: 'ephemeral-vm' }, + { id: 'b', name: 'orca-sandbox-push-test sandbox 5e6f7a8b', source: 'ephemeral-vm' }, + { id: 'vm', name: 'my recipe VM', source: 'ephemeral-vm' }, + { id: 'manual', name: 'orca-sandbox-push-test sandbox 1a2b3c4d', source: 'manual' } + ] + } as unknown as Pick + expect(selectOrcaCloudHostIdsKey(state).split('\n')).toEqual(['runtime:a', 'runtime:b']) + }) +}) diff --git a/src/renderer/src/lib/orca-cloud/use-sidebar-hidden-checkouts.ts b/src/renderer/src/lib/orca-cloud/use-sidebar-hidden-checkouts.ts new file mode 100644 index 00000000000..6e83c13220c --- /dev/null +++ b/src/renderer/src/lib/orca-cloud/use-sidebar-hidden-checkouts.ts @@ -0,0 +1,33 @@ +import { useMemo, useSyncExternalStore } from 'react' +import { useAppStore } from '@/store' +import type { AppState } from '@/store/types' +import { + readHiddenVmCheckouts, + subscribeHiddenVmCheckouts, + withOrcaCloudPrimaryHosts, + type HiddenVmCheckouts +} from '@/lib/vm-create-hidden-checkouts' +import { toRuntimeExecutionHostId } from '../../../../shared/execution-host' +import { isOrcaCloudRuntimeEnvironment } from '../../../../shared/remote-runtime/host-catalog/orca-cloud-environment-name' + +/** Orca Cloud sandbox hosts, newline-joined so the selector result compares by value. */ +export function selectOrcaCloudHostIdsKey(state: Pick): string { + return (state.runtimeEnvironments ?? []) + .filter((environment) => isOrcaCloudRuntimeEnvironment(environment)) + .map((environment) => toRuntimeExecutionHostId(environment.id)) + .join('\n') +} + +/** What sidebar lists hide: VM checkouts whose create is in progress, and every Orca Cloud clone. */ +export function useSidebarHiddenCheckouts(): HiddenVmCheckouts { + const pending = useSyncExternalStore(subscribeHiddenVmCheckouts, readHiddenVmCheckouts) + const cloudHostIdsKey = useAppStore(selectOrcaCloudHostIdsKey) + return useMemo( + () => + withOrcaCloudPrimaryHosts( + pending, + new Set(cloudHostIdsKey ? cloudHostIdsKey.split('\n') : []) + ), + [pending, cloudHostIdsKey] + ) +} diff --git a/src/renderer/src/lib/vm-create-hidden-checkouts.test.ts b/src/renderer/src/lib/vm-create-hidden-checkouts.test.ts index d56214a7ef6..3a35bfd9827 100644 --- a/src/renderer/src/lib/vm-create-hidden-checkouts.test.ts +++ b/src/renderer/src/lib/vm-create-hidden-checkouts.test.ts @@ -1,13 +1,16 @@ import { afterEach, describe, expect, it, vi } from 'vitest' import { EMPTY_SIDEBAR_FEED_DOMAINS } from '../../../shared/sidebar-feed-client/sidebar-feed-snapshot' import type { SidebarFeedDomains } from '../../../shared/sidebar-list/sidebar-feed-domains' +import { composeWorktreeHostIdentity } from '../../../shared/worktree/host-qualified-identity' import { hideVmCreateCheckout, readHiddenVmCheckouts, releaseVmCreateCheckout, settleVmCreateCheckoutAfterCleanup, + withOrcaCloudPrimaryHosts, withoutHiddenVmCheckouts, - withoutHiddenVmWorktrees + withoutHiddenVmWorktrees, + withoutHiddenVmWorktreesByRepo } from './vm-create-hidden-checkouts' type Row = { repoId: string; path: string; isMainWorktree?: boolean } @@ -78,3 +81,54 @@ describe('hidden VM checkout lifecycle', () => { expect(isListed('vm')).toBe(true) }) }) + +describe('Orca Cloud sandbox primaries', () => { + // Two cloud workspaces of one project: each sandbox lists its clone (master) as primary. + const hostA = 'runtime:sandbox-a' + const hostB = 'runtime:sandbox-b' + const cloudHosts = new Set([hostA, hostB]) + const cloneA = { + repoId: 'r', + path: '/vercel/sandbox/project', + isMainWorktree: true, + hostId: hostA + } + const cloneB = { ...cloneA, hostId: hostB } + const sockeye = { repoId: 'r', path: '/w/sockeye', isMainWorktree: false, hostId: hostA } + const otter = { repoId: 'r', path: '/w/otter', isMainWorktree: false, hostId: hostB } + const local = { repoId: 'r', path: '/Users/me/repo', isMainWorktree: true, hostId: 'local' } + + it('lists neither clone as a row, keeping the cloud workspaces and the local primary', () => { + const hidden = withOrcaCloudPrimaryHosts(readHiddenVmCheckouts(), cloudHosts) + const rows = [local, cloneA, cloneB, sockeye, otter] + + expect(withoutHiddenVmWorktrees(rows, hidden)).toEqual([local, sockeye, otter]) + expect(withoutHiddenVmWorktreesByRepo({ r: rows }, hidden)).toEqual({ + r: [local, sockeye, otter] + }) + }) + + it("reads a paired-server row's host from its host-qualified key", () => { + const { hostId: _a, ...rowA } = cloneA + const { hostId: _b, ...rowB } = cloneB + const { hostId: _s, ...rowS } = sockeye + // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the filter reads only repoId, path, isMainWorktree and the key. + const domains = { + ...EMPTY_SIDEBAR_FEED_DOMAINS, + pairedServerRows: new Map([ + [composeWorktreeHostIdentity(hostA, 'r::/vercel/sandbox/project'), rowA], + [composeWorktreeHostIdentity(hostB, 'r::/vercel/sandbox/project'), rowB], + [composeWorktreeHostIdentity(hostA, 'r::/w/sockeye'), rowS] + ]) + } as unknown as SidebarFeedDomains + const hidden = withOrcaCloudPrimaryHosts(readHiddenVmCheckouts(), cloudHosts) + + expect([...withoutHiddenVmCheckouts(domains, hidden).pairedServerRows.values()]).toEqual([rowS]) + }) + + it('leaves lists untouched when no Orca Cloud host is known', () => { + const rows = [local, cloneA] + const hidden = withOrcaCloudPrimaryHosts(readHiddenVmCheckouts(), new Set()) + expect(withoutHiddenVmWorktrees(rows, hidden)).toBe(rows) + }) +}) diff --git a/src/renderer/src/lib/vm-create-hidden-checkouts.ts b/src/renderer/src/lib/vm-create-hidden-checkouts.ts index 6faf4a20a90..f05458b8670 100644 --- a/src/renderer/src/lib/vm-create-hidden-checkouts.ts +++ b/src/renderer/src/lib/vm-create-hidden-checkouts.ts @@ -1,4 +1,5 @@ import type { SidebarFeedDomains } from '../../../shared/sidebar-list/sidebar-feed-domains' +import { getExecutionHostIdFromWorktreeHostIdentity } from '../../../shared/worktree/host-qualified-identity' import { indexPendingVmCheckouts, isPendingVmCheckout, @@ -8,10 +9,43 @@ import { /** A VM's primary checkout, registered on its host before the create that owns it finishes. */ export type HiddenVmCheckout = PendingVmCheckout -type CheckoutRow = { repoId: string; path: string; isMainWorktree?: boolean } +type CheckoutRow = { repoId: string; path: string; isMainWorktree?: boolean; hostId?: string } -/** What lists filter by: this window's pending VM checkouts and every other window's. */ -export type HiddenVmCheckouts = PendingVmCheckoutIndex +/** + * What lists filter by: this window's pending VM checkouts and every other window's, plus the hosts + * whose primary checkout is never a workspace (withOrcaCloudPrimaryHosts). + */ +export type HiddenVmCheckouts = PendingVmCheckoutIndex & { + readonly primaryHostIds?: ReadonlySet +} + +/** + * Why: each Orca Cloud workspace is its own sandbox whose clone is registered as the project there, + * and the workspace is a worktree beside it (orca-worktree mode). That clone is scaffolding, not a + * workspace: listed, every cloud workspace added another identical " primary · + * Orca Cloud" row to its project. + */ +export function withOrcaCloudPrimaryHosts( + checkouts: HiddenVmCheckouts, + hostIds: ReadonlySet +): HiddenVmCheckouts { + return hostIds.size === 0 ? checkouts : { ...checkouts, primaryHostIds: hostIds } +} + +function hidesNothing(checkouts: HiddenVmCheckouts): boolean { + return checkouts.keys.size === 0 && !checkouts.primaryHostIds?.size +} + +function isHiddenCheckout( + checkouts: HiddenVmCheckouts, + row: CheckoutRow, + hostId: string | undefined = row.hostId +): boolean { + if (row.isMainWorktree === true && hostId && checkouts.primaryHostIds?.has(hostId)) { + return true + } + return checkouts.keys.size > 0 && isPendingVmCheckout(checkouts, row) +} // Upper bound for a cleaned-up VM's rows to leave the lists (its host is retired asynchronously). const HIDDEN_AFTER_CLEANUP_MS = 60_000 @@ -136,10 +170,10 @@ export function withoutHiddenVmWorktrees( worktrees: W[], checkouts: HiddenVmCheckouts ): W[] { - if (checkouts.keys.size === 0) { + if (hidesNothing(checkouts)) { return worktrees } - const kept = worktrees.filter((worktree) => !isPendingVmCheckout(checkouts, worktree)) + const kept = worktrees.filter((worktree) => !isHiddenCheckout(checkouts, worktree)) return kept.length === worktrees.length ? worktrees : kept } @@ -148,11 +182,13 @@ export function withoutHiddenVmWorktreesByRepo( worktreesByRepo: Record, checkouts: HiddenVmCheckouts ): Record { - if (checkouts.keys.size === 0) { + if (hidesNothing(checkouts)) { return worktreesByRepo } let next: Record | null = null - for (const repoId of checkouts.repoIds) { + // Host-hidden primaries can sit under any repo; pending checkouts only under theirs. + const repoIds = checkouts.primaryHostIds?.size ? Object.keys(worktreesByRepo) : checkouts.repoIds + for (const repoId of repoIds) { const list = worktreesByRepo[repoId] if (!list) { continue @@ -166,13 +202,15 @@ export function withoutHiddenVmWorktreesByRepo( return next ?? worktreesByRepo } -function withoutHiddenRows( +function withoutHiddenRows( rows: ReadonlyMap, checkouts: HiddenVmCheckouts ): ReadonlyMap { let kept: Map | null = null for (const [key, row] of rows) { - if (isPendingVmCheckout(checkouts, row)) { + // Paired-server rows carry their host only in the host-qualified key. + const hostId = row.hostId ?? getExecutionHostIdFromWorktreeHostIdentity(key) + if (isHiddenCheckout(checkouts, row, hostId)) { kept ??= new Map(rows) kept.delete(key) } @@ -185,7 +223,7 @@ export function withoutHiddenVmCheckouts( domains: SidebarFeedDomains, checkouts: HiddenVmCheckouts ): SidebarFeedDomains { - if (checkouts.keys.size === 0) { + if (hidesNothing(checkouts)) { return domains } const workspaces = withoutHiddenRows(domains.workspaces, checkouts)