Skip to content

fix(ssh): enable server-owned SSH projects in paired clients - #8492

Closed
jae-heo wants to merge 5 commits into
stablyai:mainfrom
jae-heo:fix/headless-serve-ssh-handlers
Closed

jae-heo wants to merge 5 commits into
stablyai:mainfrom
jae-heo:fix/headless-serve-ssh-handlers

Conversation

@jae-heo

@jae-heo jae-heo commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Initialize Orca's existing SSH provider stack before a headless orca serve runtime accepts requests.
  • Extend authenticated paired-Desktop runtime RPC with server-owned SSH target add/import, connection, directory browsing, nested scanning, and SSH-project creation.
  • Route the existing Add Project UI through the selected Orca server: select a server, add/import its SSH host, browse that host, add the project, and create a workspace/session.
  • Preserve composite ownership for nested operations (Desktop → paired runtime → SSH host), including connect/status, agent detection, terminals, worktree creation, polling, deletion, and automation dispatch.
  • Keep local Desktop SSH behavior unchanged and keep the new management methods outside the phone/mobile RPC allowlist.

Fixes #8489.

Screenshots

This change reuses Orca's existing Add Project, host selector, Add SSH Host, and Remote File Browser surfaces instead of introducing a standalone screen. Visible changes are contextual:

  • selecting a paired server now exposes Project on SSH host;
  • Add SSH host to <server> makes ownership explicit;
  • an empty server-owned target list explains that no SSH targets are configured on that Orca server.

An end-to-end static screenshot would require committing pairing credentials or server state, so the conditional UI and routing are covered by renderer tests instead.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test (29,137 passed, 40 skipped)
  • macOS arm64 app packaging and deep code-sign verification
  • Linux x64 AppImage packaging and live systemd deployment
  • Focused SSH/runtime/renderer suites passed, including composite connect, agent, terminal, worktree, lifecycle, and cache-ownership regressions
  • Added or updated high-quality tests that would catch regressions

AI Review Report

Reviewed the headless and desktop startup paths, SSH manager lifecycle, runtime RPC ordering, environment-scoped renderer routing, repository persistence, and the null-BrowserWindow path. The review covered macOS, Linux, and Windows behavior; local, paired-server, and SSH execution hosts; POSIX and PowerShell remote directory browsing; nested repository scanning; session creation dependencies; and unchanged local Desktop flows.

The implementation reuses existing SSH, Git, filesystem, PTY, repository, and UI primitives. Server-scoped actions are selected only when a runtime environment owns the operation; local SSH IPC remains the fallback. Tests verify server and local routing, SSH target management, connection/browse behavior, remote repository creation, nested scans, and startup registration order.

CodeRabbit follow-up review was addressed by keeping failed runtime reconnect dialogs open, bounding runtime agent detection to 30 seconds, and reusing the centralized paired-client detector. Dedicated dialog tests cover unsuccessful and successful runtime reconnect results.

Security Audit

Reviewed RPC authorization, input validation, target ownership, paths, credentials, command construction, secrets, dependencies, and mobile exposure.

  • The new methods use the existing authenticated runtime channel for paired Desktop clients.
  • They are intentionally absent from MOBILE_RPC_METHOD_ALLOWLIST, so phone/mobile pairing cannot manage server SSH targets or add server projects.
  • Manual target input is strict and bounded; internal owner fields and config-derived proxy/jump fields cannot be injected by the client.
  • Directory browsing and project creation reuse existing SSH providers, escaping, target lookup, persistence, and host-key/key-file handling.
  • No new dependency, credential transport, shell-command construction, or authentication bypass was added.
  • Headless credential prompts that require a desktop window resolve as cancelled rather than hanging.

No follow-up security work was identified.

Notes

  • Reproduced the original Linux failure as ssh_handlers_not_registered while direct SSH connectivity worked.
  • Reproduced the installed paired-client failure as local Electron IPC resolving server-owned ssh-p8; the fixed build routes it through the owning runtime RPC instead.
  • Live E2E validation created a p8 worktree and opened its Claude terminal session and remote file explorer from the paired macOS client.
  • Build warnings were limited to existing bundle-size/dynamic-import warnings and a non-fatal development CLI symlink permission warning.
  • X (Twitter): Not provided

ELI5

Paired desktop clients can now add and use SSH projects that live on an Orca remote server. You pick the server, add or import an SSH host, browse folders, and create the project without doing that only on the server machine itself.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Serve-mode initialization now registers SSH handlers without a BrowserWindow before the runtime RPC server starts. Runtime RPC methods support SSH target management, directory browsing, remote repository addition, and SSH-aware nested repository scans. Renderer flows select desktop IPC or environment-scoped runtime RPC based on the selected host, with updated UI states, localization, and tests.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 41.94% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes implement the #8489 objectives: headless SSH handler init, server-owned SSH RPCs, UI routing, and local/mobile scope separation.
Out of Scope Changes check ✅ Passed The diff stays focused on SSH, paired-runtime routing, and supporting tests/localization, with no clear unrelated additions.
Title check ✅ Passed The title is concise and accurately summarizes the main change: enabling server-owned SSH projects in paired clients.
Description check ✅ Passed The description follows the required template with Summary, Screenshots, Testing, AI Review Report, Security Audit, and Notes sections.

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.

@jae-heo jae-heo changed the title fix(ssh): initialize handlers in headless serve fix(ssh): enable server-owned SSH projects in paired clients Jul 13, 2026
@jae-heo

jae-heo commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

Additional packaged validation on the PR head (8ec3ab9d6):

  • Built and installed the arm64 macOS app bundle (1.4.138-rc.4); deep code-signature verification passed.
  • Built the x86_64 Linux AppImage on Rocky Linux 9.5 and deployed it behind the existing orca serve systemd unit.
  • The upgraded runtime reached ready, retained the existing paired-device/E2EE identity files, and remained reachable over its configured private-network endpoint.
  • Against a previously saved SSH target, live runtime RPC validation passed for ssh.listTargets, ssh.connect (connected), and the newly exposed ssh.browseDir operation.
  • No ssh_handlers_not_registered error appeared after restart.

The prior AppImage and server profile were backed up before deployment.

@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: 2

🧹 Nitpick comments (1)
src/renderer/src/components/cmd-j/quick-action-context.ts (1)

91-97: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use isPairedWebClientWindow() helper instead of inlining the paired-web-client check.

The inline Boolean((globalThis as { __ORCA_WEB_CLIENT__?: boolean }).__ORCA_WEB_CLIENT__) duplicates the detection logic already centralized in isPairedWebClientWindow() from @/lib/desktop-window-chrome, which useGitStatusPolling.ts correctly imports. Using the helper keeps a single source of truth for the type assertion and detection semantics.

♻️ Proposed refactor
 import { getExplicitRuntimeEnvironmentIdForWorktree } from '`@/lib/worktree-runtime-owner`'
 import { selectRuntimeAwareSshStatus } from '`@/store/slices/runtime-environment-ssh`'
+import { isPairedWebClientWindow } from '`@/lib/desktop-window-chrome`'
-  const isPairedWebClient = Boolean(
-    (globalThis as { __ORCA_WEB_CLIENT__?: boolean }).__ORCA_WEB_CLIENT__
-  )
-  const sshOwnerEnvironmentId = isPairedWebClient
-    ? null
-    : getExplicitRuntimeEnvironmentIdForWorktree(state, activeWorktree.id)
+  const sshOwnerEnvironmentId = isPairedWebClientWindow()
+    ? null
+    : getExplicitRuntimeEnvironmentIdForWorktree(state, activeWorktree.id)

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 0d8e5dad-d709-4777-a008-05b4a119d401

📥 Commits

Reviewing files that changed from the base of the PR and between 8ec3ab9d60da04d1e7b3994c1412090d5ae593d4 and 369433f7eb4e1d3f60bfd8e84643eb6ef8d8a28b.

📒 Files selected for processing (24)
  • src/renderer/src/components/cmd-j/quick-action-context.ts
  • src/renderer/src/components/right-sidebar/useGitStatusPolling.ts
  • src/renderer/src/components/sidebar/ForgetSshWorkspaceDialog.tsx
  • src/renderer/src/components/sidebar/SshDisconnectedDialog.tsx
  • src/renderer/src/components/sidebar/WorktreeCard.tsx
  • src/renderer/src/components/sidebar/WorktreeList.tsx
  • src/renderer/src/components/sidebar/delete-worktree-flow.ts
  • src/renderer/src/components/sidebar/runtime-aware-ssh-workspace-forget.ts
  • src/renderer/src/components/sidebar/ssh-workspace-forget-resolution.test.ts
  • src/renderer/src/components/sidebar/ssh-workspace-forget-resolution.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/renderer/src/components/terminal-pane/ssh-pane-connect-gate.test.ts
  • src/renderer/src/components/terminal-pane/ssh-pane-connect-gate.ts
  • src/renderer/src/hooks/useAutomationDispatchEvents.ts
  • src/renderer/src/hooks/useComposerState-host-context-boundaries.test.ts
  • src/renderer/src/hooks/useComposerState.ts
  • src/renderer/src/hooks/useDetectedAgents.ts
  • src/renderer/src/lib/runtime-agent-detection-key.ts
  • src/renderer/src/runtime/runtime-environment-ssh-state.test.ts
  • src/renderer/src/runtime/runtime-environment-ssh-state.ts
  • src/renderer/src/store/slices/detected-agents.test.ts
  • src/renderer/src/store/slices/detected-agents.ts
  • src/renderer/src/store/slices/terminals.ts
  • src/renderer/src/store/slices/worktrees.test.ts

@jae-heo

jae-heo commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up packaged E2E validation on the composite-routing fix (369433f7e; current head d5647d515 adds documentation only):

  • Reproduced the paired macOS client failure: the composer used local Electron ssh:connect for the server-owned target and raised SSH target "ssh-p8" not found.
  • Updated the renderer so the full Desktop → paired linux-jae runtime → p8 SSH target chain retains its owner for connect/status, agent detection, terminal startup, worktree creation, polling, deletion, and automation paths.
  • Full validation passed: typecheck, lint, and the complete suite (28,997 passed, 38 skipped).
  • Built and deep-signature-verified the macOS arm64 app, then built and deployed the Linux x64 AppImage.
  • Re-paired the desktop with a runtime-scoped grant (the service had been started with --mobile-pairing, which correctly denied workspace RPCs). Existing device state was preserved.
  • From the packaged macOS build, connected ssh-p8 through linux-jae without the original error, created the p8 worktree /home/jae/orca-pr8492-e2e, opened its Claude terminal session, and loaded the remote file explorer.

The installed-build failure is now covered by regression tests for the composer route and the downstream nested-runtime boundaries.

@jae-heo
jae-heo force-pushed the fix/headless-serve-ssh-handlers branch from d5647d5 to eddde1d Compare July 13, 2026 07:59
@jae-heo

jae-heo commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

Final review follow-up on current head eddde1d85:

  • Rebased the branch onto current upstream/main (e98bfd67c).
  • Addressed both CodeRabbit inline findings: unsuccessful runtime reconnects now keep the dialog open, and runtime agent detection has a 30-second deadline with retryable cleanup.
  • Applied the maintainability suggestion by replacing the duplicated paired-web-client global check with isPairedWebClientWindow().
  • Added focused reconnect-dialog regression tests and updated runtime-detection timeout assertions.
  • Revalidated the rebased branch: pnpm lint, pnpm typecheck, focused review tests (28 passed), and the full suite (29,137 passed, 40 skipped).
  • Updated issue [Bug]: Paired Desktop cannot manage or use headless server SSH targets #8489 to use the correct runtime-scoped Desktop pairing command (without --mobile-pairing) and to reference current main.

Both inline review threads are resolved, with implementation/test details replied in-thread.

@jae-heo

jae-heo commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@AmethystLiang
AmethystLiang requested a review from Jinwoo-H July 13, 2026 16:47
@AmethystLiang AmethystLiang assigned OrcaWin and unassigned Jinwoo-H Jul 20, 2026
@AmethystLiang
AmethystLiang requested review from OrcaWin and removed request for Jinwoo-H July 20, 2026 18:38
@AmethystLiang AmethystLiang added the orca-remote-server Remote Orca Server / orca serve / paired remote runtime label Jul 22, 2026
@nwparker nwparker added the enhancement New feature or request label Jul 27, 2026
@jae-heo

jae-heo commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

@OrcaWin, would #8492 be easier to review and land if I split it into smaller staged PRs? The current PR spans three layers, and I can separate it into:

  1. Headless orca serve SSH-handler initialization
  2. Authenticated, bounded runtime RPCs for server-owned SSH target management
  3. Paired-client renderer routing and the Add Project UI

I’m happy to keep the current PR as-is or restructure it based on your preference.

JustShinobi added a commit to JustShinobi/orca that referenced this pull request Aug 6, 2026
Merges stablyai#8492 (fix(ssh): enable server-owned SSH projects in
paired clients) on top of an upstream/main sync, resolving conflicts against
later upstream work in the same SSH/runtime area (STA-1468 desktop topology,
the AddRemoteHostDialog panel refactor, the WorktreeCardSshHostControl pill
that replaced SshDisconnectedDialog, and folder-workspace-aware automation
dispatch).

Notable non-mechanical resolutions:
- runtime-detected-agents.ts: extended with connectionId-aware composite
  keys instead of duplicating state in detected-agents.ts (would have
  silently shadowed in the store's slice spread order).
- add-remote-host-ssh-actions.ts / AddRemoteHostSshFormPanel.tsx: threaded
  an optional server-owner routing through the shared save/import helpers
  so PR 8492's server-owned flow rides HEAD's later dialog refactor instead
  of reverting it.
- WorktreeCard.tsx: dropped PR 8492's SshDisconnectedDialog render (and the
  now-orphaned component/test files) in favor of the newer inline
  WorktreeCardSshHostControl pill, which already carries owner-aware
  reconnect logic.
- useAutomationDispatchEvents.ts: layered runtime-owner-aware SSH connect
  onto HEAD's folder-workspace-aware target resolution, scoping runtime
  ownership to the repo case since folder workspaces resolve their SSH
  target independently.

Verified with `pnpm run typecheck` (node/cli/web projects, clean) and
`oxlint` on every manually resolved file (clean). Could not run `vitest`
in this environment — the repo's vitest config passes `--no-experimental-webstorage`,
which requires Node 24+ and this sandbox has Node 20.19.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
JustShinobi added a commit to JustShinobi/orca that referenced this pull request Aug 9, 2026
… client

addSshTargetForOwner/importSshConfigForOwner reached for window.api.ssh
directly on the local (owner=null) path, bypassing the ssh client that
add-remote-host-ssh-actions.ts's callers inject for testability. Every test
in add-remote-host-ssh-actions.test.ts that exercised the local save/import
path threw on window.api being undefined and silently returned 'failed'.

The bug isn't in PR stablyai#8492 as authored — that PR's AddRemoteHostDialog.tsx
called window.api.ssh directly with no injected-client pattern; the shared
save/import helpers with an injected ssh client are a newer upstream file
this fork's Aug-5 merge had to thread PR 8492's server-owned flow onto,
and the threading dropped the injection for the local branch.

Adds an optional addLocalTarget/importLocalConfig parameter defaulting to
window.api.ssh.* (so runtime-ssh-target-management.test.ts's existing
window-stubbing tests are unaffected) and passes ssh.addTarget/
ssh.importConfig through explicitly from the one production call site.
@OrcaWin

OrcaWin commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator

Thank you, @jae-heo. This PR mapped the whole problem in #8489 and showed a working path through it. It is now superseded by two merged PRs on current main, which has moved a long way since this was opened (the permission model, owner routing, headless serve SSH registration):

Headless orca serve already registers the SSH handlers on main, so that part of this PR has landed separately.

Closing as superseded, with credit in both PR descriptions. Thanks again for the thorough write-up and the live repro.

@OrcaWin OrcaWin closed this Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request orca-remote-server Remote Orca Server / orca serve / paired remote runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Paired Desktop cannot manage or use headless server SSH targets

5 participants