From d27c8d512e456a8f43ebdb1cf9048ef2de04da67 Mon Sep 17 00:00:00 2001 From: Vitalii Yehorov Date: Tue, 3 Nov 2026 08:53:00 +0100 Subject: [PATCH 1/7] fix(agent-device): an allocate's device mode reaches the lease request (#1223) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The agent-device front built the lease request from a fixed field list, so a request for a full iOS simulator got the worker's default. It now reads agent-device's `deviceMode` (`--device-mode`) into the lease's `mode` (ADR 0007 §2), refuses one that is neither slim nor full, and keeps it off the allocate agent-device receives. Co-Authored-By: Claude Opus 5.5 --- src/agent-device/AGENTS.md | 6 +++--- src/agent-device/edge.test.ts | 20 +++++++++++++++++++ src/agent-device/front/allocate.ts | 7 +++++++ src/agent-device/shared/rpc.ts | 2 ++ .../docs/docs/using-devices/agent-device.mdx | 3 ++- 5 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/agent-device/AGENTS.md b/src/agent-device/AGENTS.md index a370cf633..6b881acd6 100644 --- a/src/agent-device/AGENTS.md +++ b/src/agent-device/AGENTS.md @@ -91,12 +91,12 @@ under leasing's signal (`lease.endWaitMs`). ## Flow: agent on a worker 1. CLI `open` → `POST /v1/agent-device/rpc` `agent_device.lease.allocate` with its lease id. -2. Front refuses a non-plain lease, no `--platform`, a bad `ttlMs`, no lease id, a `physical` that is not a boolean, or a `--target` it does not map. +2. Front refuses a non-plain lease, no `--platform`, a bad `ttlMs`, no lease id, a `physical` that is not a boolean, a `deviceMode` that is not `slim` or `full`, or a `--target` it does not map. 3. `lease.request`: `leaseId` = `requesterId` = the CLI's lease id; `--device` → model, - `--target` → class, `--os` → `osVersion`, `--image-tag` → `imageTag`, `physical: true` → `physical: true` (Simlock picks an enrolled phone); TTL = sent, capped by `capabilities.agent-device.leaseTtlCapMs`, at least 5 s; + `--target` → class, `--os` → `osVersion`, `--image-tag` → `imageTag`, `--device-mode` (`deviceMode`) → `mode`, `physical: true` → `physical: true` (Simlock picks an enrolled phone); TTL = sent, capped by `capabilities.agent-device.leaseTtlCapMs`, at least 5 s; queue wait 330 s. CLI hangs up → `lease.cancel`, retried every 1 s. 4. Grant → allocate forwarded with the device address (`udid`/`serial`; a phone's is its enrolled id), to the phone daemon for a phone and the simulator daemon otherwise (`RoutedHostLink`, which remembers each lease's daemon until the lease ends), no - `device`/`deviceKey`/`target`/`osVersion`/`imageTag`/`physical` (commands lose both keys too), `ttlMs` = max(24 h, 2 × `lease.maxTtlMs`). + `device`/`deviceKey`/`target`/`osVersion`/`imageTag`/`deviceMode`/`physical` (commands lose both keys too), `ttlMs` = max(24 h, 2 × `lease.maxTtlMs`). 5. agent-device error → simlock lease released. Success → front map entry; reply relayed with `data.lease.device` `{ model, osVersion, physical, imageTag? }` added from the grant. 6. Commands carry the lease id; rules check, renewals run, `devices` filtered. 7. Release → agent-device first, then `lease.release` → reclaim; lease-end finds no scope left. diff --git a/src/agent-device/edge.test.ts b/src/agent-device/edge.test.ts index f11d24dff..11db79875 100644 --- a/src/agent-device/edge.test.ts +++ b/src/agent-device/edge.test.ts @@ -751,6 +751,26 @@ describe("the agent-device front, through the whole worker daemon", () => { } }); + it('allocate with `deviceMode` "full" or "slim" makes a lease request whose `mode` is it and an allocate the agent-device daemon receives without it; a `deviceMode` that is neither is refused with `refused: deviceMode must be slim or full` and no lease', async () => { + const rig = await setUp({ maxRunning: 8 }); + + await granted(rig, 1, { deviceMode: "full" }); + await granted(rig, 2, { deviceMode: "slim" }); + for (const deviceMode of ["fast", 1]) { + await refused( + rig, + () => allocate(rig, 3, { deviceMode }), + "refused: deviceMode must be slim or full", + ); + } + + expect(await requestedSpecs(rig, hex(1))).toEqual([{ mode: "full", platform: "ios" }]); + expect(await requestedSpecs(rig, hex(2))).toEqual([{ mode: "slim", platform: "ios" }]); + expect(receivedAllocate(rig, 1)).not.toHaveProperty("deviceMode"); + expect(receivedAllocate(rig, 2)).not.toHaveProperty("deviceMode"); + expect(await listed(rig)).toEqual([hex(1), hex(2)]); + }); + it("the relayed allocate reply carries `data.lease.device` as `{ model, osVersion, physical: false }` on iOS and on Android without a tag, and with `imageTag` on Android with one, the daemon's `deviceKey` and `data.device` unchanged", async () => { const rig = await setUp({ drivers: (clock) => [ diff --git a/src/agent-device/front/allocate.ts b/src/agent-device/front/allocate.ts index e91c115ce..95131f6ce 100644 --- a/src/agent-device/front/allocate.ts +++ b/src/agent-device/front/allocate.ts @@ -44,6 +44,7 @@ const CLASS_OF_TARGET: Record = { }; const present = (value: unknown): boolean => value !== undefined && value !== null; +const MODES: readonly unknown[] = ["slim", "full"]; interface Plan { readonly leaseId: string; @@ -52,6 +53,7 @@ interface Plan { readonly class?: "phone" | "tv" | "desktop"; readonly imageTag?: string; readonly osVersion?: string; + readonly mode?: "slim" | "full"; readonly physical?: true; readonly ttlMs?: number; } @@ -83,6 +85,9 @@ function notPlain(params: Record): boolean { function deviceRefusal(fields: ReturnType): FrontReply | undefined { if (!present(fields.platform)) return refusal("refused: name --platform ios or android"); + if (present(fields.deviceMode) && !MODES.includes(fields.deviceMode)) { + return refusal("refused: deviceMode must be slim or full"); + } return undefined; } @@ -119,6 +124,7 @@ function stringFields(fields: ReturnType) { return { ...(typeof fields.imageTag === "string" ? { imageTag: fields.imageTag } : {}), ...(typeof fields.osVersion === "string" ? { osVersion: fields.osVersion } : {}), + ...(present(fields.deviceMode) ? { mode: fields.deviceMode as "slim" | "full" } : {}), }; } @@ -268,6 +274,7 @@ function forwardedBody( const { device: _device, deviceKey: _deviceKey, + deviceMode: _deviceMode, imageTag: _imageTag, osVersion: _osVersion, physical: _physical, diff --git a/src/agent-device/shared/rpc.ts b/src/agent-device/shared/rpc.ts index e168d9e7f..17f4e429d 100644 --- a/src/agent-device/shared/rpc.ts +++ b/src/agent-device/shared/rpc.ts @@ -98,12 +98,14 @@ export interface LeaseCallFields { readonly deviceKey: unknown; readonly imageTag: unknown; readonly osVersion: unknown; + readonly deviceMode: unknown; } export function leaseCallFields(params: Record): LeaseCallFields { return { device: params["device"], deviceKey: params["deviceKey"], + deviceMode: params["deviceMode"], imageTag: params["imageTag"], leaseId: params["leaseId"], osVersion: params["osVersion"], diff --git a/website/src/content/docs/docs/using-devices/agent-device.mdx b/website/src/content/docs/docs/using-devices/agent-device.mdx index 3d1d27ee4..0aef62888 100644 --- a/website/src/content/docs/docs/using-devices/agent-device.mdx +++ b/website/src/content/docs/docs/using-devices/agent-device.mdx @@ -95,7 +95,7 @@ The URL is the worker's HTTP address, or the gateway's (port 4700 by default), f When several agents use agent-device on one machine, each sets its own `AGENT_DEVICE_SESSION` (or passes `--session` on every command). Without one, a command falls back to the last session saved on that machine, which may be another agent's, and fails with `No active proxy device lease for this session; run open first.` or `refused: lease is not one of yours on this gateway`. -- **`open` takes a lease.** `--platform ios` or `android` is required. `--device "iPhone 16"` asks for that model. `--target mobile`, `tv` or `desktop` asks for a phone, TV or desktop device. `--os` names an OS version or a range (`26.0`, `>=18 <27`, `18 - 26`; a range gets the newest installed version in it), and on Android `--image-tag` names a system image tag such as `google_apis_playstore`. With none of these, Simlock leases a phone. The reply to `open` names the model, OS and image tag you got. If every match is taken, `open` waits in Simlock's queue for up to 330 seconds, then fails with `timed out waiting for a device; nothing was leased`. +- **`open` takes a lease.** `--platform ios` or `android` is required. `--device "iPhone 16"` asks for that model. `--target mobile`, `tv` or `desktop` asks for a phone, TV or desktop device. `--os` names an OS version or a range (`26.0`, `>=18 <27`, `18 - 26`; a range gets the newest installed version in it), and on Android `--image-tag` names a system image tag such as `google_apis_playstore`. `--device-mode full` or `slim` asks for that kind of iOS simulator; without it, the worker's default. With none of these, Simlock leases a phone. The reply to `open` names the model, OS and image tag you got. If every match is taken, `open` waits in Simlock's queue for up to 330 seconds, then fails with `timed out waiting for a device; nothing was leased`. - **The lease is an ordinary Simlock lease.** `simlock status` and the console show it, held by the token. Its id is the one agent-device chose. - **Commands keep the lease alive.** agent-device renews it before each command and while a command runs. An agent that stops sending commands loses the device one TTL later. The TTL is the one agent-device asks for, or the worker's default (15 minutes) when it asks for none. An admin can cap it with `capabilities.agent-device.leaseTtlCapMs`. - **`close` gives the device back.** Simlock ends the lease and wipes the device for the next agent. @@ -152,6 +152,7 @@ Restarting a worker's daemon ends every agent-device lease on that worker, even | `refused: malformed physical` | `physical` was not true or false. | | `refused: unknown --target ; use mobile, tv or desktop` | `--target` named a device class Simlock does not map. | | `refused: malformed osVersion`, `refused: malformed imageTag` | `--os` or `--image-tag` was not a string. | +| `refused: deviceMode must be slim or full` | `--device-mode` was neither `slim` nor `full`. | | `refused by simlock: ` | Simlock refused the lease, for example a model it does not know, an OS range it cannot read, or an image tag on iOS. | | `refused: this agent-device is too old to use through a gateway; update it` | Upgrade the agent's agent-device. | | `agent-device is not available on this simlock: ` | agent-device is missing, too old, starting or crashed on the worker. | From 4c0249b7eb170c6449c6e679f71375e0c4b6e4c4 Mon Sep 17 00:00:00 2001 From: Vitalii Yehorov Date: Wed, 4 Nov 2026 07:44:48 +0100 Subject: [PATCH 2/7] fix(agent-device): lease.request alone refuses a bad device mode (#1223) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The front checked `deviceMode` against its own list of modes, a second copy of the rule `lease.request`'s schema enforces (architecture rule 10). It now passes the value through as ADR 0007 §2 asks, so a bad one answers `refused by simlock:` with simlock's message. `deviceMode: null` stays absent, as `osVersion`, `physical` and `ttlMs` do. Co-Authored-By: Claude Opus 5.5 --- src/agent-device/AGENTS.md | 2 +- src/agent-device/edge.test.ts | 17 ++++++++++------- src/agent-device/front/allocate.ts | 4 ---- .../docs/docs/using-devices/agent-device.mdx | 3 +-- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/agent-device/AGENTS.md b/src/agent-device/AGENTS.md index 6b881acd6..0f5472b79 100644 --- a/src/agent-device/AGENTS.md +++ b/src/agent-device/AGENTS.md @@ -91,7 +91,7 @@ under leasing's signal (`lease.endWaitMs`). ## Flow: agent on a worker 1. CLI `open` → `POST /v1/agent-device/rpc` `agent_device.lease.allocate` with its lease id. -2. Front refuses a non-plain lease, no `--platform`, a bad `ttlMs`, no lease id, a `physical` that is not a boolean, a `deviceMode` that is not `slim` or `full`, or a `--target` it does not map. +2. Front refuses a non-plain lease, no `--platform`, a bad `ttlMs`, no lease id, a `physical` that is not a boolean, or a `--target` it does not map. 3. `lease.request`: `leaseId` = `requesterId` = the CLI's lease id; `--device` → model, `--target` → class, `--os` → `osVersion`, `--image-tag` → `imageTag`, `--device-mode` (`deviceMode`) → `mode`, `physical: true` → `physical: true` (Simlock picks an enrolled phone); TTL = sent, capped by `capabilities.agent-device.leaseTtlCapMs`, at least 5 s; queue wait 330 s. CLI hangs up → `lease.cancel`, retried every 1 s. diff --git a/src/agent-device/edge.test.ts b/src/agent-device/edge.test.ts index 11db79875..abd9a2934 100644 --- a/src/agent-device/edge.test.ts +++ b/src/agent-device/edge.test.ts @@ -751,24 +751,27 @@ describe("the agent-device front, through the whole worker daemon", () => { } }); - it('allocate with `deviceMode` "full" or "slim" makes a lease request whose `mode` is it and an allocate the agent-device daemon receives without it; a `deviceMode` that is neither is refused with `refused: deviceMode must be slim or full` and no lease', async () => { + it('allocate with `deviceMode` "full" or "slim" makes a lease request whose `mode` is it and an allocate the agent-device daemon receives without it; `deviceMode: null` is absent; any other `deviceMode` answers `refused by simlock:` with simlock\'s `BAD_REQUEST` message and no lease', async () => { const rig = await setUp({ maxRunning: 8 }); await granted(rig, 1, { deviceMode: "full" }); await granted(rig, 2, { deviceMode: "slim" }); + await granted(rig, 3, { deviceMode: null }); for (const deviceMode of ["fast", 1]) { - await refused( - rig, - () => allocate(rig, 3, { deviceMode }), - "refused: deviceMode must be slim or full", - ); + const expected = await simlockMessage(rig, { + leaseId: hex(9), + mode: deviceMode, + platform: "ios", + }); + await refused(rig, () => allocate(rig, 4, { deviceMode }), `refused by simlock: ${expected}`); } expect(await requestedSpecs(rig, hex(1))).toEqual([{ mode: "full", platform: "ios" }]); expect(await requestedSpecs(rig, hex(2))).toEqual([{ mode: "slim", platform: "ios" }]); + expect(await requestedSpecs(rig, hex(3))).toEqual([{ platform: "ios" }]); expect(receivedAllocate(rig, 1)).not.toHaveProperty("deviceMode"); expect(receivedAllocate(rig, 2)).not.toHaveProperty("deviceMode"); - expect(await listed(rig)).toEqual([hex(1), hex(2)]); + expect(await listed(rig)).toEqual([hex(1), hex(2), hex(3)]); }); it("the relayed allocate reply carries `data.lease.device` as `{ model, osVersion, physical: false }` on iOS and on Android without a tag, and with `imageTag` on Android with one, the daemon's `deviceKey` and `data.device` unchanged", async () => { diff --git a/src/agent-device/front/allocate.ts b/src/agent-device/front/allocate.ts index 95131f6ce..503cbe206 100644 --- a/src/agent-device/front/allocate.ts +++ b/src/agent-device/front/allocate.ts @@ -44,7 +44,6 @@ const CLASS_OF_TARGET: Record = { }; const present = (value: unknown): boolean => value !== undefined && value !== null; -const MODES: readonly unknown[] = ["slim", "full"]; interface Plan { readonly leaseId: string; @@ -85,9 +84,6 @@ function notPlain(params: Record): boolean { function deviceRefusal(fields: ReturnType): FrontReply | undefined { if (!present(fields.platform)) return refusal("refused: name --platform ios or android"); - if (present(fields.deviceMode) && !MODES.includes(fields.deviceMode)) { - return refusal("refused: deviceMode must be slim or full"); - } return undefined; } diff --git a/website/src/content/docs/docs/using-devices/agent-device.mdx b/website/src/content/docs/docs/using-devices/agent-device.mdx index 0aef62888..9fb81a130 100644 --- a/website/src/content/docs/docs/using-devices/agent-device.mdx +++ b/website/src/content/docs/docs/using-devices/agent-device.mdx @@ -152,8 +152,7 @@ Restarting a worker's daemon ends every agent-device lease on that worker, even | `refused: malformed physical` | `physical` was not true or false. | | `refused: unknown --target ; use mobile, tv or desktop` | `--target` named a device class Simlock does not map. | | `refused: malformed osVersion`, `refused: malformed imageTag` | `--os` or `--image-tag` was not a string. | -| `refused: deviceMode must be slim or full` | `--device-mode` was neither `slim` nor `full`. | -| `refused by simlock: ` | Simlock refused the lease, for example a model it does not know, an OS range it cannot read, or an image tag on iOS. | +| `refused by simlock: ` | Simlock refused the lease, for example a model it does not know, an OS range it cannot read, an image tag on iOS, or a `--device-mode` other than `slim` or `full`. | | `refused: this agent-device is too old to use through a gateway; update it` | Upgrade the agent's agent-device. | | `agent-device is not available on this simlock: ` | agent-device is missing, too old, starting or crashed on the worker. | | `agent-device is not available on this simlock: phone daemon: ` | `open --physical`, or a command on a phone lease, found the phone daemon starting or down. Simulator leases keep working; `simlock doctor` prints the phone daemon's finding. | From 85e95e02f0c6a4bf7fce7fa1aacbfdc56ee88af5 Mon Sep 17 00:00:00 2001 From: Vitalii Yehorov Date: Wed, 4 Nov 2026 08:02:21 +0100 Subject: [PATCH 3/7] fix(agent-device): document deviceMode as the wire field and test the granted mode (#1223) No released agent-device has `--device-mode` (callstack/agent-device#4183 is open), so the manual and website name the field the front reads. The edge test also checks the mode of the granted device, which `lease.requested` cannot show: it is logged before the core resolves the mode. Co-Authored-By: Claude Opus 5.5 --- src/agent-device/AGENTS.md | 2 +- src/agent-device/edge.test.ts | 17 ++++++++++++++--- .../docs/docs/using-devices/agent-device.mdx | 4 ++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/agent-device/AGENTS.md b/src/agent-device/AGENTS.md index 0f5472b79..b11210680 100644 --- a/src/agent-device/AGENTS.md +++ b/src/agent-device/AGENTS.md @@ -93,7 +93,7 @@ under leasing's signal (`lease.endWaitMs`). 1. CLI `open` → `POST /v1/agent-device/rpc` `agent_device.lease.allocate` with its lease id. 2. Front refuses a non-plain lease, no `--platform`, a bad `ttlMs`, no lease id, a `physical` that is not a boolean, or a `--target` it does not map. 3. `lease.request`: `leaseId` = `requesterId` = the CLI's lease id; `--device` → model, - `--target` → class, `--os` → `osVersion`, `--image-tag` → `imageTag`, `--device-mode` (`deviceMode`) → `mode`, `physical: true` → `physical: true` (Simlock picks an enrolled phone); TTL = sent, capped by `capabilities.agent-device.leaseTtlCapMs`, at least 5 s; + `--target` → class, `--os` → `osVersion`, `--image-tag` → `imageTag`, `deviceMode` → `mode`, `physical: true` → `physical: true` (Simlock picks an enrolled phone); TTL = sent, capped by `capabilities.agent-device.leaseTtlCapMs`, at least 5 s; queue wait 330 s. CLI hangs up → `lease.cancel`, retried every 1 s. 4. Grant → allocate forwarded with the device address (`udid`/`serial`; a phone's is its enrolled id), to the phone daemon for a phone and the simulator daemon otherwise (`RoutedHostLink`, which remembers each lease's daemon until the lease ends), no `device`/`deviceKey`/`target`/`osVersion`/`imageTag`/`deviceMode`/`physical` (commands lose both keys too), `ttlMs` = max(24 h, 2 × `lease.maxTtlMs`). diff --git a/src/agent-device/edge.test.ts b/src/agent-device/edge.test.ts index abd9a2934..abe4ddfe0 100644 --- a/src/agent-device/edge.test.ts +++ b/src/agent-device/edge.test.ts @@ -97,8 +97,9 @@ const phoneModels = { modelClasses: { "iPhone 16": "phone" }, } as const; -function iosDriver(clock: FakeClock): FakeDriver { +function iosDriver(clock: FakeClock, slimmableOsVersions?: readonly string[]): FakeDriver { return new FakeDriver({ + ...(slimmableOsVersions === undefined ? {} : { slimmableOsVersions }), availableOsVersions: ["26.5"], clock, defaultModels: { desktop: ["Mac"], phone: ["iPhone 16"], tv: ["Apple TV 4K"] }, @@ -423,6 +424,7 @@ async function devices(rig: Rig): Promise< readonly state: string; readonly address?: string; readonly driverDeviceId?: string; + readonly mode?: string; }[] > { return (await rig.daemon.dispatch("list.get", { kind: "devices" }, adminSession)) as never; @@ -751,8 +753,15 @@ describe("the agent-device front, through the whole worker daemon", () => { } }); - it('allocate with `deviceMode` "full" or "slim" makes a lease request whose `mode` is it and an allocate the agent-device daemon receives without it; `deviceMode: null` is absent; any other `deviceMode` answers `refused by simlock:` with simlock\'s `BAD_REQUEST` message and no lease', async () => { - const rig = await setUp({ maxRunning: 8 }); + it('allocate with `deviceMode` "full" or "slim" makes a lease request whose `mode` is it, grants a device of that mode, and sends an allocate the agent-device daemon receives without it; `deviceMode: null` is absent; any other `deviceMode` answers `refused by simlock:` with simlock\'s `BAD_REQUEST` message and no lease', async () => { + const rig = await setUp({ + drivers: (clock) => [iosDriver(clock, ["26.5"])], + maxRunning: 8, + }); + const grantedMode = async (n: number) => { + const lease = (await leases(rig)).find((entry) => entry.id === hex(n)); + return (await devices(rig)).find((device) => device.id === lease?.deviceId)?.mode; + }; await granted(rig, 1, { deviceMode: "full" }); await granted(rig, 2, { deviceMode: "slim" }); @@ -769,6 +778,8 @@ describe("the agent-device front, through the whole worker daemon", () => { expect(await requestedSpecs(rig, hex(1))).toEqual([{ mode: "full", platform: "ios" }]); expect(await requestedSpecs(rig, hex(2))).toEqual([{ mode: "slim", platform: "ios" }]); expect(await requestedSpecs(rig, hex(3))).toEqual([{ platform: "ios" }]); + expect(await grantedMode(1)).toBe("full"); + expect(await grantedMode(2)).toBe("slim"); expect(receivedAllocate(rig, 1)).not.toHaveProperty("deviceMode"); expect(receivedAllocate(rig, 2)).not.toHaveProperty("deviceMode"); expect(await listed(rig)).toEqual([hex(1), hex(2), hex(3)]); diff --git a/website/src/content/docs/docs/using-devices/agent-device.mdx b/website/src/content/docs/docs/using-devices/agent-device.mdx index 9fb81a130..6697f8a9f 100644 --- a/website/src/content/docs/docs/using-devices/agent-device.mdx +++ b/website/src/content/docs/docs/using-devices/agent-device.mdx @@ -95,7 +95,7 @@ The URL is the worker's HTTP address, or the gateway's (port 4700 by default), f When several agents use agent-device on one machine, each sets its own `AGENT_DEVICE_SESSION` (or passes `--session` on every command). Without one, a command falls back to the last session saved on that machine, which may be another agent's, and fails with `No active proxy device lease for this session; run open first.` or `refused: lease is not one of yours on this gateway`. -- **`open` takes a lease.** `--platform ios` or `android` is required. `--device "iPhone 16"` asks for that model. `--target mobile`, `tv` or `desktop` asks for a phone, TV or desktop device. `--os` names an OS version or a range (`26.0`, `>=18 <27`, `18 - 26`; a range gets the newest installed version in it), and on Android `--image-tag` names a system image tag such as `google_apis_playstore`. `--device-mode full` or `slim` asks for that kind of iOS simulator; without it, the worker's default. With none of these, Simlock leases a phone. The reply to `open` names the model, OS and image tag you got. If every match is taken, `open` waits in Simlock's queue for up to 330 seconds, then fails with `timed out waiting for a device; nothing was leased`. +- **`open` takes a lease.** `--platform ios` or `android` is required. `--device "iPhone 16"` asks for that model. `--target mobile`, `tv` or `desktop` asks for a phone, TV or desktop device. `--os` names an OS version or a range (`26.0`, `>=18 <27`, `18 - 26`; a range gets the newest installed version in it), and on Android `--image-tag` names a system image tag such as `google_apis_playstore`. On the `agent_device.lease.allocate` request, `deviceMode: "full"` or `"slim"` asks for that kind of iOS simulator; without it, the worker's default. agent-device 0.21.36 has no CLI flag for it. With none of these, Simlock leases a phone. The reply to `open` names the model, OS and image tag you got. If every match is taken, `open` waits in Simlock's queue for up to 330 seconds, then fails with `timed out waiting for a device; nothing was leased`. - **The lease is an ordinary Simlock lease.** `simlock status` and the console show it, held by the token. Its id is the one agent-device chose. - **Commands keep the lease alive.** agent-device renews it before each command and while a command runs. An agent that stops sending commands loses the device one TTL later. The TTL is the one agent-device asks for, or the worker's default (15 minutes) when it asks for none. An admin can cap it with `capabilities.agent-device.leaseTtlCapMs`. - **`close` gives the device back.** Simlock ends the lease and wipes the device for the next agent. @@ -152,7 +152,7 @@ Restarting a worker's daemon ends every agent-device lease on that worker, even | `refused: malformed physical` | `physical` was not true or false. | | `refused: unknown --target ; use mobile, tv or desktop` | `--target` named a device class Simlock does not map. | | `refused: malformed osVersion`, `refused: malformed imageTag` | `--os` or `--image-tag` was not a string. | -| `refused by simlock: ` | Simlock refused the lease, for example a model it does not know, an OS range it cannot read, an image tag on iOS, or a `--device-mode` other than `slim` or `full`. | +| `refused by simlock: ` | Simlock refused the lease, for example a model it does not know, an OS range it cannot read, an image tag on iOS, or a `deviceMode` other than `slim` or `full`. | | `refused: this agent-device is too old to use through a gateway; update it` | Upgrade the agent's agent-device. | | `agent-device is not available on this simlock: ` | agent-device is missing, too old, starting or crashed on the worker. | | `agent-device is not available on this simlock: phone daemon: ` | `open --physical`, or a command on a phone lease, found the phone daemon starting or down. Simulator leases keep working; `simlock doctor` prints the phone daemon's finding. | From 0ed0d3d6db7c88976dba24aeef2d5e621bc547b7 Mon Sep 17 00:00:00 2001 From: Vitalii Yehorov Date: Wed, 4 Nov 2026 08:35:52 +0100 Subject: [PATCH 4/7] docs(agent-device): a null deviceMode is absent, not refused (#1223) Co-Authored-By: Claude Opus 5.5 --- website/src/content/docs/docs/using-devices/agent-device.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/src/content/docs/docs/using-devices/agent-device.mdx b/website/src/content/docs/docs/using-devices/agent-device.mdx index 6697f8a9f..0ed88ecd9 100644 --- a/website/src/content/docs/docs/using-devices/agent-device.mdx +++ b/website/src/content/docs/docs/using-devices/agent-device.mdx @@ -152,7 +152,7 @@ Restarting a worker's daemon ends every agent-device lease on that worker, even | `refused: malformed physical` | `physical` was not true or false. | | `refused: unknown --target ; use mobile, tv or desktop` | `--target` named a device class Simlock does not map. | | `refused: malformed osVersion`, `refused: malformed imageTag` | `--os` or `--image-tag` was not a string. | -| `refused by simlock: ` | Simlock refused the lease, for example a model it does not know, an OS range it cannot read, an image tag on iOS, or a `deviceMode` other than `slim` or `full`. | +| `refused by simlock: ` | Simlock refused the lease, for example a model it does not know, an OS range it cannot read, an image tag on iOS, or a `deviceMode` other than `slim` or `full` (`null` means absent). | | `refused: this agent-device is too old to use through a gateway; update it` | Upgrade the agent's agent-device. | | `agent-device is not available on this simlock: ` | agent-device is missing, too old, starting or crashed on the worker. | | `agent-device is not available on this simlock: phone daemon: ` | `open --physical`, or a command on a phone lease, found the phone daemon starting or down. Simulator leases keep working; `simlock doctor` prints the phone daemon's finding. | From 7b95654679a7c6904e51e5cada47924307dd886f Mon Sep 17 00:00:00 2001 From: Vitalii Yehorov Date: Thu, 5 Nov 2026 11:55:07 +0100 Subject: [PATCH 5/7] docs(agent-device): a slim deviceMode is best effort (#1223) Below iOS 18.5 the driver grants a full simulator, for an explicit slim request and for a slim worker default alike. Co-Authored-By: Claude Opus 5.5 --- website/src/content/docs/docs/using-devices/agent-device.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/src/content/docs/docs/using-devices/agent-device.mdx b/website/src/content/docs/docs/using-devices/agent-device.mdx index 1838ffbf4..b5b57d206 100644 --- a/website/src/content/docs/docs/using-devices/agent-device.mdx +++ b/website/src/content/docs/docs/using-devices/agent-device.mdx @@ -123,7 +123,7 @@ Each agent-device session holds one device. To use a second device, open a secon - `--os` names an OS version or a range: `26.0`, `>=18 <27`, `18 - 26`. A range gets the newest installed version inside it. - On Android, `--image-tag` names a system image tag, such as `google_apis_playstore`. - `--physical` leases an enrolled phone (see [Use a real phone](#use-a-real-phone)). -- On the `agent_device.lease.allocate` request, `deviceMode: "full"` or `"slim"` asks for that kind of iOS simulator. Without it, you get the worker's default. agent-device 0.21.36 has no CLI flag for it. +- On the `agent_device.lease.allocate` request, `deviceMode: "full"` or `"slim"` asks for that kind of iOS simulator. Without it, you get the worker's default. [Slim is best effort](/simlock/docs/using-devices/choosing-a-device#choose-slim-or-full-ios): below iOS 18.5 you get a full simulator. agent-device 0.21.36 has no CLI flag for it. The reply to `open` names the model, OS and image tag you got. If every matching device is taken, `open` waits for up to 330 seconds, then fails with `timed out waiting for a device; nothing was leased`. From dd3237ba6f6b117d8966f0a6c92702162abad26b Mon Sep 17 00:00:00 2001 From: Vitalii Yehorov Date: Thu, 5 Nov 2026 16:21:18 +0100 Subject: [PATCH 6/7] test(agent-device): deviceMode has its own test file, and leaves batch steps (#1223) The edge test file may only shrink (ADR 0063), so the allocate test moves beside baseline.test.ts. Its title no longer claims a BAD_REQUEST code it does not assert. ruleLeaseKeys strips deviceMode as it strips the other lease keys, so a command or batch step cannot carry it to agent-device. Co-Authored-By: Claude Opus 5.5 --- src/agent-device/device-mode.test.ts | 77 +++++++++++++++++++++++++ src/agent-device/front/request-rules.ts | 2 +- src/agent-device/test-support.ts | 3 +- 3 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 src/agent-device/device-mode.test.ts diff --git a/src/agent-device/device-mode.test.ts b/src/agent-device/device-mode.test.ts new file mode 100644 index 000000000..bec235bd9 --- /dev/null +++ b/src/agent-device/device-mode.test.ts @@ -0,0 +1,77 @@ +import { describe, expect, it } from "vitest"; + +import { + adminSession, + allocate, + forwarded, + granted, + hex, + iosDriver, + leases, + receivedAllocate, + refused, + requestedSpecs, + runCommand, + setUp, + simlockMessage, + type Rig, +} from "./test-support.js"; + +async function grantedMode(rig: Rig, n: number): Promise { + const lease = (await leases(rig)).find((entry) => entry.id === hex(n)); + const devices = (await rig.daemon.dispatch( + "list.get", + { kind: "devices" }, + adminSession, + )) as unknown as readonly { readonly id: string; readonly mode?: string }[]; + return devices.find((device) => device.id === lease?.deviceId)?.mode; +} + +describe("the agent-device front's `deviceMode`", () => { + it('allocate with `deviceMode` "full" or "slim" makes a lease request whose `mode` is it, grants a device of that mode, and sends an allocate the agent-device daemon receives without it; `deviceMode: null` is absent; any other `deviceMode` answers `refused by simlock:` with the message `lease.request` gives it and no lease', async () => { + const rig = await setUp({ + drivers: (clock) => [iosDriver(clock, ["26.5"])], + maxRunning: 8, + }); + + await granted(rig, 1, { deviceMode: "full" }); + await granted(rig, 2, { deviceMode: "slim" }); + await granted(rig, 3, { deviceMode: null }); + for (const deviceMode of ["fast", 1]) { + const expected = await simlockMessage(rig, { + leaseId: hex(9), + mode: deviceMode, + platform: "ios", + }); + await refused(rig, () => allocate(rig, 4, { deviceMode }), `refused by simlock: ${expected}`); + } + + expect(await requestedSpecs(rig, hex(1))).toEqual([{ mode: "full", platform: "ios" }]); + expect(await requestedSpecs(rig, hex(2))).toEqual([{ mode: "slim", platform: "ios" }]); + expect(await requestedSpecs(rig, hex(3))).toEqual([{ platform: "ios" }]); + expect(await grantedMode(rig, 1)).toBe("full"); + expect(await grantedMode(rig, 2)).toBe("slim"); + expect(receivedAllocate(rig, 1)).not.toHaveProperty("deviceMode"); + expect(receivedAllocate(rig, 2)).not.toHaveProperty("deviceMode"); + expect((await leases(rig)).map((lease) => lease.id)).toEqual([hex(1), hex(2), hex(3)]); + }); + + it("a command with `deviceMode` on `flags`, on `input` or inside a batch step reaches agent-device without it", async () => { + const rig = await setUp(); + await granted(rig, 1); + const sent = { deviceMode: "full", platform: "ios" }; + + const onFlags = await forwarded(rig, () => runCommand(rig, "snapshot", 1, { flags: sent })); + const onInput = await forwarded(rig, () => runCommand(rig, "snapshot", 1, { input: sent })); + const inStep = await forwarded(rig, () => + runCommand(rig, "batch", 1, { + flags: { batchSteps: [{ command: "snapshot", flags: sent }] }, + }), + ); + + expect(onFlags["flags"]).toEqual({ platform: "ios" }); + expect(onInput["input"]).toEqual({ platform: "ios" }); + const steps = (inStep["flags"] as { batchSteps: { flags: unknown }[] }).batchSteps; + expect(steps[0]?.flags).toEqual({ platform: "ios" }); + }); +}); diff --git a/src/agent-device/front/request-rules.ts b/src/agent-device/front/request-rules.ts index 64a658304..25a852532 100644 --- a/src/agent-device/front/request-rules.ts +++ b/src/agent-device/front/request-rules.ts @@ -137,7 +137,7 @@ function checkTypes(unit: Unit): void { function ruleLeaseKeys(check: Check, unit: Unit): void { if (isFlat(unit)) return; for (const place of places(unit)) { - for (const key of ["osVersion", "imageTag", "deviceBaseline"]) { + for (const key of ["osVersion", "imageTag", "deviceBaseline", "deviceMode"]) { if (!(key in place)) continue; delete place[key]; check.changed = true; diff --git a/src/agent-device/test-support.ts b/src/agent-device/test-support.ts index deb5482b9..75d683514 100644 --- a/src/agent-device/test-support.ts +++ b/src/agent-device/test-support.ts @@ -91,8 +91,9 @@ export interface Rig { readonly restart: (between?: () => void) => Promise; } -export function iosDriver(clock: FakeClock): FakeDriver { +export function iosDriver(clock: FakeClock, slimmableOsVersions?: readonly string[]): FakeDriver { return new FakeDriver({ + ...(slimmableOsVersions === undefined ? {} : { slimmableOsVersions }), availableOsVersions: ["26.5"], clock, defaultModels: { desktop: ["Mac"], phone: ["iPhone 16"], tv: ["Apple TV 4K"] }, From 8998abece900b41a767a65d99881be86299bccd0 Mon Sep 17 00:00:00 2001 From: Vitalii Yehorov Date: Thu, 5 Nov 2026 16:28:45 +0100 Subject: [PATCH 7/7] docs(agent-device): the batch-step comment no longer counts the keys (#1223) Co-Authored-By: Claude Opus 5.5 --- src/agent-device/front/request-rules.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/agent-device/front/request-rules.ts b/src/agent-device/front/request-rules.ts index 25a852532..74b3745c4 100644 --- a/src/agent-device/front/request-rules.ts +++ b/src/agent-device/front/request-rules.ts @@ -133,7 +133,7 @@ function checkTypes(unit: Unit): void { } } -// why: the daemon behind the front does not know these three keys, so a request that is not the flat allocate form must not carry them; the flat allocate is exempt because simlock reads them from it. +// why: the daemon behind the front does not know these keys, so a request that is not the flat allocate form must not carry them; the flat allocate is exempt because simlock reads them from it. function ruleLeaseKeys(check: Check, unit: Unit): void { if (isFlat(unit)) return; for (const place of places(unit)) {