Skip to content

fix(web): route headless serve local worktrees through active runtime for web clients - #9090

Closed
sudoeren wants to merge 1 commit into
stablyai:mainfrom
sudoeren:fix/web-client-local-host-routing
Closed

sudoeren wants to merge 1 commit into
stablyai:mainfrom
sudoeren:fix/web-client-local-host-routing

Conversation

@sudoeren

Copy link
Copy Markdown
Contributor

Description

When a browser web client connects to a headless orca serve instance, workspaces owned by the server's local host cannot be operated: launching agents/terminals fails with "Local PTYs unavailable" and the file explorer shows "Couldn't determine which host owns this workspace."

Root cause: Worktrees on the serve machine report hostId: "local", which causes both getRuntimeEnvironmentIdForWorktree and getFileExplorerOperationOwnerFromState to resolve the owner as local — routing operations to the browser's local host (which has no PTY or filesystem) instead of the remote runtime environment.

Fix: When running in a web client with an active runtime environment, treat hostId: "local" worktrees as belonging to the runtime rather than the browser-local host. Changes span three files:

  1. worktree-runtime-owner.ts (getRuntimeEnvironmentIdForWorktree): Skip the early null return for explicit-local worktrees and fall through to the activeRuntimeEnvironmentId fallback when the client is a web browser.
  2. file-explorer-operation-owner.ts (getFileExplorerOperationOwnerFromState): When the exact worktree hostId is "local" and the web client has an active runtime environment, return {kind:'runtime', environmentId} instead of {kind:'local'}.
  3. web-client-location.ts (isWebClientLocation): Made defensive against test environments where window.location may be undefined.

No visual change

This is an architectural fix for operation routing — no UI changes.

Code review summary

  • Cross-platform compatibility: Changes only apply in web client context; Electron desktop behavior is unchanged. The isWebClientLocation() guard ensures desktop apps continue routing local worktrees to the local host.
  • SSH/remote/local compatibility: Local worktrees on a desktop app (no runtime) remain local. SSH worktrees (hostId starts with ssh:) are unaffected. Only the web-client + active-runtime combination triggers the new path.
  • Agent/integration compatibility: All agent and terminal operations benefit from the fix since they all flow through getRuntimeEnvironmentIdForWorktree.
  • Performance risk: One extra isWebClientLocation() call and optional chaining in the worktree owner resolution hot path. Negligible overhead.
  • Security risk: No new IPC or RPC surface; only changes how existing host routing decisions are made.
  • Testing: All 751 existing tests pass across 93 test files. Changes are guarded by isWebClientLocation() which uses __ORCA_WEB_CLIENT__ flag and window.location checks.

Testing notes

  • Tested via existing unit tests (751 pass). Manual testing on a headless orca serve instance with a web browser client would confirm end-to-end.
  • Platform-independent: the web client detection works identically across OS platforms.
  • Git provider independent: no git provider code was touched.

Fixes #9047

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Web-client detection now returns early for the explicit web-client flag and guards pathname access with a fallback to false. Worktree runtime resolution can continue to the active runtime fallback when a web client has an active runtime environment. File-explorer operation ownership now maps a local exact host to that active runtime environment when running in a web client.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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
Title check ✅ Passed The title clearly summarizes the main fix: routing local worktrees through the active runtime for web clients.
Description check ✅ Passed The description covers the summary, no visual change, testing, review notes, security, and platform behavior, though headings differ from the template.
Linked Issues check ✅ Passed The changes address #9047 by routing web-client local worktrees to the active runtime, restoring agent, terminal, and file explorer operations.
Out of Scope Changes check ✅ Passed The patch stays focused on web-client host routing and related detection logic with no obvious unrelated changes.

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: Pro

Run ID: 43bbaa87-be7f-4468-95a9-bda6a75f12d4

📥 Commits

Reviewing files that changed from the base of the PR and between 88068f5 and 6c57d4d.

📒 Files selected for processing (3)
  • src/renderer/src/components/right-sidebar/file-explorer-operation-owner.ts
  • src/renderer/src/lib/web-client-location.ts
  • src/renderer/src/lib/worktree-runtime-owner.ts

Comment on lines +171 to +178
if (worktreeRuntimeEnvironmentId !== null) {
return worktreeRuntimeEnvironmentId
}
// Why: worktrees on a headless serve report hostId "local", but a web
// client has no browser-local host — fall through to the runtime fallback.
if (!isWebClientLocation() || !state.settings?.activeRuntimeEnvironmentId?.trim()) {
return null
}

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 | 🟠 Major | ⚡ Quick win

Return the active runtime directly instead of falling through.

Falling through to the runtime fallback allows repo-level explicit overrides to inadvertently take precedence. If the repository has an SSH connection, the fall-through logic evaluates parsed?.kind === 'runtime' as false and returns null. On a web client, returning null maps to a local host, which lacks a PTY and will cause the exact agent and terminal launch failures this PR is intended to fix.

To ensure operations correctly route to the active runtime (and to maintain consistency with getFileExplorerOperationOwnerFromState), return the active runtime directly instead of falling out of the block.

🐛 Proposed fix to return the active runtime directly
     if (worktreeRuntimeEnvironmentId !== null) {
       return worktreeRuntimeEnvironmentId
     }
-    // Why: worktrees on a headless serve report hostId "local", but a web
-    // client has no browser-local host — fall through to the runtime fallback.
-    if (!isWebClientLocation() || !state.settings?.activeRuntimeEnvironmentId?.trim()) {
-      return null
-    }
+    // Why: worktrees on a headless serve report hostId "local", but a web
+    // client has no browser-local host — route through the active runtime.
+    if (isWebClientLocation() && state.settings?.activeRuntimeEnvironmentId?.trim()) {
+      return state.settings.activeRuntimeEnvironmentId.trim()
+    }
+    return null
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (worktreeRuntimeEnvironmentId !== null) {
return worktreeRuntimeEnvironmentId
}
// Why: worktrees on a headless serve report hostId "local", but a web
// client has no browser-local host — fall through to the runtime fallback.
if (!isWebClientLocation() || !state.settings?.activeRuntimeEnvironmentId?.trim()) {
return null
}
if (worktreeRuntimeEnvironmentId !== null) {
return worktreeRuntimeEnvironmentId
}
// Why: worktrees on a headless serve report hostId "local", but a web
// client has no browser-local host — route through the active runtime.
if (isWebClientLocation() && state.settings?.activeRuntimeEnvironmentId?.trim()) {
return state.settings.activeRuntimeEnvironmentId.trim()
}
return null

@brennanb2025

Copy link
Copy Markdown
Contributor

Taking a look!

@brennanb2025

Copy link
Copy Markdown
Contributor

Thank you for this! #9147 solves the same issue (#9047) with slightly broader coverage — notably it also avoids an SSH mis-route case on the runtime-owner fall-through. Going to consolidate on #9147 and close this one, but the approach was spot-on. Really appreciate the contribution 🙏

@AmethystLiang AmethystLiang added the orca-remote-server Remote Orca Server / orca serve / paired remote runtime label Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

orca-remote-server Remote Orca Server / orca serve / paired remote runtime

Projects

None yet

3 participants