Repository navigation
Description
Request: #1292
Problem
In the reporter's words (#1292): test runners that drive devices through simlock's agent-device proxy need a local relay and workarounds before they work. budgie's e2e suite (budgie-at/budgie#1867) runs the e2e runner from Linux against a simlock gateway and hits five gaps:
bootis denied, though the leased simulator is already booted and the e2e engine always sendsbootfirst.- A session
closeends the lease and deletes the simulator mid-run. This covers a bareclose, and alsocloseApp, which sendsclose <bundle id>. - Two runs that share a token share sessions, so they can drive each other's device.
- The allocate reply has no
udid, and nothing says the agent-deviceleaseIdis the simlock lease id. - simlock's errors don't say whether the farm is down or this device or command failed, so callers match message text.
Who it is for
A CI job, or the team writing one, that runs an e2e suite with one leased device per test worker and drives each one through simlock's agent-device front, often from a Linux runner with no Mac. budgie is the first. Agents using the agent-device CLI by hand see no change unless they opt in.
Outcome
A test runner leases devices through the agent-device front and runs its whole suite with no relay in front of simlock:
booton its leased device succeeds and names the device.- It can close and reopen sessions on a lease all run long. The device stays leased until it releases the lease or the TTL runs out.
- Two runs on one token never reach each other's device, whatever session names they use.
- It reads the device's
udid(orserial) from the allocate reply's JSON, or, on agent-device's own client, which drops that field, as theidof thebootanswer. - It tells "simlock or the worker is unreachable, try again" from "refused" and "failed" by a field, not by message text.
How it works for the user
sequenceDiagram
participant R as Test runner
participant F as simlock front
participant A as agent-device
R->>F: allocate, retainOnClose true
F->>A: allocate
F-->>R: lease, lease.device.udid
R->>F: boot --udid U
F-->>R: booted true, id U (answered by simlock)
R->>F: commands, close, new session, commands
F->>A: forwarded, tenant of this lease
A-->>F: close keeps the lease
R->>F: release
F->>A: release
F-->>R: released, device deleted
Note over R,F: an error simlock makes carries a reason and a retriable flag
Before, a runner's boot on its leased simulator:
error: UNAUTHORIZED This daemon's policy denies the boot command.
After:
{ "ok": true, "data": { "platform": "ios", "target": "mobile", "device": "iPhone 17 Pro", "id": "6F2C…", "kind": "simulator", "booted": true } }Before, close on a lease allocated with retainOnClose: true: the allocate is refused with refused: simlock leases only plain devices. After: the allocate is granted with "retainOnClose": true, and after the close the next command on the lease still works.
Before, an error simlock makes:
{ "code": "COMMAND_FAILED", "message": "agent-device is not available on this simlock: no worker connected to this gateway can serve agent-device" }After:
{ "code": "COMMAND_FAILED", "message": "agent-device is not available on this simlock: no worker connected to this gateway can serve agent-device", "details": { "reason": "SIMLOCK_UNAVAILABLE" }, "retriable": true }Examples
| Call | Today | After |
|---|---|---|
boot --udid <leased udid>, lease named |
refused by agent-device's policy | answered by simlock, booted: true |
boot naming no lease |
refused by agent-device's policy | refused by simlock |
boot --udid <another device> |
refused by simlock | refused by simlock |
allocate retainOnClose: true |
refused: simlock leases only plain devices | granted |
bare close, lease without retainOnClose |
lease ends, device deleted | the same |
bare close, lease with retainOnClose |
(cannot happen) | lease stays |
close <bundle id>, lease with retainOnClose |
(cannot happen) | lease stays |
two leases, one token, both session e2e-ios-0 |
one session, one device | two sessions, two devices |
What could go wrong
- A runner that sets
retainOnCloseand never releases keeps its device until the TTL runs out. Likely only when a run is killed, and the TTL ends it. - A front-answered
booton a leased simulator that has crashed saysbooted: true; the next command fails. Rare. - An agent running
session listwith no lease no longer sees its lease sessions.
Words used
- front: the part of simlock that serves the agent-device CLI at
/v1/agent-deviceand checks each call before agent-device sees it. - tenant: agent-device's name for who owns a session, e.g.
p_1.0a1b…; sessions are visible only to their tenant. retainOnClose: an agent-device allocate flag; a lease allocated with it survives a session close.- reason: the string naming why simlock failed a call, e.g.
SIMLOCK_UNAVAILABLE; in a JSON-RPC error aterror.data.details.reason, in a flat error ({ code, error, ok: false }) atreason. - retriable:
truewhen trying again later may succeed; in a JSON-RPC error aterror.data.retriable(where agent-device's client reads it), in a flat error atretriable.
Non-goals
- Releasing every lease of a run by its run id (CI runs: device settings in the lease request, and release every lease of a run #1294).
- An official device provider for the e2e runner, and a Linux CI docs page (An official device provider for the e2e runner, and a docs page for CI from Linux #1298).
- A credential that reaches exactly one lease (No way to give an agent access to exactly one lease: tokens never expire and a shared token is one tenant #1407).
- Labelling errors the front does not make: agent-device's own, simlock's sign-in errors before the front (
UNAUTHENTICATED,FORBIDDEN, documented as carrying no reason), a proxy's in front of simlock (e.g. Cloudflare's 52x), or a refused connection. - Changing what
closedoes for a lease allocated withoutretainOnClose.
Completion conditions
- With real agent-device on iOS, a lease allocated with
retainOnClose: trueanswersboot, survives a barecloseand aclose <app>, takes commands from a new session, and ends on release. - With real agent-device, two leases on one token, each with session
e2e-ios-0, each see only their own device. - The allocate reply names
lease.device.udidon iOS andlease.device.serialon Android, and thebootanswer'sidis the same address. - Every error the front makes, JSON-RPC and flat, carries its reason and retriable flag, and the docs list every reason.
- The agent-device docs page says how a test runner leases (
retainOnClose,boot, theudid, thatleaseIdis the simlock lease id) and what each reason means.
Open questions
Decisions
- ADR 0070 — Test runners drive a lease through the agent-device front (PR docs(adr): accept 0070, test runners drive a lease through the agent-device front (#1419) #1420): the front answers
booton the leased device,retainOnClosekeeps a lease through a close, each lease is its own tenant, and simlock's own errors carry a reason and a retriable flag.
Shared values
| Value or state | Rule | Written by | Read by | Source |
|---|---|---|---|---|
| Device address in the allocate reply | lease.device.udid for iOS, lease.device.serial for Android, beside model; the name addressField(platform) gives; agent-device's client drops it, so its users read the boot reply's id |
#1421 | runners reading the reply's JSON; #1422's boot reply uses the same address as id |
src/agent-device/front/allocate.ts:296-297, 411-427, src/agent-device/shared/selectors.ts:55 |
| Boot reply | { platform, target, device, id, kind, booted: true }; kind simulator, emulator or device; device is the name the front already read from agent-device's device list for the lease, else the model, with no call on boot; target is the allocate's --target, default mobile; a lease simlock ended gets lease ended by simlock; run disconnect, then open, one the agent ended refused: this lease has ended; open a device |
#1422 | runners (the e2e runner reads id and device) |
agent-device packages/daemon/src/sessions/handlers/session-device-status-response.ts:21-39; e2e runner surface.js:368-369 |
| Lease tenant | for a call naming a lease the token holds (an RPC naming it, or a non-RPC call carrying x-agent-device-lease-id, such as an upload or an artifact download): on a worker <principal part>.<leaseId>, on a gateway gw.<instance>.<principal part>.<leaseId>, which the gateway's relayTenant makes and the worker uses as it is; each part escaped as tenantPart escapes it, and cut to 128 characters with a hash when longer, as relayTenant cuts today; a call naming no lease keeps today's tenant |
#1424 | the session-folder cleanup (host/lease-end.ts), agent-device's sessions, uploads and artifacts |
src/agent-device/front/relay-host-link.ts:85-97, src/agent-device/worker.ts:67, src/agent-device/front/front.ts:363, agent-device packages/contracts/src/daemon-http.ts:41, packages/remote/src/upload-client.ts:218, packages/remote/src/artifact-download.ts:93, packages/daemon/src/core/tenant-owned-entry.ts:33 |
| Error reason and retriable | six reasons REFUSED_BY_SIMLOCK, SIMLOCK_UNAVAILABLE, WORKER_UNREACHABLE, NO_DEVICE_IN_TIME, SIMLOCK_FAILED, LEASE_ENDED_BY_HOST; retriable follows the condition (#1423's table: a full farm, a stopping daemon, an agent-device start failure, a lease check to retry are true; a refusal of the request itself is false); on every error the front makes: JSON-RPC at error.data.details.reason and error.data.retriable, flat at reason and retriable beside code; code unchanged |
#1423 | runners, agent-device's client (retriable from error.data only); #1422's boot refusal carries REFUSED_BY_SIMLOCK once #1423 lands |
src/agent-device/shared/replies.ts:3-94, agent-device src/daemon-client/daemon-client-rpc.ts:127, 147 |
Behaviours
| Behaviour (invoker, action, what it sees) | Seam | Cases | Task |
|---|---|---|---|
A runner allocates with retainOnClose: true, closes, and its lease stays: the next heartbeat and command work and release frees the device |
agent-device front (src/agent-device/edge.test.ts) |
bare close; close <app>; a batch with a close step |
#1421 |
| A runner reads the device address from the allocate reply | agent-device front (src/agent-device/edge.test.ts) |
iOS simulator udid; Android emulator serial |
#1421 |
A runner sends boot on its lease and simlock answers it; agent-device gets no boot |
agent-device front (src/agent-device/edge-request-rules.test.ts) |
iOS simulator; Android emulator; physical phone; a lease taken with --target tv; name read from the device list; model only; --udid of the lease; --device of its name |
#1422 |
A boot that names no lease, another token's lease, an ended lease or another device is refused |
agent-device front (src/agent-device/edge-request-rules.test.ts) |
no lease and no device; another token's lease; another device's udid; a --platform other than the lease's; a lease simlock ended; a lease the agent ended |
#1422 |
| Calls of two leases on one token reach agent-device as two tenants, and every call of one lease as one | agent-device front, worker and gateway (src/agent-device/edge.test.ts, src/agent-device/gateway-front.test.ts) |
allocate, heartbeat, command, release of one lease; the release simlock sends at lease end; an upload and an artifact download carrying the lease header; a lease header naming another token's lease on a worker (refused 403); two leases; a call naming no lease; gateway; a principal long enough to need the hash | #1424 |
| A lease's session folders are removed at lease end under its tenant | agent-device host (src/agent-device/session-folders.test.ts) |
lease released; lease ended by simlock | #1424 |
| With real agent-device on iOS, a runner's lease boots, survives closes, serves a new session, keeps two same-named sessions apart and ends on release | slow lane (e2e/slow-agent-device.test.ts) |
one run of the whole flow | #1424 |
| Every error the front makes carries its reason and retriable flag; agent-device's errors pass unchanged | agent-device front, worker and gateway (src/agent-device/edge.test.ts, src/agent-device/gateway-front.test.ts) |
each of the six reasons, as a JSON-RPC error; an allocate refused for a model simlock lacks and one failed with NO_CAPACITY; agent-device start-failed and wrong-version; a lease check failure; a flat error (an upload through an unavailable worker); an agent-device error |
#1423 |
Tasks
flowchart LR
T1[#1421 retainOnClose and address] --> T2[#1422 front answers boot] --> T3[#1424 tenant per lease and slow test]
T4[#1423 error reasons] --> T3
- A lease may keep its device through a close, and the allocate reply names the device #1421 A lease may keep its device through a close, and the allocate reply names the device — a runner can close and reopen sessions, and finds the udid without parsing. Risk: a close ends a retained lease anyway, and the runner loses its device mid-run.
- The agent-device front answers boot on the leased device #1422 The front answers
booton the leased device — a runner'sbootsucceeds. Risk: a boot naming another device gets through, or the reply lacksid. - Each lease is its own agent-device tenant #1424 Each lease is its own agent-device tenant — two runs on one token never share a session. Risk: a lease's calls get two tenants and agent-device loses its session or lease.
- Errors the agent-device front makes carry a reason and a retriable flag #1423 simlock's errors carry a reason and a retriable flag — a runner branches on a field. Risk: a reason marks a refusal retriable and a runner retries forever.
Completion conditions: the real-agent-device ones by #1424; the address by #1421; the reasons by #1423; the docs page by each task for its part, leaseId being the simlock lease id by #1421.
Open work in the same area:
- CI runs: device settings in the lease request, and release every lease of a run #1294 (release by run id): another request; no task yet. No Depends on.
- An official device provider for the e2e runner, and a docs page for CI from Linux #1298 (official e2e provider, Linux CI docs): builds on this feature; its spec should depend on Each lease is its own agent-device tenant #1424.
- No way to give an agent access to exactly one lease: tokens never expire and a shared token is one tenant #1407 (one-lease credential): another request; no shared code.
- agent-device: a worker can keep an idle iOS runner #1088 and PR feat(agent-device): a worker can keep an idle iOS runner (#1088) #1091 (keep an idle iOS runner): change
host/agent-device-supervisor.ts, which this feature does not touch. No Depends on. - agent-device: a worker restart ends every lease whose device is still running #1103 (worker restart ends leases): touches
front/heartbeat.ts; Each lease is its own agent-device tenant #1424 changes only the tenant passed to the forward. No Depends on.
Written by an agent.
Activity
V3RON commentedon Nov 7, 2026
Spec updated: all sections written from the spec session. ADR 0070 (PR #1420) is proposed, and the tasks are #1421, #1422, #1424 and #1423.
Written by an agent.
docs(adr): accept 0070, test runners drive a lease through the agent-…
V3RON commentedon Nov 7, 2026
Delivery run
Merged: none; the feature stays in one open stack.
Parked: #1422 — slow-lane check exited 69 because worker pid 89138 holds
/Users/aitwar/.simlock; hardware line 2 remains unverified. PR #1439 carriesneeds-hardware.Waiting: #1424 — on #1422 hardware clearance. #1421 (PR #1436) and #1423 (PR #1437) are reviewed, ready and CI-green; both wait for the complete feature stack.
Decided: #1422 — unsupported
runtime.udidis ignored; boot replies still name only the held lease. Recorded in the task and PR, pending the maintainer.Next: free the slow-lane machine, restore #1422 to
task:ready, and resume delivery. Verify its hardware criterion before delivering #1424 and merging the stack. Nothing was stopped or reconfigured.Written by an agent.
github-actions commentedon Nov 8, 2026
Closing: all 4 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.docs(adr): accept 0070, test runners drive a lease through the agent-…
github-actions commentedon Nov 8, 2026
Closing: all 4 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.feat(agent-device): label front errors with retry guidance (#1437)
V3RON commentedon Nov 8, 2026
Delivery run
Merged: #1420 (ADR 0070), #1437 (#1423), #1436 (#1421), #1439 (#1422), #1453 (#1424)
Parked: none
Waiting: none
Decided: none
Written by an agent.