Skip to content

perf(browser): send one atomic mouseClick on the legacy remote pane - #15402

Closed
Jinwoo-H wants to merge 5 commits into
mainfrom
sta-4752-legacy-atomic-click
Closed

Jinwoo-H wants to merge 5 commits into
mainfrom
sta-4752-legacy-atomic-click

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​416 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​415
Prod 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​560 $\color{#cf222e}{\Huge{\mathbf{−}}}$​105 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​455

Adopts the atomic browser.mouseClick RPC on the desktop's legacy screenshot-streamed remote-browser pane, replacing the four serialized RPCs previously issued per click (mouseMove+mouseDown on pointerdown, mouseMove+mouseUp on pointerup). Mirrors the decision logic mobile already uses, with a method_not_found fallback to the legacy chain cached per environment for old hosts.

Also fixes two press-lifecycle hazards: a cancelled/incoherent press no longer strands a pressed button on the remote page, and clicks whose press/release buttons differ are dropped.

Notes:

  • Addresses the STA-4752 input-latency report for viewers on the legacy path (mobile/web/old hosts). The client-hosted path (STA-4150) is unaffected — it has no input forwarding.
  • Intentionally not part of the STA-4150 stack: it targets main's stream-remote/ pane layout, which the stack's lineage predates.
  • No wire changes: browser.mouseClick is a pre-existing host method already used by mobile clients.
  • Tests: 94 tests in stream-remote/ pass including new click-vs-drag decision coverage (non-vacuity verified by forcing the atomic path off); typecheck and changed-code gates clean.
  • Known follow-up (deliberate): press-and-hold no longer shows a held state remotely (the click lands at release); pointer released outside the frame drops the drag instead of stranding a stuck button — setPointerCapture on pointerdown would recover the drag and is left as a surgical follow-up.

Desktop's screenshot-streamed remote browser spent four serialized RPCs per
click (mouseMove+mouseDown on pointerdown, mouseMove+mouseUp on pointerup).
Mobile already prefers the atomic browser.mouseClick, which dispatches CDP
Input.dispatchMouseEvent directly instead of spawning agent-browser and cannot
visibly hover between press and release. Desktop now holds the press until the
release proves the pair is a plain click (same page/environment, same button,
no modifier, movement within jitter slop) and sends one mouseClick; drags,
modified clicks, and hosts that answer method_not_found still use the
move/down/(move)/up chain, and the unsupported answer is remembered per
environment so old hosts are not re-probed per click.

Wire: browser.mouseClick is an existing host method (already used by mobile),
so no new RPC, opcode, or published content. New client / old host is covered
by the method_not_found fallback; old client / new host is unchanged.

Right-click (context-menu eval), wheel, keyboard, and the client-hosted webview
pane are untouched. A cancelled press now sends nothing instead of leaving the
remote button pressed.
A second mouse button pressed before the first release would otherwise replay
mouseDown(press button) + mouseUp(release button) and strand the first button
down on the remote page. Middle click keeps the atomic path.
@coderabbitai

coderabbitai Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Remote browser input now tracks pointer presses and classifies simple clicks by target, button, modifiers, page, environment, and movement. Valid releases use atomic browser.mouseClick calls when supported. Unsupported methods use serialized mouse movement and button RPCs. Holds dispatch mouseDown after a delay and release safely during cancellation, lifecycle changes, or unmount. Pointer cancellation now propagates from the viewport. Tests cover classification, dispatch, holds, cleanup, mismatched releases, frame changes, middle clicks, and ignored right-button input.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 36.84% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description explains the implementation and testing, but it omits most required template sections, including ELI5, Visual Proof, Linked Issue, checklist, and author details. Complete the required template sections, add the issue link in the required format, provide visual proof or N/A with a reason, and complete the testing and checklist items.
✅ Passed checks (3 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly and concisely identifies the main change: using one atomic mouseClick RPC in the legacy remote pane.
✨ 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: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 23249ccc-6285-40b6-a4a6-08c03cf6a8af

📥 Commits

Reviewing files that changed from the base of the PR and between 4ec6bbf and e6d0338.

📒 Files selected for processing (8)
  • src/renderer/src/components/browser-pane/stream-remote/remote-browser-click-dispatch.ts
  • src/renderer/src/components/browser-pane/stream-remote/remote-browser-page-input-model.test.ts
  • src/renderer/src/components/browser-pane/stream-remote/remote-browser-page-input-model.ts
  • src/renderer/src/components/browser-pane/stream-remote/remote-browser-page-pane.tsx
  • src/renderer/src/components/browser-pane/stream-remote/remote-browser-page-viewport.tsx
  • src/renderer/src/components/browser-pane/stream-remote/remote-browser-stream-errors.ts
  • src/renderer/src/components/browser-pane/stream-remote/use-remote-browser-page-input.test.ts
  • src/renderer/src/components/browser-pane/stream-remote/use-remote-browser-page-input.ts

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

Comment on lines +111 to +114
const pendingPressRef = useRef<RemoteBrowserPressState | null>(null)
// Hosts predating browser.mouseClick answer method_not_found; remember per environment so the
// legacy chain is not re-probed on every click.
const mouseClickUnsupportedEnvironmentRef = useRef<string | null>(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.

🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win

Cache unsupported status for every environment.

The ref stores one environment ID. If two environments return method_not_found, the second ID replaces the first. Returning to the first environment then probes browser.mouseClick again.

Use useRef(new Set<string>()). Check has(target.environmentId) and add the environment after method_not_found. Add a test that alternates between two unsupported environments.

Also applies to: 224-228

Comment on lines +147 to +180
const handleRemotePointerDown = (event: React.PointerEvent<HTMLImageElement>): void => {
if (busy) {
return
}
const target = runtimeTarget()
const pageId = lifecycle.tokens.remotePage
const image = imageRef.current
const operationToken = pageId ? createRemoteOperationToken(pageId) : null
const point = getRemoteImagePoint(event)
const button = getRemoteBrowserMouseButton(event.button)
if (button === 'right') {
return
}
if (!target || !pageId || !image || !operationToken || !point || !button) {
if (!target || !pageId || !image || !point || !button) {
return
}
event.preventDefault()
image.focus()
setPaneNotice(null)
enqueueRemoteInput(async () => {
if (!isCurrentRemoteOperationToken(operationToken)) {
return
}
try {
const params = { worktree: runtimeWorktree, page: pageId }
await callRuntimeRpc(
target,
'browser.mouseMove',
{ ...params, x: point.x, y: point.y },
{ timeoutMs: 15_000, suppressFeatureInteraction: true }
)
await callRuntimeRpc(
target,
'browser.mouseDown',
{ ...params, button },
{ timeoutMs: 15_000, suppressFeatureInteraction: true }
)
} catch (error) {
if (isCurrentRemoteOperationToken(operationToken)) {
if (isRemoteBrowserPageMissingError(error)) {
closeMissingRemotePage(pageId)
return
}
setPaneNotice({
kind: 'consequence',
text: error instanceof Error ? error.message : 'Remote mouse input failed.'
})
}
}
})
pendingPressRef.current = {
environmentId: target.environmentId,
pageId,
button,
point,
modified: hasRemoteBrowserClickModifier(event)
}
}

const handleRemotePointerCancel = (): void => {
pendingPressRef.current = null
}

const handleRemotePointerUp = (event: React.PointerEvent<HTMLImageElement>): void => {
const press = pendingPressRef.current
pendingPressRef.current = 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

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

rg -n -C 4 'onPointerDown|onPointerUp|onPointerCancel|setPointerCapture|releasePointerCapture' \
  src/renderer/src/components/browser-pane/stream-remote

Repository: stablyai/orca

Length of output: 2720


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

file="src/renderer/src/components/browser-pane/stream-remote/use-remote-browser-page-input.ts"
wc -l "$file"
sed -n '1,280p' "$file"
printf '\n--- related tests and usages ---\n'
rg -n -C 5 'useRemoteBrowserPageInput|handleRemotePointer|pendingPressRef|remote-browser-page-viewport' \
  src/renderer/src --glob '*.{ts,tsx}'

Repository: stablyai/orca

Length of output: 50369


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

test_file="src/renderer/src/components/browser-pane/stream-remote/use-remote-browser-page-input.test.ts"
viewport_file="src/renderer/src/components/browser-pane/stream-remote/remote-browser-page-viewport.tsx"

sed -n '1,225p' "$test_file"
printf '\n--- viewport event wiring ---\n'
sed -n '90,120p' "$viewport_file"
printf '\n--- pointer identifiers and capture usage ---\n'
rg -n -C 3 'pointerId|setPointerCapture|releasePointerCapture|pendingPressRef' \
  src/renderer/src/components/browser-pane/stream-remote \
  --glob '*.{ts,tsx}'

Repository: stablyai/orca

Length of output: 11476


🌐 Web query:

Pointer Events specification pointer capture pointerup outside element implicit capture mouse pointerdown

💡 Result:

In the Pointer Events specification, pointer capture is a mechanism that allows all subsequent events for a specific pointer to be retargeted to a single element, regardless of the pointer's actual location [1][2]. Implicit pointer capture is a specific behavior primarily associated with direct manipulation devices (such as touchscreens) [1][3]. When a pointerdown event is dispatched on an element from a direct manipulation device, the user agent automatically sets pointer capture for that pointer to the target element [1][4]. This ensures the element continues to receive events (such as pointermove or pointerup) even if the pointer moves outside the element's boundaries during the interaction [1][2]. Key behaviors regarding this process include: 1. Target Consistency: While pointer capture is active, the capturing element serves as the target for all events associated with that pointer [1][5]. Normal hit testing is bypassed, and the events are dispatched as if the pointer is always over the capturing element [1][3]. 2. Suppression of Boundary Events: Because the pointer is considered to be over the capturing element for the duration of the capture, events like pointerover, pointerenter, pointerleave, and pointerout do not fire while capture is held [2][4]. 3. Release of Capture: Pointer capture is released automatically by the user agent when a pointerup or pointercancel event occurs [2][4]. It can also be released manually by calling the element.releasePointerCapture(pointerId) method [1][2]. When capture is released, the user agent dispatches a lostpointercapture event to the element that previously held the capture, and subsequent events return to using normal hit testing mechanisms [5][6]. While implicit capture is standard for direct manipulation devices (like touch), it does not apply to mouse input in the same way; for a mouse, pointer capture is typically only set explicitly by the developer via the element.setPointerCapture(pointerId) method [1][2][4].

Citations:


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

python3 - <<'PY'
from dataclasses import dataclass

`@dataclass`
class Event:
    kind: str
    hit_target: str
    pointer_id: int = 1

def dispatch(event, capture):
    return capture.get(event.pointer_id, event.hit_target)

def current_handler_sequence(capture_enabled):
    pending = False
    capture = {}
    delivered = []

    down = Event("pointerdown", "image")
    if dispatch(down, capture) == "image":
        pending = True
        if capture_enabled:
            capture[down.pointer_id] = "image"

    # A mouse release outside the image is not delivered without capture.
    up_outside = Event("pointerup", "outside")
    target = dispatch(up_outside, capture)
    if target == "image":
        delivered.append("pointerup")
        pending = False
        capture.pop(up_outside.pointer_id, None)

    # A later pointerup over the image can consume the stale press.
    later_up = Event("pointerup", "image")
    target = dispatch(later_up, capture)
    stale_press_consumed = pending and target == "image"
    return stale_press_consumed, delivered, capture

without_capture = current_handler_sequence(False)
with_capture = current_handler_sequence(True)

assert without_capture[0] is True
assert with_capture[0] is False
assert with_capture[1] == ["pointerup"]
print("without capture: stale press is consumed by a later image pointerup")
print("with capture: outside pointerup reaches the image and clears the press")
PY

Repository: stablyai/orca

Length of output: 290


Capture the pointer when recording the press. Call event.currentTarget.setPointerCapture(event.pointerId) after validation and release it during pointer-up cleanup. Otherwise, a mouse release outside the image leaves pendingPressRef set, and a later image release can dispatch the stale press. Add a regression test for release outside the frame.

@Jinwoo-H Jinwoo-H closed this Aug 19, 2026
@Jinwoo-H Jinwoo-H reopened this Aug 19, 2026
The host's browser.mouseClick dispatches Input.dispatchMouseEvent mousePressed +
mouseReleased and nothing else, so the atomic path applied no :hover before the
press hit-test. On a page that reveals or reflows a control on hover, mousedown
and mouseup then resolve to different elements and Chromium dispatches click on
their common ancestor, so the control never fires. The removed 4-RPC chain always
moved first, which is why this only regressed with the atomic path.

Fix client-side rather than in the host handler: mouseClick has shipped since
2026-05, so a current client talks to hosts that will never gain a host-side
move. Still 2 round trips instead of 4, on the same serialized input queue.

Also reuses the hold/release halves of the legacy chain as named helpers.
…ease

pointerdown only recorded state, so the remote page saw nothing until release and
then a press whose duration was ~0ms. Long-press affordances (context menus in
web apps, hold-to-repeat spinner/scroll arrows, drag-start handles) never fired,
and no :active feedback ever reached the screencast during a hold.

A press still held after 350ms now dispatches the legacy mouseMove+mouseDown; the
release only lifts the button. Quick presses keep the atomic click path.

Every way a hold can end without a usable release now lifts the button too:
pointercancel, an incoherent or busy release, a pane identity change (routed
through the same lifecycle reset that clears the pending wheel), and unmount.
The hold is skipped outright if the page/environment moved on while it was armed.

The press state machine moves to use-remote-browser-page-press.ts; the input hook
keeps the queue, the image-point mapping, and the keyboard path.
A press whose release never reached the <img> stayed in the ref indefinitely, and
the coherence check only compared environment/page/button against the current
target — so an unrelated later pointerup over the frame passed it and was replayed
as mouseMove(old point) + down + move + up: a drag on the remote page the user
never made, at coordinates the page may have scrolled away from.

Four bounds, in order of who catches what:
- setPointerCapture on the press, so a release outside the frame arrives at all
  (this also fixes drags that end just past the pane edge);
- pointerleave and blur on the image end the gesture when capture was refused;
- the pointer id must match on release, for touch/pen where ids differ;
- an undispatched press older than 5s is stale and is never replayed.

A press dropped by any of these still lifts the remote button if the hold already
put it down.

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

🧹 Nitpick comments (1)
src/renderer/src/components/browser-pane/stream-remote/remote-browser-click-dispatch.ts (1)

63-64: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Consider releasing the button when the fallback release fails.

sendRemoteBrowserPressHold puts the remote button down. If sendRemoteBrowserHeldRelease then rejects, no further browser.mouseUp is sent for that press. The caller handleRemotePointerUp only reports the error, so the remote button stays down and blocks later interaction on the page.

Add one best-effort retry of browser.mouseUp when the release fails, then rethrow the original error.

♻️ Proposed guard for a stranded remote button
   await sendRemoteBrowserPressHold({ target, params, press })
-  await sendRemoteBrowserHeldRelease({ target, params, press, release })
+  try {
+    await sendRemoteBrowserHeldRelease({ target, params, press, release })
+  } catch (error) {
+    // The button is down remotely; one retry keeps a failed release from stranding it.
+    await callRuntimeRpc(
+      target,
+      'browser.mouseUp',
+      { ...params, button: release.button },
+      CALL_OPTIONS
+    ).catch(() => {})
+    throw error
+  }
 }

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6978f840-9f40-4fdb-8081-99469fae86d3

📥 Commits

Reviewing files that changed from the base of the PR and between e6d0338 and 6ca95cf.

📒 Files selected for processing (7)
  • src/renderer/src/components/browser-pane/stream-remote/remote-browser-click-dispatch.ts
  • src/renderer/src/components/browser-pane/stream-remote/remote-browser-page-input-model.ts
  • src/renderer/src/components/browser-pane/stream-remote/remote-browser-page-pane.tsx
  • src/renderer/src/components/browser-pane/stream-remote/use-remote-browser-page-input.test.ts
  • src/renderer/src/components/browser-pane/stream-remote/use-remote-browser-page-input.ts
  • src/renderer/src/components/browser-pane/stream-remote/use-remote-browser-page-lifecycle.ts
  • src/renderer/src/components/browser-pane/stream-remote/use-remote-browser-page-press.ts

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

@nwparker

Copy link
Copy Markdown
Contributor

Closing: since client-hosted pages took over, this legacy server-hosted path is narrow, and losing press-and-hold feedback is a behaviour change.

@nwparker nwparker closed this Oct 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.

2 participants