Skip to content

perf(browser): dispatch coordinate pointer input in process instead of one subprocess per event - #15309

Closed
atreidesend wants to merge 2 commits into
stablyai:mainfrom
atreidesend:perf/remote-browser-pointer-input
Closed

atreidesend wants to merge 2 commits into
stablyai:mainfrom
atreidesend:perf/remote-browser-pointer-input

Conversation

@atreidesend

@atreidesend atreidesend commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Moving the mouse in the remote browser pane launches a whole new process on the host for every wiggle, click and scroll tick -- about 160ms each, and a click is four of them. This makes the runtime deliver mouse events the same fast way it already delivers taps from the mobile app: directly, in process. A click drops from ~640ms to ~1.5ms, and double-click works through the pane for the first time.

What Changed

mouseMove / mouseDown / mouseUp / mouseWheel no longer go through execAgentBrowser (an execFile of the agent-browser helper per event) -- they dispatch Input.dispatchMouseEvent over the electron debugger, the way mouseClick has done since it was added for mobile. A new cdp-pointer-input.ts module tracks per-tab pointer state (position, held-buttons mask, click cadence) in a WeakMap keyed by the WebContents, so state dies with the tab.

Element-ref commands (click --element, snapshot, ...) are untouched, they genuinely need the helper's snapshot state.

Two deliberate design points worth flagging up front:

  • dispatch doesn't await the renderer's ack by default. The ack for mouse events is frame-bound: ~16ms on a tab someone is watching, ~1s per event on a tab whose renderer idles at 1Hz b/c nothing subscribes to its screencast -- and at 1Hz two clicks can never land inside the 500ms double-click interval, so awaiting costs correctness as well as latency. Events are still written to the debugger in call order, a late dispatch failure comes back as a browser_error on the caller's next pointer event instead of being swallowed, and the debugger lease is held until the in-flight command settles. ORCA_BROWSER_INPUT_AWAIT_ACK=1 restores the waiting behavior if you'd rather have the strict semantics.
  • clickCount is tracked (1 -> 2 -> 3 -> 1 for repeated presses within 500ms / 2px), where the helper hardcoded clickCount: 1. Double-click through the remote pane -- select a word, open a file from a list -- was previously impossible to express at all.

Why

Measured on the same host, same dev build, main vs this branch (loopback, p50, n=25):

main this PR
browser.mouseMove 160 ms 0.5 ms
browser.mouseWheel 160 ms 0.4 ms
one scroll notch (move+wheel, serialized) 320 ms 0.7 ms
one click (move+down+move+up -- what BrowserPane sends) 637 ms 1.5 ms

browser.eval measures 0.4-0.5ms on the same socket, so the transport was never the cost. Both ends serialize input (enqueueRemoteInput on the client, the per-session command queue on the server), which means the per-event cost multiplies into every gesture -- this is most of "the remote pane feels laggy". The helper was only translating these events into Input.dispatchMouseEvent calls of its own, so no behavior actually depended on the subprocess.

Callouts

Some deltas from the helper path, all deliberate, listed so nothing is surprising in review:

  • result shapes are byte-identical to the shipped helper's (checked by running the pinned agent-browser 0.27 binary): {moved:true}, {pressed:true}, {released:true}, {scrolled:true,deltaX,deltaY}. No wire or schema change, so mixed-version pairs just get a faster server (checked against docs/reference/remote-wire-compatibility.md -- nothing there applies).
  • success now means 'dispatched', not 'renderer processed it' (see above). In practice a read through the same pipeline lands after the input -- measured 20/20 clicks and 10/10 typed strings visible to an immediately-following browser.eval, no sleep -- but that ordering is measured, not contractual.
  • wheel dispatches at the tracked pointer position. The helper dispatched wheel at (0,0) regardless of any preceding mouse move (the CLI never passes x/y), so inner scrollables under the cursor never scrolled and whatever sat at the top-left corner did. Both panes (desktop and mobile) send mouseMove before every wheel, so interactive scrolling gets strictly better; headless automation that relied on the (0,0) targeting would notice.
  • two clicks at the same point within 500ms now produce a real dblclick with detail: 2, as a physical mouse would. The old path physically couldn't produce sub-500ms pairs (4x160ms per click), so nothing existing can have depended on fast pairs staying detail: 1 -- but newly-fast CLI scripting that double-invokes a control in <500ms will now look like a double-click to the page, b/c it is one.
  • button: 'back' / 'forward' pass through as real X1/X2 presses with the right buttons-mask bits, as the helper dispatched them. (The element-click path's existing left-coercion is untouched.)
  • mouseUp with no button releases the held button; the helper always released left, which left a right-button press stuck forever. Both panes always pass the button, so only CLI/RPC callers see this.
  • non-finite coordinates/deltas are rejected up front (browser_error) -- an un-awaited dispatch would otherwise report success and park chromium's invalid-params error on a later event.
  • wc.focus() on mouseDown mirrors what mouseClick already does. The helper never focused anything, so relative to the old down/up path this widens the focus surface the same way every mobile tap already does -- flagging for coordination with fix(browser): restore host focus after synthetic mouse presses #10875/fix(browser): stop agent browser input from stealing the user's focus #11732 (agent-input focus stealing), which this PR neither fixes nor worsens beyond the established precedent.
  • when the automation-visibility feature swaps the pane's guest WebContents, pointer state resets with it -- equivalent to today, where that swap restarted the helper and dropped its mouse state. Both panes send a mouseMove before any down/up/wheel in the same serialized queue, which re-establishes position.

Linked Issue

Fixes #15308

Visual Proof

Before/after recordings attached here -- the same click / double-click / scroll sequence driven through the exact RPCs the pane sends, at human cadence, recorded from the screencast frames the pane receives. Before is current main, after is this branch: same 1680px scrolled, but before crawls and never fires dblclick; after is instant, fires dblclick, and selects the word.

before-pointer.mp4
after-pointer.mp4

Testing

  • pnpm exec vitest run --config config/vitest.config.ts src/main/browser/ -- the whole directory passes, including the new agent-browser-bridge-pointer-input.test.ts (13 tests: CDP payloads for move/down/up/wheel, position tracking, per-tab state isolation, clickCount escalation and reset, back/forward passthrough, non-finite rejection, deferred-failure surfacing, ack-await mode, lease release ordering, queue cleanup).
  • pnpm run typecheck, pnpm exec oxlint, pnpm run check:code-quality:changed, pnpm run check:max-lines-ratchet -- all clean.
  • Live verification on a headless linux serve host (source build of this branch, real E2EE pairing transport): a 24-check input-fidelity suite passes 24/24 -- click, double-click (fires dblclick and selects a word), right-click (contextmenu), drag-selection across a text span, plus the keyboard checks. The same suite on a main build of the same base fails both double-click checks. Latency numbers above were taken on the same rig, main vs branch.
  • Platforms actually tested: linux headless serve. I'd expect macOS/Windows impact to be limited to the dispatch mechanism those platforms already use for mouseClick on every mobile tap, but I haven't run them myself.
  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

AI Disclosure

Built with Claude Code (Fable 5). It started as a hand-validated patch prototype running against a remote runtime I use daily; all the numbers here come from scripted probes against real instances (including the main-branch baseline, same host and build), and claims about the helper's current behavior were re-checked by running the pinned agent-browser 0.27 binary directly. I reviewed the diff before submitting.

Notes

Security: no new inputs parsed beyond a finiteness check, RPC surface and schemas unchanged. Cross-platform: the electron debugger dispatch path is the same one mouseClick uses on all three platforms. Remote/SSH: no wire change, server-side speedup only. Performance: hot path loses a subprocess spawn per event, nothing new beyond a small per-tab state object.

Review

Adversarially reviewed with independent agent passes before submission: correctness (races, debugger-lease lifetimes, event ordering, per-tab state isolation), cross-platform (the dispatch path is the one mouseClick already uses on macOS/Windows/Linux; no platform-conditional code added), remote/SSH and mixed versions (no wire or schema change; result shapes byte-compared against the shipped helper binary), agent/integration compatibility (element-ref commands untouched; helper fallback preserved), performance (removes a subprocess spawn per event from the hot path), and basic security (no new parsed inputs, no new surface). Findings that survived review are disclosed in Callouts above.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • 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)

…f one subprocess per event

mouseMove, mouseDown, mouseUp and mouseWheel each spawned the agent-browser
helper per event, and the remote pane serializes its events, so one click cost
four spawns and a scroll notch two. The helper was only translating these into
Input.dispatchMouseEvent calls of its own -- no snapshot or element-ref state
involved -- so we can dispatch over the electron debugger directly, the way
mouseClick already does. Measured on the same host and build, main vs this
change (loopback p50, n=25): mouseMove 160ms -> 0.5ms, scroll notch 320ms ->
0.7ms, click 637ms -> 1.5ms.

Dispatch doesn't await the renderer's ack by default, b/c the ack is
frame-bound: ~16ms on a watched tab, ~1s per event on a tab with no screencast
subscriber, and at 1Hz two clicks can never land inside the 500ms double-click
interval -- so awaiting costs correctness as well as latency. A late failure is
reported on the caller's next pointer event instead of being swallowed, the
debugger lease is held until the in-flight command settles, and
ORCA_BROWSER_INPUT_AWAIT_ACK=1 restores the waiting behavior.

Pointer state is tracked per WebContents: position carries from mouseMove into
down/up/wheel, the buttons mask accumulates across held buttons as the helper
did, and repeated presses at the same point inside 500ms now report clickCount
2/3 (the helper hardcoded 1, which made dblclick through the remote pane
impossible to express). Wheel dispatches at the tracked pointer position
instead of the (0,0) the helper used, so inner scrollables under the cursor
actually scroll. Back/forward buttons pass through as real X1/X2 presses, and
non-finite coordinates are rejected up front -- an un-awaited dispatch would
otherwise report success and park chromium's invalid-params error on a later
event.

Result shapes match the helper byte for byte: {moved:true}, {pressed:true},
{released:true}, {scrolled:true,deltaX,deltaY}. Element-ref commands still use
the helper.

Co-Authored-By: Claude Fable 5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Pointer commands now dispatch through Electron CDP instead of agent-browser subprocesses. The implementation tracks pointer state per tab, normalizes buttons, counts clicks, validates values, and dispatches movement, button, and wheel events. It supports optional renderer acknowledgements and coordinates debugger-lease release with pending dispatches. Tests cover command behavior, validation, error handling, tab isolation, lease timing, and queue cleanup.

Merge Risk: 🟡 Moderate · up to b97a7

The PR substantially speeds pointer input, but deferred event dispatch can let an older failed send overwrite newer pointer state, causing later clicks, drags, or scrolling to target incorrectly. Merge should wait for this state-management issue to be fixed or explicitly accepted by the owner.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: in-process coordinate pointer dispatch instead of per-event subprocesses.
Description check ✅ Passed The description explains the change, rationale, testing, compatibility considerations, visual proof, and linked issue in substantial detail.
Linked Issues check ✅ Passed The implementation satisfies issue #15308 by removing pointer subprocess overhead, preserving element-reference handling, and improving pointer fidelity.
Out of Scope Changes check ✅ Passed The code and tests remain focused on coordinate pointer dispatch, pointer state, failure handling, and related performance and fidelity behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 02513e7c-965a-4d39-982f-e418538041af

📥 Commits

Reviewing files that changed from the base of the PR and between 2f0f9a8 and 0a5319c.

📒 Files selected for processing (4)
  • src/main/browser/agent-browser-bridge-command-transport.test.ts
  • src/main/browser/agent-browser-bridge-pointer-input.test.ts
  • src/main/browser/agent-browser-bridge.ts
  • src/main/browser/cdp-pointer-input.ts

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

Comment thread src/main/browser/cdp-pointer-input.ts Resolved
…ailed dispatches

Two state-tracking gaps in the in-process pointer path:

Releasing one of several held buttons set the active button to 'none',
so a later unqualified mouseUp defaulted to left and could never
release the still-held button. The active button is now derived from
the remaining mask.

And b/c callers mutate pointer state before dispatching, a dispatch
that failed (in either ack mode) left the state claiming buttons that
were never pressed. Each dispatch now carries a pre-dispatch snapshot
and the failure paths restore it, so a retry after the surfaced error
starts from reality.

Co-Authored-By: Claude Fable 5 <[email protected]>

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/browser/cdp-pointer-input.ts (1)

155-188: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Serialize unacknowledged pointer dispatches per tab.

processQueue starts the next command when dispatchCdpPointerEvent returns, before the CDP promise settles. If an older send then rejects, its revert snapshot overwrites newer pointer state. Await each send before advancing the queue, or apply rollback only for the matching dispatch sequence. Add a deferred-send regression test.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6981ca22-5a21-47c8-a259-8196a1260678

📥 Commits

Reviewing files that changed from the base of the PR and between 0a5319c and b97a78d.

📒 Files selected for processing (3)
  • src/main/browser/agent-browser-bridge-pointer-input.test.ts
  • src/main/browser/agent-browser-bridge.ts
  • src/main/browser/cdp-pointer-input.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/browser/agent-browser-bridge.ts
  • src/main/browser/agent-browser-bridge-pointer-input.test.ts

Included review availability: Your plan includes up to 10 reviews per rolling hour; 7 remain after this review.

@nwparker

Copy link
Copy Markdown
Contributor

Superseded by #20593.

This PR was opened against a main that has since moved ~2000 commits; agent-browser-bridge.ts was split into a class chain, so this branch no longer applies. #20593 is the same change rebuilt on current main, following the conventions #15310 established for keyboard input.

Two claims in this PR's description did not survive re-verification and are corrected there:

  • The frame-bound-ack rationale for not awaiting the dispatch. Measured against browser.eval on the same socket and queue, an awaited mouseMove costs the same as an awaited eval — the dispatch adds ~0ms. perf(browser): dispatch coordinate pointer input in process instead of one subprocess per event #20593 awaits, and drops the deferred-failure machinery and the ORCA_BROWSER_INPUT_AWAIT_ACK escape hatch entirely.
  • "non-finite coordinates/deltas are rejected up front" as a like-for-like. Running the pinned 0.27 binary, mouse wheel NaN succeeded there and silently scrolled 100px. That is disclosed as a deliberate behavior change rather than parity.

The 6 reviews here are worth reading against #20593 — the review threads don't carry over.

@nwparker nwparker closed this Sep 14, 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.

Interactive input in the remote browser pane costs ~160ms per event -- every mouse/key event spawns a subprocess on the host

2 participants