Skip to content

Fix remote terminal focus snapping during agent runs - #5435

Merged
Jinwoo-H merged 1 commit into
mainfrom
Jinwoo-H/remote-server-split-focus-5418
Jun 16, 2026
Merged

Jinwoo-H merged 1 commit into
mainfrom
Jinwoo-H/remote-server-split-focus-5418

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Jun 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Preserve a valid local remote-session tab selection when runtime snapshots only repeat stale host active metadata
  • Preserve local split-pane focus and active pane title/PTY while remote agent status/title snapshots continue publishing
  • Add regression coverage for remote terminal tab and split-pane focus stealing

Fixes #5418

Testing

  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/runtime/web-session-tabs-sync.test.ts
  • pnpm exec vitest run --config config/vitest.config.ts src/main/runtime/rpc/methods/session-tabs.test.ts src/main/runtime/runtime-rpc.test.ts src/main/runtime/orca-runtime.test.ts src/renderer/src/runtime/web-session-tabs-sync.test.ts src/renderer/src/components/tab-group/useTabGroupWorkspaceModel.focus.test.ts src/renderer/src/store/slices/terminals.test.ts
  • pnpm exec oxlint --format github
  • pnpm run typecheck

Note: typecheck passed with the existing local Node engine warning because this shell is on Node v26 while the repo requests Node 24.

Made with Orca 🐋


Open in Stage

@ghost

ghost commented Jun 16, 2026 •

Copy link
Copy Markdown

Ready to review this PR? Stage has broken it down into 3 individual chapters for you:

Title
1 Preserve local split-pane focus during remote snapshots
2 Maintain local tab selection across remote updates
3 Add regression tests for focus preservation
Open in Stage

Chapters generated by Stage for commit abd4869 on Jun 16, 2026 5:52am UTC.

@coderabbitai

coderabbitai Bot commented Jun 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 72789054-fa14-48cf-b579-3863d8da60bd

📥 Commits

Reviewing files that changed from the base of the PR and between 352ce6dbaba6ea903e119c98bd0fb6342b70ef6c and 85938562ec26b777008bfbac3bc7f4f292abac4e.

📒 Files selected for processing (8)
  • src/renderer/src/components/cmd-j/palette-host-badge.test.ts
  • src/renderer/src/components/settings/RepositoryHostSetupsSection.test.tsx
  • src/renderer/src/components/settings/cli-source-control-integration-cards.test.tsx
  • src/renderer/src/components/settings/provider-rate-limit-scope-panels.test.tsx
  • src/renderer/src/components/settings/task-tracker-integration-cards.test.tsx
  • src/renderer/src/components/sidebar/worktree-list-groups.test.ts
  • src/renderer/src/components/task-source-context-summary.test.ts
  • src/renderer/src/lib/project-host-setup-options.test.ts
✅ Files skipped from review due to trivial changes (1)
  • src/renderer/src/components/sidebar/worktree-list-groups.test.ts

📝 Walkthrough

Walkthrough

The change addresses two independent concerns. First, web-session-tabs-sync.ts is updated to preserve local focus state when applying remote session snapshots: chooseRemoteTerminalLayout now accepts an optional existingLayout and reuses its activeLeafId when still valid; buildMirroredTerminalTabs accepts existingLayoutsByTabId to derive activeSurface and pass the existing layout to the layout chooser; and applyWebSessionTabsSnapshot introduces findCurrentVisibleUnifiedTabId to resolve the currently visible unified tab id, adds "current still exists" checks to active tab derivation, prioritises group selection by matching nextActiveUnifiedTabId, and prefers the validated current visible type before snapshot-derived defaults. Two new tests verify these invariants. Second, eight test files across the renderer components are updated to derive the local host display label dynamically from getLocalExecutionHostLabel() instead of hardcoding strings, ensuring test assertions reflect actual runtime values.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers Summary, Testing, and mentions AI review, but Screenshots and Security Audit sections are missing from the required template sections. Add Screenshots section (state 'No visual change' if applicable) and Security Audit section with basic security review from AI agent.
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 (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main fix: preventing remote terminal focus from snapping during agent runs, which directly addresses the core issue being resolved.
Linked Issues check ✅ Passed The code changes directly address issue #5418 by preventing tab focus stealing and preserving local split-pane focus during remote agent operations through improved snapshot reconciliation logic.
Out of Scope Changes check ✅ Passed All changes are within scope: core fix to web-session-tabs-sync logic, comprehensive test updates, and test file modifications to use dynamic local host labels instead of hardcoded strings.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 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 and usage tips.

@Jinwoo-H Jinwoo-H changed the title Fix remote session tab focus stealing Fix remote terminal focus snapping during agent runs Jun 16, 2026
Co-authored-by: Orca <help@stably.ai>
@Jinwoo-H
Jinwoo-H force-pushed the Jinwoo-H/remote-server-split-focus-5418 branch from 8593856 to abd4869 Compare June 16, 2026 05:52
@Jinwoo-H
Jinwoo-H merged commit 413fb31 into main Jun 16, 2026
1 check passed
Jinwoo-H added a commit that referenced this pull request Jun 17, 2026
A newly created remote terminal/browser tab did not get focus: #5435 made the
session-tab reconcile keep the CURRENT active tab over the snapshot's active
tab (to stop agent-run status echoes from stealing focus), which also blocked
genuine create/activate from taking focus. A transient 'is this tab new' signal
couldn't fix it because racing/duplicate snapshots re-applied and snapped focus
back.

Root cause: the snapshot's activeTabId is overloaded — it means both
user-intended focus (on create/activate) and server-side active surface (echoed
during agent runs). The client can't tell them apart from the snapshot alone.

Fix — client-initiated focus intent (the durable version of what mobile already
does with pendingActiveSessionTabIdRef):
- web-session-focus-intent.ts: a small per-worktree store of the host tab id the
  client expects to focus, persisting until a snapshot matches it.
- createWebRuntimeSessionTerminal / createWebRuntimeSessionBrowserTab record the
  intent when they create with activate.
- applyWebSessionTabsSnapshot honors the snapshot's active tab over sticky-current
  ONLY when it matches a pending intent (then consumes it); otherwise keeps
  current focus, so unsolicited server-active (agent echoes) still never steals
  focus — #5435 preserved.

Tests: new 'focuses a brand-new remote terminal' test (intent set) passes; both
#5435 'does not let repeated snapshots steal focus' tests (no intent) stay green.

Verified live via the electron skill against a headless serve: creating a
terminal (or a second/back-to-back terminal, or a browser tab) on a remote
worktree focuses the new tab immediately AND it stays focused after snapshots
settle (no snap-back); opening a new terminal still focuses the terminal.

Co-authored-by: Orca <help@stably.ai>
@AmethystLiang

Copy link
Copy Markdown
Contributor

thanks for reporting. looking into it

enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
AmoabaKelvin added a commit that referenced this pull request Nov 10, 2026
…0828)

`orca agent launch --focus` and `worktree create --agent --activate` left a
chat launch unselected: main marked the chat active only in its tab listing,
which the window follows solely on its own focus intent (#5435). Send the
existing focusEditorTab for that chat; when its tab is not listed yet, record
the focus intent so the listing selects it unless the user moved on.

Co-authored-by: Manuel Meurer <manuel@meurer.io>
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]: Split terminals not working on a remote server

2 participants