Repository navigation
Keep embedded browser commands on the registered Orca target - #9633
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThe bridge now routes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/main/browser/agent-browser-bridge.ts (1)
1482-1485: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win
String(result.value)collapses object/array eval results to"[object Object]".With
returnByValue: true,result.valueis the actual JS value, so expressions returning objects/arrays stringify to"[object Object]"/"a,b"rather than a JSON representation. If the prioragent-browser evalpassthrough serialized structured results, this is a behavior regression for non-primitive returns. ConsiderJSON.stringifyfor non-primitive values.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 500a7d19-f61e-46b9-a4b6-1e16010552ac
📒 Files selected for processing (4)
src/main/browser/agent-browser-bridge.test.tssrc/main/browser/agent-browser-bridge.tssrc/main/runtime/orca-runtime-browser.tssrc/shared/runtime-types.ts
| await Promise.race([ | ||
| wc.loadURL(navigationUrl), | ||
| new Promise<never>((_resolve, reject) => { | ||
| navigationTimeout = setTimeout( | ||
| () => | ||
| reject( | ||
| new Error( | ||
| `Browser navigation timed out after ${EMBEDDED_NAVIGATION_TIMEOUT_MS}ms` | ||
| ) | ||
| ), | ||
| EMBEDDED_NAVIGATION_TIMEOUT_MS | ||
| ) | ||
| navigationTimeout.unref?.() | ||
| }) | ||
| ]) | ||
| } catch (error) { | ||
| if (!this.getWebContents(target.webContentsId)) { | ||
| throw this.createPageUnavailableError(`orca-tab-${target.browserPageId}`) | ||
| } | ||
| throw new BrowserError( | ||
| 'browser_error', | ||
| `Failed to navigate browser page ${target.browserPageId}: ${error instanceof Error ? error.message : String(error)}` | ||
| ) | ||
| } finally { | ||
| if (navigationTimeout) { | ||
| clearTimeout(navigationTimeout) | ||
| } | ||
| } |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🌐 Web query:
Electron webContents loadURL promise rejects ERR_ABORTED redirect download
💡 Result:
The ERR_ABORTED (-3) error when using webContents.loadURL in Electron is often expected behavior rather than a bug, particularly when a navigation is interrupted by a redirect to a downloadable file or another page [1][2][3]. In Chromium, when a requested URL is identified as a download after headers are received, the initial navigation is aborted, which triggers this error [1]. To handle this, you should catch the error on the promise returned by loadURL and ignore it if the error code is ERR_ABORTED [2]. Example implementation: win.webContents.loadURL(url).catch((error) => { if (error.code === 'ERR_ABORTED') { return; // Ignore expected aborts during redirects or downloads } throw error; }); If the abort is caused by a download, Electron will trigger the will-download event on the session [4][5]. You can handle the download logic within that event listener in your main process [4]: win.webContents.session.on('will-download', (event, item, webContents) => { item.setSavePath('/path/to/save/file'); item.once('done', (event, state) => { if (state === 'completed') { console.log('Download successful'); } else { console.log(Download failed: ${state}); } }); }); If you are experiencing this error during redirects that are not intended to be downloads, ensure you are not triggering additional navigations (like history.pushState or location.hash changes) before the initial page has finished loading, as these can also cause the original load request to be aborted [3].
Citations:
- 1: ERR_ABORTED during download electron/electron#6054
- 2: loadUrl error "ERR_ABORTED (-3) error" can't be catched electron/electron#27574
- 3: loadURL / loadFile calls throw "ERR_ABORTED (-3) error" if location.hash or history.pushState called on the page before page loaded electron/electron#17526
- 4: https://electronjs.org/docs/latest/api/download-item
- 5: https://electronjs.org/docs/latest/api/web-contents
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Map the relevant file and inspect the navigation/reload implementations.
ast-grep outline src/main/browser/agent-browser-bridge.ts --view expanded >/tmp/outline.txt || true
printf '\n--- outline (filtered) ---\n'
sed -n '1,220p' /tmp/outline.txt | sed -n '/goto\|reload\|loadURL\|did-finish-load\|did-fail-load/p' || true
printf '\n--- surrounding lines 730-860 ---\n'
sed -n '730,860p' src/main/browser/agent-browser-bridge.ts
printf '\n--- surrounding lines 1260-1345 ---\n'
sed -n '1260,1345p' src/main/browser/agent-browser-bridge.ts
printf '\n--- search for loadURL usages and ERR_ABORTED handling ---\n'
rg -n "loadURL\\(|ERR_ABORTED|did-finish-load|did-fail-load|will-download|navigationTimeout|Promise\\.race" src/main/browser/agent-browser-bridge.tsRepository: stablyai/orca
Length of output: 9074
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '\n--- search for ERR_ABORTED handling across src ---\n'
rg -n "ERR_ABORTED|error\\.code === 'ERR_ABORTED'|code === 'ERR_ABORTED'" src || true
printf '\n--- search for Promise.race patterns with timeouts in src/main/browser/agent-browser-bridge.ts ---\n'
rg -n "Promise\\.race\\(|setTimeout\\(|unref\\(\\)?" src/main/browser/agent-browser-bridge.ts || true
printf '\n--- inspect any other navigation helpers in this file ---\n'
rg -n "did-finish-load|did-fail-load|loadURL\\(|reload\\(|goBack\\(|goForward\\(" src/main/browser/agent-browser-bridge.ts || trueRepository: stablyai/orca
Length of output: 1762
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '\n--- browser-manager.ts around ERR_ABORTED handling ---\n'
sed -n '780,880p' src/main/browser/browser-manager.ts
printf '\n--- BrowserPane.tsx around the redirect/cancel handling comment ---\n'
sed -n '3870,3925p' src/renderer/src/components/browser-pane/BrowserPane.tsx
printf '\n--- promise.race / unhandled-rejection semantics probe ---\n'
node - <<'JS'
process.on('unhandledRejection', (reason) => {
console.log('UNHANDLED', reason && reason.message ? reason.message : String(reason));
});
(async () => {
let rejectLate;
const slowReject = new Promise((_, reject) => {
rejectLate = reject;
});
const fast = Promise.resolve('ok');
const raced = Promise.race([fast, slowReject]);
const result = await raced;
console.log('race result:', result);
// Reject after race settled.
rejectLate(new Error('late failure'));
await new Promise((r) => setTimeout(r, 50));
console.log('done');
})();
JSRepository: stablyai/orca
Length of output: 6852
Handle ERR_ABORTED from loadURL() here
wc.loadURL() can reject on legitimate redirect/download navigations, which will currently be reported as browser_error. Ignore ERR_ABORTED explicitly or switch goto to the event-based pattern used by reload().
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tests/e2e/browser-embedded-owner-routing.spec.ts (1)
13-14: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a "why" comment for the shortened temp root.
shortTempRootisn't self-explanatory — the reason to avoidos.tmpdir()directly on macOS/Linux is that AF_UNIX socket paths are capped at ~104-108 bytes, and macOS's default tmpdir (/var/folders/.../T/) is often long enough to blow that limit for the helper socket path built fromhelperSocketDir. As per coding guidelines,**/*.{ts,tsx}: "For non-obvious TypeScript code, add a concise comment explaining why the constraint exists, not how the code works."📝 Proposed comment
+// Why: AF_UNIX socket paths are capped at ~104-108 bytes on macOS/Linux, and +// os.tmpdir() (e.g. macOS's /var/folders/.../T/) is often too long once the +// session id suffix is appended. Use the short system tmp root instead. const shortTempRoot = process.platform === 'win32' ? os.tmpdir() : path.join(path.parse(os.tmpdir()).root, 'tmp')Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: dbe6a938-1a58-4fe1-bb91-6df3a09c3909
📒 Files selected for processing (1)
tests/e2e/browser-embedded-owner-routing.spec.ts
| expect(existsSync(externalLaunchMarker)).toBe(false) | ||
| expect(evaluation).toMatchObject({ | ||
| ok: true, | ||
| result: { result: 'destination-webview', origin: server.destinationUrl } | ||
| }) | ||
| expect(existsSync(path.join(helperSocketDir, `${sessionName}.pid`))).toBe(false) |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Pid-file removal check isn't polled like the earlier equivalents.
Lines 157-159 and 190-194 both wrap the same kind of pid-file-existence assertion in expect.poll to tolerate async cleanup timing, but line 231 checks existsSync(...) synchronously right after the eval call. If helper-session cleanup on eval completes slightly after the runtime response resolves, this assertion can flake.
🐛 Proposed fix
- expect(existsSync(path.join(helperSocketDir, `${sessionName}.pid`))).toBe(false)
+ await expect
+ .poll(() => existsSync(path.join(helperSocketDir, `${sessionName}.pid`)), { timeout: 5_000 })
+ .toBe(false)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| expect(existsSync(externalLaunchMarker)).toBe(false) | |
| expect(evaluation).toMatchObject({ | |
| ok: true, | |
| result: { result: 'destination-webview', origin: server.destinationUrl } | |
| }) | |
| expect(existsSync(path.join(helperSocketDir, `${sessionName}.pid`))).toBe(false) | |
| expect(existsSync(externalLaunchMarker)).toBe(false) | |
| expect(evaluation).toMatchObject({ | |
| ok: true, | |
| result: { result: 'destination-webview', origin: server.destinationUrl } | |
| }) | |
| await expect | |
| .poll(() => existsSync(path.join(helperSocketDir, `${sessionName}.pid`)), { timeout: 5_000 }) | |
| .toBe(false) |
🧰 Tools
🪛 ast-grep (0.44.1)
[warning] Importing child_process exposes a command-execution surface; ensure any command/argument built from input is validated, and prefer execFile/spawn with an argument array over exec.
Context: import { execFile } from 'node:child_process'
Note: [CWE-78] Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').
(detect-child-process-typescript)
…e load (#9822) * fix(browser): stop failing goto when a redirect or download aborts the load Electron's loadURL rejects with ERR_ABORTED (-3) when the initial navigation is superseded — a client-side/meta redirect (common in SSO flows) or a download-triggered load. Since #9633 drives goto through wc.loadURL directly, that rejection surfaced as a spurious 'Failed to navigate' browser_error even though the page landed fine. Treat ERR_ABORTED like offscreen-browser-backend already does: resolve with the page's actual URL/title. Every other loadURL failure still fails closed. * fix(browser): settle replacement navigation after abort * fix(browser): clean up aborted navigation destruction race
…i#9633) * fix(browser): keep embedded commands on registered target * fix(browser): cover internal helper ownership paths * test(browser): cover stale helper routing in Electron * fix(browser): preserve direct command result semantics --------- Co-authored-by: OrcaWin <[email protected]>
…e load (stablyai#9822) * fix(browser): stop failing goto when a redirect or download aborts the load Electron's loadURL rejects with ERR_ABORTED (-3) when the initial navigation is superseded — a client-side/meta redirect (common in SSO flows) or a download-triggered load. Since stablyai#9633 drives goto through wc.loadURL directly, that rejection surfaced as a spurious 'Failed to navigate' browser_error even though the page landed fine. Treat ERR_ABORTED like offscreen-browser-backend already does: resolve with the page's actual URL/title. Every other loadURL failure still fails closed. * fix(browser): settle replacement navigation after abort * fix(browser): clean up aborted navigation destruction race
Summary
Reproduction
A deterministic fake registers an Orca Electron webContents, initializes the helper, marks its session stale, and records helper calls without
--cdp. Before this fix,gotoandevaluateeach produced one wrong-owner call:The regression harness now proves both commands remain on the registered embedded target without launching a real browser.
Validation
browser.gotoandbrowser.evalupdate the visible webview without launching the sentinel or recreating the helperFixes #9510