Repository navigation
Description
Request: none
Problem
A developer or agent whose leased device runs on another machine cannot point their everyday tools at it. simlock tunnel carries TCP between the caller's machine and a leased Android device, but only to ports inside Android, and an iOS simulator's lease is refused. So on iOS, Metro, a mock API or Flutter's hot reload cannot cross machines. On Android, a local adb, and so Android Studio's debugger, Layout Inspector, profilers and Logcat, cannot see the remote emulator at all, because adb reaches an emulator through a port the emulator program opens on the worker, not a port inside Android.
Who it is for
A developer or coding agent on their own machine, holding a lease on a simulator or emulator that runs on a worker reached through a gateway or on a lone worker over HTTP. They build and serve the app locally (Metro, Expo, Flutter, a mock backend) and want their local debugger and IDE to work on the remote device.
Outcome
- On a leased iOS simulator,
simlock tunnel forward <port>reaches a port an app in that simulator listens on, andsimlock tunnel reverse <port>lets an app in it reachlocalhost:<port>on the caller's machine, as on Android today. - An iOS forward never reaches anything on the worker but the lease's own simulator: not Simlock's daemon, its adb server, or another lease's app.
simlock tunnel emulator adbmakes the caller's own adb list the remote emulator, so Android Studio and every adb-based tool work on it.- An iPhone lease stays refused, and an emulator port on a phone or an iOS lease is refused, each with a message that says what is supported.
How it works for the user
flowchart TD
A[simlock tunnel ... on the caller's machine] --> B{lease}
B -->|iOS simulator: forward/reverse| C[READY, one line per tunnel]
B -->|Android emulator: emulator adb| D[READY, then adb connect runs]
B -->|iPhone, or emulator adb on a phone/iOS| E[refused TUNNEL_UNSUPPORTED, exit 1]
C --> F{forward connection}
F -->|the lease's simulator listens| G[bytes flow]
F -->|another process or none| H[that connection closed, tunnel stays]
C --> I{reverse port free on the worker?}
I -->|no| J[refused TUNNEL_PORT_IN_USE, exit 1]
D --> K{adb found and connected?}
K -->|no| L[warning with the command to run, tunnel stays]
Before, iOS:
$ simlock tunnel reverse 8081
{"code":"TUNNEL_UNSUPPORTED","message":"Lease 3f2a: the lease is on an iOS simulator; tunnels need an Android emulator or phone"}
After, iOS:
$ simlock tunnel reverse 8081 forward 9100
reverse device:8081 -> localhost:8081 (lease 3f2a)
forward localhost:9100 -> device:9100 (lease 3f2a)
Another lease on the same worker already reversed 8081:
$ simlock tunnel reverse 8081
{"code":"TUNNEL_PORT_IN_USE","message":"Lease 3f2a: reverse 8081: port 8081 is already in use on the worker; pick another port"}
After, Android:
$ simlock tunnel emulator adb
emulator localhost:61544 -> emulator:adb (lease 9c1d)
adb: connected to 127.0.0.1:61544
$ adb devices
List of devices attached
127.0.0.1:61544 device
No adb on the caller's machine:
$ simlock tunnel emulator adb:6000
emulator localhost:6000 -> emulator:adb (lease 9c1d)
warning: emulator adb: adb was not found; run: adb connect 127.0.0.1:6000
Examples
| Command, lease | Today | After |
|---|---|---|
forward 9100, iOS simulator, its app listens on 9100 |
TUNNEL_UNSUPPORTED |
bytes flow |
forward 9100, iOS simulator, app listens on ::1 only |
TUNNEL_UNSUPPORTED |
bytes flow |
forward 5038, iOS simulator, port is the worker's adb server |
TUNNEL_UNSUPPORTED |
tunnel opens; each connection closed, and stderr shows warning: forward 5038: nothing on the lease's simulator listens on port 5038 |
forward 9100, iOS simulator, another lease's simulator listens |
TUNNEL_UNSUPPORTED |
connection closed, same message |
reverse 8081, iOS simulator, port free on the worker |
TUNNEL_UNSUPPORTED |
READY |
reverse 8081, iOS simulator, port taken on 127.0.0.1 or ::1 |
TUNNEL_UNSUPPORTED |
TUNNEL_PORT_IN_USE |
reverse <the worker's HTTP port>, iOS simulator, port held on all interfaces (0.0.0.0 or ::) |
TUNNEL_UNSUPPORTED |
TUNNEL_PORT_IN_USE |
| any device-port tunnel, iPhone | TUNNEL_UNSUPPORTED |
TUNNEL_UNSUPPORTED, new message |
emulator adb, Android emulator |
usage error | READY, adb connect |
emulator adb:6000, Android emulator |
usage error | READY on caller port 6000 |
emulator adb, Android phone or iOS |
usage error | TUNNEL_UNSUPPORTED |
emulator console, emulator grpc, emulator 5555 |
usage error | usage error |
emulator adb:80 |
usage error | usage error (caller port 1024 to 65535) |
emulator adb emulator adb |
usage error | usage error |
forward 6000 emulator adb:6000 |
usage error | usage error (same caller port twice) |
What could go wrong
- Two people on one worker both want Metro's 8081 on iOS: the second is refused and must move Metro to another port. Likely on a busy worker.
- An iOS forward to an app that listens on a port only briefly may be closed if the check runs before the app listens. Rare.
- A Play Store emulator image shows
unauthorizedin the caller's adb. Only when someone leases such an image. - The caller's adb reboots or kills the app on its own lease's emulator. Expected; it is their device.
Words used
- device port: a port opened on the leased device, e.g. Flutter's VM Service on 9100 or Metro's 8081 an app connects to. On an iOS simulator it is a port on the worker Mac's loopback, because a simulator shares the Mac's network.
- emulator port: a port the emulator program opens on the worker for one emulator, chosen by name, e.g.
adb, which is the emulator's console port + 1 (5587 foremulator-5586). - caller port: the port on the caller's machine, e.g.
6000inemulator adb:6000. - owner check: before an iOS forward connection, the worker finds the process listening on the port and accepts it only when its environment says
SIMULATOR_UDID=<the lease's simulator>.
Non-goals
- iPhone tunnels (usbmuxd), Android
localabstractsockets, the emulator console and gRPC ports. - Named tool presets (
--tool metro), finding a port from the device log, running a host-bound tool (xctrace) on the worker, moving files. - Leasing host ports with the device (Host ports leased with the device #162).
- Filtering what the caller's adb does to its own emulator.
- Making a Play Store image accept the caller's adb key.
Completion conditions
- On a real iOS simulator against a lone worker,
simlock tunnel forward <p>reaches a listener in that simulator, and a forward to a worker port no simulator owns has its connection closed with the message. - On a real iOS simulator,
simlock tunnel reverse <p>lets a process in the simulator reachlocalhost:<p>on the caller. - A second
reverseof a port already taken on the worker is refusedTUNNEL_PORT_IN_USE. - On a real emulator through a gateway,
simlock tunnel emulator adbmakes a separate adb server list the emulator asdevice,adb shell echo okprintsok, and Simlock's own adb server still lists the emulator after the tunnel exits. - An iPhone lease and
emulator adbon a phone or iOS lease are refusedTUNNEL_UNSUPPORTEDwith the messages in Shared values. remote-agents.mdx,errors.mdxandcli.mdxdescribe iOS tunnels andsimlock tunnel emulator adb.
Open questions
Decisions
- ADR 0064 — A tunnel reaches an iOS simulator's ports and an emulator's adb port (PR docs(adr): propose 0064, a tunnel reaches an iOS simulator's ports and an emulator's adb port (#1282) #1287): the two target kinds, the iOS owner check and exact-port reverse, the
adbemulator port and full adb for the holder, the CLI's adb connect, no protocol bump.
Shared values
| Value or state | Rule | Written by | Read by | Source |
|---|---|---|---|---|
TUNNEL_UNSUPPORTED message, device ports |
the lease is on an iPhone; tunnels need an Android emulator or phone, or an iOS simulator (an iOS simulator no longer gets it) |
#1288 | #1289 | src/core/device-tcp.ts:16-19 (today's text) |
TUNNEL_UNSUPPORTED message, emulator port |
emulator adb: the lease is on <an Android phone|an iOS simulator|an iPhone>; emulator ports need an Android emulator |
#1289 | — | new |
| iOS forward reset reason | RESET {reason} with nothing on the lease's simulator listens on port <p>, for no listener and for a listener of any other process; the tunnel and other connections stay |
#1288 | — | src/tunnel/AGENTS.md 3a (failed connect is RESET {reason}) |
| CLI forward reset warning | stderr warning: forward <d>: <the RESET reason> (an emulator tunnel: warning: emulator adb: <the RESET reason>), at most once per 10 s per tunnel, every platform; reasons carry no tunnel prefix; the tunnel stays |
#1288 | #1289 | src/cli/commands/tunnel.ts:247-249 (today the reason is dropped) |
| iOS reverse in-use refusal | TUNNEL_PORT_IN_USE reverse <p>: port <p> is already in use on the worker; pick another port, when anything already answers a connect to 127.0.0.1:<p> or [::1]:<p> (a listener on all interfaces, 0.0.0.0 or ::, included), or 127.0.0.1:<p> or [::1]:<p> cannot be bound; nothing stays bound. macOS lets the two loopback binds succeed while another process holds the port on all interfaces, so the bind alone is not the check |
#1288 | — | src/ports/tcp-listener.ts:24-25 (in-use is its own answer); round-0 check on this Mac: a process held [::]:46811, then Node bound 127.0.0.1:46811 and ::1:46811 |
HELLO and OPEN emulator entry |
{kind:"emulator", emulatorPort:"adb"}; READY echoes it; the caller's OPEN for it carries the same JSON with an even id; any other emulatorPort or a missing one is BAD_REQUEST HELLO tunnels must each be {kind, devicePort} or {kind: "emulator", emulatorPort: "adb"}; it counts toward the 8 tunnels per lease |
#1289 | #1289 | src/tunnel/sessions.ts:74-87 |
emulator adb port |
127.0.0.1:<console port + 1> of the lease's emulator, console port from its serial emulator-<console port> |
#1289 | — | src/drivers/android/adb-registrar.ts:29-31, src/drivers/android/adb-tools.ts:145 |
| CLI emulator syntax | emulator adb[:<caller-port>]; caller port 1024 to 65535, else a free loopback port; one emulator adb per command; no caller port twice across all tunnels; other names usage errors |
#1289 | — | src/cli/commands/tunnel.ts:48-81 |
| CLI emulator output | stdout emulator localhost:<c> -> emulator:adb (lease <id>) once READY; after adb connect 127.0.0.1:<c> prints connected to, stdout adb: connected to 127.0.0.1:<c>; otherwise stderr warning: emulator adb: <adb was not found|adb answered: <adb's first line>|adb did not answer in 10 s>; run: adb connect 127.0.0.1:<c> |
#1289 | — | src/cli/commands/tunnel.ts:497-502 (line pattern) |
| CLI adb lookup and disconnect | adb is adb (adb.exe on Windows) on PATH, else platform-tools/adb (adb.exe on Windows) under the first of $ANDROID_HOME, $ANDROID_SDK_ROOT, then Android Studio's default SDK folder (~/Library/Android/sdk; on Windows %LOCALAPPDATA%\Android\Sdk) that holds it, the same folders the Android driver searches, in a list of the CLI's own because the CLI never imports a driver; adb connect waited at most 10 s; on every exit after a connect was run, adb disconnect 127.0.0.1:<c> waited at most 2 s, its failure ignored |
#1289 | — | src/drivers/android/sdk-paths.ts:28-50 (the driver's folders), src/cli/AGENTS.md:8 (never imports drivers) |
Behaviours
| Behaviour (invoker, action, what it sees) | Seam | Cases | Task |
|---|---|---|---|
| The iOS driver says which leases take device-port tunnels | iOS driver device-tcp, fake processes and listeners | simulator → yes; iPhone → no, with the iPhone message through the tunnel module | #1288 |
| A holder's iOS forward connection reaches the port only when the lease's simulator listens there, lookup output taken from F18's real lines | iOS driver device-tcp, fake processes and listeners | lease's simulator on 127.0.0.1 → bytes both ways; on ::1 only → bytes; on * → 127.0.0.1 dialled; lease's app on * and another process on 127.0.0.1 → ::1 dialled; lease's app on [::1] and another simulator's on 127.0.0.1 → ::1 dialled, never 127.0.0.1; another simulator's process → reset with the reason; a worker process with no SIMULATOR_UDID, or with SIMULATOR_UDID=<udid> only inside an argument → reset; lookup exit 1, no output → reset "nothing … listens"; lookup exit 2 → reset "could not check the port's owner"; lookup or connect still pending at 5 s → reset timeout, at 4.9 s still waiting; a second connection after the app moved to another simulator's process → reset (checked per connection) |
#1288 |
| A holder's iOS reverse listens on exactly the device port, on both loopbacks | iOS driver device-tcp, fake listeners | both free → connections from 127.0.0.1 and ::1 arrive; 127.0.0.1 taken → TUNNEL_PORT_IN_USE, ::1 not left bound; ::1 taken → same, 127.0.0.1 not left bound; another process holds 0.0.0.0:<p> or [::]:<p> → TUNNEL_PORT_IN_USE, nothing bound; close frees both ports |
#1288 |
| A lease end with an aborted signal (nuke, a stopping daemon) still closes reverses whose rules need no reclaim | worker module over a lease socket, fake device-tcp | a fake device-tcp whose reverse needs no reclaim → close runs and its ports are freed; an emulator-like fake → close skipped, as today |
#1288 |
| A user's forward connection that the worker resets shows the reason | CLI command, fake ports | first reset → warning: forward <d>: <reason> on stderr; a second within 10 s → nothing; one 10 s later → printed again; the tunnel stays |
#1288 |
| On a real simulator against a lone worker, iOS forward and reverse work and the owner check holds | slow lane e2e/slow-ios-tunnel.test.ts |
forward to a listener in the simulator; forward to a worker-only listener → connection closed and the warning names the reason; reverse from the simulator to the caller's localhost; a second reverse of the same port → TUNNEL_PORT_IN_USE |
#1288 |
A holder's HELLO with an emulator entry is checked and answered |
worker module over a lease socket, fake device-tcp | {kind:"emulator", emulatorPort:"adb"} on an emulator → READY echoing it; with two device-port tunnels → 3 counted toward 8; emulatorPort console or missing → BAD_REQUEST; on a phone, an iOS simulator, an iPhone → TUNNEL_UNSUPPORTED with the emulator-port message |
#1289 |
| A holder's emulator connection reaches the emulator's adb port | worker module, fake device-tcp | caller OPEN emulator → bytes both ways; OPEN emulator when HELLO named none → BAD_REQUEST, 4003; the port refuses → RESET {reason}, tunnel stays |
#1289 |
| The real loopback listener asked for any free port reports the port it bound | NodeTcpListenerFactory, real sockets |
listen(0) → a port above 0 that a client can connect to; listen(<a taken port>) → undefined, as today |
#1289 |
| The catalog says which leases take an emulator port | core driver catalog, fake drivers | a driver whose deviceTcp has the emulator members → delegated; one without them (iOS) → unsupported; no deviceTcp → unsupported |
#1289 |
| The Android driver connects an emulator port to the right worker port | Android driver device-tcp, fake connector | emulator-5586 → 127.0.0.1:5587; emulator-5682 → 5683; a phone → unsupported; nothing listening → TUNNEL_FAILED with the reason; no answer in 5 s → TUNNEL_FAILED timeout |
#1289 |
A user runs simlock tunnel emulator adb… and sees the tunnel line, and adb connected or a warning |
CLI command, fake ports and fake process runner | emulator adb (free port → the bound port, not 0, in the line and in adb connect); reverse 8081 emulator adb → one HELLO with both, two lines, a reverse OPEN still reaches localhost:8081; * daemon not running then connected to → info line; already connected to → info line; emulator adb:6000 → READY on 6000; adb missing on PATH and in every SDK folder → warning; found only under $ANDROID_HOME → used; found only in the default SDK folder → used; adb answers failed to authenticate → warning with that line; adb hangs past 10 s → warning; the worker resets an emulator connection → warning: emulator adb: <reason>, once per 10 s; on Ctrl-C, a refusal after READY, lease end and a lost connection → adb disconnect run; disconnect fails → exit code unchanged; disconnect hangs → exit at 2 s, code unchanged; Ctrl-C while connect still runs → connect killed, no warning, disconnect run |
#1289 |
A user's simlock tunnel emulator … that cannot run exits 2 with a usage error, and the help line names emulator adb[:<caller-port>] |
CLI command | tunnel emulate adb (unknown kind); emulator console; emulator grpc; emulator 5555; emulator; emulator adb:80; emulator adb:70000; emulator adb:; emulator adb emulator adb; forward 6000 emulator adb:6000 |
#1289 |
| On a real emulator through a gateway, the caller's own adb sees and drives the emulator | slow lane e2e/slow-android-tunnel.test.ts |
a separate adb server (its own port and HOME) lists device; shell echo ok → ok; after exit Simlock's server still lists the emulator device |
#1289 |
Tasks
flowchart LR
ADR[#1287 ADR 0064] --> T1[#1288 iOS simulator tunnels]
T1 --> T2[#1289 emulator adb port]
- iOS simulator tunnels: forward only to the lease's simulator, reverse on the exact port #1288 iOS simulator tunnels — a holder forwards to and reverses from a leased iOS simulator, only ever reaching that simulator. Risk: a forward is closed because the check misreads the listener.
- simlock tunnel emulator adb: the caller's own adb sees the remote emulator #1289 the
adbemulator port —simlock tunnel emulator adbmakes the caller's adb and Android Studio see the remote emulator. Risk: the caller's adb shows the emulator offline.
Completion conditions: the first three and the iPhone refusal → #1288; the emulator one and the emulator-port refusals → #1289; the docs line → both, each for its part.
Open work in the same area:
- Size test: a code file stays at 1,400 lines and a test file at 2,500 #1263–Android driver: catalog.ts owns device profiles, fit and the resolved-spec cache #1273 (the size test and the Android driver split, Split the source and test files too big for agents to read whole #1259): merged on 2026-11-04.
src/drivers/ios/index.tsandsrc/daemon/main.tsare on the size test's shrink-only list; iOS simulator tunnels: forward only to the lease's simulator, reverse on the exact port #1288 and simlock tunnel emulator adb: the caller's own adb sees the remote emulator #1289 keep their logic in other files and raise those listed numbers by the wiring lines they add, each saying so in its PR. No dependency left. - Host ports leased with the device #162 Host ports leased with the device: the same worker loopback port space as iOS reverse; no dependency, ADR 0064 lets iOS reverse refuse a taken port, and Host ports leased with the device #162's ports would simply be taken.
- ios.simulator.headless false shows each simulator in DeviceHub or Simulator.app #1239 iOS headless window (task:ready): edits the same
IosSimctlDriver.createcall insrc/daemon/main.ts, the iOS driver's options type,src/drivers/ios/AGENTS.mdand the same two shrink-only lines; iOS simulator tunnels: forward only to the lease's simulator, reverse on the exact port #1288 depends on ios.simulator.headless false shows each simulator in DeviceHub or Simulator.app #1239. - Through a gateway, simlock adb and simctl take live input (an interactive mode) #1177 live input for
simlock adbthrough a gateway:device.exec, not the tunnel; no dependency.
Written by an agent.
Activity
V3RON commentedon Nov 5, 2026
Spec updated: Problem to Shared values and Behaviours written; tasks #1288 (iOS simulator tunnels) and #1289 (
simlock tunnel emulator adb) added; ADR 0064 on #1287.Written by an agent.
docs(adr): propose 0064, a tunnel reaches an iOS simulator's ports an…
feat(tunnel): simlock tunnel emulator adb, the caller's own adb sees …
github-actions commentedon Nov 5, 2026
Closing: all 2 sub-issues are closed. The PR that closed the last one walks the completion conditions (delivery rule 9); reopen this if one does not hold on
main. Flip its ADRs to Accepted if delivery has not.github-actions commentedon Nov 5, 2026
Closing: all 2 sub-issues are closed. The PR that closed the last one walks the completion conditions (delivery rule 9); reopen this if one does not hold on
main. Flip its ADRs to Accepted if delivery has not.V3RON commentedon Nov 5, 2026
Delivery run
Merged: #1287 (ADR 0064), #1336 (#1288), #1346 (#1289)
Parked: none
Waiting: none
Decided: #1288 — prove a connect that resolves after the 5 s reset → a test case pins its stream closed; #1288 — prove the
::1host of the Node listener, probe and connector → a::1case in eachsrc/portstest (the slow lane does not reach it); #1289 — an Android driver with notcpStreamConnector→ a case pins theTUNNEL_FAILEDrefusal; #1289 — the daemon's emulator-port wiring → proven by the slow lane onlyAsleep: 2 min
Written by an agent.