Keep host action updates scoped to affected rows

This commit is contained in:
Brennan Benson
2026-11-08 23:57:57 -08:00
parent c63cdfbb1f
commit 25b8afb673
6 changed files with 129 additions and 43 deletions
@@ -558,8 +558,6 @@
1 src/renderer/src/components/stats/ShareUsageButton.tsx
2 src/renderer/src/components/status-bar/ClaudeSwitcherForOwner.tsx
1 src/renderer/src/components/status-bar/PortsStatusSegment.tsx
1 src/renderer/src/components/status-bar/RuntimeHostStatusRow.tsx
2 src/renderer/src/components/status-bar/SshTargetStatusRow.tsx
1 src/renderer/src/components/status-bar/icons.tsx
3 src/renderer/src/components/status-bar/status-bar-density.ts
2 src/renderer/src/components/status-bar/use-codex-switcher-controller.ts
@@ -110,6 +110,37 @@ function connectionState(targetId: string, status: SshConnectionStatus): SshConn
return { targetId, status, error: null, reconnectAttempt: 0 }
}
function addStoppedServer() {
state.runtimeEnvironments = [
{
id: 'server',
name: 'Server',
createdAt: 0,
updatedAt: 0,
lastUsedAt: null,
runtimeId: null,
source: 'manual',
preferredEndpointId: 'direct',
endpoints: [
{ id: 'direct', kind: 'websocket', label: 'Direct', endpoint: 'ws://127.0.0.1:1' }
]
}
]
state.runtimeStatusByEnvironmentId.set('server', {
status: null,
checkedAt: 0,
remoteControl: {
state: 'closed',
reconnectAttempt: 7,
pendingRequestCount: 0,
subscriptionCount: 0,
lastConnectedAt: null,
lastClose: null,
lastError: null
}
})
}
beforeEach(() => {
vi.clearAllMocks()
state.runtimeEnvironments = []
@@ -191,6 +222,80 @@ describe('the status menu with a very large imported SSH host list', () => {
}
)
it.each([13_692, 136_920])(
'splits %i SSH hosts only when SSH inputs change during actions',
async (count) => {
state.sshTargetLabels = new Map(
Array.from({ length: count }, (_, index) => [`ssh-${index}`, `node-${index}`])
)
const retryId = `ssh-${count - 1}`
state.sshConnectionStates = new Map([
['ssh-0', connectionState('ssh-0', 'connected')],
[retryId, { ...connectionState(retryId, 'reconnecting'), reconnectAttempt: 2 }]
])
addStoppedServer()
let settleDisconnect: () => void = () => undefined
let settleSsh: () => void = () => undefined
let settleRuntime: (value: boolean) => void = () => undefined
const disconnectRequest = new Promise<void>((resolve) => {
settleDisconnect = resolve
})
const sshRequest = new Promise<void>((resolve) => {
settleSsh = resolve
})
const runtimeRequest = new Promise<boolean>((resolve) => {
settleRuntime = resolve
})
const disconnect = vi.fn(() => disconnectRequest)
vi.stubGlobal('api', { ssh: { connect: vi.fn(() => sshRequest), disconnect } })
vi.mocked(connectRuntimeHostAndReloadProjects).mockImplementationOnce(() => runtimeRequest)
inventoryVisits.registry = inventoryVisits.split = inventoryVisits.overall = 0
const view = render(
<TooltipProvider>
<SshStatusSegment compact={false} iconOnly={false} />
</TooltipProvider>
)
expect(inventoryVisits).toEqual({ registry: count, split: count, overall: count })
await act(async () =>
fireEvent.click(screen.getByRole('button', { name: 'Disconnect node-0' }))
)
expect(disconnect).toHaveBeenCalledWith({ targetId: 'ssh-0' })
expect(inventoryVisits).toEqual({ registry: count, split: count, overall: count })
await act(async () => settleDisconnect())
expect(inventoryVisits).toEqual({ registry: count, split: count, overall: count })
// A real SSH pending input changes the cap projection once, without rebuilding its inventory.
await act(async () => fireEvent.click(screen.getByRole('menuitem', { name: 'Retry now' })))
expect(screen.getByRole('button', { name: `Stop node-${count - 1}` })).toBeTruthy()
expect(inventoryVisits).toEqual({ registry: count, split: count * 2, overall: count })
// Runtime start and settlement leave this nonempty SSH selection unchanged.
await act(async () => fireEvent.click(screen.getByRole('button', { name: 'Connect Server' })))
expect(screen.getByRole('button', { name: 'Stop Server' })).toBeTruthy()
expect(inventoryVisits).toEqual({ registry: count, split: count * 2, overall: count })
await act(async () => settleRuntime(true))
expect(screen.getByRole('button', { name: 'Connect Server' })).toBeTruthy()
expect(inventoryVisits).toEqual({ registry: count, split: count * 2, overall: count })
// A separate backend publication legitimately changes inventory, but cannot drop the pending row.
state.sshConnectionStates = new Map(state.sshConnectionStates).set(
retryId,
connectionState(retryId, 'disconnected')
)
view.rerender(
<TooltipProvider>
<SshStatusSegment compact={false} iconOnly={false} />
</TooltipProvider>
)
expect(screen.getByRole('button', { name: `Stop node-${count - 1}` })).toBeTruthy()
expect(inventoryVisits).toEqual({ registry: count * 2, split: count * 3, overall: count * 2 })
await act(async () => settleSsh())
expect(screen.queryByText(`node-${count - 1}`)).toBeNull()
expect(inventoryVisits).toEqual({ registry: count * 2, split: count * 4, overall: count * 2 })
vi.unstubAllGlobals()
}
)
it('renders a bounded number of idle host rows instead of one per imported host', () => {
render(
<TooltipProvider>
@@ -277,34 +382,7 @@ describe('the status menu with a very large imported SSH host list', () => {
)
state.sshTargetLabels = new Map()
state.sshConnectionStates = new Map()
state.runtimeEnvironments = [
{
id: 'server',
name: 'Server',
createdAt: 0,
updatedAt: 0,
lastUsedAt: null,
runtimeId: null,
source: 'manual',
preferredEndpointId: 'direct',
endpoints: [
{ id: 'direct', kind: 'websocket', label: 'Direct', endpoint: 'ws://127.0.0.1:1' }
]
}
]
state.runtimeStatusByEnvironmentId.set('server', {
status: null,
checkedAt: 0,
remoteControl: {
state: 'closed',
reconnectAttempt: 7,
pendingRequestCount: 0,
subscriptionCount: 0,
lastConnectedAt: null,
lastClose: null,
lastError: null
}
})
addStoppedServer()
render(
<TooltipProvider>
<SshStatusSegment compact={false} iconOnly={false} />
@@ -1,4 +1,5 @@
import React, { useCallback, useMemo, useRef, useState } from 'react'
import { useShallow } from 'zustand/react/shallow'
import { MonitorSmartphone, Server } from 'lucide-react'
import { toast } from 'sonner'
import {
@@ -104,20 +105,25 @@ export function SshStatusSegment({
)
const menu = useRemoteHostMenuState(menuOpen, hostExists)
const { connect: trackConnect, cancel: cancelConnect } = menu
const selectPendingSshTargets = useShallow((pending: ReadonlySet<string>) => {
const targetIds = new Set<string>()
for (const id of pending) {
const host = parseExecutionHostId(id)
if (host?.kind === 'ssh') {
targetIds.add(host.targetId)
}
}
return targetIds
})
const pendingTargetIds = selectPendingSshTargets(menu.pending)
const {
connected: connectedTargets,
inactive: disconnectedTargets,
hiddenIdleCount
} = useMemo(() => {
const pendingTargetIds = new Set<string>()
for (const id of menu.pending) {
const host = parseExecutionHostId(id)
if (host?.kind === 'ssh') {
pendingTargetIds.add(host.targetId)
}
}
return splitSshStatusMenuRows(targets, { projectHostIds, pendingTargetIds })
}, [targets, projectHostIds, menu.pending])
} = useMemo(
() => splitSshStatusMenuRows(targets, { projectHostIds, pendingTargetIds }),
[targets, projectHostIds, pendingTargetIds]
)
const displayedTargets = [...connectedTargets, ...disconnectedTargets]
const displayedHosts = [...connectedRuntimeHosts, ...inactiveRuntimeHosts]
menu.observe([
@@ -61,7 +61,11 @@ export function useRemoteHostMenuState(open: boolean, hostExists: (id: string) =
[mounted]
)
const cancel = useCallback((id: string) => {
controllers.current.get(id)?.abort()
const controller = controllers.current.get(id)
if (!controller) {
return
}
controller.abort()
controllers.current.delete(id)
setPending(new Set(controllers.current.keys()))
}, [])
+1 -1
View File
@@ -4910,7 +4910,7 @@
"access_revoked_explanation": "Mit einem neuen Kopplungslink vom Server erneut koppeln, um die Verbindung wiederherzustellen.",
"managed_access_revoked_explanation": "Orca konnte sich über SSH nicht erneut koppeln; verbinde dich, um es noch einmal zu versuchen.",
"connect_access_revoked_explanation": "Verbinden, um es erneut zu versuchen.",
"server_replaced_explanation": "Wähle in Einstellungen › Remote-Orca-Server für diesen Server Vergessen… und verbinde dann den SSH-Host, um ihn mit seinem aktuellen Server zu koppeln.",
"server_replaced_explanation": "Wähle in Einstellungen › Entfernte Orca-Server für diesen Server Vergessen… und verbinde dann den SSH-Host, um ihn mit seinem aktuellen Server zu koppeln.",
"update_required_explanation": "Orca auf diesem Computer oder auf dem Server aktualisieren und anschließend erneut verbinden."
},
"NativeChatResumeStatusSegment": {
+1 -1
View File
@@ -4357,7 +4357,7 @@
"access_revoked_explanation": "サーバーで発行した新規ペアリングリンクで再度ペアリングし、接続し直してください。",
"managed_access_revoked_explanation": "Orca は SSH 経由で再ペアリングできなかったため、接続して再試行してください。",
"connect_access_revoked_explanation": "接続してもう一度お試しください。",
"server_replaced_explanation": "設定 › リモート Orca サーバーでこのサーバーの「削除…」を選択し、SSH ホストに接続して現在のサーバーとペアリングしてください。",
"server_replaced_explanation": "設定 › リモート Orca サーバーでこのサーバーの「登録を解除…」を選択し、SSH ホストに接続して現在のサーバーとペアリングしてください。",
"update_required_explanation": "このコンピュータまたはサーバーの Orca を更新してから、再度接続してください。"
},
"NativeChatResumeStatusSegment": {