Skip to content

Test runners work through the agent-device proxy without a relay #1419

Closed
4 of 4 issues completed
Closed

Description

@V3RON

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:

  1. boot is denied, though the leased simulator is already booted and the e2e engine always sends boot first.
  2. A session close ends the lease and deletes the simulator mid-run. This covers a bare close, and also closeApp, which sends close <bundle id>.
  3. Two runs that share a token share sessions, so they can drive each other's device.
  4. The allocate reply has no udid, and nothing says the agent-device leaseId is the simlock lease id.
  5. 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:

  • boot on 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 (or serial) from the allocate reply's JSON, or, on agent-device's own client, which drops that field, as the id of the boot answer.
  • 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
Loading

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 retainOnClose and 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 boot on a leased simulator that has crashed says booted: true; the next command fails. Rare.
  • An agent running session list with no lease no longer sees its lease sessions.

Words used

  • front: the part of simlock that serves the agent-device CLI at /v1/agent-device and 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 at error.data.details.reason, in a flat error ({ code, error, ok: false }) at reason.
  • retriable: true when trying again later may succeed; in a JSON-RPC error at error.data.retriable (where agent-device's client reads it), in a flat error at retriable.

Non-goals

Completion conditions

  • With real agent-device on iOS, a lease allocated with retainOnClose: true answers boot, survives a bare close and a close <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.udid on iOS and lease.device.serial on Android, and the boot answer's id is 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, the udid, that leaseId is the simlock lease id) and what each reason means.

Open questions

Decisions

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
Loading

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:

Written by an agent.

Sub-issues

Sub-issues

4 of 4 Issues completed
Loading 4 sub-issues

Activity

  1. added
    feature:spec
    on Nov 7, 2026
  2. V3RON commented on Nov 7, 2026

    @V3RON
    ContributorAuthor

    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.

  3. added
    feature:planned
    and removed
    feature:spec
    on Nov 7, 2026
  4. V3RON commented on Nov 7, 2026

    @V3RON
    ContributorAuthor

    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 carries needs-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.udid is 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.

  5. github-actions commented on Nov 8, 2026

    @github-actions
    Contributor

    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.

  6. github-actions commented on Nov 8, 2026

    @github-actions
    Contributor

    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.

  7. V3RON commented on Nov 8, 2026

    @V3RON
    ContributorAuthor

    Delivery run

    Merged: #1420 (ADR 0070), #1437 (#1423), #1436 (#1421), #1439 (#1422), #1453 (#1424)
    Parked: none
    Waiting: none
    Decided: none

    Written by an agent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature:planned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions