Skip to content

fix(browser): stop the first browser command on a new Windows tab hanging until it fails - #24237

Merged
Jinwoo-H merged 3 commits into
mainfrom
sta-8934-browser-snapshot
Oct 1, 2026
Merged

Jinwoo-H merged 3 commits into
mainfrom
sta-8934-browser-snapshot

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

On Windows, the first browser command an agent ran on a new tab (snapshot, screenshot, and so on) hung for 30 seconds, then failed with "the Orca runtime closed the connection, restart Orca". The browser helper had already finished in a third of a second. A background process it started kept the helper's output pipe open, so Orca kept waiting for "end of output" until it gave up. Orca now takes the result as soon as the helper exits, so the command returns in about a second.

What Changed

Before: the first helper-backed browser command on a fresh tab failed after about 30 s with runtime_unavailable. That covered snapshot, screenshot, get, capture start, upload and others. It happened again after every 10 minutes of browser inactivity, when the helper's background daemon restarts. Retrying usually worked, and restarting Orca didn't help.
After: the command returns as soon as the helper finishes, in about 1–3 s on a real Windows machine.

Mechanism:

  • Orca runs the bundled agent-browser helper with Node's execFile, which returns only once the child's stdout/stderr pipes close.
  • On Windows, the helper's background daemon inherits those pipes. This is upstream Bug: [Windows] CLI hangs when PowerShell captures output after close-then-open sequence vercel-labs/agent-browser#1407, still open.
  • So even though the helper printed its result and exited in about 300 ms, execFile waited for the 90 s command timeout. The local RPC server's 30 s idle cutoff closed the CLI's connection first, and the CLI reported that as runtime_unavailable.
  • Fix: 500 ms after the helper exits, the bridge releases the pipes, so execFile returns with the full output and the real exit code (agent-browser-bridge-raw-process.ts). A helper that never exits is still bounded by the 90 s timeout.

Why

  • Treat the helper's exit as done: a background process that inherited a pipe shouldn't decide when a command is finished.
  • Output isn't lost: the 500 ms grace keeps output already in the pipe. The helper can't exit until its last write is in the pipe, so the rest is read when the exit is noticed.
    • Verified with 5 MB payloads, including with Orca's main loop frozen for 1–3 s right after the exit.
  • macOS/Linux: the pipes close together with the exit, so this has no effect there.
  • Not upgrading agent-browser (0.27 → 0.38): that wouldn't fix this; feat(source-control): full-row hover, tooltips, and staged discard-all #1407 still reproduces on 0.37.1. This workaround can be removed once upstream ships a fix.
  • Not changing the RPC server's 30 s idle cutoff (or classifying browser methods as long-polls, as fix(runtime): keep WSL browser CLI RPCs alive #18404 does): with this fix the commands finish far inside 30 s, so no timeout change is needed.
    • Whether the server should stop cutting off genuinely slow requests is a separate trade-off: those requests would succeed, but genuine hangs would fail later.
    • That change is on its own branch, sta-8934-rpc-idle-timeout, for a separate decision.

Linked Issue

Fixes #23911
Fixes #18093

Visual Proof

N/A: no UI change. This fixes CLI and browser-helper behaviour; timings are under Testing.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • New real-process test (agent-browser-bridge-raw-process.test.ts): a helper starts a detached child that inherits its pipes, writes 5 MB of JSON, and exits. The call must return promptly with the full payload. Without the fix it times out.

  • Results: pnpm test src/main/browser/ and the RPC transport suites: 1,914 passed. pnpm tc:node, oxlint and check:code-quality:changed are clean.

Windows, end to end on this PR's head (507f7609aaf: browser fix only, server's 30 s cutoff unchanged; native Windows, agent-browser 0.27.0, dev builds in isolated hidden instances; each command is the first on a freshly created tab unless marked):

Command Before (main) After, desktop app After, headless
snapshot 30.2 s, runtime_unavailable 1.4–1.6 s, works (4 tabs) 1.4 s, works (3 tabs)
screenshot 30.2 s, runtime_unavailable 1.7 s, works 1.7 s, works
exec "get title" – 1.3 s, works 1.3 s, works
cookie get – 1.3 s fresh, 0.4 s on a used tab 1.3 s fresh, 0.4 s on a used tab
snapshot after the helper's daemon idled out and restarted – 1.0 s, works –

The idle-restart row used a 60 s idle timeout instead of 10 min. The process list showed the old daemon exit and a new one start for that snapshot.

Notes

  • Separate, not fixed here: wait --text on a hidden page still fails at 30.2 s with runtime_unavailable, on used tabs as well as fresh ones. Underneath is agent-browser's own read timeout on a page that isn't rendering, which the server's 30 s cutoff turns into the misleading error.
  • Not verified: upload, sites other than example.com and github.com, and the packaged installer. Only dev builds were run. It also fails on tabs that aren't fresh, and the page reports visibilityState: "hidden", so it looks like a separate issue with hidden pages that aren't rendering.
  • SSH/remote and backwards compatibility: there's no wire or protocol change. The change is local to how Orca runs the helper process.
  • Supersedes fix(runtime): keep WSL browser CLI RPCs alive #18404.

… the connection"

On Windows, the first helper-backed browser command on a fresh tab (snapshot,
screenshot, wait, get, capture start, ...) produced nothing for 30 s and then
failed with runtime_unavailable and "Restart Orca", which never helped.

Two defects combined:

- The local RPC transport destroyed any connection that had written nothing
  for 30 s, including one still waiting on our reply. Only long-poll methods
  sent keepalives, so every slower unary RPC (browser helper commands allow
  90 s, emulator 180 s, skill share 10 min) was cut off and the CLI reported
  the close as a dead runtime. The idle timer is now suspended while a
  dispatch is in flight and re-armed when none remain; the client's own
  deadline bounds the wait. No wire change.

- On Windows, agent-browser's daemon inherits the helper's stdio pipes
  (vercel-labs/agent-browser#1407), so EOF never arrives and execFile waited
  for the 90 s timeout even though the helper had printed its result and
  exited in ~300 ms. The bridge now releases the pipes shortly after the
  helper exits, so the call settles with its full output. Every new tab and
  every daemon restart after the 10-minute idle timeout hit this.

Fixes #23911
Fixes #18093
@greptile-apps

greptile-apps Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 3/5

[Medium risk] Fixes browser process cleanup to handle lingering child processes.

The PR does not appear safe to merge while slow unary requests can still be closed at 30 seconds and large browser output can still be truncated.

Findings

  1. P1 Large output can be truncated ▶
  2. P2 Failed tests leave resources behind ▶

Summary

The PR adds a browser-helper pipe workaround and tests for output held open by a descendant process.

  • The recent changes remove the transport-side idle-timeout fix and its in-flight regression test, leaving slow unary RPCs subject to the 30-second cutoff.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[CLI sends unary RPC] --> B[Server dispatches request]
  B --> C{Response within 30 seconds?}
  C -- Yes --> D[CLI receives result]
  C -- No --> E[Socket idle timeout destroys connection]
  E --> F[CLI reports runtime_unavailable]
Loading

Reviews (3) · Last reviewed commit: "revert(runtime): move the RPC idle-timer..."

Comment on lines +101 to +105
child.once('exit', () => {
setTimeout(() => {
child.stdout?.destroy()
child.stderr?.destroy()
}, AGENT_BROWSER_EXIT_DRAIN_MS)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Large output can be truncated

If a helper exits after producing a large screenshot or PDF and its output is still draining 500 ms later, destroying the pipes discards unread bytes. The command then receives incomplete JSON and can fail with browser_error even though the helper succeeded. The 5 MB test covers a fast local drain, not this slower case.

Comment on lines +39 to +47
const stdout = await bridge['runAgentBrowserRaw']('orca-tab-raw', [
'-e',
HELPER_WITH_LINGERING_DAEMON
])
const output: { daemonPid: number; payload: string } = JSON.parse(stdout)
try {
expect(output.payload).toHaveLength(PAYLOAD_BYTES)
} finally {
process.kill(output.daemonPid)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Failed tests leave resources behind

The test starts a detached child, but the finally block is reached only if the raw call resolves and its output parses. If either fails, that child remains running until its 20-second timer expires. The temporary directory created for the test is also never removed, so repeated runs leave directories behind.

@coderabbitai

coderabbitai Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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

📝 Walkthrough

Walkthrough

The browser bridge now delays stdout and stderr destruction after a child process exits. Its tests use emitter-backed child-process fixtures and cover a large payload with inherited open pipes. The Unix-socket transport disables its idle timeout during in-flight dispatches and restores it after the last dispatch ends. New tests cover delayed replies and incomplete input lines.

Priority: ⬆️ High

Severity of issue fixed: Medium

Merge Risk: 🔵 Low · up to 07a5e

A localized test cleanup gap can leave an orphaned process after a failed assertion; fix it before merging.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 07a5e

The inspected access checks remain in place, and no new privilege or confirmed security vulnerability was established. However, a stalled operation now depends on the caller disconnecting to release its connection; that safeguard is not fully verified.

Retained concerns

  • Low · reliability · inferred: A non-keepalive request whose handler never settles no longer triggers the server's idle connection cleanup. If its caller remains connected, it can retain one of the 32 connection slots indefinitely. Multiple stalled callers could therefore block other local RPC users. This is a conditional failure-containment risk; universal caller-side disconnection on deadline expiry has not been verified.
Security review details

Security Blast Radius

  • inferred — The identified containment risk concerns shared connection capacity in one runtime instance. Reaching downstream handlers requires the runtime token; Unix connections also face owner-only socket permissions. The inspected changes do not establish broader tenant, service or environment exposure.

Trust Boundaries and Controls

  • observed — Both Unix sockets and Windows named pipes use the same local message handler and token-authentication gate before dispatch. Windows endpoint construction does not demonstrate equivalent OS-level protection to Unix mode 0600; effective pipe permissions remain outside the verified coverage.

Resilience and Maintainability Implications

  • inferred — Existing cleanup supports recovery through reply, disconnection or shutdown. Existing long-poll keepalives already permitted extended waits, so indefinite connection retention is not established as a new attacker capability. The unresolved regression is automatic reclamation of a stalled unary connection when its caller does not disconnect.

Hardening Proposals

  • proposed — Consider a server-owned, method-aware deadline or pending-request watchdog that accommodates legitimate long operations while bounding stalled connection retention independently of caller cooperation.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 11 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR addresses the linked connection-closure failures. For [#23911], UnixSocketTransport suspends the 30-second idle timeout during an in-flight request and restores it after the final request. Te…
Out of Scope Changes check ✅ Passed The production changes are limited to local RPC idle-timeout handling and browser-helper pipe release. The changed tests validate these behaviors. The shared fake-child helper supports the updated pro…
Title check ✅ Passed The title clearly identifies the primary change: preventing the first browser command on a new Windows tab from hanging and failing.
Description check ✅ Passed The description is mostly complete. It explains the user impact, mechanism, rationale, linked issues, testing, platform coverage, and unresolved scope. The AI Disclosure, Review, Agent skill upstream …
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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 critical issues — one minor stale-comment suggestion inline.

Reviewed changes — the two independent timeout fixes in 13aa5400cf, their new tests, and the test-harness change:

  • Pause the local RPC idle timer while a dispatch is in flight (unix-socket-transport.ts): the 30s per-connection idle timeout is disarmed via setTimeout(0) on dispatch and re-armed only once inflight drains, so 90s browser/emulator/skill-share/Linear requests are no longer destroyed at 30s. A connection that never sends a complete line is still closed at 30s, and there is no wire change.
  • Release helper stdio after the child exits (agent-browser-bridge-raw-process.ts): 500ms after exit, stdout/stderr are destroyed so execFile settles even when a Windows daemon inherits the pipes (vercel-labs/agent-browser#1407).
  • Test coverage: a new real-process test drives a 5MB payload behind a pipe-holding descendant; transport tests pin the timer pause/re-arm and the partial-line close; createFakeAgentBrowserChild makes the execFile fakes EventEmitters.

I ran the transport, raw-process, and tab-routing suites (24 passed). Both fixes are load-bearing: removing the stdio drain times the raw-process test out, and removing the pause/re-arm fails the in-flight-request test. I also confirmed against real Node v24 that setTimeout(0) disarms without removing the registered timeout callback and that re-arming fires it.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | 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.

Caution

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

⚠️ Outside diff range comments (1)

🟡 Minor · Record the daemon PID outside the JSON output. · agent-browser-bridge-raw-process.test.ts:43-52

src/main/browser/agent-browser-bridge-raw-process.test.ts:43-52
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Record the daemon PID outside the JSON output.

JSON.parse(stdout) runs before cleanup. If the output is malformed, the detached daemon remains alive for up to 20 seconds. Record the PID in a temporary file before writing JSON, then read that file in finally when parsing fails.

Do not add a broad ESRCH catch. The daemon's 20-second timer exceeds the test's 10-second timeout, so the normal cleanup path reaches a live daemon.

Suggested fix
-import { mkdtempSync, rmSync } from 'node:fs'
+import { mkdtempSync, readFileSync, rmSync } from 'node:fs'
...
 const { spawn } = require('node:child_process')
 const daemon = spawn(process.execPath, ['-e', 'setTimeout(() => {}, 20000)'], {
   stdio: 'inherit',
   detached: true
 })
 daemon.unref()
+require('node:fs').writeFileSync(process.env.ORCA_DAEMON_PID_FILE, String(daemon.pid))
 process.stdout.write(JSON.stringify({ daemonPid: daemon.pid, payload: 'x'.repeat(${PAYLOAD_BYTES}) }))
...
+    const daemonPidFile = join(userDataPath.current, 'daemon.pid')
     const stdout = await bridge['runAgentBrowserRaw']('orca-tab-raw', [
       '-e',
       HELPER_WITH_LINGERING_DAEMON
-    ])
-    const output: { daemonPid: number; payload: string } = JSON.parse(stdout)
+    ], { envOverrides: { ORCA_DAEMON_PID_FILE: daemonPidFile } })
+    let daemonPid: number | undefined
     try {
+      const output: { daemonPid: number; payload: string } = JSON.parse(stdout)
+      daemonPid = output.daemonPid
       expect(output.payload).toHaveLength(PAYLOAD_BYTES)
     } finally {
-      process.kill(output.daemonPid)
+      process.kill(daemonPid ?? Number(readFileSync(daemonPidFile, 'utf8')))
     }

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: cf36ba3f-ef3d-45b9-bece-a86768a51902

📥 Commits

Reviewing files that changed from the base of the PR and between 13aa540 and 07a5e54.

📒 Files selected for processing (2)
  • src/main/browser/agent-browser-bridge-raw-process.test.ts
  • src/main/runtime/rpc/unix-socket-transport.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/runtime/rpc/unix-socket-transport.ts

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

The browser fix alone resolves the ticket: with the pipe release, a fresh-tab
snapshot takes ~1.4 s, well under the 30 s idle window. Whether the server
should stop cutting off slow in-flight RPCs is a separate trade-off against
fail-fast on genuine hangs, now on sta-8934-rpc-idle-timeout.
@Jinwoo-H Jinwoo-H changed the title fix(browser): stop slow browser commands failing with "runtime closed the connection" fix(browser): stop the first browser command on a new Windows tab hanging until it fails Oct 1, 2026

@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 — the delta since the prior pullfrog review at 07a5e54:

  • Reverted the local RPC idle-timer fix (unix-socket-transport.ts and its tests). That change now lives on the separate sta-8934-rpc-idle-timeout branch, leaving this PR with only the browser-helper stdio-drain fix. src/main/runtime/rpc/** is back to base state and absent from the diff, so no partial revert or dangling references were left behind.

The remaining fix is unchanged from the previously reviewed 13aa5400cf and still stands on its own: releasing the helper's stdio 500ms after exit makes execFile settle in ~1s, well inside the 30s RPC idle cutoff the reverted commit was addressing. The prior pullfrog comment thread is resolved.

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

@Jinwoo-H
Jinwoo-H merged commit 1b0ee96 into main Oct 1, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant