fix(desktop): give the launch wait's last read the slowest read's time

VA
2h ago
+289-15

What

app.open() on the desktop engine reports an unreadable window the same way every time. A read only runs out of time when it is slower than the reads before it, and a window that becomes readable in the last read the wait starts still opens.

Why

windowReadable gave each read only what was left of the 10 s wait. A read starting a few milliseconds before the deadline timed out however fast the app answered, so the same unreadable window got two different errors depending on where the 100 ms poll landed. It also flaked surface.test.ts "names the failure the last read of an unreadable window answered with" on CI. Core's waits already solve this with ReadWindow; the launch wait now follows the same rule.

How it works

  1. ReadWindow is exported next to Deadline from @e2e-dev/core/engine (packages/core/src/engine/index.ts:54), and windowReadable runs each read through it, with the wait's deadline and the operation's deadline as the cap (packages/desktop/src/launch-wait.ts:50, packages/desktop/src/launch-wait.ts:65), where it used to pass only deadline - Date.now(). Each read may run until the wait's deadline plus the slowest finished read, capped by the operation's deadline, so no read runs past the operation's budget and an open bounded by its own budget still ends as OPERATION_TIMEOUT. A read that fails retryably inside the read itself does not count toward the slowest finished read, as in core's waits.
  2. A read that started with less than one poll tick, or the slowest finished read, of the wait left and that gave no answer counts as cut off by the wait ending, not by a slow app (packages/desktop/src/launch-wait.ts:74, with the rule in ReadWindow.cutOff). The error then describes the read before it as the last read, with no "(a read ran out of time)". A read that started with more than that and still timed out keeps that wording.
  3. New unit tests drive windowReadable on a fake clock with scripted read times, so the last read lands a sliver before the deadline on every run (packages/desktop/tests/unit/launch-wait.test.ts).

Alternative dropped: skipping the last read when too little time is left. That keeps the message stable but drops a window that becomes readable at the end of the wait, which the current tests require to open.

Issue

Fixes #2455

Verified

Ran it locally: yes

Desktop unit tests drive the engine through a scripted driver on any OS, so they are the surface for this change. The desktop testbed needs a Mac with the native driver, which this machine does not have. No pnpm bench:ab table: the benchmark suites run the web engine and the runner, and neither exercises the desktop launch wait.

New tests first, on main, then with this change (pnpm --filter @e2e-dev/desktop exec vitest run tests/unit/launch-wait.test.ts):

mainthis PR
5 failed, 7 passed. The sliver test got "SpikeForm launched, but its window cannot be read through accessibility (a read ran out of time): the last read that finished listed 1 window, 1 unreadable. The window may be off screen", the late-readable test failed the open with the same message, and the 10 s operation test and the two hang tests (a last read starting with less than the slowest read left, and one starting with less than one poll tick left) flipped the same way12 passed

Full desktop unit suite with this change (pnpm --filter @e2e-dev/desktop run test:unit): 9 files passed, 285 tests passed, 3 skipped. Core time tests (pnpm --filter e2e exec vitest run tests/unit/time.test.ts): 31 passed. Desktop, core, and e2e typecheck and repo lint clean.

Checklist

  • Changeset added (pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only.
  • Breaking change: title carries !, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md).
  • Docs updated in the same PR: the docs/**/*.mdx page for the behavior, and skills/e2e/ if the skill describes it.
  • Contract change: emitted .d.ts reviewed, tests/types/sdk-types.ts updated; wire change edits the schema and both fixtures.
  • Engine contract change (e2e/engine): changesets for e2e, @e2e-dev/web, and @e2e-dev/mobile.

Summary by CodeRabbit

  • Bug Fixes
    • Improved reporting when desktop app launches encounter unreadable windows, including when the app is running in the background.
    • Adjusted the final window read so it can use the remaining wait time while staying within the overall launch timeout. This helps distinguish a read that ends with the wait from one that times out on its own.
  • New Features
    • Added a reusable timing utility for managing window reads against an operation’s deadline.