Skip to content

fix(ports): the ports panel scans and stops on the workspace's own host - #27258

Merged
OrcaWin merged 3 commits into
mainfrom
OrcaWin/d4-d4-v4c-2
Oct 10, 2026
Merged

OrcaWin merged 3 commits into
mainfrom
OrcaWin/d4-d4-v4c-2

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​324 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​324
Prod 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​440 $\color{#cf222e}{\Huge{\mathbf{−}}}$​67 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​373

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

  • Before:
    • The tab picked its view from two signals: the repo's connectionId and the workspace's owner, with the Active Server as fallback.
    • A workspace on SSH host t behind a paired server E has connectionId: t on its repo row. That id means t as E sees it, but the tab read it as an SSH target this computer dials. So it showed this computer's own t, or "SSH connection lost".
    • A recipe VM workspace whose repo row names no host ([Bug]: Ports tab scans the Active Server instead of the recipe workspace's SSH target #24067) got no scan at all.
    • A recipe VM target never publishes connection state to the renderer, so its SSH view always said "SSH connection lost", even though the relay's detected ports were arriving.
  • After: the tab asks resolveOwner, the shared owner resolver, which never reads the Active Server. It then picks one of four views:
    • This app or a paired server's own machine: the existing scan and Stop, unchanged, now bound to the owner's endpoint.
    • A user SSH target this computer dials: the existing SSH view, with forwarding, bound to the owner's target id instead of the repo's connectionId.
    • An SSH target behind a paired server, or a recipe VM: a new host-scoped view. It asks the endpoint that owns the host to scan through workspacePorts.scanHost (from feat(ports): host-scoped port scan and stop on the server #27188, capability workspace-ports.host-scoped.v1). For a paired server that endpoint is the server; for a recipe VM it is this app's own runtime.
      • A recipe VM target never publishes connection state to the renderer, so the SSH view could only ever say "SSH connection lost". The runtime scan can tell the two cases apart: it shows the VM's ports, or it says the VM is unreachable. It never shows an empty "no ports" list for a VM it could not reach.
      • If the server answers for a host other than the one the workspace runs on, the rows are dropped.
      • Stop goes through killHost and names the host the row was scanned on. Today the server refuses SSH Stop, and these rows are unattributed, so no Stop button shows.
      • There is no "Open in Browser" on these rows. That would open on the server's own machine, which is not where the port is.
    • Owner unknown or ambiguous: "Workspace host unknown", instead of scanning some other host.
  • An older server is never asked to scan its SSH host. It only knows how to scan itself, so the tab says "Update the server to see ports on its SSH hosts."

Why

  • One owner answer for the whole tab. The bug came from the view choice and the scan target reading different signals. Rows and Stop now come from the same host context.
  • New methods, not a new field. An old server would drop an unknown field and scan or kill on itself. The client checks the capability first and also treats method_not_found as "update server". It never falls back to the old repo-scoped scan or kill for an SSH host behind a server.
  • No browser open for SSH hosts behind a server. There is no forwarding path from this client to that host yet. A link that opens the wrong machine is worse than no link.

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.

    • Cases: local, direct SSH, a recipe VM whose repo row names no host, paired server, nested SSH known from the repo or named by the workspace row, the same ssh:t behind two servers (unknown), folder workspaces (local, paired server, nested SSH), the floating workspace, and an unknown workspace.
    • Checked against origin/main's routing logic: nested SSH resolved to direct-ssh t on this computer, and the recipe row resolved to no host.
  • workspace-port-host-scoped-scan.test.ts:

    • scanHost is called with the workspace selector.
    • An older server (no capability) is never called, and the tab says "update server".
    • method_not_found also gives "update server".
    • Rows the server scanned on a different host are dropped.
    • A recipe VM is scanned through this app's own runtime with no capability probe. If the VM is unreachable, the tab says so; it never shows an empty list.
    • Same pid and port on E and T: Stop for a row from T calls only killHost with ssh:t, never the server-local kill.
  • 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-owner suites pass. pnpm tc, oxlint, check:code-quality:changed, check:owner-routing-ratchet and 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

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • SSH: a host the tab cannot reach or cannot identify is shown as unavailable or unknown, never as "no ports". Nothing is signalled on a host other than the one the row was scanned on.
  • Folder workspaces: covered (local, paired server, nested SSH).
  • Backwards compatibility: capability-gated, as described above. Old clients keep using scan and kill unchanged.
  • Mobile, Windows: no change. Paths are not touched.
  • Review: Astra found one P1 in the first version: inferring a recipe VM's reachability from its target id prefix. Recipe VMs now use the runtime scan instead.
  • Out of scope: the status-bar popover and the workspace card still use their own routing (useWorktreeRuntimeTarget).

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

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.
@OrcaWin
OrcaWin requested a review from brennanb2025 as a code owner October 10, 2026 13:59
m4air added 2 commits October 10, 2026 07:05
…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.
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

Walkthrough

Ports-panel ownership now derives from the active workspace rather than the repository connection or Active Server. The panel routes to endpoint, direct-SSH, or host-scoped views, and shows an unknown-host state when it cannot resolve a supported host. Host-scoped views scan and stop ports through the execution host. Endpoint and SSH panels receive their targets as props. Local port rows omit browser-open actions when no callback is provided.


Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: 🔵 Low · up to 4bc35

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 | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 29.41% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 17 functions across 10 files. (1 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: the Ports panel scans and stops processes on the workspace’s own host.
Description check Passed The description is complete and addresses the required sections. It explains the user-visible change, implementation, rationale, linked issue, testing, compatibility, and UI proof. Manual testing was …
Linked Issues check Passed Issue #24067 is closed and provides historical context only. The linked-issue requirements state that no active directly linked issue targets remain. Therefore, this pull request has no applicable cod…
Out of Scope Changes check Passed The changes stay within the Ports panel scope described by PR #27258. Production changes update owner selection, local and SSH routing, host-scoped scanning and stopping, and related UI behavior. Test…

Full details: Docstring Coverage

Explanation

Docstring coverage is 29.41% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 17 functions across 10 files. (1 skipped: 1 unsupported.)


  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a35b5927-fd9b-40fb-9a51-1500e6005c89
📥 Commits

Reviewing files that changed from the base of the PR and between 61a99d7 and 4bc3592.

📒 Files selected for processing (11)
  • src/renderer/src/components/right-sidebar/PortsPanel.tsx
  • src/renderer/src/components/right-sidebar/host-scoped-ports-panel.tsx
  • src/renderer/src/components/right-sidebar/local-port-row.tsx
  • src/renderer/src/components/right-sidebar/local-port-section.tsx
  • src/renderer/src/components/right-sidebar/local-workspace-ports-panel.tsx
  • src/renderer/src/components/right-sidebar/ports-panel-host.test.ts
  • src/renderer/src/components/right-sidebar/ports-panel-host.ts
  • src/renderer/src/components/right-sidebar/ssh-ports-panel.tsx
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/lib/workspace-port-host-scoped-scan.test.ts
  • src/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.

Comment on lines +47 to +67
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])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 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

@OrcaWin
OrcaWin merged commit 291549e into main Oct 10, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Ports tab scans the Active Server instead of the recipe workspace's SSH target

1 participant