Skip to content

feat(ports): host-scoped port scan and stop on the server - #27188

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

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

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​534 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​532
Prod 10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​276 $\color{#cf222e}{\Huge{\mathbf{−}}}$​24 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​252

ELI5

When you are connected to an Orca server, that server can now look for running ports, and stop them, on the machine where a given workspace actually runs: the server itself or one of the server's SSH hosts. Before this, the server only ever looked at itself, whichever workspace you asked about.

What Changed

This is the server half only. The ports panel does not call these methods yet; the follow-up PR (D4-V4c-2) switches the panel over. Nothing changes for users until that lands.

  • Before: workspacePorts.scan and workspacePorts.kill only take a repoId. The server scans its own machine, skips SSH workspaces entirely, and Stop rescans the server and calls process.kill there. A client cannot ask about an SSH host behind the server. Adding a "host" field to these methods would not be safe: an old server would drop the field and scan or signal itself, so Stop on a row from SSH host T could kill a process with the same pid on server E.
  • After: two new methods, advertised as the workspace-ports.host-scoped.v1 capability:
    • workspacePorts.scanHost({ worktree }): the server works out where that workspace runs, using the same resolver file reads use (resolveRuntimeFileTarget, which covers git worktrees, folder workspaces and the floating workspace). It scans that host and returns the rows along with executionHostId, named from the server's point of view (local or ssh:<target>).
      • Local: the existing ownership-attributing scanner.
      • SSH: the relay's existing ports.detect over the live connection. Those rows come back as external, because the relay cannot attribute a listener to a workspace.
      • A host that is not connected, times out, sends back garbage, or runs an OS the relay cannot scan returns unavailableReason. It never returns an empty list, which would look like "nothing is listening".
    • workspacePorts.killHost({ worktree, executionHostId, pid, port }): works out the workspace's host again. If that is not the host the row was scanned on, Stop is refused. On the local host it uses the existing re-scan-then-SIGTERM ownership proof. On an SSH host it refuses with a reason.
  • The old methods keep their wire shape.
  • Two root fixes found in review, which also tighten the old path:
    • Which workspaces can authorize Stop. The set of workspaces allowed to authorize a local Stop now comes from host routing (the same rule the rest of the server uses), not from the repo row's connectionId. An SSH repo that carries only executionHostId, or a repo hosted by another server, can no longer make a process on this machine look workspace-owned.
    • Failed relay scans. The relay's ports.detect now fails when it could not read the socket table: /proc/net/tcp is unreadable, or on Windows neither netstat nor PowerShell answered. Before, it answered an empty list, which looked like "nothing is listening". A missing tcp6 (IPv6 off) still counts as none. On the desktop, the SSH port poller already treats a failed request as "try again next tick" and keeps the last result. An older relay still answers empty, as it does today.

Why

  • New methods instead of a new optional field: an old server silently drops an unknown field and acts on itself. With a distinct, capability-gated method, an old server answers method_not_found, which the client turns into "update server" (V4c-2). It can never end up scanning or stopping the wrong machine.
  • Addressed by workspace instead of by a client-chosen host: the server owns its catalog. The client cannot point it at an arbitrary host, and the answer always says which host was scanned.
  • Design adjustment (D4 rev3, V4c): the design wanted SSH Stop to re-prove ownership on the SSH host through the relay before sending the signal. The relay has no way to attribute a listener to a workspace and no way to send a signal, so ownership cannot be proven there today. Sending a signal anyway would be unsafe, and adding relay methods is its own mixed-version change. So SSH Stop is refused with a clear reason. The desktop does not offer Stop for SSH ports today either, so nothing is lost. A later relay change can add an attributed scan plus signal behind its own capability.
  • Permission: workspace, the same as the existing methods. They are not on the mobile allowlist, and the SSH-bridge CLI has no binder for them, so both are denied by default.

Linked Issue

None. This is a stack prerequisite. D4-V4c-2 closes #24067.

Visual Proof

N/A: this is a server-only RPC addition with no UI caller yet.

Testing

  • src/main/ports/workspace-port-execution-host.test.ts:

    • local scan
    • SSH scan through the relay, never the local scanner
    • disconnected, failed, unsupported and malformed SSH scans all report unavailable
    • a workspace hosted by another server is refused
    • local Stop re-proves ownership
    • the same pid and port on this machine and the SSH host: a row scanned on the SSH host never signals the local pid
    • SSH Stop is refused
  • src/main/runtime/orca-runtime-workspace-ports-host.test.ts: the runtime resolves the workspace (including a folder workspace) on the server and routes to its SSH host's multiplexer. A host mismatch refuses Stop. Only workspaces this host runs can authorize Stop: SSH repos with only executionHostId, legacy connectionId repos and runtime-hosted repos are all excluded.

  • src/relay/port-scan-handler.test.ts and windows-port-scan.test.ts: an unreadable socket table, or both Windows scanners failing, rejects instead of answering empty. A missing tcp6 still scans.

  • src/main/runtime/rpc/methods/workspace-ports.test.ts: dispatch for both methods. killHost without executionHostId is rejected.

  • tests/e2e/cross-version-wire/workspace-ports-host-scoped-downgrade.unit.test.ts, against the newest release:

    • an old client's scan and kill parse the same on old and new servers
    • an old server has neither the capability nor the methods
    • a new server advertises both and requires the scanned host on Stop
  • pnpm tc:node, oxlint, pnpm run check:code-quality:changed, verify:rpc-params-catalog.

  • 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: host verdicts stay honest. A missing connection is reported as unavailable, never as "no ports", and nothing is ever signalled on a host where ownership was not proven.
  • Windows: the relay scans win32 hosts as it already does.
  • Mobile: not exposed.
  • Backwards compatibility: covered by the cross-version test.

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)

Add workspacePorts.scanHost/killHost, addressed by workspace and resolved on the
server to the workspace's own execution host (this machine or one of its SSH
hosts). Stop is bound to the host its row was scanned on and is refused on SSH
hosts, where ownership cannot be proven. Advertised as
workspace-ports.host-scoped.v1.
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2f59c08a-921e-4c1b-af53-8aa046859df3


📥 Commits

Reviewing files that changed from the base of the PR and between 754268c and 908cd82.



📒 Files selected for processing (7)
  • src/main/ports/workspace-port-ownership.ts
  • src/main/runtime/orca-runtime-list-managed-worktrees.ts
  • src/main/runtime/orca-runtime-workspace-ports-host.test.ts
  • src/relay/port-scan-handler.test.ts
  • src/relay/port-scan-handler.ts
  • src/relay/windows-port-scan.test.ts
  • src/relay/windows-port-scan.ts


Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.




📝 Walkthrough
📝 Walkthrough

Walkthrough

The change adds host-scoped workspace port scan and kill requests, results, and RPC methods. Runtime methods resolve the execution host for a worktree and delegate to local or SSH-specific operations. SSH scans use the ports.detect RPC and return unavailable results for disconnected hosts, errors, malformed results, or unsupported platforms. Stop requests reject mismatched host IDs and SSH hosts. Probe selection uses host routing to identify workspaces that run locally. Linux and Windows port scanners now report specified read or fallback failures as errors instead of returning empty results. The runtime advertises a capability for host-scoped workspace port operations.



Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: 🟡 Moderate · up to 908cd

Scanning ports for a runtime-hosted workspace reports the host as unavailable instead of detecting its ports. Resolve runtime-host routing before merging.

Pre-merge checks | Passed 3 | Failed 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check Warning Issue #24067 requires the Ports panel to resolve recipe-backed workspaces to the workspace SSH target, scan that target, show detected ports, and avoid silent fallback to the Active Server. This PR ad… Update the Ports panel and its host resolver to use the host-scoped capability and methods. Resolve the recipe runtime's sshTargetId, scan that host, preserve unavailable results, and verify detected ports and forwarding without Active Se…
Docstring Coverage Warning Docstring coverage is 23.53% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 17 functions across 15 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Out of Scope Changes check Passed The production changes add host-scoped workspace-port RPC methods, execution-host resolution, capability and parameter types, local and SSH scan handling, ownership safeguards, and relay scan failure …
Title check Passed The title clearly and concisely identifies the main change: host-scoped port scanning and stopping on the server.
Description check Passed The description is detailed and covers the user-facing behavior, implementation, rationale, security, SSH and cross-platform considerations, testing, compatibility, and scope. It states that the PR is…

Full details: Linked Issues check

Explanation

Issue #24067 requires the Ports panel to resolve recipe-backed workspaces to the workspace SSH target, scan that target, show detected ports, and avoid silent fallback to the Active Server. This PR adds the server-side scanHost and killHost methods and tests, but the PR description states that the Ports panel does not call these methods yet. The linked issue behavior is therefore not complete.

Resolution

Update the Ports panel and its host resolver to use the host-scoped capability and methods. Resolve the recipe runtime's sshTargetId, scan that host, preserve unavailable results, and verify detected ports and forwarding without Active Server fallback.


  • 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: 7e513768-e029-4635-a666-ad17336ba1e4
📥 Commits

Reviewing files that changed from the base of the PR and between cb69d52 and 754268c.

⛔ Files ignored due to path filters (1)
  • src/shared/rpc-contract/rpc-params-catalog.generated.ts is excluded by !**/*.generated.*
📒 Files selected for processing (10)
  • src/main/ports/workspace-port-execution-host.test.ts
  • src/main/ports/workspace-port-execution-host.ts
  • src/main/runtime/orca-runtime-list-managed-worktrees.ts
  • src/main/runtime/orca-runtime-workspace-ports-host.test.ts
  • src/main/runtime/rpc/methods/workspace-ports.test.ts
  • src/main/runtime/rpc/methods/workspace-ports.ts
  • src/shared/protocol-version.ts
  • src/shared/rpc-contract/workspace-ports-params.ts
  • src/shared/workspace-ports.ts
  • tests/e2e/cross-version-wire/workspace-ports-host-scoped-downgrade.unit.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.

Comment on lines +164 to +174
// Why the workspace, not a client-named host: this server resolves where the workspace runs.
async scanWorkspacePortsOnHost(worktreeSelector: string): Promise<WorkspacePortHostScanResult> {
const { executionHostId } = await this.resolveRuntimeFileTarget(worktreeSelector)
return scanWorkspacePortsOnExecutionHost(executionHostId, this.getWorkspacePortHostDeps())
}

async killWorkspacePortOnHost(
args: WorkspacePortHostKillRequest
): Promise<WorkspacePortKillResult> {
const { executionHostId } = await this.resolveRuntimeFileTarget(args.worktree)
return killWorkspacePortOnExecutionHost(executionHostId, args, this.getWorkspacePortHostDeps())

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

rg -n 'projectHostSetupId|sshTargetId|resolveRuntimeFileTarget|recipe-backed|recipeBacked' src/main/runtime src/shared | head -130
sed -n '155,185p' src/main/runtime/orca-runtime-list-managed-worktrees.ts

Repository: stablyai/orca

Length of output: 16842


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- resolver declaration and implementation references ---'
rg -n -F --glob '*.ts' -- 'resolveRuntimeFileTarget' src/main/runtime src/shared | head -120
printf '%s\n' '--- host-routing definitions and callers ---'
rg -n -F --glob '*.ts' -- 'resolveWorktreeHostRouting' src/main src/shared
rg -n -F --glob '*.ts' -- 'worktree.hostId' src/main/runtime src/shared | head -100
printf '%s\n' '--- recipe/runtime identifiers ---'
rg -n -F --glob '*.ts' -- 'projectHostSetupId' src/main/runtime src/shared | head -160
rg -n -F --glob '*.ts' -- 'sshTargetId' src/main/runtime src/shared | head -180

Repository: stablyai/orca

Length of output: 25349


🏁 Script executed:

set -o pipefail
rg -n -F --glob '*.ts' -- 'resolveRuntimeFileTarget' src/main/runtime src/shared || test "$?" -eq 1
rg -n -F --glob '*.ts' -- 'resolveWorktreeHostRouting' src/main src/shared || test "$?" -eq 1
rg -n -F --glob '*.ts' -- 'projectHostSetupId' src/main/runtime src/shared || test "$?" -eq 1
rg -n -F --glob '*.ts' -- 'sshTargetId' src/main/runtime src/shared || test "$?" -eq 1

Repository: stablyai/orca

Length of output: 22235


🏁 Script executed:

set -o pipefail
git show --format= --stat 754268c91492085f1b10962def85cefeebb4b94e -- src/main/runtime src/shared | sed -n '1,240p'
printf '%s\n' '--- exact resolver block ---'
sed -n '185,240p' src/main/runtime/orca-runtime-persist-headless-terminal-title.ts
printf '%s\n' '--- routing helper ---'
sed -n '1,150p' src/shared/worktree-execution-host-resolution.ts
printf '%s\n' '--- recipe/runtime construction matches ---'
rg -n -i --glob '*.ts' 'recipe|projectHostSetupId|sshTargetId' src/main/runtime src/shared | head -240

Repository: stablyai/orca

Length of output: 35625


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- execution host conversion ---'
rg -n -F --glob '*.ts' -- 'getSshTargetIdForExecutionHost' src/shared src/main/runtime
sed -n '180,270p' src/shared/execution-host.ts
printf '%s\n' '--- runtime record and store fields ---'
sed -n '1,220p' src/shared/ephemeral-vm-runtimes.ts
sed -n '1,230p' src/shared/ephemeral-vm-runtime-store.ts
printf '%s\n' '--- runtime/worktree construction ---'
rg -n -i --glob '*.ts' 'orca-worktree|provisioned-root|environmentId|runtimeId|hostId.*runtime|executionHostId.*runtime' src/main/runtime src/shared | head -260

Repository: stablyai/orca

Length of output: 41309


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- runtime-aware target resolution ---'
rg -n -i --glob '*.ts' 'selectRuntimeAwareSshStatus|runtimeEnvironmentId|sshTargetId' src/main/runtime src/main/ports src/shared | head -320
printf '%s\n' '--- runtime file target contract ---'
sed -n '1,180p' src/main/runtime/runtime-file-command-target.ts
sed -n '1,150p' src/main/runtime/runtime-file-commands-constructor.ts
printf '%s\n' '--- port host dependencies and multiplexer ---'
sed -n '1,190p' src/main/ports/workspace-port-execution-host.ts
rg -n -F --glob '*.ts' -- 'getActiveMultiplexer' src/main src/shared

Repository: stablyai/orca

Length of output: 42514


Resolve the active runtime target before scanning.

resolveRuntimeFileTarget can return runtime:<environment>, but this method passes that value directly to scanWorkspacePortsOnExecutionHost. Runtime hosts are intentionally not direct SSH hosts: getSshTargetIdForExecutionHost('runtime:env-a') returns null, and the scanner returns unavailable for runtime hosts. Resolve the active runtime record for the worktree, use its sshTargetId with the runtime environment, and pass that target to the SSH relay. Keep the unavailable result only when no active target exists.

…y scan is not empty

Port ownership probes now come from host routing instead of the repo row's
connectionId, so an SSH repo that carries only executionHostId (or a runtime-
hosted repo) can no longer make a local listener look workspace-owned.

The relay's ports.detect now fails when it could not read the socket table
(unreadable /proc/net/tcp, or neither Windows scanner answering) instead of
answering an empty list, so a host scan reports unavailable rather than none.
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