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
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,9 @@ const WorkspaceItem: React.FC<WorkspaceItemProps> = ({
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;
Expand All @@ -307,8 +306,6 @@ const WorkspaceItem: React.FC<WorkspaceItemProps> = ({
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,
Expand Down Expand Up @@ -1356,14 +1353,10 @@ const WorkspaceItem: React.FC<WorkspaceItemProps> = ({
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. */}
<span className="openbitfun-nav-panel__workspace-item-remote-host">
{remoteMeta.badgeLabel}
</span>
{remoteMeta.showStatusText ? (
<span className="openbitfun-nav-panel__workspace-item-remote-status">
{remoteMeta.statusLabel}
</span>
) : null}
</span>
</Tooltip>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down
67 changes: 66 additions & 1 deletion src/web-ui/src/features/ssh-remote/SSHRemoteProvider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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 () => {
Expand All @@ -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();

Expand Down
64 changes: 52 additions & 12 deletions src/web-ui/src/features/ssh-remote/SSHRemoteProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -328,6 +330,40 @@ export const SSHRemoteProvider: React.FC<SSHRemoteProviderProps> = ({ 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<string, number>());
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;
Expand Down Expand Up @@ -969,6 +1005,7 @@ export const SSHRemoteProvider: React.FC<SSHRemoteProviderProps> = ({ 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)) {
Expand All @@ -979,7 +1016,11 @@ export const SSHRemoteProvider: React.FC<SSHRemoteProviderProps> = ({ 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 => {
Expand All @@ -988,6 +1029,15 @@ export const SSHRemoteProvider: React.FC<SSHRemoteProviderProps> = ({ 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
Expand All @@ -999,23 +1049,13 @@ export const SSHRemoteProvider: React.FC<SSHRemoteProviderProps> = ({ 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,
Expand Down
3 changes: 1 addition & 2 deletions src/web-ui/src/locales/en-US/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -678,8 +678,7 @@
"connected": "Connected",
"connecting": "Connecting",
"disconnected": "Disconnected",
"error": "Connection error",
"unknown": "Status unknown"
"error": "Connection error"
}
},
"actions": {
Expand Down
3 changes: 1 addition & 2 deletions src/web-ui/src/locales/zh-CN/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -678,8 +678,7 @@
"connected": "已连接",
"connecting": "连接中",
"disconnected": "已断开",
"error": "连接异常",
"unknown": "状态未知"
"error": "连接异常"
}
},
"actions": {
Expand Down
3 changes: 1 addition & 2 deletions src/web-ui/src/locales/zh-TW/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -678,8 +678,7 @@
"connected": "已連線",
"connecting": "連線中",
"disconnected": "已中斷",
"error": "連線異常",
"unknown": "狀態未知"
"error": "連線異常"
}
},
"actions": {
Expand Down
Loading