Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.
TypeScript adeagent-ideai-agentsautomationbotclaude-codecodexghosttygrok-bothermes-agentmobile-appmuseopenclawopencodeorchestrationpiruntimeterminalworktreesyc-backed
fix(browser): keep SSH workspace browser pages from reloading when you switch back (#36266)
Kelvin Amoaba7358da227b79
diff --git a/src/renderer/src/components/browser-pane/assemble-chrome/browser-deferred-lifecycle.test.tsx b/src/renderer/src/components/browser-pane/assemble-chrome/browser-deferred-lifecycle.test.tsxindex 6d245ceed20..ff360dbb72d 100644--- a/src/renderer/src/components/browser-pane/assemble-chrome/browser-deferred-lifecycle.test.tsx+++ b/src/renderer/src/components/browser-pane/assemble-chrome/browser-deferred-lifecycle.test.tsx@@ -41,7 +41,10 @@ vi.mock('@/lib/worktree-runtime-owner', () => ({vi.mock('@/components/contextual-tours/use-contextual-tour', () => ({useContextualTour: () => {}}))-vi.mock('../host-guest/webview-registry', () => ({ destroyPersistentWebview: mocks.destroy }))+vi.mock('../host-guest/webview-registry', () => ({+ destroyPersistentWebview: mocks.destroy,+ webviewRegistry: new Map()+}))vi.mock('./BrowserMobileDriverOverlay', () => ({ BrowserMobileDriverOverlay: () => null }))vi.mock('./browser-page-pane', () => ({BrowserPagePane: ({ browserTab, isActive }: { browserTab: BrowserPage; isActive: boolean }) => (@@ -54,13 +57,16 @@ vi.mock('../workspace-doc/workspace-doc-page-pane', () => ({)}))-import BrowserPaneOverlayLayer from './BrowserPaneOverlayLayer'-import {- acquireBrowserAutomationVisibility,- releaseBrowserAutomationVisibility-} from '../host-guest/browser-automation-visibility'-import { hydrateBrowserDrivers } from '@/lib/pane-manager/browser-mobile-driver-state'-import { hydrateBrowserRemoteViewerPages } from '@/lib/pane-manager/browser-remote-viewer-state'+import type BrowserPaneOverlayLayerComponent from './BrowserPaneOverlayLayer'+import type * as AutomationVisibility from '../host-guest/browser-automation-visibility'+import type * as MobileDriverState from '@/lib/pane-manager/browser-mobile-driver-state'+import type * as RemoteViewerState from '@/lib/pane-manager/browser-remote-viewer-state'++let BrowserPaneOverlayLayer: typeof BrowserPaneOverlayLayerComponent+let acquireBrowserAutomationVisibility: typeof AutomationVisibility.acquireBrowserAutomationVisibility+let releaseBrowserAutomationVisibility: typeof AutomationVisibility.releaseBrowserAutomationVisibility+let hydrateBrowserDrivers: typeof MobileDriverState.hydrateBrowserDrivers+let hydrateBrowserRemoteViewerPages: typeof RemoteViewerState.hydrateBrowserRemoteViewerPagesfunction createState(): MockState {const browsers: BrowserWorkspace[] = ['a', 'b'].map((id) => ({@@ -147,7 +153,15 @@ function redraw(view: ReturnType<typeof render>, active = true): void {const settle = () => act(async () => {})describe('deferred browser lifecycle through the overlay and SSH gate', () => {- beforeEach(() => {+ beforeEach(async () => {+ // Verified SSH routes outlive mounts at module scope; each test starts unverified.+ vi.resetModules()+ ;({ default: BrowserPaneOverlayLayer } = await import('./BrowserPaneOverlayLayer'))+ ;({ acquireBrowserAutomationVisibility, releaseBrowserAutomationVisibility } =+ await import('../host-guest/browser-automation-visibility'))+ ;({ hydrateBrowserDrivers } = await import('@/lib/pane-manager/browser-mobile-driver-state'))+ ;({ hydrateBrowserRemoteViewerPages } =+ await import('@/lib/pane-manager/browser-remote-viewer-state'))mocks.state = createState()mocks.store = createStore(() => mocks.state!)mocks.executionHostId = 'local'diff --git a/src/renderer/src/components/browser-pane/assemble-chrome/ssh-routed-browser-page-gate.test.tsx b/src/renderer/src/components/browser-pane/assemble-chrome/ssh-routed-browser-page-gate.test.tsxindex 64014d4d6f5..0c4e411905a 100644--- a/src/renderer/src/components/browser-pane/assemble-chrome/ssh-routed-browser-page-gate.test.tsx+++ b/src/renderer/src/components/browser-pane/assemble-chrome/ssh-routed-browser-page-gate.test.tsx@@ -1,12 +1,14 @@// @vitest-environment happy-domimport { act, cleanup, render, screen } from '@testing-library/react'import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'-import { useAppStore } from '@/store'+import type { useAppStore as AppStore } from '@/store'+import type { SshRoutedBrowserPageGate as Gate } from './ssh-routed-browser-page-gate'const mocks = vi.hoisted(() => ({executionHostId: 'local' as string,prepare: vi.fn(),- destroyPersistentWebview: vi.fn()+ destroyPersistentWebview: vi.fn(),+ webviewRegistry: new Map<string, { getAttribute: (name: string) => string | null }>()}))vi.mock('@/lib/worktree-runtime-owner', () => ({@@ -14,13 +16,14 @@ vi.mock('@/lib/worktree-runtime-owner', () => ({}))vi.mock('../host-guest/webview-registry', () => ({- destroyPersistentWebview: mocks.destroyPersistentWebview+ destroyPersistentWebview: mocks.destroyPersistentWebview,+ webviewRegistry: mocks.webviewRegistry}))-import { SshRoutedBrowserPageGate } from './ssh-routed-browser-page-gate'+let useAppStore: typeof AppStore+let SshRoutedBrowserPageGate: typeof Gateconst PAGE_IDS = ['page-1', 'page-2'] as const-const initialHostState = useAppStore.getState()const settle = () =>act(async () => {@@ -28,7 +31,11 @@ const settle = () =>})describe('SshRoutedBrowserPageGate', () => {- beforeEach(() => {+ beforeEach(async () => {+ // Verified routes outlive mounts at module scope; each test starts with a fresh store and no verified route.+ vi.resetModules()+ ;({ useAppStore } = await import('@/store'))+ ;({ SshRoutedBrowserPageGate } = await import('./ssh-routed-browser-page-gate'))useAppStore.setState({sshConnectionStates: new Map([[@@ -39,15 +46,13 @@ describe('SshRoutedBrowserPageGate', () => {})mocks.prepare.mockReset().mockResolvedValue({ partition: 'persist:orca-browser-v1-routed' })mocks.destroyPersistentWebview.mockReset()+ mocks.webviewRegistry.clear()Object.defineProperty(window, 'api', {configurable: true,value: { browser: { prepareSshWorkspacePartition: mocks.prepare } }})})- afterEach(() => {- cleanup()- useAppStore.setState({ sshConnectionStates: initialHostState.sshConnectionStates })- })+ afterEach(() => cleanup())it('renders children with no override for non-SSH workspaces without any prepare call', async () => {mocks.executionHostId = 'local'@@ -79,6 +84,52 @@ describe('SshRoutedBrowserPageGate', () => {})})+ describe('remounting after the route was verified', () => {+ const gate = () => (+ <SshRoutedBrowserPageGate worktreeId="wt-1" sessionProfileId={null} pageIds={PAGE_IDS}>+ {(partition) => <div data-testid="page">{String(partition)}</div>}+ </SshRoutedBrowserPageGate>+ )+ beforeEach(async () => {+ mocks.executionHostId = 'ssh:target-a'+ render(gate())+ await settle()+ cleanup()+ mocks.destroyPersistentWebview.mockClear()+ })++ const parkGuest = (pageId: string, partition: string): void => {+ mocks.webviewRegistry.set(pageId, { getAttribute: () => partition })+ }++ it('keeps guests already on the routed partition instead of reloading them', async () => {+ parkGuest('page-1', 'persist:orca-browser-v1-routed')+ parkGuest('page-2', 'orca-doc-preview')+ // Worktree switches and paint mounts remount the chrome; a preparing pass would destroy and reload the guest.+ render(gate())+ expect(screen.getByTestId('page').textContent).toBe('persist:orca-browser-v1-routed')+ await settle()+ expect(screen.getByTestId('page').textContent).toBe('persist:orca-browser-v1-routed')+ expect(mocks.destroyPersistentWebview).not.toHaveBeenCalled()+ })++ it('destroys a parked guest that browsed with local egress meanwhile', () => {+ // Routing was off when this page opened; another gate on the target has since re-verified the route.+ parkGuest('page-1', 'persist:orca-browser-v1-routed')+ parkGuest('page-2', 'persist:local-default')+ render(gate())+ expect(mocks.destroyPersistentWebview.mock.calls).toEqual([['page-2']])+ })++ it('shows the error card when main has retired the route since', async () => {+ mocks.prepare.mockRejectedValue(new Error('browser_local_route_profile_unavailable'))+ render(gate())+ await settle()+ expect(screen.queryByTestId('page')).toBeNull()+ expect(screen.getByRole('button', { name: 'Retry' })).toBeTruthy()+ })+ })+it('never renders the page on failure and retries on demand', async () => {mocks.executionHostId = 'ssh:target-a'mocks.prepare.mockRejectedValueOnce(new Error('browser_tunnel_execution_host_unavailable'))diff --git a/src/renderer/src/components/browser-pane/assemble-chrome/ssh-routed-browser-page-gate.tsx b/src/renderer/src/components/browser-pane/assemble-chrome/ssh-routed-browser-page-gate.tsxindex 60115a21f62..6e12196d6ac 100644--- a/src/renderer/src/components/browser-pane/assemble-chrome/ssh-routed-browser-page-gate.tsx+++ b/src/renderer/src/components/browser-pane/assemble-chrome/ssh-routed-browser-page-gate.tsx@@ -2,7 +2,8 @@ import { useEffect } from 'react'import { Globe } from 'lucide-react'import { translate } from '@/i18n/i18n'import { Button } from '@/components/ui/button'-import { destroyPersistentWebview } from '../host-guest/webview-registry'+import { DOC_PREVIEW_PARTITION } from '../../../../../shared/doc-preview-scheme'+import { destroyPersistentWebview, webviewRegistry } from '../host-guest/webview-registry'import {useSshWorkspaceBrowserRoute,type SshWorkspaceBrowserRouteErrorKind@@ -17,7 +18,7 @@ export function SshRoutedBrowserPageGate({}: {worktreeId: stringsessionProfileId: string | null- /** Pages this gate guards; their guests are destroyed whenever mounting is not allowed. */+ /** Pages this gate guards; their guests are destroyed whenever they could browse off the verified route. */pageIds: readonly string[]children: (routedPartition: string | null) => React.JSX.Element}): React.JSX.Element {@@ -25,16 +26,28 @@ export function SshRoutedBrowserPageGate({worktreeId,sessionProfileId)- const mountable = state.kind === 'unrouted' || state.kind === 'ready'+ const unrouted = state.kind === 'unrouted'+ const routedPartition = state.kind === 'ready' ? state.partition : nulluseEffect(() => {- if (mountable) {+ if (unrouted) {return}// Chrome unmount only parks guests; destroy pre-route guests so they cannot keep browsing with local egress behind the gate.for (const pageId of pageIds) {+ if (routedPartition) {+ const partition = webviewRegistry.get(pageId)?.getAttribute('partition')+ // Guests already on the verified route (or a local doc preview) survive remounts without reloading.+ if (+ partition === undefined ||+ partition === routedPartition ||+ partition === DOC_PREVIEW_PARTITION+ ) {+ continue+ }+ }void destroyPersistentWebview(pageId)}- }, [mountable, pageIds])+ }, [unrouted, routedPartition, pageIds])if (state.kind === 'unrouted') {return children(null)diff --git a/src/renderer/src/components/browser-pane/use-ssh-workspace-browser-route.host-connection.test.tsx b/src/renderer/src/components/browser-pane/use-ssh-workspace-browser-route.host-connection.test.tsxindex 88ea8f49dcd..c33ca8065f2 100644--- a/src/renderer/src/components/browser-pane/use-ssh-workspace-browser-route.host-connection.test.tsx+++ b/src/renderer/src/components/browser-pane/use-ssh-workspace-browser-route.host-connection.test.tsx@@ -3,6 +3,7 @@ import { act, cleanup, renderHook } from '@testing-library/react'import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import type { WorktreeHostConnection } from '@/lib/worktree-host-connection-phase'import type { SshConnectionStatus } from '../../../../shared/ssh-types'+import type { useSshWorkspaceBrowserRoute as UseSshWorkspaceBrowserRoute } from './use-ssh-workspace-browser-route'const mocks = vi.hoisted(() => {const hostConnection: WorktreeHostConnection = {@@ -24,7 +25,7 @@ vi.mock('@/lib/worktree-host-connection-phase', () => ({useWorktreeHostConnection: () => mocks.hostConnection}))-import { useSshWorkspaceBrowserRoute } from './use-ssh-workspace-browser-route'+let useSshWorkspaceBrowserRoute: typeof UseSshWorkspaceBrowserRouteconst READY_PARTITION = 'persist:orca-browser-v1-routed'@@ -55,7 +56,10 @@ function setHost(}describe('useSshWorkspaceBrowserRoute under a reconnecting SSH host', () => {- beforeEach(() => {+ beforeEach(async () => {+ // Verified routes outlive mounts at module scope; each test starts unverified.+ vi.resetModules()+ ;({ useSshWorkspaceBrowserRoute } = await import('./use-ssh-workspace-browser-route'))mocks.prepare.mockReset()mocks.executionHostId = 'ssh:target-a'Object.defineProperty(window, 'api', {diff --git a/src/renderer/src/components/browser-pane/use-ssh-workspace-browser-route.ts b/src/renderer/src/components/browser-pane/use-ssh-workspace-browser-route.tsindex 30eb6daa3d9..521c217fad1 100644--- a/src/renderer/src/components/browser-pane/use-ssh-workspace-browser-route.ts+++ b/src/renderer/src/components/browser-pane/use-ssh-workspace-browser-route.ts@@ -28,6 +28,31 @@ export function classifySshWorkspaceBrowserRouteError(return 'unknown'}+// A remounted gate starts from its last verified partition instead of destroying guests already on it.+const verifiedPartitionByRoute = new Map<string, string>()++function readyRouteState(+ partition: string,+ targetId: string,+ expectedSshTargetGeneration: number | undefined+): SshWorkspaceBrowserRouteState {+ return {+ kind: 'ready',+ partition,+ targetId,+ ...(expectedSshTargetGeneration !== undefined ? { expectedSshTargetGeneration } : {})+ }+}++function verifiedRouteState(+ routeKey: string,+ targetId: string,+ expectedSshTargetGeneration: number | undefined+): SshWorkspaceBrowserRouteState | null {+ const partition = verifiedPartitionByRoute.get(routeKey)+ return partition ? readyRouteState(partition, targetId, expectedSshTargetGeneration) : null+}+/** Mount only a proxy-verified partition; preparing/failed routes must never fall back to local egress. Unrouted access requires an explicit opt-out. */export function useSshWorkspaceBrowserRoute(worktreeId: string,@@ -59,8 +84,20 @@ export function useSshWorkspaceBrowserRoute(count: 0,skipProbe: false})- const [state, setState] = useState<SshWorkspaceBrowserRouteState>(- targetId ? { kind: 'preparing' } : { kind: 'unrouted' }+ // Persist “Try anyway”: forwarding may work while the loopback probe is forbidden; do not re-prompt every launch.+ const skipProbe = attempt.skipProbe || probeSkippedTargetIds?.includes(targetId ?? '') === true+ const routeKey = JSON.stringify([+ targetId,+ browserProfileId,+ expectedSshTargetGeneration ?? null,+ skipProbe+ ])+ const [state, setState] = useState<SshWorkspaceBrowserRouteState>(() =>+ targetId+ ? (verifiedRouteState(routeKey, targetId, expectedSshTargetGeneration) ?? {+ kind: 'preparing'+ })+ : { kind: 'unrouted' })const hostConnection = useWorktreeHostConnection(worktreeId, targetId)const routeHost =@@ -81,16 +118,16 @@ export function useSshWorkspaceBrowserRoute(}}- // Persist “Try anyway”: forwarding may work while the loopback probe is forbidden; do not re-prompt every launch.- const skipProbe = attempt.skipProbe || probeSkippedTargetIds?.includes(targetId ?? '') === trueuseEffect(() => {if (!targetId) {setState({ kind: 'unrouted' })return}- setState({ kind: 'preparing' })+ // A verified route stays mounted while main re-confirms; a retired target or profile still reaches the error card.+ const verified = verifiedRouteState(routeKey, targetId, expectedSshTargetGeneration)+ setState(verified ?? { kind: 'preparing' })// Preparing during dial can only fail ssh-unavailable; wait for the connected transition.- if (awaitingHost) {+ if (!verified && awaitingHost) {return}let cancelled = false@@ -103,15 +140,12 @@ export function useSshWorkspaceBrowserRoute(}).then((result) => {if (!cancelled) {- setState({- kind: 'ready',- partition: result.partition,- targetId,- ...(expectedSshTargetGeneration !== undefined ? { expectedSshTargetGeneration } : {})- })+ verifiedPartitionByRoute.set(routeKey, result.partition)+ setState(readyRouteState(result.partition, targetId, expectedSshTargetGeneration))}}).catch((error: unknown) => {+ verifiedPartitionByRoute.delete(routeKey)if (!cancelled) {const message = error instanceof Error ? error.message : String(error)setState({@@ -124,7 +158,15 @@ export function useSshWorkspaceBrowserRoute(return () => {cancelled = true}- }, [targetId, expectedSshTargetGeneration, browserProfileId, attempt, skipProbe, awaitingHost])+ }, [+ targetId,+ expectedSshTargetGeneration,+ browserProfileId,+ skipProbe,+ routeKey,+ attempt,+ awaitingHost+ ])// Derive target changes synchronously; stale unrouted/other-target state could mount a local-egress guest before the effect corrects it.const effectiveState: SshWorkspaceBrowserRouteState = !targetId@@ -135,7 +177,10 @@ export function useSshWorkspaceBrowserRoute(const rederive = (nextSkipProbe: boolean): void => {// Set preparing with the attempt so the effect can wait for dialing without cancelling its own prepare.setState({ kind: 'preparing' })- setAttempt((current) => ({ count: current.count + 1, skipProbe: nextSkipProbe }))+ setAttempt((current) => ({+ count: current.count + 1,+ skipProbe: nextSkipProbe+ }))}return {state: effectiveState,