# Desktop preview unload proof

Base: [bef412cff6](https://github.com/pingdotgg/t3code/commit/bef412cff61b1b91ff92aecb313ed1776838c786), the merge-base of current main and the requested head.
Head: [068d23ade9](https://github.com/pingdotgg/t3code/commit/068d23ade977d09a0eb36158520167d4944ef350).

Both applications were built from their respective commits with `vp run build:desktop` and launched as real Electron applications under `headless-desktop`, using fresh isolated T3 homes, the same synthetic git project and replayed conversation, 1440 by 900 content dimensions, and the light app theme. Capacity captures additionally use reduced-motion mode on both sides. The probe uses identical ASCII HTML on each side. Different loopback ports allow the two real 31-minute capacity waits to run concurrently.

The application was not patched or mocked. The drivers use the app's CLI, WebSocket RPC and actual MCP endpoint to create state and send operations. Native Close and the separate web client's Close are clicked in the real UI. The replay wrapper forwards the repository's free replay agent; for capacity owners it withholds the final prompt response so that each real provider session remains active. It saves the agent's own MCP credential locally for the driver and those credentials are not uploaded.

The Lifecycle monitor is a real page mounted in the app's Browser panel. It displays live beacons from the probe. These are full app screenshots, including the conversation and the tab strip. They are not standalone dashboards rendered from a saved log. Stills were saved after two identical captures 500 ms apart. Videos are sequences of actual app captures at 5 frames per second.

## Reproduction

1. Add a synthetic git project and seed one completed free replay turn. Open its thread in Electron.
2. Open the native, server-runtime probe and activate its button. Click the desktop tab's own Close button.
3. Pair a separate Chromium web client with the desktop's server, open the same thread, and show its clicked desktop-backed probe as a stream. Click Close in that web client.
4. Send two simultaneous `preview.close` requests for one activated native probe. Both must settle; the unload sequence must run once. The supplementary driver also consumes and acknowledges the preview event stream and records the number of removal events.
5. Open a probe whose initial script sends its load beacon and blocks for three seconds, preventing desktop page setup from completing. Close immediately after that beacon. Head preserves the surface until setup settles and unload runs; base removes it immediately.
6. In fresh capacity state, start five replay owners. The first four each open eight hidden native agent tabs. Keep a desktop-runtime monitor outside the server tab budget. Wait 31 real minutes, without adjusting any clock or timeout. Ask the fifth owner to open a replacement, observe lifecycle beacons for the oldest page and the replacement's loaded native page.
7. Controls: reload an activated probe on each side; both deliver the full lifecycle and a new load. For the grace limit, block `beforeunload` for ten seconds; head gives it an opportunity to run and removes the surface after the existing five-second grace rather than hanging.

## Running the scratch drivers

Install dependencies and build each checkout first. Put these scripts together in a scratch folder. Each output directory must be new. For example:

```sh
headless-desktop node driver.cjs /checkout/head /scratch/head-run 9451 4789
headless-desktop node driver.cjs /checkout/base /scratch/base-run 9452 4790
headless-desktop node capacity-driver.cjs /checkout/base /scratch/base-capacity 9452 4790
headless-desktop node supplement-driver.cjs /checkout/head /scratch/head-controls 9453 4791
headless-desktop node supplement-driver.cjs /checkout/base /scratch/base-controls 9454 4792
```

The final capacity comparison uses `capacity-driver.cjs` and independent fresh state on both commits. Two earlier long-running capture sessions ended with SIGTERM before complete capacity captures; those attempts are excluded. While the final tabs age, `capacity-ui-seed.cjs` opens the fifth owner’s Browser panel in advance, selects reduced motion and returns to the monitor. This avoids the new thread’s default floating preview and keeps private run-context text out of captures; it does not access the 32 hidden pages. The seed helper attaches to the driver’s Node inspector solely to use its existing Playwright connection, and changes no app or server code. Read-only `preview.list` manifests confirm eight hidden server tabs for each of the first four owners, none marked headless, before the idle wait ends. After opening the fifth owner’s Browser panel, `capacity-placeholder.cjs` replaces its empty server placeholder with a desktop-runtime monitor. Final manifests show eight hidden server tabs for each of four owners and only desktop-runtime monitors in the fifth and main threads. The final read-only native-page audit confirms exactly 32 capacity pages plus those two desktop monitors and the app window, with no about:blank page. The initial driver's unacknowledged event subscription is not used for removal counts; the supplementary driver explicitly acknowledges chunks.

While a capacity driver is in its idle wait, run `node capacity-ui-seed.cjs /checkout/head <driver-pid>` (or the base checkout and its driver PID). It validates the PID’s working directory and outputs an audit of the 32 native capacity pages. Then run `node capacity-placeholder.cjs /checkout/head /scratch/head-capacity 9451 4789` (or base and its ports) to keep the panel open without taking a server slot. The final audit uses `node capacity-ui-seed.cjs /checkout/head <driver-pid> 9229 audit`, which reads URLs without navigating. Run one inspector helper at a time because its temporary local port is shared.

The scripts require no paid provider. No repository tests are used as proof.
