Repository navigation
Description
Part of #1503.
Scope
Each driver can name every phone plugged into the worker by USB, enrolled or not, without sending anything to a phone. Nothing reads it yet: the next task's auto-enroll does. No user-visible change.
In short
A new driver read, listAttachedPhysical(), answers the canonical IDs of the phones on USB: the Android USB serial, the iOS UDID. It answers in any adb or pairing state, so a phone that is not trusted yet is listed. A phone reached only over the network, an emulator and a simulator are not listed. When the platform cannot be read, it throws, so a caller can't mistake a failed read for "no phones".
flowchart LR
C[caller] --> D["Driver.listAttachedPhysical() (new)"]
D --> A["Android: adb devices -l on 5037, behind the protocol gate"]
D --> I["iOS: devicectl list devices"]
If this goes wrong, a user would later see a plugged-in phone never auto-enrolled, or a log line about a network phone.
Technical spec
Facts
Commit e4adf46 (origin/main).
| # | Fact | Source |
|---|---|---|
| F1 | Driver declares inspectPhysical and listPresentPhysical(enrolledIds); there is no method that lists every phone. |
src/core/driver.ts:322-323 |
| F2 | Four classes implement it: the Android driver, the iOS driver, core's FakeDriver and the e2e fake driver. |
git grep -n "listPresentPhysical(" on origin/main: src/drivers/android/index.ts:700, src/drivers/ios/index.ts:1527, src/core/fake-driver.ts:599, e2e/fake-driver/fake-driver.ts:607 |
| F3 | Android runs adb -P 5037 devices -l through #run, which first calls #gate.check() and answers blocked with no command when it is not open. A non-zero exit or a throw answers failed. |
src/drivers/android/physical-handler.ts:323-335, :186 |
| F4 | parseDevices marks an entry usb when a token starts with usb:; on Windows, also when the serial is not a network or emulator serial. |
src/drivers/android/physical-handler.ts:344-355, :363-365 |
| F5 | Today a failed Android listing is read as no entries, so every enrolled phone reads not present. | src/drivers/android/physical-handler.ts:186-187 |
| F6 | iOS runs devicectl list devices --json-output <file> with a 30 s limit, reading result.devices. A timeout, a non-zero exit, or a missing or malformed list answers ok: false. |
src/drivers/ios/physical.ts:325-337, :382-391 |
| F7 | iOS presence counts an entry only with transportType wired and reality not simulated. pairingState other than paired is untrusted. |
src/drivers/ios/physical.ts:201-204 |
| F8 | pickEntry prefers a wired entry when one UDID is listed more than once. |
src/drivers/ios/physical.ts:107-114 |
| F9 | The Android canonical ID is the USB serial; the iOS one is the UDID. | ADR 0022 §6 |
| F10 | When nothing listens on 5037 the gate is open, so adb -P 5037 devices -l starts the default server, as any physical adb command may. |
src/drivers/android/physical-handler.ts:323-328; ADR 0022 §5 "Simlock's call may start that server" |
Modules touched
Searches: listPresentPhysical( (F2), parseDevices, #list(.
flowchart LR
CD["core/driver.ts (changed)"]
AD["drivers/android index + physical-handler (changed)"]
ID["drivers/ios index + physical (changed)"]
FD["core/fake-driver.ts (changed)"]
ED["e2e/fake-driver (changed)"]
AD --> CD
ID --> CD
FD --> CD
ED --> CD
src/core/driver.ts:listAttachedPhysical(): Promise<readonly string[]>onDriver, with a doc comment: canonical IDs of USB phones in any state, sorted, no duplicates; throws when the platform cannot be read.src/drivers/android/physical-handler.ts,index.ts: fromparseDevices, everyusbentry's serial. TheList of devices attachedheader line is no entry: todayparseDevicesreads it as serialList, stateof, and on Windows marks itusb(F4), so the listing drops it (orparseDevicesstops returning it).blockedorfailedthrows anErrornaming the reason (the gate's message, or "could not read the device list (adb devices -l)").src/drivers/ios/physical.ts,index.ts: from#list, theudidof every entry withtransportTypewiredandrealitynotsimulated, in anypairingState.ok: falsethrows with itswhy.e2e/fake-driver/fake-driver.tsandtypes.ts: the fake listsids[0]of every scripted physical device that is attached:presentis notfalse, orabsentReasonislockedoruntrusted.src/core/fake-driver.ts: its presence is the separate mapsetPhysicalPresencefills, and a device is not present until it is called (src/core/fake-driver.ts:73-80,:198). It listsids[0]of each device whose presence is set to present, or absent with reasonlockedoruntrusted. A scripted failure throws, like the fake's other scripted calls.docs/internal/agent-rules/safety.mdrules 7 and 8: name the host-level USB list as the one read made beyond enrolled IDs (ADR 0073 §5).src/drivers/android/AGENTS.md"Physical phones": the listing may start the 5037 server (F10).
Contract and event changes
None: Driver is internal. Searched src/contract for listPresentPhysical: no hits.
Other code on the same state
None. The new read keeps no state and runs the same host commands the presence read does (F3, F6). Searched for devices -l and "list", "devices": the presence and inspection reads only, each a separate invocation.
Failure modes
| Call | Outcome | What happens | Limit, counted from |
|---|---|---|---|
Android adb devices -l |
ok | USB serials listed | 30 s (READ_TIMEOUT_MS, physical-handler.ts:24), from the call |
| Android | gate not open | throws the gate's message; no adb command runs |
the gate's 5 s (ADR 0022 §5), from the check |
| Android | exits non-zero, times out or throws | throws | 30 s |
iOS devicectl list devices |
ok | wired UDIDs listed | 30 s, from the call |
| iOS | timed out, non-zero, malformed | throws with the reason | 30 s |
No state is written.
Rules in play
- Safety rule 7, "read only for enrolled IDs": narrowed by ADR 0073 §5 to allow the host-level list. This task edits the rule's text to say so.
- Safety rule 8, "
listPresentPhysical()answers only for enrolled IDs": unchanged for that method. The new one is named as the exception. - ADR 0022 §5, "Right before every physical
adbcommand it sends … reads the server's protocol version": the listing goes through#run, so the gate runs first. - Safety rule 1, "never runs a command on one that is not enrolled": both commands are host-level and name no phone.
src/drivers/android/AGENTS.md, "The 5037 server is never started, stopped or adopted on purpose": the listing may start it as a side effect ofadb, as today's reads do (F10). This task adds that to the manual's line.
Tests
Seam: each handler's own test file with its scripted process runner, modelled on the listPresentPhysical describes (src/drivers/android/physical-handler.test.ts:1059, src/drivers/ios/physical.test.ts). Fixtures are copies of real adb devices -l and devicectl list devices output already used there (src/drivers/ios/fixtures/devicectl-list-devices.json holds wired, localNetwork and sameMachine entries).
- The Android driver lists the phones on USB: one table,
usb:indevice,unauthorizedandofflineare listed; a192.168.1.5:5555serial andemulator-5554are not; a protocol mismatch throws and runs noadbcommand; a non-zeroadbexit throws; on Windows (platform: "win32", as thephysical handler on Windowsdescribe at:1659) a USB serial is listed and the header line is not. - The iOS driver lists the wired phones: one table, wired
pairedand wiredunpairedare listed; alocalNetworkentry, asameMachineentry and asimulatedentry are not; one UDID listed wired and over the network is listed once; a timeout, a non-zero exit and a missingresult.devicesthrow.
Done when
pnpm exec vitest run --project unit src/drivers/android/physical-handler.test.tsand… src/drivers/ios/physical.test.tspass, with the two Tests lines' cases.Driver.listAttachedPhysicalexists on every implementer in F2 (git grep -n "listAttachedPhysical("), and CI's typecheck passes.- Safety rules 7 and 8 name the host-level list.
Out of scope
- Calling the new read, the config key, the events: A worker enrols the phones plugged into it under devices.autoEnroll #1508.
- Phones on the network (Enrol Android phones reached over the network (adb connect host:port) #1250).
Depends on
Written by an agent.
Activity
test: the iOS driver lists the wired phones (#1507)
feat(drivers): the iOS driver and the fakes list the phones on USB (#…
feat(drivers): drivers list the phones on USB, enrolled or not (#1511)