Repository navigation
fix(mobile): boot a shut-down device when none is booted and no device is named - #1674
Conversation
…e is named With no `device` and nothing booted, the engine called agent-device's boot with only the platform, which fails with AMBIGUOUS_MATCH on any Mac with several simulators. Pass agent-device's opt-in `pick: 'newest'` (0.21.35+) when the selection names no device. Fixes ENG-1037
There was a problem hiding this comment.
1 issue found across 10 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/mobile/src/pool.ts">
<violation number="1" location="packages/mobile/src/pool.ts:66">
P2: A shut-down inventory entry can still be claimed by another session, but `bind()` checks claims only on booted entries and returns `[{}]` when none are booted; this request can therefore take the held device. Filter cold candidates with the same own-session predicate before requesting `pick: 'newest'`.
(Based on your team's feedback about cold-pick session ownership.)</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
| */ | ||
| export function bootRequest(selection: DeviceSelection): DeviceSelection & Pick<DeviceBootOptions, 'pick'> { | ||
| const named = selection.device ?? selection.udid ?? selection.serial; | ||
| return named === undefined ? { ...selection, pick: 'newest' } : selection; |
There was a problem hiding this comment.
P2: A shut-down inventory entry can still be claimed by another session, but bind() checks claims only on booted entries and returns [{}] when none are booted; this request can therefore take the held device. Filter cold candidates with the same own-session predicate before requesting pick: 'newest'.
(Based on your team's feedback about cold-pick session ownership.)
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At packages/mobile/src/pool.ts, line 66:
<comment>A shut-down inventory entry can still be claimed by another session, but `bind()` checks claims only on booted entries and returns `[{}]` when none are booted; this request can therefore take the held device. Filter cold candidates with the same own-session predicate before requesting `pick: 'newest'`.
(Based on your team's feedback about cold-pick session ownership.) </comment>
<file context>
@@ -54,6 +55,17 @@ export function deviceSelection(
+ */
+export function bootRequest(selection: DeviceSelection): DeviceSelection & Pick<DeviceBootOptions, 'pick'> {
+ const named = selection.device ?? selection.udid ?? selection.serial;
+ return named === undefined ? { ...selection, pick: 'newest' } : selection;
+}
+
</file context>
There was a problem hiding this comment.
[claude-opus-5-5] responding on behalf of krzysztof
Valid, and it is agent-device's pick, not e2e's: the tie-break (J in agent-device 0.21.36's sdk-device.js) sorts the shut-down candidates by target, OS, and name and never reads claimedBy. No boot option or selector field lets e2e exclude a device from it. The only e2e-side fix is picking the device in e2e and binding its UDID, the approach #1433 dropped in favor of the upstream pick.
The realistic trigger is narrow: two runs starting on a cold Mac at once, where the second lists the device the first is still booting as shut down but claimed. Before this PR both failed with AMBIGUOUS_MATCH; now both can pick the same device. Leaving this open for the maintainer: accept it until agent-device's pick skips claimed devices, or pick in e2e.
🟢 e2e ios agent: 21 passed, 1 skipped25 agent steps · 12 replayed from cache · 75 model calls · 582.1k tokens (78% cached) · $0.0455 All 22 tests in 1 file
Tested by e2e 0.23.0 · 10m 9s · ios-simulator · run artifacts |
🟢 e2e android agent: 20 passed24 agent steps · 15 replayed from cache · 42 model calls · 242.4k tokens (83% cached) · $0.0160 All 20 tests in 1 file
Tested by e2e 0.23.0 · 7m 25s · android-emulator · run artifacts |
🟢 e2e ios: 55 passed, 1 skippedAll 56 tests in 7 files
Tested by e2e 0.23.0 · 6m 53s · ios-simulator · run artifacts |
🟢 e2e android: 57 passed, 1 skippedAll 58 tests in 7 files
Tested by e2e 0.23.0 · 10m 33s · android-emulator · run artifacts |
|
[claude-opus-5-5] responding on behalf of krzysztof Ready for review. Left for a human:
|
|
I changed |
I filed callstack/agent-device#4402 |
An iOS target with no
device, on a Mac where no simulator is booted, failse2e runinprepare:The
e2e initiOS preset writesmobile({ platform: 'ios' }), so the first run of a fresh project hits this on most Macs.Issue
Refs ENG-1037
Cause
With nothing booted, the pool binds one empty slot, and both
warmand the worker'sinitcalldevices.boot({ platform: 'ios' }). agent-device ranks every shut-down iPhone simulator equally and throwsAMBIGUOUS_MATCH.Fix
bootRequest(packages/mobile/src/pool.ts) addspick: 'newest'when the selection names no device. Both boot calls go through it. A named device, UDID, or serial is sent unchanged.newestprefers a phone or tablet over a TV, then the newest OS, then name order (not device age:iPhone 16esorts beforeiPhone 17). Several booted matches still fail. Shut-down Android AVDs report no OS version, so on Android the name decides.mobile.mdx, thedeviceoption JSDoc and its reference copy, the skill's setup reference) say how the device is picked.Known gaps, all in agent-device
A Vision Pro simulator can win the pick. agent-device reports visionOS simulators as
target: 'mobile'and ranks them level with iPhones under--platform ios, and no selector field excludes them. On equal OS versions the name decides, soApple Vision ProbeatsiPhone 17. Checked with agent-device's ownresolveInventoryDeviceSelectionon 0.21.36 and on0.21.37-nightly.20261110.154: shut-down Apple Vision Pro, iPhone 17 Pro, iPhone 17, and iPad Pro, all on 26.1, giveApple Vision Pro; without the Vision Pro,iPhone 17. So on a Mac with the visionOS runtime installed, the run goes from a clearAMBIGUOUS_MATCHto booting the Vision Pro and failing later. Macs without that runtime get the fix. Naming adeviceavoids both. The real fix is ranking visionOS below iOS in agent-device's pick, not a second picker in e2e (the approach #1433 dropped).The pick ignores session claims. agent-device's tie-break never reads
claimedBy, so two runs starting at once on a cold Mac can both pick the device the first is still booting. Before this PR both failed withAMBIGUOUS_MATCH. Left open for the maintainer in the review thread.A paired iPhone that isn't connected counts as booted.
Verifying this on a Mac with a paired iPhone turned up callstack/agent-device#4209 (reported from #1528): agent-device lists a paired iPhone that CoreDevice cannot reach as
booted: true. With nothing booted, e2e then drives that phone instead of reaching the no-booted path, and the run fails at app launch. The fix, callstack/agent-device#4210, merged on 2026-11-04, after 0.21.36, so it is only in nightlies. No e2e change is needed for it: the pool already readsbooted. Once agent-device 0.21.37 ships, a bump picks it up, and ENG-1037 can be closed after a live run on a Mac with a paired phone.Verified
Ran it locally: no - the live simulator run was blocked by callstack/agent-device#4209 (above); unit tests only.
tests/unit/engine.test.tsandprovider.test.tsnow expect{ platform: 'ios', pick: 'newest' }for an unscoped boot, and the existing UDID tests still expect nopick. RevertingbootRequestfails all four.e2e initiOS preset (Settings app, nodevice), built packages, main and this branch. On both, agent-device listed the unavailable paired iPhone as booted (Unreachable paired iOS device is listed as booted and passes boot callstack/agent-device#4209 above), so e2e logged1 booted ios device(s); driving 1: <the paired iPhone>and never reached the changed code. No simulator was booted.bootrefuses,--pick newestboots iPhone 17, two booted devices still refuse).Made with Claude Opus 5.5 (
claude-opus-5-5) in Claude Code, running inside T3 Code.