Repository navigation
fix(browser): stop the first browser command on a new Windows tab hanging until it fails - #24237
Conversation
… 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
|
| child.once('exit', () => { | ||
| setTimeout(() => { | ||
| child.stdout?.destroy() | ||
| child.stderr?.destroy() | ||
| }, AGENT_BROWSER_EXIT_DRAIN_MS) |
There was a problem hiding this comment.
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.
| 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) |
There was a problem hiding this comment.
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.
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 📝 WalkthroughWalkthroughThe 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 A localized test cleanup gap can leave an orphaned process after a failed assertion; fix it before merging. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to 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
Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
ℹ️ 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 viasetTimeout(0)on dispatch and re-armed only onceinflightdrains, 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 afterexit,stdout/stderrare destroyed soexecFilesettles 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;
createFakeAgentBrowserChildmakes theexecFilefakes 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.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟡 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 winRecord 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 infinallywhen parsing fails.Do not add a broad
ESRCHcatch. 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
📒 Files selected for processing (2)
src/main/browser/agent-browser-bridge-raw-process.test.tssrc/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.
There was a problem hiding this comment.
✅ 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.tsand its tests). That change now lives on the separatesta-8934-rpc-idle-timeoutbranch, 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.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

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 coveredsnapshot,screenshot,get,capture start,uploadand 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:
agent-browserhelper with Node'sexecFile, which returns only once the child's stdout/stderr pipes close.execFilewaited 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 asruntime_unavailable.execFilereturns 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
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,oxlintandcheck:code-quality:changedare 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):snapshotruntime_unavailablescreenshotruntime_unavailableexec "get title"cookie getsnapshotafter the helper's daemon idled out and restartedThe 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
wait --texton a hidden page still fails at 30.2 s withruntime_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.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 reportsvisibilityState: "hidden", so it looks like a separate issue with hidden pages that aren't rendering.