Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(desktop): preview CDP sessions no longer hard-crash the app #9068

Mergedsethwebster(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/9068/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

Closes #9067.

The desktop app was hard-crashing (SIGSEGV in the browser process) after heavy preview automation — three crashes in one day, across two nightlies and two Electron versions. Symbolicated dumps showed Chromium's DevTools layer dispatching into a freed DevToolsAgentHostClient: Electron's webContents.debugger wrapper is cppgc-managed but registered with content as a raw pointer, and its destructor never detaches, so a GC sweep of an attached debugger leaves the session dangling (reported upstream as electron/electron#53376). Our exposure: nothing pinned the wrapper for the control session's lifetime, and the cleanup finalizer re-read wc.debugger — which throws once the webview is destroyed — so detach was silently skipped exactly when it mattered.

The fix pins the debugger reference in BrowserControlSession and routes every attach, detach, and sendCommand through it:

  • While a control session exists, the wrapper is strongly referenced, so Chromium's force-detach during WebContents teardown always finds a live client.
  • The scope finalizer detaches through the pinned reference, which stays valid after the WebContents wrapper is destroyed (Debugger.detach() is a safe no-op if the agent host is already closed).

New test drives the real-world shape the old mocks hid: a webview whose debugger getter throws after destruction. It fails on the previous code (detach never called) and passes with the fix. vp test run apps/desktop/src/preview/Manager.test.ts (64 passed), desktop tsgo --noEmit and lint clean.

Fable 5 via Claude Code.


Note

High Risk Touches CDP attach/detach lifecycle for preview automation; incorrect pinning or teardown could regress crashes or leave debugger sessions attached.

Overview Fixes browser-process crashes during heavy preview automation by keeping the Electron Debugger wrapper alive for each preview control session and routing all CDP traffic through that pinned handle instead of re-reading webContents.debugger.

BrowserControlSession now stores the debugger captured at attach time. Session setup, teardown (off / detach), automation sendCommand, and color-scheme emulation all use control.debugger, so cleanup still runs when the webview is already destroyed (when wc.debugger would throw per electron/electron#53376).

Adds a test where the webview’s debugger getter throws after destruction and asserts detach still runs on navigate/cleanup.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 6441d6d276b27f081d057c7b0119a1759888286e. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Pin Electron.Debugger reference in BrowserControlSession to prevent preview CDP crashes

  • Captures wc.debugger into a local wcDebugger at control session creation in Manager.ts, so all attach, detach, message listener, and sendCommand calls use the pinned reference instead of re-accessing wc.debugger at runtime
  • Adds a readonly debugger field to BrowserControlSession and exposes the pinned instance on it, so controlAction, applyColorScheme, and restoreControlSession all route through control.debugger
  • Adds an effect test in Manager.test.ts that marks the WebContents as destroyed, then asserts debugger.off('message', ...) and debugger.detach() still run via the pinned reference
  • Risk: any code outside PreviewManager that still reads wc.debugger directly on a destroyed WebContents will still crash; only the in-tree session paths are hardened
Macroscope summarized 6441d6d.
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. Approvability

      Verdict: Approved at 6441d6d

      Macroscope's review found this PR approvable — This is a focused desktop bug fix that pins the existing Electron debugger wrapper for each control session and routes existing commands and cleanup through it, preventing crash-prone garbage collection and destroyed-WebContents cleanup failures. A targeted regression test covers the affected lifecycle, with no product-default or static-analysis changes.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).

Sign in to join this conversation.