fix(electron): report why a launch failed, and launch past macOS's reopen-windows alert
What
When an Electron app fails to start, app.open() now says why, and a later launch does not stall:
- A failed launch reports the app's own failure (
the app quit before it opened a window ...,no window loaded a page ...) with its stderr, not the test'sTEST_TIMEOUT. - A launch whose window loaded just as the wait ran out still gets its main process connected and its downloads folder set.
- On macOS the app starts with
-ApplePersistenceIgnoreState YES. An app the engine killed in an earlier test no longer stalls its next launch behind the system's "reopen windows?" alert. - A stderr line over 500 characters shows only its length in the message, so no part of a secret is quoted.
- An attempt ends cleanly even when its user-data directory cannot be removed, and a dialog handler still running from one attempt never answers the next attempt's dialogs.
Why
- The launch used the operation's whole time to wait for a window. When nothing loaded, the operation's own timeout fired first, so the test saw
TEST_TIMEOUTand never the reason the engine had worked out. - On macOS a killed Electron app leaves saved window state. The next launch of that binary showed a modal alert before
readyand waited its full timeout. This is what stalled the local testbed after an interrupted run. - Quoting a long stderr line in full would fill the report. A cut at any point, white space included, could keep the first part of a secret the app printed, and the run's redaction matches only whole values (
AGENTS.md, security invariants).
How it works
launch()keepsFAILURE_REPORT_MS(750 ms, at most half the time) out of the window wait. With under 1.5 s left, half is less than the report can take, so a very short launch can still end inTEST_TIMEOUT. On failure it asks the main process whether Electron is ready (250 ms each), kills the app, and waits 250 ms for it to exit (packages/electron/src/app-process.ts:183,:227). The nextquit(), which runs before the user-data directory is removed, waits for the rest of that exit (app-process.ts:159-169).- Setting up the app after its window loaded uses whatever time is left, at least 1 ms, rather than failing when none is left (
app-process.ts:209). processArgumentsadds-ApplePersistenceIgnoreState YESondarwin, after the app's own arguments, because Electron takes the first argument that is not a switch as the app's path (packages/electron/src/launcher.ts:40). macOS reads the setting only as two arguments, so the app'sprocess.argvends with both,-ApplePersistenceIgnoreStateandYES. On Electron 45.5.0,systemPreferences.getUserDefaultreads nothing for-ApplePersistenceIgnoreState=YES. The reference's launch-arguments table lists the switch and says the app sees both words.quotedLinequotes a stderr line whole up to 500 characters, and gives only the length of a longer one (app-process.ts:480). The reference'sAPP_NOT_OPENrow says so.endAttemptclears the attempt and the dialog handlers before it removes the user-data directory, so a removal that throws leaves no state behind (packages/electron/src/surface.ts:134).DialogRouter.reset()bumps a generation, and a handler of an earlier generation reports nothing (packages/electron/src/dialogs.ts:37-55).- The integration tests' window helper kills its Electron when no window opens within 20 s, under vitest's hook timeout (
packages/electron/tests/integration/test-window.ts).
Verified
Ran it locally: yes, on macOS (Apple Silicon) with Electron 45.5.0.
- At
2b89ed4ebthis branch passed the Electron package's unit and integration tests, the Electron testbed run through the built CLI (pnpm --filter @e2e-dev/electron-testbed test), andpnpm check. After the stderr change at head it passes the unit tests,tests/integration/launch.test.ts, typecheck, and oxlint. - main against this branch: this branch's tests run against
origin/main'spackages/electron/src. These tests fail there and pass here:
| Suite | Test | main | this PR |
|---|---|---|---|
| unit | DialogRouter keeps a handler that outlives its attempt from failing the next one | fails | passes |
| integration | launch quotes no part of a long stderr line, which could cut a secret that holds white space | fails | passes |
| integration | launch reports why a launch failed within the operation's time, for an app whose main process is stuck | fails | passes |
The macOS launch argument has its own unit test (packages/electron/tests/unit/launch.test.ts); it is not in the table, because the local runs started main's Electron with the argument too. A launch whose window loaded just as its wait ran out has no test: it needs the load to land inside that last millisecond.
- Benchmark:
pnpm bench:ab --suite electron-testbed, the merge base with main against this head, on a Mac. This head starts the app with-ApplePersistenceIgnoreState; the base was given the same line locally and uncommitted, since without it a launch after a killed app stalls 120 s on the reopen-windows alert, which would swamp the timings.
Result: the suite and every step are the same (suite -0.1%, 95% CI -0.4% to +0.2%), and the step counts match. One fixture test (mouse moves) changes its step sequence between runs of the same build, as it does on main, so it is noise.
bench:ab output
bench-ab: 7c1b2b25 (merge base with origin/main) vs 718c2948
apps/electron-testbed: e2e run --workers 1. 6 pairs in random order, resolved after 6 pairs. Threshold ±5% and 10 ms. darwin arm64, Apple M5 Pro x18, Node 26.13.1, load 2.8.
Behavior
These tests are left out of the timing rows below.
- unstable on head (2 different step sequences) tests/fixture.e2e.ts › electron.keyboard and a window's page › moves, presses, and scrolls with the mouse where the test points it (electron)
Timings
Every row but the process wall clock covers the 86 tests whose behavior matched.
| Metric | base median (IQR) | head median (IQR) | change (95% CI) | verdict |
|---|---|---|---|---|
| wall (process) | 66.13 s (66.07 s-66.17 s) | 66.05 s (66.00 s-66.08 s) | -0.1% (-0.5% to +0.3%) | same |
| suite (sum of attempts) | 65.21 s (65.13 s-65.25 s) | 65.12 s (65.04 s-65.16 s) | -0.1% (-0.4% to +0.2%) | same |
| action (events) | 17.03 s (17.03 s-17.04 s) | 17.02 s (17.01 s-17.03 s) | -0.1% (-0.2% to +0.0%) | same |
| step app.open | 25.50 s (25.43 s-25.50 s) | 25.45 s (25.33 s-25.50 s) | -0.2% (-1.0% to +1.0%) | same |
| step locator.selectOption | 4.73 s (4.73 s-4.74 s) | 4.73 s (4.73 s-4.73 s) | -0.0% (-0.1% to +0.0%) | same, under the floor |
| step locator.tap | 4.42 s (4.41 s-4.42 s) | 4.42 s (4.40 s-4.42 s) | -0.0% (-0.3% to +0.3%) | same, under the floor |
| step locator.fill | 3.40 s (3.40 s-3.40 s) | 3.40 s (3.40 s-3.40 s) | -0.1% (-0.3% to +0.1%) | same, under the floor |
| step app.restart | 2.11 s (2.11 s-2.18 s) | 2.10 s (2.10 s-2.11 s) | -0.2% (-2.5% to +0.4%) | same, under the floor |
| step locator.dragTo | 1.44 s (1.43 s-1.44 s) | 1.44 s (1.43 s-1.44 s) | -0.0% (-0.7% to +0.5%) | same, under the floor |
| step locator.pressSequentially | 1.09 s (1.09 s-1.10 s) | 1.09 s (1.09 s-1.09 s) | -0.2% (-0.6% to +1.2%) | same, under the floor |
| step window.title | 1.00 s (1.00 s-1.01 s) | 1.00 s (1.00 s-1.01 s) | +0.0% (-0.1% to +0.3%) | same, under the floor |
| step electron.window | 956 ms (955 ms-956 ms) | 956 ms (955 ms-956 ms) | +0.1% (-0.2% to +0.3%) | same, under the floor |
| step electron.waitForWindow | 935 ms (933 ms-936 ms) | 937 ms (935 ms-946 ms) | +0.6% (-0.1% to +2.4%) | same, under the floor |
| step locator.scrollIntoView | 932 ms (932 ms-932 ms) | 931 ms (931 ms-931 ms) | -0.1% (-0.3% to 0.0%) | same, under the floor |
| step electron.launch | 917 ms (915 ms-917 ms) | 916 ms (915 ms-921 ms) | -0.2% (-9.6% to +5.9%) | same, under the floor |
| step locator.longPress | 905 ms (904 ms-906 ms) | 904 ms (904 ms-905 ms) | -0.1% (-0.3% to +0.1%) | same, under the floor |
| step locator.waitFor | 903 ms (903 ms-904 ms) | 903 ms (903 ms-904 ms) | +0.1% (-0.1% to +0.2%) | same, under the floor |
| step expect.toHaveValue | 776 ms (768 ms-782 ms) | 775 ms (774 ms-779 ms) | +0.0% (-1.7% to +1.7%) | same, under the floor |
| step locator.setInputFiles | 598 ms (595 ms-600 ms) | 595 ms (589 ms-597 ms) | -0.3% (-2.4% to +1.2%) | same, under the floor |
| step expect.toBeVisible | 530 ms (522 ms-533 ms) | 520 ms (517 ms-520 ms) | -2.2% (-4.1% to +0.5%) | same |
| step electron.waitForDownload | 525 ms (524 ms-526 ms) | 525 ms (524 ms-526 ms) | -0.1% (-1.4% to +0.9%) | same, under the floor |
| step expect.not.toHaveValue | 518 ms (517 ms-519 ms) | 519 ms (518 ms-520 ms) | +0.3% (-0.2% to +1.1%) | same, under the floor |
| step electron.evaluate | 509 ms (507 ms-512 ms) | 500 ms (498 ms-502 ms) | -2.0% (-3.9% to +0.1%) | same |
| step expect.toHaveText | 356 ms (354 ms-358 ms) | 348 ms (342 ms-351 ms) | -2.4% (-7.5% to -0.3%) | same, under the floor |
| step app.clearState | 339 ms (339 ms-339 ms) | 339 ms (338 ms-339 ms) | 0.0% (-0.6% to +0.4%) | same |
| step locator.check | 326 ms (324 ms-329 ms) | 322 ms (320 ms-323 ms) | -1.7% (-2.4% to -0.0%) | same, under the floor |
| step app.screenshot | 123 ms (118 ms-128 ms) | 124 ms (115 ms-132 ms) | +2.1% (-11.6% to +12.6%) | same, under the floor |
| step app.stopRecording | 114 ms (111 ms-118 ms) | 111 ms (110 ms-113 ms) | +0.5% (-20.3% to +4.3%) | same, under the floor |
| step expect.toHaveCount | 106 ms (104 ms-109 ms) | 111 ms (108 ms-112 ms) | +3.8% (+0.0% to +13.1%) | same, under the floor |
| step locator.clear | 52 ms (51 ms-52 ms) | 51 ms (50 ms-52 ms) | 0.0% (-6.6% to +1.0%) | same |
| step locator.press | 51 ms (49 ms-51 ms) | 50 ms (49 ms-50 ms) | -2.0% (-3.9% to +6.0%) | same, under the floor |
| step electron.keyboard.press | 50 ms (49 ms-50 ms) | 48 ms (47 ms-52 ms) | -2.1% (-5.0% to +3.9%) | same, under the floor |
| step locator.focus | 43 ms (42 ms-45 ms) | 42 ms (41 ms-43 ms) | -2.2% (-6.8% to +1.2%) | same, under the floor |
| step locator.swipe | 35 ms (35 ms-37 ms) | 36 ms (34 ms-36 ms) | +0.0% (-6.9% to +15.0%) | same, under the floor |
| step app.startRecording | 34 ms (34 ms-34 ms) | 34 ms (34 ms-34 ms) | 0.0% (-14.4% to +4.3%) | same |
| step expect.toBeChecked | 34 ms (33 ms-34 ms) | 33 ms (33 ms-33 ms) | -2.9% (-7.1% to +1.6%) | same, under the floor |
| step electron.keyboard.type | 23 ms (22 ms-23 ms) | 23 ms (22 ms-23 ms) | 0.0% (-4.3% to +4.5%) | same |
| step expect.toBeDisabled | 22 ms (22 ms-23 ms) | 23 ms (21 ms-23 ms) | 0.0% (-6.6% to +4.5%) | same |
| step expect.toBeHidden | 21 ms (21 ms-21 ms) | 22 ms (21 ms-22 ms) | +2.4% (-2.1% to +4.8%) | same, under the floor |
| step locator.uncheck | 20 ms (18 ms-21 ms) | 20 ms (19 ms-20 ms) | -4.8% (-5.1% to +14.2%) | same, under the floor |
| step expect.toBeEditable | 20 ms (19 ms-20 ms) | 19 ms (18 ms-19 ms) | -2.5% (-12.5% to +2.6%) | same, under the floor |
| step expect.not.toBeChecked | 19 ms (19 ms-19 ms) | 19 ms (17 ms-19 ms) | -7.4% (-13.2% to +8.5%) | same, under the floor |
| step expect.toBeInViewport | 16 ms (16 ms-17 ms) | 16 ms (16 ms-17 ms) | -2.8% (-9.3% to +6.5%) | same, under the floor |
| step electron.keyboard.down | 15 ms (14 ms-17 ms) | 14 ms (14 ms-15 ms) | -3.4% (-14.8% to 0.0%) | same, under the floor |
| step electron.keyboard.up | 15 ms (14 ms-15 ms) | 15 ms (14 ms-15 ms) | 0.0% (-6.5% to +11.2%) | same |
| step expect.toHaveAttribute | 14 ms (14 ms-14 ms) | 15 ms (15 ms-16 ms) | +7.1% (-3.6% to +17.8%) | same, under the floor |
| step expect.not.toBeInViewport | 14 ms (13 ms-15 ms) | 14 ms (13 ms-14 ms) | 0.0% (-13.3% to +11.8%) | same |
| step locator.dblclick | 12 ms (12 ms-13 ms) | 13 ms (12 ms-13 ms) | +4.1% (0.0% to +8.7%) | same, under the floor |
| step expect.not.toBeEmpty | 11 ms (11 ms-11 ms) | 10 ms (10 ms-11 ms) | -4.7% (-9.1% to 0.0%) | same, under the floor |
| step expect.toBeEmpty | 11 ms (10 ms-11 ms) | 10 ms (10 ms-10 ms) | -9.1% (-13.0% to 0.0%) | same, under the floor |
| step locator.hover | 10 ms (10 ms-15 ms) | 10 ms (10 ms-14 ms) | 0.0% (-20.9% to +22.5%) | same |
| step expect.not.toBeEditable | 10 ms (9 ms-10 ms) | 9 ms (8 ms-9 ms) | -10.6% (-20.0% to 0.0%) | same, under the floor |
| step window.reload | 9 ms (9 ms-9 ms) | 9 ms (9 ms-9 ms) | 0.0% (-5.1% to +5.4%) | same |
| step electron.keyboard.insertText | 8 ms (8 ms-8 ms) | 8 ms (7 ms-8 ms) | 0.0% (-6.5% to 0.0%) | same |
| step expect.toContainText | 8 ms (8 ms-8 ms) | 8 ms (8 ms-8 ms) | 0.0% (0.0% to 0.0%) | same |
| step screen.tree | 6 ms (5 ms-6 ms) | 6 ms (6 ms-6 ms) | 0.0% (-15.5% to +29.6%) | same |
| step app.back | 6 ms (6 ms-7 ms) | 6 ms (6 ms-6 ms) | 0.0% (-13.4% to 0.0%) | same |
| step expect.not.toHaveAttribute | 6 ms (6 ms-6 ms) | 7 ms (6 ms-7 ms) | 0.0% (0.0% to +16.7%) | same |
| step expect.not.toBeHidden | 6 ms (6 ms-6 ms) | 6 ms (6 ms-6 ms) | 0.0% (-8.7% to +9.5%) | same |
| step expect.toHaveRole | 6 ms (5 ms-6 ms) | 5 ms (5 ms-5 ms) | 0.0% (-25.5% to 0.0%) | same |
| step expect.toBeFocused | 5 ms (5 ms-6 ms) | 5 ms (4 ms-5 ms) | -10.6% (-33.3% to +11.8%) | same, under the floor |
| step expect.not.toHaveRole | 5 ms (5 ms-5 ms) | 5 ms (5 ms-5 ms) | 0.0% (-8.7% to +9.5%) | same |
| step expect.toHaveAccessibleName | 5 ms (4 ms-5 ms) | 4 ms (4 ms-5 ms) | 0.0% (-20.0% to +11.8%) | same |
| step expect.toBeSelected | 4 ms (4 ms-4 ms) | 4 ms (4 ms-4 ms) | 0.0% (0.0% to +11.8%) | same |
| step window.evaluate | 4 ms (3 ms-5 ms) | 4 ms (3 ms-5 ms) | 0.0% (-51.0% to +66.7%) | same |
| step expect.not.toBeEnabled | 4 ms (4 ms-4 ms) | 4 ms (4 ms-4 ms) | 0.0% (0.0% to +11.8%) | same |
| step expect.toHaveScreenshot | 2 ms (1 ms-2 ms) | 1 ms (1 ms-1 ms) | 0.0% (-50.0% to 0.0%) | same |
| step window.close | 1 ms (1 ms-1 ms) | 1 ms (1 ms-1 ms) | 0.0% (0.0% to +41.4%) | same |
| step window.activate | 1 ms (0 ms-1 ms) | 0 ms (0 ms-1 ms) | +41.4% (0.0% to +100.0%) | same, under the floor |
| step electron.onDialog | 0 ms (0 ms-0 ms) | 1 ms (0 ms-1 ms) | - (- to -) | same, under the floor |
Counters
| Counter | base | head |
|---|---|---|
| events navigation | 123-131 | 121-125 |
| steps | 579 | 579-580 |
Tests outside the threshold: 0 of 86
With 86 tests compared at 95%, about 4.3 could land outside by chance.
Fresh-context review (Codex gpt-6.2-sol, read-only, on this branch's diff):
- Fixed: a cut at 500 characters could keep the start of a secret the app printed. Bot review then found that a cut at white space still splits a secret that holds white space, so a longer line now shows only its length (
515881330). - Fixed: the failed launch could still wait up to 2 s for the killed app to exit and lose its reason to the operation's timeout; it now waits 250 ms and the next quit waits for the rest (
aa55c2e8c, no test: it needs a process that exits slowly after a kill). - Fixed: added the changeset.
- Dismissed: the reference lists
APP_NOT_OPENfor a launch with no window, while the engine raisesINVALID_STATE. Core mapsINVALID_STATEto the test'sAPP_NOT_OPEN(packages/core/src/internal/errors.ts:381), which is the code a test sees.
Bot review (cubic, CodeRabbit) on 2b89ed4eb: five inline findings are left as is, as unlikely edge cases. They need less than 1.5 s of a 30 s default budget left at launch, a killed app that takes seconds to exit, rmSync failing after its retries, or a splash that closes during setup while its replacement is still loading. A sixth asked for a stricter assertion in the stderr test, which the new test replaces. CodeRabbit's summary also names Windows' taskkill (up to 5 s) on a failed launch's kill. That path is the same kill a failed launch reached on main when the app did not quit within its grace time. Each thread's reply gives the reason.
🤖 Generated with Claude Code
Summary by CodeRabbit
- Bug Fixes
- Improved launch-failure reporting when the app exits before opening a window or fails to load a page within the launch time.
- Launch failures reserve time to gather diagnostic details and shut down the app; very long error lines are represented by their length.
- Improved cleanup after failed launches and prevented dialog errors from an earlier attempt from affecting the next.
- Documentation
- Clarified launch-time failure cases, including apps waiting on a macOS keychain prompt.
- Documented a macOS launch option that suppresses the reopen-windows prompt and noted that apps interpreting extra launch arguments as files or URLs should skip both related arguments.