Skip to content

Route terminal links based on pane ownership, not global state - #12233

Merged
AmethystLiang merged 2 commits into
mainfrom
clicking-on-links-on-remote-host-makes-it-reconnect
Aug 3, 2026
Merged

AmethystLiang merged 2 commits into
mainfrom
clicking-on-links-on-remote-host-makes-it-reconnect

Conversation

@AmethystLiang

Copy link
Copy Markdown
Contributor

Summary

Fixes links clicked on remote-runtime and SSH panes incorrectly routing through the global active runtime state. Links are now routed based on the clicked pane's actual ownership (local, runtime-hosted, or SSH), preventing unwanted reconnections when clicking links on remote hosts.

Changes

  • Added resolveTerminalHttpLinkSourceOwner() to determine whether a pane is local, runtime-owned, or SSH-owned by inspecting its PTY ID and transport state
  • Extracted HTTP URL parsing into extractTerminalHttpLinks() for reuse across link handlers
  • Updated link handlers (handleOscLink, handleTerminalWebLinkClick, installHttpLinkClickFallback) to receive and pass the source pane's ownership
  • Modified terminalUrlOpenHintOptionsFor() to suppress the modifier-inversion hint when a remote pane cannot reach Orca, preventing false routing promises
  • Updated localhost label resolution to account for link source ownership — remote panes' loopback URLs are no longer labeled with local worktree names
  • Threaded pane ID through tooltip hooks so each hovered pane's ownership is resolved independently, not against global state

Screenshots

No visual change

Testing

  • Added terminal-http-link-source-owner.test.ts covering local, runtime, SSH, and legacy remote PTY classification
  • Added terminal-runtime-host-link-routing.test.ts covering OSC 8, WebLinksAddon, and click-fallback routing for runtime-owned, SSH-owned, and local panes
  • Updated existing hint and routing tests to verify ownership-based behavior
  • pnpm lint
  • pnpm typecheck
  • pnpm test

Notes

Workspace-bound runtimes are per-workspace, so activeRuntimeEnvironmentId is commonly null while a pane lives on a remote host. Link routing now correctly uses pane ownership instead of global runtime state. Local panes retain in-app routing when a different pane's runtime is active.

AmethystLiang and others added 2 commits August 2, 2026 22:00
Terminal link clicks classified ownership from the global
activeRuntimeEnvironmentId, which is null when runtimes are bound per
workspace, so a link clicked in a remote-hosted pane opened a local-only
Orca browser tab and never reached the host. Thread each pane's resolved
runtimeEnvironmentId into openHttpLink as sourceOwner across the OSC 8,
WebLinksAddon, and click-fallback paths.

Co-authored-by: Orca <[email protected]>
Clicking links on remote-hosted panes was routing based on global runtime state, causing unexpected reconnections. Now link routing decisions (where to open: Orca vs system browser) are based on the actual pane's owner — local, SSH connection, remote runtime, or unknown — regardless of whether any runtime is globally active. This ensures a local pane can route to Orca while another pane's remote runtime is active, and a remote pane always routes to the system browser.
@AmethystLiang
AmethystLiang merged commit db53252 into main Aug 3, 2026
43 checks passed
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The change adds terminal HTTP URL extraction and per-pane source ownership resolution. Ownership now flows through terminal lifecycle handling, URL hit testing, OSC links, click hints, tooltips, and web-link routing. Runtime- and SSH-owned links use system-browser routing, while local links retain Orca routing. Localhost display labeling now uses the resolved source owner. Tests cover ownership, extraction, routing, modifier behavior, and pane-scoped tooltip callbacks.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the change, testing, and notes but omits the required AI Review Report and Security Audit sections and does not report pnpm build. Add the AI Review Report and Security Audit sections, confirm cross-platform review, and report whether pnpm build was run.
Docstring Coverage ⚠️ Warning Docstring coverage is 6.25% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: terminal links now route according to pane ownership instead of global state.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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

🧹 Nitpick comments (1)
src/renderer/src/components/terminal-pane/terminal-osc-link-routing.ts (1)

86-90: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract the duplicated sourceOwner fallback into a shared helper. Both sites compute the identical default: deps.sourceOwner ?? (deps.runtimeEnvironmentId ? { kind: 'runtime', runtimeEnvironmentId: deps.runtimeEnvironmentId } : { kind: 'local' }). A shared helper keeps the two call sites in sync if the fallback rule changes.

  • src/renderer/src/components/terminal-pane/terminal-osc-link-routing.ts#L86-L90: replace the inline fallback with a call to a shared helper, e.g. resolveHttpLinkSourceOwnerFallback(deps.sourceOwner, deps.runtimeEnvironmentId).
  • src/renderer/src/components/terminal-pane/terminal-web-link-click.ts#L34-L38: replace the inline fallback with the same shared helper call.
♻️ Proposed shared helper
// e.g. in a shared location near HttpLinkSourceOwner's definition
export function resolveHttpLinkSourceOwnerFallback(
  sourceOwner: HttpLinkSourceOwner | undefined,
  runtimeEnvironmentId: string | null | undefined
): HttpLinkSourceOwner {
  return (
    sourceOwner ??
    (runtimeEnvironmentId ? { kind: 'runtime', runtimeEnvironmentId } : { kind: 'local' })
  )
}

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e4e00ed0-60b5-4a5f-a011-45435d0c3c86

📥 Commits

Reviewing files that changed from the base of the PR and between 93a2ad8 and 47bd85f.

📒 Files selected for processing (16)
  • src/renderer/src/components/terminal-pane/terminal-http-link-source-owner.test.ts
  • src/renderer/src/components/terminal-pane/terminal-http-link-source-owner.ts
  • src/renderer/src/components/terminal-pane/terminal-http-url-extraction.ts
  • src/renderer/src/components/terminal-pane/terminal-link-open-hints.test.ts
  • src/renderer/src/components/terminal-pane/terminal-link-open-hints.ts
  • src/renderer/src/components/terminal-pane/terminal-osc-link-routing.ts
  • src/renderer/src/components/terminal-pane/terminal-runtime-host-link-routing.test.ts
  • src/renderer/src/components/terminal-pane/terminal-url-link-hit-testing.ts
  • src/renderer/src/components/terminal-pane/terminal-web-link-click.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts
  • src/renderer/src/lib/http-link-modifier-routing.test.ts
  • src/renderer/src/lib/http-link-routing.test.ts
  • src/renderer/src/lib/http-link-routing.ts
  • src/renderer/src/lib/pane-manager/pane-dom-creation.test.ts
  • src/renderer/src/lib/pane-manager/pane-dom-creation.ts
  • src/renderer/src/lib/pane-manager/pane-manager-types.ts

Comment on lines +77 to +85
function findHttpUrlCandidateEnd(lineText: string, startIndex: number): number {
const scanEnd = Math.min(lineText.length, startIndex + TERMINAL_HTTP_URL_MAX_LENGTH + 1)
for (let index = startIndex; index < scanEnd; index += 1) {
if (isHttpUrlBodyTerminator(lineText.charCodeAt(index))) {
return index
}
}
return scanEnd
}

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

Fix: parenthesized URLs get truncated at the first paren.

isHttpUrlBodyTerminator treats ( and ) as unconditional terminators. A URL that legitimately contains a paren, such as http://en.wikipedia.org/wiki/C_(programming_language), gets cut at the first (, producing http://en.wikipedia.org/wiki/C_ instead of the full URL.

Track paren balance in findHttpUrlCandidateEnd so an opening paren does not terminate the scan, and only an unmatched closing paren terminates it. Note that after this change, isHttpUrlTrailingPunctuation still unconditionally trims a trailing ), so a legitimately matched closing paren immediately followed by other trailing punctuation (for example a sentence period) can still get stripped; this needs a corresponding adjustment or a targeted test to confirm the final behavior.

Consider adding unit tests for extractTerminalHttpLinks covering parenthesized URLs, trailing punctuation, and the length-limit boundary; no dedicated test file for this function exists in this batch, which is likely why this edge case was not caught.

🐛 Proposed fix for paren handling in the scan
 function findHttpUrlCandidateEnd(lineText: string, startIndex: number): number {
   const scanEnd = Math.min(lineText.length, startIndex + TERMINAL_HTTP_URL_MAX_LENGTH + 1)
-  for (let index = startIndex; index < scanEnd; index += 1) {
-    if (isHttpUrlBodyTerminator(lineText.charCodeAt(index))) {
-      return index
-    }
-  }
+  let parenDepth = 0
+  for (let index = startIndex; index < scanEnd; index += 1) {
+    const code = lineText.charCodeAt(index)
+    if (code === 0x28) {
+      parenDepth += 1
+      continue
+    }
+    if (code === 0x29) {
+      if (parenDepth === 0) {
+        return index
+      }
+      parenDepth -= 1
+      continue
+    }
+    if (isHttpUrlBodyTerminator(code)) {
+      return index
+    }
+  }
   return scanEnd
 }
 function isHttpUrlBodyTerminator(code: number): boolean {
   return (
     isAsciiWhitespace(code) ||
     code === 0x22 ||
     code === 0x27 ||
     code === 0x21 ||
     code === 0x2a ||
-    code === 0x28 ||
-    code === 0x29 ||
     code === 0x7b ||

Also applies to: 99-117, 119-143

giirrr added a commit to giirrr/orca that referenced this pull request Aug 3, 2026
Conflict resolution: `installHttpLinkClickFallback` deps — main added
`getSourceOwner` (stablyai#12233, pane-owned link routing) and this branch added
`getMouseEventsRequireAlt`. Both are independent optional deps on the
same object, so both are kept; the merged
`terminal-url-link-hit-testing.ts` already declares all three.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…yai#12233)

* fix(terminal): route remote-runtime link clicks to the system browser

Terminal link clicks classified ownership from the global
activeRuntimeEnvironmentId, which is null when runtimes are bound per
workspace, so a link clicked in a remote-hosted pane opened a local-only
Orca browser tab and never reached the host. Thread each pane's resolved
runtimeEnvironmentId into openHttpLink as sourceOwner across the OSC 8,
WebLinksAddon, and click-fallback paths.

Co-authored-by: Orca <[email protected]>

* fix(terminal): route link clicks based on pane ownership, not global sta

Clicking links on remote-hosted panes was routing based on global runtime state, causing unexpected reconnections. Now link routing decisions (where to open: Orca vs system browser) are based on the actual pane's owner — local, SSH connection, remote runtime, or unknown — regardless of whether any runtime is globally active. This ensures a local pane can route to Orca while another pane's remote runtime is active, and a remote pane always routes to the system browser.

---------

Co-authored-by: Orca <[email protected]>
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.

1 participant