Skip to content

fix(browser): focus owning split from guest input - #22271

Closed
KAPUIST wants to merge 10 commits into
stablyai:mainfrom
KAPUIST:fix/browser-split-focus
Closed

KAPUIST wants to merge 10 commits into
stablyai:mainfrom
KAPUIST:fix/browser-split-focus

Conversation

@KAPUIST

@KAPUIST KAPUIST commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Clicking inside a browser page now makes that split active, so Ctrl+Tab switches tabs in the split you clicked.

What Changed

Previously, clicking page content could leave another split active and send Ctrl+Tab there. The main process now forwards the registered browser page ID on mouse-down and before forwarding keyboard shortcuts. The renderer resolves that page's visible tab and owning split from current state.

Inactive workspaces, background tabs, automation-controlled pages, and mobile-driven pages cannot take desktop split focus through this subscription. Listeners are removed on cleanup. Regression tests cover event order, consecutive interactions, ignored pages, and cleanup.

Why

Browser page content runs in a separate Electron guest, so its clicks do not bubble into the surrounding pane. Window blur also misses transitions between guests. Observing guest input identifies the source directly and updates split ownership before shortcut handling.

Linked Issue

Fixes #22144

Visual Proof

Same macOS native-input sequence in both captures: focus B's address bar, click inside A's page, then press Ctrl+Tab. Each split starts on Tab 1.

Before: B incorrectly switches to Tab 2; A stays on Tab 1. This is a controlled reproduction with only the new ownership notification disabled in the built app, not a separate upstream build.

before.png

After: A switches to Tab 2; B stays on Tab 1. Captured from the committed fix.

after.png

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Agent-run verification on macOS with Node 24.21.0, including the review follow-up in c721efd837:

  • Four browser shortcut E2E specs: 14 passed with ORCA_BACKGROUND_LAUNCH=1, hidden windows, and a freshly rebuilt Electron E2E bundle. This covers split clicks/Ctrl+Tab, Find, navigation/reload/zoom/address-bar shortcuts, element selection, and floating-browser scope.
  • The guest-input regression now uses CDP mouse/key dispatch instead of sendInputEvent, avoiding its native-window-focus requirement. Existing debugger attachments are preserved. A temporary negative control that removed the production mouse observer failed at the first split-focus assertion, confirming the test exercises the production path.
  • pnpm typecheck: passed. The changed-code quality gate against 17ffbf3b31897b55078062f399510a1cd62205d3 passed with zero new findings. Commit hooks also passed.
  • pnpm build: desktop, relay, CLI, renderer, projected web, mobile web, and bundled-skill checks passed after installing mobile dependencies with its frozen lockfile. The final native computer helper step failed: Swift 6.4 built under .build/out/Products/Release, while the unchanged script expects per-triple .build/<triple>/release inputs for lipo.
  • pnpm lint: initially passed without mobile dependencies; after the required mobile install, its native-code-quality stage reports nine circular-import findings in unchanged mobile files. The full lint gate is not green.
  • Full pnpm test: 87,524 passed, 90 failed, 679 skipped, 1 expected failure; 9,268 files passed and 23 failed. The run exited 1 and also reported one worker error after I stopped a file-descriptor test worker blocked in lsof for over 12 minutes. A second stalled lsof probe was stopped as well. This was not a clean completed pass; remaining failures include real-shell/agent integration, host process inspection, and runtime tests.
  • Follow-up diagnosis: all 67 tests in eight account-home files passed after removing inherited CODEX_HOME, ORCA_CODEX_HOME, and ORCA_CODEX_LAUNCH_PREFLIGHT only from the child test environment. A cloud-import suite's 3 tests passed after installing the separate cloud workspace and building its relay-contract/postgres-schema packages. These reruns do not turn the original full run green.
  • Additional pnpm typecheck:e2e: failed with 220 diagnostics after dependency setup, none naming browser-split-shortcuts.spec.ts; this is separate from the passing standard pnpm typecheck command.

The original implementation's scoped main/preload/renderer tests passed previously (2,799 passed, 2 skipped). The earlier native mouse/keyboard check and screenshots are from 80a97e510447; they were agent-run, not human manual testing. No foreground/native-focus rerun was performed on the user's desktop.

Reviewer reproduction: open two browser splits with two tabs each, focus B's address bar, click page content in A, and press Ctrl+Tab. Only A should switch tabs. Repeat between browser splits and check that Find still opens in the intended pane.

AI Disclosure

OpenAI Codex (GPT-6) assisted with implementation and verification. Claude Opus 5 independently reviewed the full diff read-only.

Review

Opus 5 returned APPROVE with no blocking findings on the earlier implementation; its optional suggestion was to reduce duplicated test stubs. The latest main integration was self-reviewed and verified with the checks above; it has not had another Opus review.

Agent skill upstream boundary

  • Not applicable: no agent skill content changed.

Notes

macOS was exercised. Windows, Linux, and live SSH/mobile end-to-end behavior were not run locally. The change uses existing cross-platform Electron events, introduces no remote wire-format change, and does not require a Git worktree. Web clients expose a no-op subscription. While automation or mobile owns a page, this subscription deliberately ignores its interactions, including local clicks.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

The unchecked final item is intentional: full-repository lint/test and the final native build are not green locally; see the explicit results above.

@coderabbitai

coderabbitai Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 8cd4492f-2969-4a6b-a5dd-3516ef52cf7e

📥 Commits

Reviewing files that changed from the base of the PR and between 6a0d43d and c721efd.

📒 Files selected for processing (1)
  • tests/e2e/browser-split-shortcuts.spec.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/e2e/browser-split-shortcuts.spec.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

Browser guest mouse-down and key-down events now emit ui:browserGuestInteraction. The preload API validates page IDs and supports unsubscribe callbacks. BrowserPaneOverlayLayer uses these events to focus the owning group when worktree and page-state guards pass. Unit and end-to-end tests cover event forwarding, routing conditions, listener cleanup, and split-tab shortcuts.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to c721e

No actionable merge-blocking risk is established by the supplied evidence.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Issue #22144 requires a browser-content click to focus the owning split and route group-scoped shortcuts to that split. setupGuestShortcutForwarding sends ui:browserGuestInteraction with the brows…
Out of Scope Changes check ✅ Passed The production changes, preload subscription, web-client no-op adapter, mocks, retention census exception, and regression tests support the browser-guest focus behavior in issue #22144. The CDP input …
Docstring Coverage ✅ Passed Docstring coverage is 86.67% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 17 files.
Title check ✅ Passed The title clearly and concisely describes the primary change: focusing the split that owns browser guest input.
Description check ✅ Passed The description follows the required template and explains the user impact, implementation, rationale, linked issue, visual proof, testing, AI disclosure, compatibility considerations, and known non-g…

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.

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • Main-process input observation: setupGuestShortcutForwarding now reports guest ownership via a new before-mouse-event (mouseDown only) listener and on every before-input-event keyDown, emitting ui:browserGuestInteraction with the page id before shortcut forwarding. Listener is removed on cleanup.
  • Preload subscription: onBrowserGuestInteraction admits only a non-empty string payload and returns an exact removeListener unsubscribe; typed on UiCommandEventApi, no-op on the web build.
  • Renderer focus resolution: BrowserPaneOverlayLayer subscribes only while its worktree is active and, reading useAppStore.getState() at event time, focuses the owning group only when the worktree is active, the page is neither automation-visible nor mobile-driven, it maps to the group's active browser tab, and that group is not already focused.
  • Regression tests: new main/preload unit tests assert exact send sequences and payload admission; BrowserPaneOverlayLayer tests pin ignore rules, consecutive clicks, and subscription lifecycle; the e2e spec drives real Electron sendInputEvent into two served guests and asserts the focused split plus real page mousedown delivery, then that Ctrl+Tab lands on the clicked split.

I traced the full path end to end: registration passes browserPageId ?? legacyBrowserTabId, which the renderer's (tab.activePageId ?? tab.id) lookup matches for both shapes, and RecentTabSwitcher reads getState() fresh, so the interaction-before-shortcut ordering wins the race without a React re-render. Floating-panel guests carry the floating workspace worktree id and are excluded by the activeWorktreeId gate; offscreen guests never install this forwarding. No blocking or actionable concerns.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

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

Run ID: c179d235-c250-401a-a19b-304bfda10ab9

📥 Commits

Reviewing files that changed from the base of the PR and between 2da8dd4 and 6a0d43d.

📒 Files selected for processing (12)
  • src/main/browser/browser-guest-shortcut-forwarding.test.ts
  • src/main/browser/browser-manager-guest-shortcuts.test.ts
  • src/preload/api/ui-bridge-tab-and-browser-commands.ts
  • src/preload/api/ui-command-event-api.ts
  • src/renderer/src/components/browser-pane/assemble-chrome/BrowserPaneOverlayLayer.test.tsx
  • src/renderer/src/components/browser-pane/assemble-chrome/browser-deferred-lifecycle.test.tsx
  • src/renderer/src/components/browser-pane/host-guest/browser-guest-retention-site-census.test.ts
  • tests/e2e/browser-floating-shortcut-scope.spec.ts
  • tests/e2e/browser-split-grab-shortcut.spec.ts
  • tests/e2e/browser-split-navigation-shortcuts.spec.ts
  • tests/e2e/browser-split-shortcuts.spec.ts
  • tests/e2e/helpers/browser-split-fixture.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • Merged latest main and reconciled split-focus coverage: the branch absorbed main's BrowserPageCommandTarget signatures for the address-bar/reload/history callbacks (from #22340) and the shared tests/e2e/helpers/browser-split-fixture.ts; the spec now calls createBrowserSplit(page, { first, second }).
  • Added a remote-viewer regression test: BrowserPaneOverlayLayer.test.tsx now proves local split focus still fires while a remote viewer retains the page for painting, pinning that remote viewing is not a focus gate.
  • Classified input-ownership reads in the retention census: the overlay's isBrowserAutomationVisible/isBrowserPageMobileDriven reads are whitelisted as non-retention per file and symbol, while the file stays a RETENTION_SITES consumer of useBrowserGuestPaintRetention.
  • Stubbed the new subscription in the deferred-lifecycle harness: browser-deferred-lifecycle.test.tsx gains a ui.onBrowserGuestInteraction no-op so the overlay effect can mount.
  • Pinned English in four browser shortcut E2E specs: uiLanguage: 'en' in beforeEach makes the English-label selectors deterministic across hosts.

The production path is unchanged since the reviewed 2da8dd4; the delta is the main merge and test reconciliation only. I ran the seven touched unit-test files in the merged state (88 passed).

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • Guest-input E2E now dispatches over CDP: the split-focus regression in tests/e2e/browser-split-shortcuts.spec.ts attaches to each guest's own debugger and sends Input.dispatchMouseEvent (press/release) and Input.dispatchKeyEvent (raw Ctrl+Tab) instead of sendInputEvent, so it no longer depends on the containing BrowserWindow being shown — the concern that prompted this change (headless ORCA_E2E_HEADLESS=1 suppressing native focus).
  • Preserves pre-existing debugger attachments: the helper attaches only when debugger.isAttached() is false and detaches only an attachment it created, so automation/screencast sessions on the same guest are left intact and the repo's hidden-window launch policy is respected.

No production code changed in this delta; the previously reviewed main/preload/renderer path is untouched.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@nwparker

Copy link
Copy Markdown
Contributor

Thanks for the PR! Main already does this through #31859 (1b0e56e). browser-guest-mouse-press.ts sends ui:browserPagePointerDown when a guest page gets a mouseDown. BrowserPaneOverlayLayer then resolves the page's owning tab and calls focusOwningGroup, so #22144 is closed. Closing — please reopen if there's a remaining case main doesn't cover.

@nwparker nwparker closed this Oct 27, 2026
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]: Clicking inside browser page content does not focus its owning split, so Ctrl+Tab targets the previously focused group

2 participants