Skip to content

perf(browser): bump agent-browser to 0.27.3 to drop its per-command settle sleep - #27192

Closed
outof-place wants to merge 1 commit into
stablyai:mainfrom
outof-place:perf/agent-browser-warm-cli
Closed

outof-place wants to merge 1 commit into
stablyai:mainfrom
outof-place:perf/agent-browser-warm-cli

Conversation

@outof-place

Copy link
Copy Markdown
Contributor

ELI5

Most browser commands an agent sends to Orca (snapshot, click, fill, screenshot...) went through a helper program that paused for 150 ms before every command. A newer patch release of that helper removes the pause, so these commands now come back in about 5–40 ms instead of 160–480 ms. Removing the pause also exposed a small race in how Orca resets a helper session, and this PR fixes that too.

What Changed

  • agent-browser 0.27.0 → 0.27.3. The range moves from ~0.27.0 to ~0.27.3 and the lockfile follows. This is the same minor line. 0.27.2 removed the unconditional 150 ms thread::sleep in ensure_daemon() that every warm CLI call paid (Fix agent-facing reliability bugs and cut warm command latency to ~1ms vercel-labs/agent-browser#1432).
  • Stale-session reset waits for the closing daemon (closeStaleAgentBrowserSession in agent-browser-bridge-execution.ts).
    • Before: Orca ran agent-browser --session <name> close and continued as soon as the CLI exited.
    • Now: after a successful close it also waits until that daemon's <session>.pid file is gone. waitForAgentBrowserSessionExit in agent-browser-session-reset.ts polls every 25 ms and resolves the socket directory the way agent-browser's get_socket_dir() does.
    • The wait shares the reset's existing 3 s deadline. If the daemon is still alive at the deadline, the reset fails closed with the same browser_owner_unavailable error as a close that never returns.

What users see: agent browser automation gets faster per command, as shown under Trade-offs. Nothing else changes.

Why

  • Why the bump is safe to take now. The sleep was agent-browser's guard against a daemon that is shutting down right after the liveness check. 0.27.2 replaced it with a respawn-and-retry when the socket turns out to be unreachable.
  • What the old sleep was hiding. Orca's reset path (Windows, or an inherited AGENT_BROWSER_SOCKET_DIR) runs close on a name that may have no daemon yet.
    • That close spawns a daemon, which lingers for its shutdown delay.
    • With 0.27.3, the very next command can reach that live-but-dying daemon instead of a fresh one wired to Orca's CDP proxy.
    • tests/e2e/browser-embedded-owner-routing.spec.ts catches exactly this: on 0.27.3 without the fix, the snapshot returns about:blank, "(empty page)", and the spec fails 2 of 2 runs.
  • Why wait on the pid file. The daemon removes its .pid (with .sock, .version and .stream) when it exits, on every platform. That makes it the one signal that means "that daemon is gone".
  • Alternatives considered:
    • Stay on 0.27.0. Every agent-browser command keeps paying 150 ms.
    • Jump to the latest release (0.39). It changes far more than the warm-call path. That deserves its own review, separate from a latency fix.
    • A fixed sleep after close. That re-adds a guessed delay to every reset, and it is still a guess.
    • close --all. It acts only on daemons that already exist and never spawns one. But it closes every session in the socket directory, and an inherited directory can be shared with another profile.

Linked Issue

Fixes #27191

Visual Proof

N/A. This is a latency and dependency change with no UI. The measurements below cover the behaviour.

Trade-offs

Setup. macOS 27, Apple M4 Max, Node 24.20.0, on a shared machine with load average 8–20.

  • The driver is a throwaway spec on Orca's own headless e2e fixture, not part of this PR. It serves a local test page, opens it in a browser tab and calls each runtime method 8 times.
  • Same build both ways: only node_modules/agent-browser/bin/agent-browser-darwin-arm64 was swapped between versions.
  • Figures are medians of the 8 calls, from 2 runs per version. The same driver checked that the clicks and fills landed: 8 clicks counted and the final input value matched, on both versions.

A. Merge risk and mitigations

  • Behaviour changes inside 0.27.1–0.27.3, from the upstream changelog. Clicks scroll off-viewport elements into view and detect click interception by overlays before dispatching input. JavaScript dialogs are handled promptly. wait honours its documented 25 s default and --timeout. type parses --clear and --delay instead of typing them. find label matches aria-label and aria-labelledby. The rest is Windows ARM64 install fallback and Linux release builds pinned to glibc 2.28, which is below Orca's 2.31 floor.
  • Most visible of these: a click on an element covered by an overlay may now report interception instead of clicking the overlay.
  • Coverage: every browser unit suite (src/main/browser, src/main/runtime/orca-runtime-browser*: 219 files, 1975 passed, 2 skipped) and the four browser e2e specs that drive agent-browser and pointer input (13 passed; the owner-routing spec 3 more times with --repeat-each=3).
  • The reset change runs only on the reset path (Windows, inherited socket directories, or a reused session name whose socket still exists). When the pid file is already gone it adds no wait.

B. User-facing trade-offs, both directions

Command (runtime round trip, p50) 0.27.0 0.27.3
browser.snapshot 166 ms 11–12 ms
browser.click 167–171 ms 11–16 ms
browser.hover 163 ms 9–11 ms
browser.focus 161 ms 5–6 ms
browser.fill (3 agent-browser calls) 480 ms 14–15 ms
browser.get title 160–162 ms 5 ms
browser.screenshot 193–195 ms 38 ms
first command of a session, reset path (inherited socket dir, 1 run each) 405 ms 354 ms
first command of a session, owned socket dir 126–134 ms 127–137 ms
  • Latency drops by about 150 ms per agent-browser call. goto, eval and pointer RPCs don't use agent-browser and are unchanged (goto 14–16 ms both ways).
  • CPU and memory: no new process, timer or buffer. The reset wait is a 25 ms existsSync poll that only runs until the closing daemon exits.
  • Bare CLI against a running daemon (no browser): 162–173 ms on 0.27.0, 11–13 ms on 0.27.3.

C. Maintenance cost

  • One dependency line and its lockfile entry.
  • About 40 production lines including comments: one exported wait helper, plus one .then in the reset callback that reuses the reset's existing deadline and error.
  • Tests: the wait helper (directory resolution, waiting, deadline, unsafe names) and two bridge tests (the first command runs only after the pid file is gone; the reset fails closed when the daemon never exits).

Verdict: free win. About 150 ms comes off every agent-browser-backed command, with no CPU or memory cost. The one race the old sleep covered is now closed explicitly.

Testing

Ran locally on the final branch:

  • pnpm test src/main/browser src/main/runtime/orca-runtime-browser --maxWorkers=4: 219 files; 1975 passed, 2 skipped.
  • A fresh e2e build, then tests/e2e/browser-embedded-owner-routing.spec.ts, browser-pointer-input-dispatch.spec.ts, browser-tab.spec.ts and browser-fedcm-fallback.spec.ts (--project electron-headless --workers=2, with ORCA_BACKGROUND_LAUNCH=1): 13 passed. On 0.27.3 without the reset fix, browser-embedded-owner-routing failed 2 of 2 runs.
  • pnpm run tc:node
  • ORCA_CODE_QUALITY_BASE=upstream/main pnpm run check:code-quality:changed
  • pnpm run check:max-lines-ratchet

Not run locally: Windows and Linux, the full pnpm test and pnpm lint, and packaging. Windows takes the reset path on every new session, so its CI matters most. Its pid-file location comes from the same get_socket_dir() rule the helper mirrors.

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

AI Disclosure

Implemented with Claude Opus 5.5 via Claude Code: diagnosis, code, tests and measurements. A human (outof-place) directed the work.

Review

Start with waitForAgentBrowserSessionExit in agent-browser-session-reset.ts, then its single call site in closeStaleAgentBrowserSession.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Security: no change. The reset still fails closed instead of reusing a daemon it could not verify.
  • Cross-platform: the bump ships new binaries for every platform. The reset helper uses the same directory rule on every OS.
  • SSH and remote: remote hosts that run agent-browser get the same per-command saving. orcad's external-Chromium sessions don't use this reset path.
  • Mobile: no change.
  • Backward compatibility: no wire change. A daemon left running by an older agent-browser is replaced on its version mismatch, as before.
  • Related, not fixed here: on an idle session name, agent-browser close itself auto-launches a local browser before closing it. This happens on both versions; I saw it with a stub AGENT_BROWSER_EXECUTABLE_PATH. That is wasted work on the reset path and worth a separate issue.

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). Only the commands listed under Testing ran locally; the rest is left to CI.

🤖 Generated with Claude Code

…ettle sleep

agent-browser 0.27.0 sleeps 150 ms in ensure_daemon() on every warm CLI
call before reusing the daemon; 0.27.2 removed it (#1432). Every browser
command Orca routes through agent-browser (snapshot, click, fill, hover,
focus, get, screenshot, exec passthrough...) paid that sleep.

The sleep also hid a race in the stale-session reset: `close` on an idle
session name spawns a daemon that lingers for its shutdown delay, and
without the sleep the next command can reach that daemon and run against
its own browser instead of Orca's page. The reset now waits for the
closing daemon's pid file to disappear (bounded by the existing 3 s reset
timeout, failing closed like a close that never returns).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

Walkthrough

The agent-browser dependency requirement changes to ~0.27.3. The stale-session reset resolves the session socket directory and polls its PID file after a successful close command. It continues to the next browser command after confirming that the session exited. If the session does not exit by the deadline, the reset rejects with browser_owner_unavailable. Tests cover directory resolution, polling, and reset outcomes.


Priority: ⬆️ High

Severity of issue fixed: Medium

Merge Risk: 🔵 Low · up to e154b

The dependency update and the stale-session exit wait look sound on supported paths. The only remaining concern is test portability: the two new lifecycle tests hard-code POSIX paths and would fail on Windows. Normalizing those paths is a small follow-up.

Pre-merge checks | Passed 4 | Inconclusive 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Linked Issues check Inconclusive Issue #27191 requires removal of the 150 ms agent-browser delay and handling the stale-session race. The PR changes package.json to ~0.27.3, adds PID-file polling with the existing reset deadline,… Provide reviewable evidence that the installation resolves agent-browser to 0.27.3 or a later 0.27.x release, such as an included lockfile entry or CI dependency-resolution output.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly identifies the dependency update and its primary performance benefit. It is concise and directly related to the pull request changes.
Description check Passed The description is detailed and covers the required sections, including the user impact, implementation, rationale, linked issue, testing, AI disclosure, compatibility considerations, and checklist st…
Out of Scope Changes check Passed The reported changes are limited to the agent-browser dependency range, stale-session exit verification, and tests for that behavior. These changes directly support issue #27191. No unrelated implemen…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 4 files. (1 skipped: 1 …

Full details: Linked Issues check

Explanation

Issue #27191 requires removal of the 150 ms agent-browser delay and handling the stale-session race. The PR changes package.json to ~0.27.3, adds PID-file polling with the existing reset deadline, and adds focused lifecycle and session-reset tests. The reviewed summary does not verify the resolved dependency version because pnpm-lock.yaml is excluded from review. Therefore, the required 0.27.3 dependency resolution cannot be established.


  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d1396c21-40da-4a78-9678-d0393d200ea1
📥 Commits

Reviewing files that changed from the base of the PR and between cb69d52 and e154b5e.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (5)
  • package.json
  • src/main/browser/agent-browser-bridge-execution.ts
  • src/main/browser/agent-browser-bridge-session-lifecycle.test.ts
  • src/main/browser/agent-browser-session-reset.test.ts
  • src/main/browser/agent-browser-session-reset.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

Comment on lines +161 to +162
existsSyncMock.mockImplementation(
(...args: unknown[]) => args[0] === '/tmp/orca-ab-test/orca-tab-tab-1.pid' && ++pidChecks <= 2

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

Use platform-normalized PID paths in both mocks. On Windows, join() passes a backslash-normalized path to existsSync, so neither forward-slash comparison matches. The success test fails its ordering assertion, and the timeout test resolves instead of rejecting. (nodejs.org)

  • src/main/browser/agent-browser-bridge-session-lifecycle.test.ts#L161-L162: compare with join('/tmp/orca-ab-test', 'orca-tab-tab-1.pid').
  • src/main/browser/agent-browser-bridge-session-lifecycle.test.ts#L187-L188: use the same normalized comparison.
📍 Affects 1 file
  • src/main/browser/agent-browser-bridge-session-lifecycle.test.ts#L161-L162 (this comment)
  • src/main/browser/agent-browser-bridge-session-lifecycle.test.ts#L187-L188

@nwparker

Copy link
Copy Markdown
Contributor

The roughly 150 ms per-command saving is real, but closing this upgrade as not planned after an independent real-binary transition test. A surviving 0.27.0 remote browser with two tabs and an unsaved draft was restarted by the first 0.27.3 command: the active tab changed, the input became empty and live JavaScript state was lost. Reset/scrollbar fixes do not preserve that update transition. This fails our zero-negative-user-facing-trade-off requirement; we will not add a dual-version or native fork subsystem to obtain it.

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

Every agent-browser-backed browser command waits an extra 150 ms (agent-browser 0.27.0 settle sleep)

2 participants