Skip to content

fix(browser): a crashed page no longer crashes Orca when its viewport is resized - #23852

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/browser-crash-viewport-segfault
Sep 29, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/browser-crash-viewport-segfault

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

If a page in Orca's built-in browser crashed and you then picked a viewport size (for example a phone size), the whole Orca app could crash and close, taking every terminal and agent with it.
Now Orca skips resizing a crashed page, and the size you picked is applied as soon as the page loads again.

What Changed

The problem. Orca's main process crashed with a segmentation fault (SIGSEGV) when a browser tab's page had crashed and something then asked Chromium to resize that page's viewport.
It was first seen by the #23718 identity regression audit (follow-up 2): 2 of 2 on the #23718 merge and 1 of 1 on its parent, using a forced renderer crash.
I reproduced it on current main on macOS with a natural crash and no debugging hooks: a page that runs out of memory while it is still loading crashes again on Orca's automatic recovery reload, which leaves the tab dead; choosing a phone preset from the viewport menu 5 seconds later closed Orca 2 of 2 times.
It is not a regression from a recent PR: the unsafe call pattern predates #23718.

Who can hit it. Anyone whose browser-tab page crashes (out of memory, a renderer bug, or the OS killing it) while a viewport resize is in flight or soon after, if Orca's automatic reload has not rebuilt the page yet.
The same resize is sent by four other paths, all affected in the same way: the viewport preset reapplied when a page finishes loading, the agent viewport command, raw CDP commands an agent sends through Orca's CDP proxy (for example set viewport), and the device-size emulation for a paired phone watching a browser tab.
When the automatic reload succeeds, the unsafe window is only about 1 to 3 ms after the crash (measured over 48 real crashes), so the stuck-tab case above is the realistic trigger.

Not affected. Every other command Orca sends to a crashed page, which I tested one by one on a dead page without a crash: touch emulation, user-agent changes, running page scripts, mouse input, screenshots, and clearing the viewport size.
Pages that have not crashed behave exactly as before.

What you see now. Orca stays open. Picking a viewport size on a crashed tab is remembered but not applied to the dead page; when the page reloads (or you navigate it anywhere) it comes up at the size you picked.
An agent's viewport command on a crashed tab now returns an error ("The page crashed; its viewport can be changed again once it reloads.") instead of taking down the app.

Mechanism. Chromium's handlers for Emulation.setDeviceMetricsOverride and Emulation.setVisibleSize call WebContentsImpl::SetDeviceEmulationSize, which dereferences the page's view without checking that it exists. A crashed renderer takes its view with it until a reload builds a new one, so either command sent in that gap is a null-pointer crash in Orca's main process (symbolized stack in Testing below).
A new function, sendGuestCdpCommand in src/main/browser/guest-cdp-command.ts, is now the one gate these commands pass through: it refuses those two commands while the tab's webContents.isCrashed() is true (or the tab is destroyed) and forwards everything else unchanged.
The check runs in the same task as the send, and Chromium sets isCrashed() in the same task that drops the view, so the renderer cannot die between the check and the send. On reload, Chromium creates the new view before it clears the crashed state, so a page reported as not crashed always has a view.
Routed through it: the viewport preset writer, the agent viewport command, the CDP bridge's command sender (which agent commands use), the CDP proxy's forwarder, and the paired-phone screencast's device-size emulation. It takes only the three members it uses (isDestroyed, isCrashed, debugger.sendCommand).
The existing reapply-on-load behaviour is what restores the chosen size after recovery; nothing new had to be added for that.

Why

The bug is a missing null check inside Chromium, so Orca cannot fix the dereference itself; the fix has to make sure Orca never sends those two commands while the view is gone.
I put that rule in one function that every sender of those commands goes through, rather than a check inside the preset code alone, because the agent, CDP proxy and screencast paths send the same commands and would still crash the app.
I considered blocking every command to a crashed page. I rejected it because nothing else I tested crashes, and it would change agent behaviour for no gain: commands such as navigation are how an agent could recover a dead tab.
I considered sending dontSetVisibleSize: true with the metrics command, which skips the unsafe call. I rejected it because it changes how emulation sizes the page on every healthy tab and does not cover Emulation.setVisibleSize.
I considered tracking crashes in Orca's own state from the render-process-gone event. I rejected it because asking Chromium directly (isCrashed()) cannot go stale, while a stored flag would have to be cleared at exactly the right moment on reload.

Linked Issue

No issue; found by the #23718 identity regression audit (follow-up 2).

Visual Proof

After (this branch, M4Air, macOS): the page crashed while loading and stayed dead, a phone preset was applied 5 s later, and Orca is still running. Navigating the tab loads the page in the phone viewport (the page reports 375×667; device pixel ratio 2, 5 touch points, no hover, iPhone user agent).

After: Orca still running, tab in phone viewport after the crash

Before (main at this branch's parent, 31012ae): there is nothing to show because the app closes. Its log ends with Electron exited with signal SIGSEGV, and the macOS crash report's faulting thread is the browser main thread (EXC_BAD_ACCESS, KERN_INVALID_ADDRESS at 0x0).

Testing

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

Live, on the M4Air (macOS, Electron 43.7.5), an isolated profile and home per run, driving the real viewport menu path (store + IPC):

Build Case Result
this branch 45e9a41 page crashes while loading, phone preset 5 s later (no debugger, no forced crash) 2 of 2 alive, phone viewport after navigation
this branch forced renderer crash, preset IPC in the same moment 3 of 3 alive
this branch forced renderer crash, menu preset in the same moment 2 of 2 alive, phone viewport after reload
this branch crash with no preset change (control) alive
main 31012ae (parent) page crashes while loading, phone preset 5 s later 2 of 2 SIGSEGV
main 31012ae forced renderer crash, preset IPC in the same moment 1 of 1 SIGSEGV

A third run of the first branch case died one second after launch, before any test step ran, with no crash report (its network service and window process ended together). I counted it as invalid, not as a pass.

Root cause, symbolized from the macOS crash report with Electron's published symbols for 43.7.5: electron::api::Debugger::SendCommand → content::DevToolsSession::DispatchProtocolMessage → Emulation::DomainDispatcherImpl::setDeviceMetricsOverride → EmulationHandler::SetDeviceMetricsOverride → WebContentsImpl::SetDeviceEmulationSize (faulting frame). The same stack showed up in every crash, both forced and natural.
Per command, sent straight to a page whose isCrashed() was true (logged just before each send): Emulation.setDeviceMetricsOverride and Emulation.setVisibleSize crashed the app; Emulation.setTouchEmulationEnabled, Emulation.setUserAgentOverride, Emulation.clearDeviceMetricsOverride, Runtime.evaluate, Input.dispatchMouseEvent and Page.captureScreenshot did not.

Unit tests (head 94fb9ca96df): guest-cdp-command.test.ts (refuses both commands on a crashed or destroyed page, forwards other commands, session id handling) and browser-manager-viewport-crashed-guest.test.ts (a preset on a crashed tab sends no resize, and the same preset applies once the page is alive again). With the guard removed, all 4 guard tests fail. Every browser-manager*, cdp-*, agent-browser-bridge*, browser-screencast-* and runtime browser test file passes (54 files, 604 tests); their mocks gained isCrashed. Three screencast and CDP files that cannot import @streamparser/json in my local install were left to CI.

Not tested live: the agent viewport command, the CDP proxy and the paired-phone screencast on a crashed tab (covered by the shared gate and the unit tests), and Windows or Linux. The Chromium code involved is the same on every platform.

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Security: none; the change only withholds two commands. Cross-platform: the Chromium code is shared across macOS, Windows and Linux. Remote SSH: browser pages always run in the local Electron app, so SSH is unaffected. Mobile: a paired phone watching a crashed tab no longer triggers the crash through its device-size emulation. Compatibility: no persisted data or wire change. Performance: one isCrashed() call on two rarely sent commands.
Open PR #23812 also edits browser-manager-viewport.ts; this PR changes one line there, away from its hunks.

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)

…gfaulted Orca

Chromium's Emulation.setDeviceMetricsOverride and Emulation.setVisibleSize
resize the page's view without checking it still exists
(WebContentsImpl::SetDeviceEmulationSize). A crashed page renderer takes
its view with it until a reload builds a new one, so either command sent
in that gap killed Orca's whole main process with SIGSEGV.

One gate, sendGuestCdpCommand, now refuses those two commands while the
tab's renderer is gone. The viewport preset writer, the agent viewport
command, the agent bridge's command sender, the CDP proxy and the
screencast device metrics all send through it. The check runs in the same
task as the send, so the renderer cannot die in between. The page's own
reload reapplies the chosen preset on dom-ready, as it already did.
… cast

CI's changed-lines gate rejects new type assertions. The gate only uses
isDestroyed, isCrashed and debugger.sendCommand, so it now takes exactly
that shape; the viewport test keeps the one fixture cast its siblings use,
with a line-specific SAFETY note.
@brennanb2025
brennanb2025 marked this pull request as ready for review September 29, 2026 10:21
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Status: ready for review. Not merged, and auto-merge is not enabled.

Review session

  • Readiness checklist at the start: pass, no blockers.
  • Review loop 1 (same model): clean. It found every sender of the two resize commands routed through the gate, no behaviour change for healthy pages, and no performance cost. So no second loop, and no architecture challenge, was needed.
  • Precedent check: the approach matches the standard way to handle this Chromium bug. It checks isCrashed() right before sending exactly these two commands, rather than tracking crash state separately.
  • Readiness checklist at the end: it found one real problem, which CI had also caught. The changed-lines gate rejected 4 type assertions in the new tests. Fixed in 94fb9ca96df: the gate now takes only the three members it uses, so its test double needs no cast, and the viewport test uses the same line-specific SAFETY cast its sibling tests use.
  • One possible hole left out of scope: a resize wrapped in the deprecated Target.sendMessageToTarget. No Orca path and no current agent client sends it.

Live QA (M4Air, macOS, isolated profiles, real viewport menu path; the Grok QA seat was unavailable, returning HTTP 402, so I drove it myself)

Build Result
this branch 45e9a418f9 8 of 8 alive
main at its parent (31012aeb09) 3 of 3 SIGSEGV
  • The fixed runs covered: a page that crashes while loading and stays dead, with a phone preset 5 s later (2/2); a forced crash with the preset in the same moment (5/5); and a control (1/1).
  • After the fix, the chosen phone preset is in effect once the tab loads a page (screenshot in the PR body).
  • 94fb9ca96df changes only a TypeScript type and two tests, so runtime behaviour is identical to the build under QA.

CI on 94fb9ca96df: all required checks pass (static analysis, typecheck, 5 test shards, relay integration, package, package (windows), verify). The rest are skipped by path filters.

Also checked

@coderabbitai

coderabbitai Bot commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 40 seconds.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 561bcc62-e1a0-4c41-bb6b-0564b5c6dc01

📥 Commits

Reviewing files that changed from the base of the PR and between 31012ae and 94fb9ca.

📒 Files selected for processing (15)
  • src/main/browser/agent-browser-bridge-state-commands.ts
  • src/main/browser/agent-browser-bridge-test-harness.ts
  • src/main/browser/browser-manager-viewport-crashed-guest.test.ts
  • src/main/browser/browser-manager-viewport-test-fixtures.ts
  • src/main/browser/browser-manager-viewport.ts
  • src/main/browser/browser-screencast-debugger-command.ts
  • src/main/browser/browser-screencast-device-metrics.ts
  • src/main/browser/browser-screencast-lifecycle.test.ts
  • src/main/browser/browser-screencast-snapshot-scaling.test.ts
  • src/main/browser/browser-screencast-web-contents-test-double.ts
  • src/main/browser/cdp-debugger-channel.ts
  • src/main/browser/cdp-debugger-lifecycle.ts
  • src/main/browser/cdp-ws-proxy-test-harness.ts
  • src/main/browser/guest-cdp-command.test.ts
  • src/main/browser/guest-cdp-command.ts

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.

@greptile-apps

greptile-apps Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[High risk] Adds crash detection to viewport resize commands.

The PR appears safe to merge; the remaining issue is a non-blocking gap in recovery test coverage.

Summary

The PR routes viewport-resizing CDP commands from the browser manager, agent bridge, CDP forwarding paths, and screencast through a shared guard that refuses them for crashed or destroyed guests. It adds unit coverage for the guard and for a refused viewport write, though the recovery test does not exercise the reload event.

Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Viewport preset] --> G[sendGuestCdpCommand]
  B[Agent viewport] --> G
  C[CDP bridge and proxy] --> G
  D[Paired-phone screencast] --> G
  G -->|resize; guest crashed or destroyed| E[Reject command]
  G -->|otherwise| F[Electron debugger.sendCommand]
Loading

Reviews (1) · Last reviewed commit: "test(browser): type the CDP gate's targe..."

Comment on lines +73 to +75
// The reloaded page's dom-ready reapplies the store's preset.
setRendererCrashed(false)
await expect(browserManager.setViewportOverride('tab-crashed', PHONE)).resolves.toBe(true)

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 Reload recovery remains untested. The test flips isCrashed and calls setViewportOverride again, rather than triggering the dom-ready handler that reapplies the preset in production. It would pass even if a reload stopped reapplying the selected size, leaving that part of the fix without regression coverage.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@greptile-apps

greptile-apps Bot commented Sep 29, 2026

Copy link
Copy Markdown

Comments Outside Diff

These findings could not be posted inline.

  • P2 Reload recovery remains untested src/main/browser/browser-manager-viewport-crashed-guest.test.ts:75 ▶

    Reload recovery remains untested. The test flips isCrashed and calls setViewportOverride again, rather than triggering the dom-ready handler that reapplies the preset in production. It would pass even if a reload stopped reapplying the selected size, leaving that part of the fix without regression coverage.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@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 — this run read the complete diff (15 files) against main at 31012aeb09 and traced every caller of the two view-resizing CDP methods.

  • New CDP gate — sendGuestCdpCommand refuses Emulation.setDeviceMetricsOverride / Emulation.setVisibleSize while the guest is crashed or destroyed, forwards everything else, and keeps the check in the same task as the send.
  • Every sender routed through it — the viewport preset writer, the agent viewport command, the CDP bridge sender (which also carries cdp-auxiliary-commands.setViewport), the CDP proxy forwarder, and the paired-phone screencast device metrics. A repo-wide grep for the two method names confirms no remaining direct debugger.sendCommand caller.
  • Screencast timeout extraction — runDebuggerCommandWithTimeout lets browser-screencast-device-metrics wrap the gated send without changing microtask timing for existing sendDebuggerCommand callers.
  • Tests and doubles — new guard tests plus isCrashed added to the shared viewport fixture, bridge harness, proxy harness, and screencast doubles. The new tests fail if the guard is removed (pre-existing code writes the metrics command with no crash check).

Verified locally: ORCA_BACKGROUND_LAUNCH=1 pnpm test src/main/browser/ (206 files, 1926 passed), pnpm tc clean, pnpm run check:code-quality:changed reports 0 new findings across the 15 changed files.

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

@brennanb2025
brennanb2025 merged commit 4ebec19 into main Sep 29, 2026
58 checks passed
brennanb2025 added a commit that referenced this pull request Sep 29, 2026
…3789, #23812, #23852) into brennanb2025/codex-home-single-writer

#23744 moves every agent's folder pre-trust into the PTY spawn hook (and
the structured Codex chat create), removing Codex's launch-prep and
resume-prep trust writes. markCodexProjectTrusted now takes the config
files to write.

Conflicts:
- agent-trust-presets.ts: #23744's configFiles signature and nested lane
  acquisition, with this branch's lane rationale (hook installs read and
  rewrite across awaits); main's "capture->restore window" wording
  described the grant snapshot this branch removed.
- agent-trust-write-deadline.ts: the Codex writer waits only on
  managed-home installs' inline grant; the real-home background approval
  holds no lane. #23744's SSH/SFTP writer is gone, so it is no longer
  named; its 1.5 s short deadline is kept.
- codex-trust-config-concurrent-launch.test.ts: this branch's tests
  (a launch's write lands while a grant session runs; the renamed
  sibling-failure case) with #23744's new call signature.

Outside the conflicts: codex-launch-during-real-home-grant.test.ts passed
launchAgent/workspacePath into launch prep, which #23744 removed; its
launch helper now runs launch prep and then applyAgentWorkspaceTrust, as
the spawn builder does, so it still proves a launch and its project trust
land while the real-home approval hangs.
Jinwoo-H pushed a commit that referenced this pull request Sep 30, 2026
… is resized (#23852)

* fix(browser): never resize a browser tab whose page crashed, which segfaulted Orca

Chromium's Emulation.setDeviceMetricsOverride and Emulation.setVisibleSize
resize the page's view without checking it still exists
(WebContentsImpl::SetDeviceEmulationSize). A crashed page renderer takes
its view with it until a reload builds a new one, so either command sent
in that gap killed Orca's whole main process with SIGSEGV.

One gate, sendGuestCdpCommand, now refuses those two commands while the
tab's renderer is gone. The viewport preset writer, the agent viewport
command, the agent bridge's command sender, the CDP proxy and the
screencast device metrics all send through it. The check runs in the same
task as the send, so the renderer cannot die in between. The page's own
reload reapplies the chosen preset on dom-ready, as it already did.

* test(browser): type the CDP gate's target so its test double needs no cast

CI's changed-lines gate rejects new type assertions. The gate only uses
isDestroyed, isCrashed and debugger.sendCommand, so it now takes exactly
that shape; the viewport test keeps the one fixture cast its siblings use,
with a line-specific SAFETY note.

(cherry picked from commit 4ebec19)
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.

1 participant