fix(ios-runner): a caller deadline no longer kills a starting runner
Merged
OK
2mo ago+703+703+012345678901234567890123456789-78-78-01234567890123456789
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.tsowns the typed distinction (a separate module grew the Apple facade eager-import closure, which the budget test rejects):isCallerDeadlineAbortReason,callerDeadlineExpired(moved fromrunner-client.ts), andresolveRunnerStartupSignal, which forwards the registered request signal and every non-deadline abort but drops a caller deadline.ensureRunnerSessionopens the startup budget on that signal. A client disconnect still kills the xctestrun build and launch.executeRunnerCommandno longer invalidates a starting session when the abort was the caller's deadline; the session staysstartingand the next request joins it through the existing reuse path. The error still carriesreadinessPhase: 'runner-start'.RunnerSession.launchDeadlineopens when the runner process is launched (the request'sstartupTimeoutMs, else the 45 s default). Every joiner measures readiness from that one clock, and the reuse check retires astartingsession past it (ios_runner_session_invalidated, reasonrunner_launch_budget_exhausted) so the same request relaunches. A hung runner is given up once, not once per joiner.ensureRunnerSessionopens the start budget fromstartupTimeoutMs, elseDEFAULT_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 typedrunner_start_budget_exhausted; a start that fails after its caller left logsios_runner_detached_start_failed. The build budget is the remainder of that clock (an explicitbuildTimeoutMscan only shorten it), andlaunchDeadlinenever exceeds what remains. Sizing:preparedefaults to 240 s for the same work, the iOS CI lane gives a coldprepare420 s, and the wait on a peer's build of the same artifact is already 10 min.ensureRunnerSessionruns 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 oneager-closure-budgets.test.ts(new module in the facade closure) and Smoke on anxcrun --show-sdk-versionETIMEDOUT probe before the test ran (#2940).- New tests: a
TimeoutErrorabort during launch leaves the launch signal unaborted, the sessionstarting, 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, thenwait text General 4000three 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 withwait_readiness_exhausted/readinessPhase: runner-start(4190 ms wall). The detached start went on:ios_runner_startup_ensure_xctestrunclosed at 52.316 withdurationMs: 5342,launch_xcodebuildat 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_timings10718 ms total) and succeeded at 53.898. #3 and a later #4 succeeded in about 250 ms on that runner. Zeroios_runner_detached_start_failed, zerorunner_start_budget_exhausted, onelaunch_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_xctestrunrejects 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 explicitstartupTimeoutMsbounds the whole start ahead of the default. Both fail with the timer neutered.