Skip to content

Rotate a leased iOS simulator from the CLI, MCP, HTTP and agent-device #1105

Closed

Description

@leonardoxr

Request: #1098

Problem

A leased iOS simulator can be rotated only through the 0x07 message on the lease's input WebSocket, and only when capabilities.input.enabled is on for the worker and the gateway (off by default). An agent driving the device from a shell, the simlock CLI, MCP or agent-device has no way to send it: simlock has no rotate command, the MCP server has no rotate tool, and agent-device orientation rotates through its own XCTest runner, after which taps can land on the wrong control (#1080). Agents on other machines fall back to SSH and a script that drives the simulator directly, which needs SSH access and Simlock's device set.

Who it is for

A coding agent testing a page or game that runs only in landscape on phones, on a leased iPhone simulator, from the worker or from another machine through a gateway, with the CLI, MCP, plain HTTP or agent-device.

Outcome

  • The holder of an iOS-simulator lease turns it to portrait, portrait_upside_down, landscape_left or landscape_right with one call, from the CLI, an MCP tool, an HTTP route, or the JS client, on a worker or through a gateway.
  • This works whether or not capabilities.input.enabled is on.
  • It sends the same event as the input socket's 0x07, so Simlock's touches on the input socket land on the right control afterwards.
  • agent-device orientation <name> on a Simlock iOS-simulator lease rotates through Simlock instead of agent-device's own runner.
  • An iPad simulator counts as an iOS simulator. On the CLI, MCP, HTTP and the client, a lease on anything else (an Apple TV, Watch or Vision simulator, an Android emulator, an Android phone or tablet, an iPhone or iPad) is refused at once with an error that names what the lease is on. agent-device orientation on such a lease still goes to agent-device, as today.
  • Through a gateway, the answer and any error name the lease id the agent holds.
  • The call answers once the event is written to the input helper; a write that fails is an error, never a success. Nothing confirms the screen turned: an app locked to one orientation, or the home screen, stays as it is.

How it works for the user

flowchart TD
  A[Agent holds an iOS-simulator lease] --> B{How it asks}
  B -->|simlock rotate landscape-left| C[device.rotate]
  B -->|MCP rotate_device| C
  B -->|POST /v1/leases/id/rotate| C
  B -->|agent-device orientation landscape-left| F[Simlock's agent-device front] --> C
  C --> D{Lease on an iOS simulator?}
  D -->|no| E[ROTATION_UNSUPPORTED]
  D -->|yes| G{Input helper starts?}
  G -->|no| H[INPUT_UNAVAILABLE]
  G -->|yes| I[0x07 sent: simulator rotates; answer with the orientation]
Loading

Before:

$ simlock rotate landscape-left
Unknown command: rotate

After, on the holder's only lease:

$ simlock rotate landscape-left
Rotated lease 3f9c… to landscape_left
$ simlock rotate sideways
Unknown orientation sideways; use portrait, portrait-upside-down, landscape-left or landscape-right
$ simlock rotate landscape-left --lease 7a2e…      # an Android emulator lease
Lease 7a2e… is on an Android emulator; only an iOS simulator can be rotated

Examples

The orientation a caller names:

Input CLI and agent-device front, today CLI and agent-device front, after HTTP and client, after
landscape_left no command (CLI); forwarded to agent-device (front) landscape_left landscape_left
landscape-left as above landscape_left 400 BAD_REQUEST
LEFT as above landscape_left 400 BAD_REQUEST
right as above landscape_right 400 BAD_REQUEST
upside-down as above portrait_upside_down 400 BAD_REQUEST
portrait as above portrait portrait
auto as above refused: unknown orientation 400 BAD_REQUEST
landscapeLeft as above refused: unknown orientation 400 BAD_REQUEST
empty as above refused: unknown orientation 400 BAD_REQUEST

The lease a caller rotates:

Lease on Today After
iOS simulator, input socket open only through the socket rotates; the socket's helper is used
iOS simulator, no socket cannot rotates; a helper starts, sends, and stops
iOS simulator on a worker with no helper (not macOS-built) cannot INPUT_UNAVAILABLE
Apple TV simulator cannot ROTATION_UNSUPPORTED (an Apple TV simulator)
iPad simulator only through the socket rotates
Android emulator cannot through Simlock ROTATION_UNSUPPORTED
Android phone or iPhone cannot through Simlock ROTATION_UNSUPPORTED
Another requester's lease — FORBIDDEN, as for exec
An unknown lease id — UNKNOWN_LEASE, as for exec

What could go wrong

  • The simulator does not turn although the call answered: the app is locked to one orientation. Likely for games; the docs say so.
  • agent-device's landscape-left and Simlock's landscape_left turn the device opposite ways. Unlikely (both name the device's own orientation); not checked: after this feature both paths go through Simlock, and the manual check confirms each turns the device to landscape.
  • After a rotation, agent-device's press @ref still misses: that is agent-device's mapping (Rotating a leased iOS simulator to landscape leaves taps in the wrong place #1080), not this feature.
  • The screen stream keeps the first picture's scale after a rotation, as it does today.

Words used

  • orientation: which edge of the device is up, one of portrait, portrait_upside_down, landscape_left, landscape_right (the input socket's names).
  • alias: another spelling the CLI and the agent-device front accept for an orientation, e.g. landscape-left or left for landscape_left.
  • input helper: the program Simlock starts per lease to send touches and rotations to an iOS simulator (simlock-screen-capture --input).
  • agent-device front: the part of Simlock that receives agent-device's requests on a gateway or worker and leases devices for them.

Non-goals

  • Rotating Android emulators or phones, or a physical iPhone.
  • Confirming that the screen turned, or reporting the new orientation in the input socket's 0x82 (ADR 0052 keeps it portrait).
  • Fixing agent-device's press @ref in landscape (Rotating a leased iOS simulator to landscape leaves taps in the wrong place #1080, agent-device's half).
  • An auto orientation that follows a sensor.
  • The screen stream following a rotation's new scale.
  • A business event for a rotation.
  • orientation as a step inside an agent-device batch: it goes to agent-device, as today.
  • An automated slow-lane test of the rotation: the hardware path was proven on a Mac in feat(input): rotate a leased iOS simulator with 0x07 #1081; this feature adds ways to reach it, checked once by hand.

Completion conditions

  • On a Mac with Xcode, by hand, recorded on The agent-device front answers orientation on an iOS-simulator lease #1109's PR: through a gateway, POST /v1/leases/{id}/rotate {"orientation":"landscape_left"} turns a leased iPhone simulator running the Appduct fixture app to landscape, and after the same call with portrait, agent-device orientation landscape-left turns it the same way.
  • The MCP tool rotate_device, POST /v1/leases/{id}/rotate and the client's rotate rotate the held lease, with capabilities.input.enabled off.
  • Rotating a lease that is not on an iOS simulator answers ROTATION_UNSUPPORTED on the CLI, MCP, HTTP and the client; agent-device orientation on it reaches agent-device as today.
  • The CLI reference, the HTTP reference, the MCP tools page, the agent-device page and watching-the-screen describe the action.

Open questions

none

Decisions

Shared values

Value or state Rule Written by Read by Source
device.rotate op the device must be a simulator on platform ios whose model passes isRotatableModel; role agent, effect write, authorize as device.exec: an agent owns the lease and names no requesterId; an admin (a gateway's uplink) is held to the lease's requester, requesterId defaulting to its principal; input {leaseId, orientation, requesterId?} (requesterId as device.exec's), output {leaseId, orientation}; a gateway forwards with the worker's lease id and the namespaced requester, as for exec, and answers with the caller's own lease id in the output and in ROTATION_UNSUPPORTED/INPUT_UNAVAILABLE details and messages task 1 tasks 2, 3 src/contract/operations.ts:435-497, src/gateway/fleet-coordinator.ts:489-499
orientation names exactly the four of INPUT_ORIENTATIONS, owned by the contract (src/contract/orientation.ts, a helper); core's list reads it; anything else in the contract is BAD_REQUEST task 1 tasks 2, 3 src/core/input.ts:35-40
isRotatableModel(model) and modelFamily(model) contract orientation.ts; rotatable when the model starts with iPhone or iPad; family tv, watch, vision for Apple TV, Apple Watch, Apple Vision, else unknown; the iOS driver's product families (src/drivers/ios/index.ts:246-252) #1107 #1107, #1109 src/drivers/ios/index.ts:246-252
alias table trimmed, case-insensitive; portrait; portrait_upside_down, portrait-upside-down, upside-down; landscape_left, landscape-left, left; landscape_right, landscape-right, right; exported from the contract's orientation.ts with one parse function task 1 tasks 2, 3 new
unknown orientation message Unknown orientation <input>; use portrait, portrait-upside-down, landscape-left or landscape-right task 1 (contract) task 2 (CLI usage error, exit 2; MCP BAD_REQUEST tool error), task 3 (INVALID_ARGS) new
ROTATION_UNSUPPORTED 422, CLI exit 12, details {leaseId, platform, physical, class}; message Lease <leaseId> is on <device>; only an iOS simulator can be rotated, <device> one of an Apple TV simulator, an Apple Watch simulator, an Apple Vision simulator, a <model> simulator (another iOS model), an Android emulator, an Android phone, an Android tablet, an iPhone, an iPad; class is the physical class, or the simulator's family (tv, watch, vision, unknown), or emulator task 1 tasks 2, 3 src/contract/errors.ts:289-340 (neighbours)
INPUT_UNAVAILABLE 503, CLI exit 1, details {leaseId, reason}; message Lease <leaseId>'s simulator cannot take input: <reason>; also answered when the write to the helper fails task 1 tasks 2, 3 src/core/input.ts:96-113
DeviceInput.send returns a promise that resolves once the message is written to the device and rejects when the write fails; socket callers ignore it task 1 task 1 src/core/input.ts:88
HTTP route POST /v1/leases/{id}/rotate, body {orientation}, reply 200 {leaseId, orientation} task 1 — src/http/lease-declarations.ts:338-350
protocol task 1 bumps the protocol by one task 1 — src/contract/protocol.ts:13
per-lease device input one per lease, keyed by lease id, owned by the daemon; dropped when it fails (onFailed), so the next user opens a fresh one; opened by the first user (socket or rotate), closed when no socket holds it and no rotate is in flight; closed at lease reclaim task 1 input module src/input/sessions.ts:32-82

Behaviours

Behaviour (invoker, action, what it sees) Seam Cases Task
A holder calls device.rotate on its iOS-simulator lease and gets {leaseId, orientation}; the helper received 0x07 with that orientation daemon dispatch each of the four names; input module on with a socket open (its helper is reused, no second open); input module off (helper opened, then closed) #1107
A caller rotates a lease it may not touch, or names a bad orientation, and is refused daemon dispatch unknown lease id → UNKNOWN_LEASE; another requester's lease → FORBIDDEN; an agent naming a requesterId → FORBIDDEN; admin naming a requesterId that is not the lease's → FORBIDDEN; landscape-left, auto, empty → BAD_REQUEST #1107
A holder rotates a lease not on an iOS phone or tablet simulator and gets ROTATION_UNSUPPORTED naming it; no helper starts daemon dispatch Apple TV simulator; Android emulator; Android phone; iPhone; an iPad simulator rotates #1107
A holder rotates when the helper cannot start or the write fails and gets INPUT_UNAVAILABLE with the reason daemon dispatch no input factory for the platform; helper open rejects; write rejects; a helper that failed earlier is replaced by a fresh one; a socket's failed write closes it 1013 and the daemon keeps running #1107
An input socket opened after a rotate's helper closed gets a fresh helper; a socket open during a rotate keeps its helper after the rotate answers daemon input-lease wiring socket opens after; socket open during; lease reclaimed while the rotate's open is pending → UNKNOWN_LEASE, nothing sent #1107
An agent calls POST /v1/leases/{id}/rotate on a worker and through a gateway and gets 200 {leaseId, orientation}, or the error code's status HTTP route worker ok; gateway ok (forwarded to the worker's lease id, answered with the caller's); gateway ROTATION_UNSUPPORTED and INPUT_UNAVAILABLE name the caller's lease id; unknown lease 404; Android 422; helper missing 503 #1107
A client program calls client.rotate(leaseId, orientation) and gets the op's output client ok; ROTATION_UNSUPPORTED thrown as a typed error #1107
The core alias parser maps a spelling to an orientation or the unknown message core every row of the Examples table #1107
A user runs simlock rotate <orientation> [--lease <id>] and sees Rotated lease <id> to <orientation>, or a usage error CLI command alias accepted; unknown name → exit 2; no lease → error; two leases without --lease → error naming them; --lease given; ROTATION_UNSUPPORTED → exit 12; through a gateway #1108
An MCP client calls rotate_device {orientation} and the held lease rotates MCP server ok; no held lease → NO_LEASE; alias accepted; unknown name → BAD_REQUEST tool error with the unknown message; ROTATION_UNSUPPORTED → tool error #1108
agent-device sends orientation <name> on a Simlock iOS-simulator lease and gets agent-device's own reply for an orientation it requested but did not confirm, without the command reaching agent-device agent-device front gateway front; worker front; alias spellings; auto or unknown → INVALID_ARGS; helper missing → COMMAND_FAILED; worker gone → the front's worker-unreachable reply; a lease adopted after a gateway restart, valid name → rotated #1109
agent-device sends orientation <name> on a lease not on an iOS phone or tablet simulator, or one Simlock no longer knows, and it is forwarded to agent-device as today agent-device front Android emulator; Android phone; iPhone (with auto too); Apple TV simulator (with auto too); a lease Simlock no longer knows (UNKNOWN_LEASE); a lease adopted after a gateway restart, auto → forwarded #1109

Tasks

Sub-issues: #1107, #1108, #1109 (not linked as GitHub sub-issues yet: the author has no write access; a maintainer links them).

flowchart LR
  T1[#1107: device.rotate op, HTTP, gateway, client] --> T2[#1108: simlock rotate + MCP rotate_device]
  T1 --> T3[#1109: agent-device front answers orientation]
Loading

Completion conditions: the first (the manual Mac check, run by the maintainer) is #1109's Done when; the second is #1107 and #1108; the third is #1107, #1108 and #1109; the fourth is each task's docs (watching-the-screen is #1107's; the CLI reference and connect-your-agent #1108's; the agent-device page #1109's).

Open work in the same area:

Written by an agent.

Activity

  1. leonardoxr commented on Oct 31, 2026

    @leonardoxr
    ContributorAuthor

    Spec approved by the maintainer: the feature, ADR 0053 (PR #1106, now Accepted — not yet implemented) and tasks #1107, #1108, #1109, each checked ready.

    The author has no write access to this repository, so a maintainer still needs to:

    Delivery order: #1106 (ADR) at the bottom of the stack, then #1107, then #1108 and #1109 side by side. #1109's Done when includes a manual check on a worker Mac that the maintainer records on its PR.

    Written by an agent.

  2. V3RON commented on Nov 1, 2026

    @V3RON
    Contributor

    Delivered: ADR 0053 (#1106, Accepted), #1107 (#1122), #1108 (#1123), #1109 (#1124), all merged 2026-10-31. The manual worker-Mac check on #1124 passed.

    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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions