Commit b3324a7
fix(device-record): refuse multi-sim ambiguity, thread deviceId through script (#177)
Closes #173 (sub-issue 1).
Symptom: device_record action=start silently picked one of multiple booted
simulators non-deterministically, costing the user a 175s recording when
it captured iPhone 15 Pro's home screen while iPhone 17 Pro was being
driven by Maestro. The shell script's `xcrun simctl io booted recordVideo`
and `adb shell screenrecord` both use implicit device resolution that
breaks under multi-device conditions.
Fix shape:
1. New `deviceId` arg on device_record start (iOS UDID or Android serial).
2. Pre-flight resolver in the TS handler:
- 0 candidates → existing NO_DEVICE path
- 1 candidate, no deviceId → auto-select; mark autoSelected: true
- explicit deviceId (any candidate count) → must match a candidate
or refuse with code=DEVICE_AMBIGUOUS listing all candidates. An
explicit selection is authoritative — a stale or typo'd UDID is
a failure mode, not a hint.
- >1 candidates, no deviceId → DEVICE_AMBIGUOUS with the candidate
list so the caller knows the valid identifiers (the GH #173 surface)
3. Echo `deviceId` and `autoSelected` in the start response so callers
can verify they got the device they meant.
4. record_proof.sh accepts `--udid <UDID>` (iOS) and `--serial <SERIAL>`
(Android) flags, threads them into `xcrun simctl io <UDID>` and
`adb -s <SERIAL>`. Falls back to `booted`/auto when no flag passed
(single-device case, backward-compatible).
5. Android stop path now reads the persisted serial sidecar and uses
`adb -s <serial>` for pkill/pull/rm. Without this, multi-device stop
would hit "ambiguous device" or operate on the wrong target — codex-pair
caught the gap during review.
6. Defensive: on every Android start, unconditionally write OR clear the
serial sidecar. Leaving a stale sidecar from a prior recording would
misroute the next stop to a now-disconnected device — also codex-pair.
Implementation details:
- parseAllBootedIosDevices: returns ALL booted simulators (not just first)
- parseAllAdbDevices: returns ALL connected devices including physical
(parseAdbDevicesEmu in device-screenshot-raw.ts only matches emulator-*;
for device_record's ambiguity check we need physical devices too)
- resolveTargetDevice: pure function exported for unit tests
- Backward-compatible: single-device callers see no change (autoSelected,
no flag forwarded to the script)
Tests (1481/1481 passing, +10 net new):
- parseAllBootedIosDevices: returns all booted, skips Shutdown
- parseAllBootedIosDevices: empty/malformed JSON → []
- parseAllAdbDevices: returns emulators AND physical devices (key
distinction from device-screenshot-raw's emu-only parser)
- parseAllAdbDevices: skips header and empty lines
- resolveTargetDevice: 1 candidate, no deviceId → auto-select
- resolveTargetDevice: 1 candidate + mismatched deviceId → AMBIGUOUS
(the design fix codex-pair pushed back on — explicit-selection-is-
authoritative)
- resolveTargetDevice: 1 candidate + matching deviceId → use it (not
auto-selected)
- resolveTargetDevice: >1 candidates + matching deviceId → use it
- resolveTargetDevice: >1 candidates + no deviceId → AMBIGUOUS with
full candidate list (THE GH #173 fix surface)
- resolveTargetDevice: >1 candidates + non-matching deviceId →
AMBIGUOUS (typo surfaces fast)
Out of scope (not introduced by this PR; flagged by codex-pair as
pre-existing issues in record_proof.sh):
- /tmp PID file used for `kill` without strict validation (HIGH)
- /tmp venv path predictable (HIGH)
- Literal `$` instead of `$$` in raw_file/device_path names — typo'd
unique suffix (MED)
These should be addressed in a separate hardening pass.
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>1 parent a18669f commit b3324a7
6 files changed
Lines changed: 493 additions & 9 deletions
File tree
- scripts
- cdp-bridge
- dist
- tools
- src
- tools
- test/unit
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
14 | 105 | | |
15 | 106 | | |
16 | 107 | | |
| |||
66 | 157 | | |
67 | 158 | | |
68 | 159 | | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
69 | 189 | | |
70 | | - | |
| 190 | + | |
71 | 191 | | |
72 | 192 | | |
73 | 193 | | |
74 | 194 | | |
75 | 195 | | |
76 | 196 | | |
77 | 197 | | |
| 198 | + | |
| 199 | + | |
78 | 200 | | |
79 | 201 | | |
80 | 202 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
743 | 743 | | |
744 | 744 | | |
745 | 745 | | |
746 | | - | |
| 746 | + | |
747 | 747 | | |
748 | 748 | | |
749 | 749 | | |
750 | 750 | | |
| 751 | + | |
751 | 752 | | |
752 | 753 | | |
753 | 754 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
24 | 152 | | |
25 | 153 | | |
26 | 154 | | |
| |||
97 | 225 | | |
98 | 226 | | |
99 | 227 | | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
100 | 267 | | |
101 | 268 | | |
102 | 269 | | |
103 | | - | |
| 270 | + | |
104 | 271 | | |
105 | 272 | | |
106 | 273 | | |
| |||
110 | 277 | | |
111 | 278 | | |
112 | 279 | | |
| 280 | + | |
| 281 | + | |
113 | 282 | | |
114 | 283 | | |
115 | 284 | | |
| |||
0 commit comments