From 2e7232d1f66b021f392cb393cd270ae25bdde576 Mon Sep 17 00:00:00 2001 From: Bob Lee Date: Thu, 12 Nov 2026 10:30:48 +0800 Subject: [PATCH] fix(web-ui): never show an unknown remote workspace status In Peer Device Mode the SSH provider only recorded a status when a per-workspace event named a remote workspace, so a peer's other remote workspaces (a hydrated list emits none) rendered "Status unknown". Ask the peer for each connection's state on Peer activation, surface switches, and any workspace change that leaves a connection without a status. A peer host that does not report SSH state keeps the mirrored connected state; an unreachable peer reads as an error. A row whose first check has not landed shows connecting instead of unknown, and the unknown label is removed. The remote pill now keeps the same dot + host shape in every state; the dot and tint carry the status and the tooltip spells it out. Previously the hover actions squeezed the host label to nothing while the status text could not shrink. --- .../sections/workspaces/WorkspaceItem.tsx | 15 ++--- .../workspaces/WorkspaceListSection.scss | 16 ----- .../ssh-remote/SSHRemoteProvider.test.tsx | 67 ++++++++++++++++++- .../features/ssh-remote/SSHRemoteProvider.tsx | 64 ++++++++++++++---- src/web-ui/src/locales/en-US/common.json | 3 +- src/web-ui/src/locales/zh-CN/common.json | 3 +- src/web-ui/src/locales/zh-TW/common.json | 3 +- 7 files changed, 125 insertions(+), 46 deletions(-) diff --git a/src/web-ui/src/app/components/NavPanel/sections/workspaces/WorkspaceItem.tsx b/src/web-ui/src/app/components/NavPanel/sections/workspaces/WorkspaceItem.tsx index e64d74e9a0..1fe14efd61 100644 --- a/src/web-ui/src/app/components/NavPanel/sections/workspaces/WorkspaceItem.tsx +++ b/src/web-ui/src/app/components/NavPanel/sections/workspaces/WorkspaceItem.tsx @@ -295,10 +295,9 @@ const WorkspaceItem: React.FC = ({ return null; } - const status = remoteConnStatus ?? 'unknown'; - const statusLabel = t(`nav.workspaces.remote.status.${status}`, { - defaultValue: t('nav.workspaces.remote.status.unknown'), - }); + // No status yet means the first check for this connection is still running. + const status = remoteConnStatus ?? 'connecting'; + const statusLabel = t(`nav.workspaces.remote.status.${status}`); const badge = remoteBadge ?? remoteWorkspaceBadge(workspace); const connectionLabel = badge?.connection ?? ''; const hostLabel = badge?.host || connectionLabel; @@ -307,8 +306,6 @@ const WorkspaceItem: React.FC = ({ status, statusLabel, badgeLabel: badge?.label ?? connectionLabel, - /** A green dot already reads as "fine"; spell out only the states that need attention. */ - showStatusText: status !== 'connected', tooltip: t('nav.workspaces.remote.tooltip', { connection: connectionLabel, host: hostLabel, @@ -1356,14 +1353,10 @@ const WorkspaceItem: React.FC = ({ className={`openbitfun-nav-panel__workspace-item-status-dot is-${remoteMeta.status}`} aria-hidden="true" /> + {/* Same shape in every state: the dot and tint carry the status, the tooltip spells it out. */} {remoteMeta.badgeLabel} - {remoteMeta.showStatusText ? ( - - {remoteMeta.statusLabel} - - ) : null} )} diff --git a/src/web-ui/src/app/components/NavPanel/sections/workspaces/WorkspaceListSection.scss b/src/web-ui/src/app/components/NavPanel/sections/workspaces/WorkspaceListSection.scss index 43d8a27eb8..f60b10ad8c 100644 --- a/src/web-ui/src/app/components/NavPanel/sections/workspaces/WorkspaceListSection.scss +++ b/src/web-ui/src/app/components/NavPanel/sections/workspaces/WorkspaceListSection.scss @@ -445,18 +445,6 @@ text-overflow: ellipsis; } - &__workspace-item-remote-status { - flex-shrink: 0; - white-space: nowrap; - opacity: 0.85; - - &::before { - content: '·'; - margin-right: 4px; - opacity: 0.6; - } - } - &__workspace-item:not(.is-active) &__workspace-item-remote { opacity: 0.8; } @@ -477,10 +465,6 @@ background: var(--openbitfun-color-status-danger-emphasis); } - &.is-unknown { - background: var(--openbitfun-color-content-muted); - } - &.is-connecting { background: var(--openbitfun-color-status-warning-emphasis); animation: openbitfun-status-dot-pulse 1.4s ease-in-out infinite; diff --git a/src/web-ui/src/features/ssh-remote/SSHRemoteProvider.test.tsx b/src/web-ui/src/features/ssh-remote/SSHRemoteProvider.test.tsx index aea42349fe..af1be6b881 100644 --- a/src/web-ui/src/features/ssh-remote/SSHRemoteProvider.test.tsx +++ b/src/web-ui/src/features/ssh-remote/SSHRemoteProvider.test.tsx @@ -1046,9 +1046,10 @@ describe('SSHRemoteProvider workspace connection state', () => { expect(ACPClientAPI.invalidateRemoteRequirementProbeCache).toHaveBeenCalledWith('conn-1'); }); - it('mirrors peer-owned remote workspaces as connected without starting the reconnect timeout', async () => { + it('reads peer-owned remote workspace status from the peer without starting the reconnect timeout', async () => { vi.useFakeTimers(); peerModeFlagMock.active = true; + sshApiMock.isConnected.mockResolvedValue(true); const remoteWorkspace = createRemoteWorkspace(); workspaceManagerMock.getState.mockReturnValue({ @@ -1063,7 +1064,10 @@ describe('SSHRemoteProvider workspace connection state', () => { expect(sshApiMock.listSavedConnections).not.toHaveBeenCalled(); emitWorkspaceManagerEvent({ type: 'workspace:opened', workspace: remoteWorkspace }); + await act(async () => { await Promise.resolve(); }); + expect(sshApiMock.isConnected).toHaveBeenCalledWith('conn-1'); + expect(sshApiMock.connect).not.toHaveBeenCalled(); expect(latestStatuses['conn-1']).toBe('connected'); await act(async () => { @@ -1075,6 +1079,67 @@ describe('SSHRemoteProvider workspace connection state', () => { expect(notificationService.error).not.toHaveBeenCalled(); }); + it('gives every peer remote workspace a status even when the hydrated list emits no per-workspace event', async () => { + peerModeFlagMock.active = true; + const remoteWorkspace = createRemoteWorkspace(); + const second = { ...createRemoteWorkspace(), id: 'ws-remote-2', connectionId: 'conn-2' }; + workspaceManagerMock.getState.mockReturnValue({ + loading: false, + openedWorkspaces: new Map([[remoteWorkspace.id, remoteWorkspace], [second.id, second]]), + activeWorkspaceId: null, + }); + sshApiMock.isConnected.mockImplementation(async (connectionId: string) => connectionId === 'conn-1'); + + await renderProvider(); + emitWorkspaceManagerEvent({ type: 'workspace:loading', loading: false }); + await act(async () => { await Promise.resolve(); }); + + expect(latestStatuses).toEqual({ 'conn-1': 'connected', 'conn-2': 'disconnected' }); + }); + + it('keeps a peer that does not report SSH state mirrored as connected, and an unreachable peer as an error', async () => { + peerModeFlagMock.active = true; + const remoteWorkspace = createRemoteWorkspace(); + const second = { ...createRemoteWorkspace(), id: 'ws-remote-2', connectionId: 'conn-2' }; + workspaceManagerMock.getState.mockReturnValue({ + loading: false, + openedWorkspaces: new Map([[remoteWorkspace.id, remoteWorkspace], [second.id, second]]), + activeWorkspaceId: null, + }); + sshApiMock.isConnected.mockImplementation(async (connectionId: string) => { + throw new Error(connectionId === 'conn-1' + ? "command 'ssh_is_connected' is not supported on cli peer host: the CLI peer host does not run this desktop IDE surface" + : 'peer request timed out'); + }); + + await renderProvider(); + emitWorkspaceManagerEvent({ type: 'workspace:active-changed', workspace: null }); + await act(async () => { await Promise.resolve(); await Promise.resolve(); }); + + expect(latestStatuses).toEqual({ 'conn-1': 'connected', 'conn-2': 'error' }); + }); + + it('reads a newly rendered peer surface again instead of reusing another device status', async () => { + peerModeFlagMock.active = true; + const remoteWorkspace = createRemoteWorkspace(); + workspaceManagerMock.getState.mockReturnValue({ + loading: false, + openedWorkspaces: new Map([[remoteWorkspace.id, remoteWorkspace]]), + activeWorkspaceId: remoteWorkspace.id, + }); + sshApiMock.isConnected.mockResolvedValue(true); + + await renderProvider(); + emitWorkspaceManagerEvent({ type: 'workspace:opened', workspace: remoteWorkspace }); + await act(async () => { await Promise.resolve(); }); + expect(latestStatuses['conn-1']).toBe('connected'); + + sshApiMock.isConnected.mockResolvedValue(false); + await act(async () => { activateSurface('peer-c'); await Promise.resolve(); }); + + expect(latestStatuses['conn-1']).toBe('disconnected'); + }); + it('cancels the pending reconnect timeout when peer device mode activates', async () => { vi.useFakeTimers(); diff --git a/src/web-ui/src/features/ssh-remote/SSHRemoteProvider.tsx b/src/web-ui/src/features/ssh-remote/SSHRemoteProvider.tsx index d702e26ad5..85a03e61ea 100644 --- a/src/web-ui/src/features/ssh-remote/SSHRemoteProvider.tsx +++ b/src/web-ui/src/features/ssh-remote/SSHRemoteProvider.tsx @@ -16,9 +16,11 @@ import { isPeerDeviceModeActive } from '@/infrastructure/peer-device/peerModeFla import { getActiveSurfaceScope, isSurfaceChangedError, + onSurfaceActivated, runInSurfaceScope, type SurfaceScope, } from '@/infrastructure/peer-device/deviceSurface'; +import { classifyPeerHostRefusal } from '@/infrastructure/peer-device/peerHostRefusal'; import { useI18n } from '@/infrastructure/i18n'; import { confirmWarning } from '@/infrastructure/confirm-dialog'; import { @@ -328,6 +330,40 @@ export const SSHRemoteProvider: React.FC = ({ children } setWorkspaceStatuses(prev => ({ ...prev, [connId]: st })); }, []); + /** + * Peer Device Mode: the peer owns every SSH transport, so ask it instead of + * leaving its remote workspaces without a status. A host that does not report + * SSH transport state (a CLI peer) still owns the workspace it opened, so it + * keeps the mirrored `connected` state; only an unreachable peer is an error. + */ + const peerStatusProbesRef = useRef(new Map()); + const reconcilePeerRemoteStatuses = useCallback((force: boolean) => { + if (!mountedRef.current || !isPeerDeviceModeActive()) return; + const scope = getActiveSurfaceScope(); + const probes = peerStatusProbesRef.current; + for (const workspace of workspaceManager.getState().openedWorkspaces.values()) { + const connId = workspace.workspaceKind === WorkspaceKind.Remote ? workspace.connectionId?.trim() : ''; + if (!connId || probes.get(connId) === scope.epoch) continue; + if (!force && workspaceStatusesRef.current[connId]) continue; + probes.set(connId, scope.epoch); + void runInSurfaceScope(scope, 'probe peer SSH status', () => sshApi.isConnected(connId)) + .then( + (connected): ConnectionStatus => (connected ? 'connected' : 'disconnected'), + (error): ConnectionStatus | null => { + if (isSurfaceChangedError(error)) return null; + if (classifyPeerHostRefusal(error)) return 'connected'; + log.warn('Failed to read peer SSH connection status', { connectionId: connId, error }); + return 'error'; + }, + ) + .then(status => { + if (probes.get(connId) === scope.epoch) probes.delete(connId); + if (!status || !mountedRef.current || !scope.isCurrent() || !isPeerDeviceModeActive()) return; + setWorkspaceStatuses(prev => (prev[connId] === status ? prev : { ...prev, [connId]: status })); + }); + } + }, []); + const reportRemoteWorkspaceReconnectFailure = useCallback((workspace: RemoteWorkspace) => { if (isPeerDeviceModeActive()) { return; @@ -969,6 +1005,7 @@ export const SSHRemoteProvider: React.FC = ({ children } } workspaceStatusTimeouts.current.clear(); log.info('Paused SSH heartbeat while peer device mode is active'); + reconcilePeerRemoteStatuses(true); } else if (detail?.active === false) { if (showFileBrowserRef.current && connectionIdRef.current && isConnectedRef.current && usedConnectionIds().has(connectionIdRef.current)) { @@ -979,7 +1016,11 @@ export const SSHRemoteProvider: React.FC = ({ children } }; window.addEventListener('peer-mode:changed', onPeerModeChanged); return () => window.removeEventListener('peer-mode:changed', onPeerModeChanged); - }, [stopHeartbeat, usedConnectionIds]); + }, [reconcilePeerRemoteStatuses, stopHeartbeat, usedConnectionIds]); + + // Statuses are keyed by connection ID, which another device may reuse: a + // newly rendered peer surface reads every one of its connections again. + useEffect(() => onSurfaceActivated(() => reconcilePeerRemoteStatuses(true)), [reconcilePeerRemoteStatuses]); useEffect(() => { return workspaceManager.addEventListener(event => { @@ -988,6 +1029,15 @@ export const SSHRemoteProvider: React.FC = ({ children } pruneHeartbeats(); return; } + if (isPeerDeviceModeActive()) { + // Peer Device Mode: the peer owns the SSH connection lifecycle. Never + // run the controller-side reconnect/timeout removal path — those + // invokes route to the peer and would delete the peer's workspace. + // A hydrated list may arrive without per-workspace events, so every + // change reads the status of any connection that has none yet. + reconcilePeerRemoteStatuses(false); + return; + } const workspace = 'workspace' in event && event.workspace?.workspaceKind === WorkspaceKind.Remote ? event.workspace @@ -999,23 +1049,13 @@ export const SSHRemoteProvider: React.FC = ({ children } if (!connId) { return; } - if (isPeerDeviceModeActive()) { - // Peer Device Mode: the peer owns the SSH connection lifecycle. Mirror - // its opened remote workspaces as connected and never run the - // controller-side reconnect/timeout removal path — those invokes route - // to the peer and would delete the peer's workspace. - if (workspaceStatusesRef.current[connId] !== 'connected') { - setWorkspaceStatus(connId, 'connected'); - } - return; - } if (!workspaceStatusesRef.current[connId]) { setWorkspaceStatus(connId, 'connecting'); } const metadataOnly = event.type === 'workspace:updated' || event.type === 'workspace:primary-assistant-changed'; void checkRemoteWorkspaceRef.current(!metadataOnly); }); - }, [pruneHeartbeats, restoredScope, setWorkspaceStatus]); + }, [pruneHeartbeats, reconcilePeerRemoteStatuses, restoredScope, setWorkspaceStatus]); const connect = useCallback(async ( _connId: string, diff --git a/src/web-ui/src/locales/en-US/common.json b/src/web-ui/src/locales/en-US/common.json index 19d96eca02..93d790cc3d 100644 --- a/src/web-ui/src/locales/en-US/common.json +++ b/src/web-ui/src/locales/en-US/common.json @@ -678,8 +678,7 @@ "connected": "Connected", "connecting": "Connecting", "disconnected": "Disconnected", - "error": "Connection error", - "unknown": "Status unknown" + "error": "Connection error" } }, "actions": { diff --git a/src/web-ui/src/locales/zh-CN/common.json b/src/web-ui/src/locales/zh-CN/common.json index a91b634aeb..7340e0eb4c 100644 --- a/src/web-ui/src/locales/zh-CN/common.json +++ b/src/web-ui/src/locales/zh-CN/common.json @@ -678,8 +678,7 @@ "connected": "已连接", "connecting": "连接中", "disconnected": "已断开", - "error": "连接异常", - "unknown": "状态未知" + "error": "连接异常" } }, "actions": { diff --git a/src/web-ui/src/locales/zh-TW/common.json b/src/web-ui/src/locales/zh-TW/common.json index e0d790ff28..562837251c 100644 --- a/src/web-ui/src/locales/zh-TW/common.json +++ b/src/web-ui/src/locales/zh-TW/common.json @@ -678,8 +678,7 @@ "connected": "已連線", "connecting": "連線中", "disconnected": "已中斷", - "error": "連線異常", - "unknown": "狀態未知" + "error": "連線異常" } }, "actions": {