fix(desktop): say why a launch left no window to drive

Merged
OK
1d ago
+389-106

What

Two app.open() errors now say what happened.

  • The launched process exited and a copy of the app was already running: the error names that copy (its process id) and says an app that runs one copy at a time hands the launch to it, so quit it first. The same hint is added when no new process could be claimed at all.
  • The window never became readable: the error says how many windows the last read listed, how many were unreadable, whether one answered no root element, and the failure of that read. A last read that listed nothing reports only its failure.

No attach mode: the engine still drives only a copy it launched.

Why

With a single-instance app already open (reported with a Chromium-based browser), the engine launched a second copy, that process handed off to the running one and exited, and the test failed with <App> quit right after it launched, before it showed a window. Nothing pointed at the copy that was open. <App> launched, but its window cannot be read through accessibility. The window may be off screen carried no facts, so a report of it could not be diagnosed.

How it works

  1. crates/e2e-desktop-napi/src/launch.rs: the driver already lists the copies of the bundle id running before open -n (before). The launch answer now carries them as running_before, and so do the details of the unclaimed failure.
  2. packages/desktop/src/launch-wait.ts windowReadable (the launch wait, moved out of surface.ts): when the launched process is gone, the copies of running_before that still run are named in the error. One that has quit since is not blamed. launchFailure in surface.ts adds the same text to the unclaimed error.
  3. The hint stays a condition ("an app that runs one copy at a time ... If this app does"): only the app knows, and the copy may be one another run launched.
  4. capture is split in two: readWindows returns what one read came to (the windows listed, the failure of each window with no accessibility element, the screen if one was read), and readable maps that to the screen or the retryable NODE_STALE as before. The launch wait calls both and keeps the last read's result, or the driver failure of a read that listed nothing. No state is shared with other reads.
  5. packages/desktop/src/launch-report.ts (new) describeLastRead formats that one value as a clause of the unreadable-window error; handOffClause writes the running-copy hint.

surface.ts is over the file-size limit, so the new code is in modules beside it, and the launch wait moved to launch-wait.ts with it: surface.ts is 49 lines shorter than on main (1575, was 1624).

Issue

From a teammate's findings report on the desktop engine (findings 1b, error only, and 6). No Linear tool in this session, so the title carries no ticket id.

Verified

Ran it locally: yes

Built CLI and native driver, background mode, against a scratch single-instance AppKit app in /tmp (a second copy exits 0.4 s after launch when another copy runs). I launched the first copy myself with open -g -n, then ran a test that calls app.open().

mainthis PR
No copy runningpassespasses
A copy running, the new process exits<App> quit right after it launched, before it showed a window (the message at surface.ts:498; not run on main)ENGINE_FAILURE: Single quit right after it launched, before it showed a window: a copy of it was already running (process 32164), and an app that runs one copy at a time hands the launch to that copy and exits. If this app does, quit the running copy first: the engine drives only a copy it launched
A copy running, LSMultipleInstancesProhibited (macOS starts no new process)... was opened, but no new process carries this launch's token, so none can be shown to be its own; the end of the attempt looks for it againthe same, then ; a copy of it was already running (process 32691), and an app that runs one copy at a time hands the launch to that copy and exits. If this app does, quit the running copy first: the engine drives only a copy it launched

The copy I launched was still running after each failed run, then I quit it. The testbed's tests/sign-in.e2e.ts passes on the rebuilt driver (10 of 10).

The unreadable-window message, live, same setup, against two more scratch AppKit apps:

Appapp.open() error on this PR
Its NSWindow is no accessibility element (the window server shows it, AXWindows does not list it)ENGINE_FAILURE: Opaque launched, but its window cannot be read through accessibility: the last read listed 1 window, 1 unreadable. The window may be off screen
Its NSApplication answers AXWindows with nothingENGINE_FAILURE: Opaque launched, but its window cannot be read through accessibility: the last read failed with APP_UNRESPONSIVE (reading the app's windows failed: the app refused the value). The window may be off screen

The other shapes (a window whose snapshot fails, a root that never answers, a read out of time) ran on the scripted driver:

SpikeForm launched, but its window cannot be read through accessibility: the last read listed 2 windows, 2 unreadable; the last read failed with WINDOW_NOT_FOUND (window w-mine has no accessibility element). The window may be off screen
SpikeForm launched, but its window cannot be read through accessibility: the last read listed 1 window, 0 unreadable, 1 whose root element did not answer. The window may be off screen
... cannot be read through accessibility (a read ran out of time): the last read failed with TIMEOUT (TIMEOUT from the fake). The window may be off screen
SpikeForm launched, but its window cannot be read through accessibility: the last read failed with APP_NOT_FOUND (no app has that process id). The window may be off screen

The last of these is the test for stale counts. Run against the source of the second commit (fc7cefaa12) it fails with the last read listed 1 window, 1 unreadable; the last read failed with APP_NOT_FOUND (...): the list of the read before.

pnpm --filter @e2e-dev/desktop test:unit (253 pass, 1 skipped), pnpm check, cargo fmt --check, cargo clippy -D warnings, and cargo test -p e2e-desktop-napi (58 pass, one new for the wire field) pass.

Fresh-context review: four findings, all fixed in the second commit (a stale failure named as the last one, a root-unread window counted as readable, a copy another run launched blamed without a condition, a test that could not fail). The README paragraph it flagged is updated too.

Maintainability review: the ambient launchReads field on the surface is gone (third commit), which also fixes a last read that failed to list being reported with the list of the read before it. The testbed's tests/sign-in.e2e.ts passes again on the rebuilt driver, and after the move of the launch wait (fourth commit, 10 of 10).