fix(ios-runner): a caller deadline no longer kills a starting runner

Merged
OK
2mo ago
+703-78

Summary

Closes #2894.

A wait poll bounds each attempt with an abort whose reason is a TimeoutError (runWithinWaitDeadline). ensureRunnerSession merged that signal with the request cancellation and handed the result to the detached xcodebuild test-without-building launch, where exec kills the process tree on abort. So a short-timeout wait that landed during runner start killed the runner, the lifecycle invalidated the half-started session, and the retry paid the whole start again: on a slow host it never caught up.

This is option (b) from the issue: the start is budgeted by startupTimeoutMs only.

  • runner-contract.ts owns the typed distinction (a separate module grew the Apple facade eager-import closure, which the budget test rejects): isCallerDeadlineAbortReason, callerDeadlineExpired (moved from runner-client.ts), and resolveRunnerStartupSignal, which forwards the registered request signal and every non-deadline abort but drops a caller deadline.
  • ensureRunnerSession opens the startup budget on that signal. A client disconnect still kills the xctestrun build and launch.
  • executeRunnerCommand no longer invalidates a starting session when the abort was the caller's deadline; the session stays starting and the next request joins it through the existing reuse path. The error still carries readinessPhase: 'runner-start'.
  • RunnerSession.launchDeadline opens when the runner process is launched (the request's startupTimeoutMs, else the 45 s default). Every joiner measures readiness from that one clock, and the reuse check retires a starting session past it (ios_runner_session_invalidated, reason runner_launch_budget_exhausted) so the same request relaunches. A hung runner is given up once, not once per joiner.
  • ensureRunnerSession opens the start budget from startupTimeoutMs, else DEFAULT_RUNNER_START_BUDGET_MS (10 min), once the session lock is held. The budget owns a timer that aborts the start's signal when spent, so the xctestrun build and launch are killed through exec, the lock is released and a caller still attached gets a typed runner_start_budget_exhausted; a start that fails after its caller left logs ios_runner_detached_start_failed. The build budget is the remainder of that clock (an explicit buildTimeoutMs can only shorten it), and launchDeadline never exceeds what remains. Sizing: prepare defaults to 240 s for the same work, the iOS CI lane gives a cold prepare 420 s, and the wait on a peer's build of the same artifact is already 10 min.
  • ensureRunnerSession runs the lock-held start detached and races it against the caller's own signal. A wait whose deadline lands mid cold build returns on time; the build is neither killed nor repeated, and the next request queues on the session lock and joins the session it registers. The HTTP progress sink skips a response that already ended, since a detached start can emit progress after its caller returned.

Touched: 4 source files, 2 test files (1 new).

Validation

Tested commit 8ebce7d3e (rebased on 16e07572a; adds the start budget the whole start owns).

  • pnpm check:affected --run: passed on this head. The first push failed Coverage on eager-closure-budgets.test.ts (new module in the facade closure) and Smoke on an xcrun --show-sdk-version ETIMEDOUT probe before the test ran (#2940).
  • New tests: a TimeoutError abort during launch leaves the launch signal unaborted, the session starting, the lease retained, and a second command reuses it with one xcodebuild launch total; a plain abort and the registered request signal still kill the start; six unit cases on the signal helper. Reverting the lifecycle change fails the liveness assertion; reverting the session change fails the launch-signal assertion.
  • Live, iPhone 17 Pro / iOS 26.5 simulator, CLI at 8ebce7d3e, --json --debug, Settings open: removed the xctestrun cache and the snapshot-bridge cache, killed the bridge and the runner, then wait text General 4000 three times back to back. #1 (request_start 19:15:46.711Z) opened the runner start at 46.928, the xctestrun rebuild began at 46.978 (runner_xctestrun_cache: rebuild), and the response left at 50.714 with wait_readiness_exhausted / readinessPhase: runner-start (4190 ms wall). The detached start went on: ios_runner_startup_ensure_xctestrun closed at 52.316 with durationMs: 5342, launch_xcodebuild at 52.325. So the deadline landed 3.7 s into a 5.3 s build, 1.6 s before launch. #2 (start 50.912) joined the same session at 52.328 (ios_runner_session_reuse, ios_runner_session_startup_timings 10718 ms total) and succeeded at 53.898. #3 and a later #4 succeeded in about 250 ms on that runner. Zero ios_runner_detached_start_failed, zero runner_start_budget_exhausted, one launch_xcodebuild.
  • Tests: a second deadline-bounded request joining a start past its launch budget sees the invalidation, a second xcodebuild launch and a new session; a deadline firing mid ensure_xctestrun rejects the caller while the build is still pending, leaves the build signal unaborted and lets the next request join with one build and one launch total. Against the previous head the second test hangs for the full vitest timeout.
  • Tests for the start budget: a build that never resolves, caller deadline fired, request registration cleared; the next request settles within the default under fake timers with the build signal aborted (runner_start_budget_exhausted), the lock released, the device relaunched. An explicit startupTimeoutMs bounds the whole start ahead of the default. Both fail with the timer neutered.