Give each concurrent test action its own simulator via a per-(device, OS) pool #3026
All Vouch review confidence checks passed
Residual risk 0.33 = Change Risk (0.59) × (1 − Review Confidence (0.45)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.59 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #3026"
general
weight: 0.35
erneestoc
Summary
Split out from #3021 per review feedback, redesigned as a simulator pool after further discussion: instead of serializing concurrent tests on one shared simulator, each concurrent test action gets its own.
Problem
A simulator can only service one test session at a time. Two failure modes follow whenever Bazel actually executes several simulator tests concurrently (CI runs
--local_test_jobs=2):1. Session collisions: concurrent
xcodebuild test-without-building/xctestsessions against the same reused simulator disrupt each other — 300s hangs, orFailed to initialize for UI testing: … kAXErrorCannotComplete.2. Creation races: concurrent tests racing through the create action each fail to find an existing simulator and create same-named duplicates. CI logs from #3021 show two
BAZEL_TEST_iPhone 16_26.0devices created 3 seconds apart, with every simulator test on that machine hanging from then on.These are the dominant source of iOS test flakiness on this repo's CI. They stay invisible on main because the affected tests are almost always remote-cache hits; any PR that touches the runner invalidates those caches and forces real concurrent executions (#3021 hit this for 6 consecutive builds across 8 different agents until the interim locks landed on its branch).
Design
shlock(1)pid lockfile in$TMPDIR. Slots are not keyed on device type or OS version, so a single invocation running tests across several simulator types still hands every concurrent test its own device.…_1,…_2), which stays booted between test actions for warm reuse like slot 0.${SIMULATOR_POOL_LOCK_DIR:-${TMPDIR:-/tmp}}. Bazel pointsTMPDIRat the per-user temp dir (/var/folders/…/T/), which is shared across sandboxed test actions and writable there — unlikeTEST_TMPDIR, which is per-action. Verified underdarwin-sandboxwith two concurrent test actions.TMPDIRis not part of the action's declared environment (bazel aqueryshows onlyPATH), so under remote execution the worker decides what it is, and a worker handing each action its ownTMPDIRwould silently put every test back on slot 0.--test_env=SIMULATOR_POOL_LOCK_DIR=…points the pool at a directory the execution environment actually shares. Set-but-unusable warns and falls back rather than failing the test.shlockatomically reclaims dead slots. (First attempt used a kernel flock held on an fd vialockf(1); abandoned because macOSlockf's fd mode misbehaves under try-lock probing — after one failed probe, every subsequent probe in that process fails even on free lock files.)xcodebuild test-without-buildingsits silent until the Bazel timeout — the device is carrying a dead test session from a previously terminated test, and every new session against it hangs. Two complementary defenses: (1) the runner traps TERM/INT after claiming its simulator and shuts the device down (Bazel delivers SIGTERM with a grace period before SIGKILL), so the next attempt cold-boots clean; (2) for deaths the trap cannot catch — SIGKILL, grace overruns — the runner keeps a session marker holding its pid (same pid-liveness pattern as the pool locks), removed on any controlled exit, and the creator reboots any booted device whose marker names a dead pid before reusing it. Normal completions leave the device booted for warm reuse, in every slot. This also self-heals agents whose devices are already wedged: the first attempt still times out, but the device is recycled and the retry passes.simctl bootstatus -bhas no deadline of its own, so a device wedged mid-boot consumed the whole test timeout and was SIGKILLed — leaving it wedged for the next attempt. The boot is now bounded against the test's ownTEST_TIMEOUT(minus a 30s cleanup reserve, 30s floor — the bound exists to fail cleanly before SIGKILL, not to ration boot time, so slow first-boot data migrations still get nearly the whole budget), and a timed-out boot is deliberately left in progress: the boot is owned by CoreSimulatorService and continues in the background, so a flaky-test retry re-entersbootstatusand resumes where the previous attempt left off — a slow first-boot data migration completes across attempts instead of restarting from zero each time.bootedwhile being unusable — if the test that started its initial boot was killed partway through, the device staysbootedbut never becomes able to run tests, and every later test reusing it hangs. Reusedbooteddevices are now probed for readiness (SpringBoard insimctl spawn <udid> launchctl list, bounded at 30s) and rebooted if not responding.ios_test_runner(doesn't setSIMULATOR_POOL_SLOT→ slot 0 → today's behavior),reuse_simulator = False, device runs, and machines withoutshlock(1)(degrades to today's single-simulator behavior).Review feedback addressed
$TMPDIRinstead of shelling out togetconf DARWIN_USER_TEMP_DIR.--local_test_jobsalready bounds overlapping boots.SIMULATOR_POOL_SLOTnow parses as a hard error instead of silently falling back to slot 0.SIMULATOR_POOL_LOCK_DIRso the lock directory is configurable for execution environments that do not share$TMPDIR.Test plan
darwin-sandbox(shared$TMPDIRis writable and lockable there, and identical across concurrent test actions, under bothdarwin-sandboxand--spawn_strategy=local).SIMULATOR_POOL_LOCK_DIR: three concurrent claimers with differing$TMPDIRs still get distinct slots when pointed at a shared dir; unwritable dir, missing dir and unset$TMPDIRall fall back to slot 0 immediately instead of hanging; propagation through--test_envconfirmed.//test:ios_xctestrun_runner_ui_testbehaves identically to main; single-test runs claim slot 0 and reuse the historically-named simulator.