Repository navigation
fix(ports): the ports panel scans and stops on the workspace's own host - #27258
Conversation
The panel now picks its host from the workspace owner instead of the repo's connectionId and the Active Server. A direct SSH or recipe VM workspace uses the SSH view for its own target; an SSH target behind a paired server is scanned by that server through workspacePorts.scanHost (workspace-ports.host-scoped.v1), and Stop goes through killHost with the host the row was scanned on. An older server is never asked and the panel says to update it; an unknown owner says so instead of scanning another host.
…ble VM reads as unavailable Recipe VM targets publish no connection state to the renderer, so the SSH view cannot tell a reachable VM from one whose relay is reconnecting. Route them through workspacePorts.scanHost on this app's own runtime, which reports a missing relay as unavailable, and keep the SSH view for user SSH targets.
📝 Walkthrough
Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: 🔵 Low · up to A stopped port can briefly reappear in the Ports panel. The change is mergeable with this bounded display risk understood, though ordering scan results would avoid it. Pre-merge checks |
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
a35b5927-fd9b-40fb-9a51-1500e6005c89
📒 Files selected for processing (11)
src/renderer/src/components/right-sidebar/PortsPanel.tsxsrc/renderer/src/components/right-sidebar/host-scoped-ports-panel.tsxsrc/renderer/src/components/right-sidebar/local-port-row.tsxsrc/renderer/src/components/right-sidebar/local-port-section.tsxsrc/renderer/src/components/right-sidebar/local-workspace-ports-panel.tsxsrc/renderer/src/components/right-sidebar/ports-panel-host.test.tssrc/renderer/src/components/right-sidebar/ports-panel-host.tssrc/renderer/src/components/right-sidebar/ssh-ports-panel.tsxsrc/renderer/src/i18n/locales/en.jsonsrc/renderer/src/lib/workspace-port-host-scoped-scan.test.tssrc/renderer/src/lib/workspace-port-scan-client.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
| const refresh = useCallback(async () => { | ||
| setRefreshing(true) | ||
| try { | ||
| const next = await scanWorkspacePortsOnExecutionHost(host) | ||
| setScanned({ key: hostKey, scan: next }) | ||
| } catch (error) { | ||
| const message = error instanceof Error ? error.message : String(error) | ||
| setScanned({ | ||
| key: hostKey, | ||
| scan: { | ||
| executionHostId: host.executionHostId, | ||
| platform: 'unknown', | ||
| scannedAt: Date.now(), | ||
| ports: [], | ||
| unavailableReason: message || 'Workspace port scan failed.' | ||
| } | ||
| }) | ||
| } finally { | ||
| setRefreshing(false) | ||
| } | ||
| }, [host, hostKey]) |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Discard stale scan results after a refresh is superseded.
The hostKey tag hides results from a previous host. It does not order concurrent scans for the same host. A scan can still be running when one of these events starts another scan on the same hostKey:
- the 30-second interval fires;
- the user selects Refresh;
- a Stop completes and calls
refresh().
If the older scan returns last, setScanned replaces the newer result with the older one. A process that Stop just ended can then appear again until the next interval runs. The older scan's finally block can also set refreshing to false while the newer scan is still running.
Add a request counter in a useRef. Apply state only when the call's id is still the latest id.
🐛 Proposed fix
+ const requestIdRef = useRef(0)
const refresh = useCallback(async () => {
+ const requestId = ++requestIdRef.current
setRefreshing(true)
try {
const next = await scanWorkspacePortsOnExecutionHost(host)
+ if (requestId !== requestIdRef.current) return
setScanned({ key: hostKey, scan: next })
} catch (error) {
+ if (requestId !== requestIdRef.current) return
const message = error instanceof Error ? error.message : String(error)
...
} finally {
- setRefreshing(false)
+ if (requestId === requestIdRef.current) setRefreshing(false)
}
}, [host, hostKey])Based on learnings: "guard against race conditions: use a useRef counter/id ... only apply setState ... if the captured id still matches."
Source: Learnings
ELI5
The Ports tab now looks for running ports on the machine where the open workspace actually runs. Before, it sometimes looked at a different machine: the "Active Server", or this computer's own SSH connection with the same name as one of the server's SSH hosts.
What Changed
connectionIdand the workspace's owner, with the Active Server as fallback.tbehind a paired serverEhasconnectionId: ton its repo row. That id meanstasEsees it, but the tab read it as an SSH target this computer dials. So it showed this computer's ownt, or "SSH connection lost".resolveOwner, the shared owner resolver, which never reads the Active Server. It then picks one of four views:connectionId.workspacePorts.scanHost(from feat(ports): host-scoped port scan and stop on the server #27188, capabilityworkspace-ports.host-scoped.v1). For a paired server that endpoint is the server; for a recipe VM it is this app's own runtime.killHostand names the host the row was scanned on. Today the server refuses SSH Stop, and these rows are unattributed, so no Stop button shows.Why
method_not_foundas "update server". It never falls back to the old repo-scopedscanorkillfor an SSH host behind a server.Linked Issue
Fixes #24067
(#27188 closed this issue automatically because its body mentioned it. That was the server half only. This PR is the client half the issue describes.)
Visual Proof
N/A. The panel layouts are the existing ones. The new view reuses the existing port rows, and the "unknown" state is one line of text. No local Electron run on this load-capped machine. Behaviour is covered by the tests below.
Testing
ports-panel-host.test.ts: the host the tab picks, with another server as Active Server.ssh:tbehind two servers (unknown), folder workspaces (local, paired server, nested SSH), the floating workspace, and an unknown workspace.origin/main's routing logic: nested SSH resolved todirect-ssh ton this computer, and the recipe row resolved to no host.workspace-port-host-scoped-scan.test.ts:scanHostis called with the workspace selector.method_not_foundalso gives "update server".EandT: Stop for a row fromTcalls onlykillHostwithssh:t, never the server-localkill.Old client with a new server, and new server with an old client, at the wire level:
tests/e2e/cross-version-wire/workspace-ports-host-scoped-downgrade.unit.test.ts(feat(ports): host-scoped port scan and stop on the server #27188).Existing right-sidebar, status-bar, workspace-port and
resolve-ownersuites pass.pnpm tc, oxlint,check:code-quality:changed,check:owner-routing-ratchetand the localization checks also pass.I manually tested these changes locally
Automated tests added/updated, or explained why not below
Review
Agent skill upstream boundary
Notes
scanandkillunchanged.useWorktreeRuntimeTarget).Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)