Repository navigation
feat(ports): host-scoped port scan and stop on the server - #27188
Conversation
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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: 🟡 Moderate · up to 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 |
|
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:
7e513768-e029-4635-a666-ad17336ba1e4
⛔ Files ignored due to path filters (1)
src/shared/rpc-contract/rpc-params-catalog.generated.tsis excluded by!**/*.generated.*
📒 Files selected for processing (10)
src/main/ports/workspace-port-execution-host.test.tssrc/main/ports/workspace-port-execution-host.tssrc/main/runtime/orca-runtime-list-managed-worktrees.tssrc/main/runtime/orca-runtime-workspace-ports-host.test.tssrc/main/runtime/rpc/methods/workspace-ports.test.tssrc/main/runtime/rpc/methods/workspace-ports.tssrc/shared/protocol-version.tssrc/shared/rpc-contract/workspace-ports-params.tssrc/shared/workspace-ports.tstests/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.
| // 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()) |
There was a problem hiding this comment.
🎯 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.tsRepository: 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 -180Repository: 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 1Repository: 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 -240Repository: 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 -260Repository: 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/sharedRepository: 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.
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.
workspacePorts.scanandworkspacePorts.killonly take arepoId. The server scans its own machine, skips SSH workspaces entirely, and Stop rescans the server and callsprocess.killthere. 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.workspace-ports.host-scoped.v1capability: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 withexecutionHostId, named from the server's point of view (localorssh:<target>).ports.detectover the live connection. Those rows come back asexternal, because the relay cannot attribute a listener to a workspace.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.connectionId. An SSH repo that carries onlyexecutionHostId, or a repo hosted by another server, can no longer make a process on this machine look workspace-owned.ports.detectnow fails when it could not read the socket table:/proc/net/tcpis unreadable, or on Windows neither netstat nor PowerShell answered. Before, it answered an empty list, which looked like "nothing is listening". A missingtcp6(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
method_not_found, which the client turns into "update server" (V4c-2). It can never end up scanning or stopping the wrong machine.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: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 onlyexecutionHostId, legacyconnectionIdrepos and runtime-hosted repos are all excluded.src/relay/port-scan-handler.test.tsandwindows-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.killHostwithoutexecutionHostIdis rejected.tests/e2e/cross-version-wire/workspace-ports-host-scoped-downgrade.unit.test.ts, against the newest release:scanandkillparse the same on old and new serverspnpm 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
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)