Skip to content

The agent-device front answers orientation on an iOS-simulator lease #1109

Closed

Description

@leonardoxr

Part of #1105.

Scope

An agent-device user on a Simlock iPhone or iPad simulator lease runs agent-device orientation <name>, and Simlock's agent-device front rotates the simulator through device.rotate and answers itself, so the command never reaches agent-device's own XCTest rotation. On any other lease, or one Simlock no longer knows, the command goes to agent-device as today. The front's lease map records whether a lease is physical so it can tell. The agent-device page describes it. The feature's manual Mac check is recorded on this PR by the maintainer.

In short

After this PR, agent-device orientation landscape-left on a Simlock iPhone-simulator lease turns the simulator through Simlock's input helper. The front answers with agent-device's own reply for a rotation it requested but cannot confirm: data {action: "orientation", orientation: "<name>", confirmed: false, warning: "Requested <name>; the device owner reported no resulting orientation, so the rotation is unconfirmed.", message: "Rotation requested: <name> (unconfirmed)"}, <name> agent-device's spelling of the parsed orientation (landscape-left). On an iPhone or iPad simulator lease, auto or an unknown name is refused INVALID_ARGS with Unknown orientation <input>; use portrait, portrait-upside-down, landscape-left or landscape-right. A helper that cannot start answers COMMAND_FAILED with the INPUT_UNAVAILABLE message.

flowchart LR
  A[agent-device orientation] --> F[front: command on a lease]
  F --> Q{map: ios, not physical, iPhone/iPad model?}
  Q -->|no| P[forward to agent-device - as today]
  Q -->|yes, or adopted with an iPhone/iPad model| N{name parses?}
  N -->|no, simulator| I[INVALID_ARGS - new]
  N -->|no, adopted| P
  N -->|yes| R[device.rotate - new]
  R -->|ROTATION_UNSUPPORTED, UNKNOWN_LEASE, FORBIDDEN| P
  R -->|ok| Y[unconfirmed reply - new]
  R -->|INPUT_UNAVAILABLE| E[COMMAND_FAILED]
  R -->|WORKER_UNREACHABLE| U[front's worker-unreachable reply]
Loading
$ agent-device orientation landscape-left      # before: agent-device's runner rotates; taps may miss (#1080)
Rotated to landscape-left
$ agent-device orientation landscape-left      # after, Simlock iPhone-simulator lease
Rotation requested: landscape-left (unconfirmed)
$ agent-device orientation auto                # after, same lease
Unknown orientation auto; use portrait, portrait-upside-down, landscape-left or landscape-right
$ agent-device orientation auto                # after, physical iPhone or Android lease: as today

If this goes wrong, an Android or iPhone lease's orientation stops reaching agent-device, or an iOS rotation turns the opposite way from agent-device's.

Technical spec

Facts

Commit 795733b. agent-device at tag v0.21.32 (package.json:76 pins @agent-device/proxy 0.21.32).

# Fact Source
F1 agent-device's orientation reaches the front as JSON-RPC agent_device.command with params.command; the front lower-cases it src/agent-device/shared/rpc.ts:80-88, src/agent-device/front/request-rules.ts:321-333
F2 The command's lease id is meta.leaseId or flags.leaseId src/agent-device/shared/rpc.ts:118-123
F3 agent-device reads the orientation from positionals[0] v0.21.32:packages/daemon/src/execution/orientation-runtime.ts:23
F4 agent-device's names: portrait, portrait-upside-down, landscape-left, landscape-right, aliases upside-down, left, right, trimmed and lower-cased; auto separately v0.21.32:packages/contracts/src/device-rotation.ts:7-12, v0.21.32:packages/contracts/src/device-rotation.ts:49-82
F5 agent-device's unconfirmed reply data is {action:'orientation', orientation, confirmed:false, warning:'Requested <r>; the device owner reported no resulting orientation, so the rotation is unconfirmed.', message:'Rotation requested: <r> (unconfirmed)'} v0.21.32:packages/daemon/src/execution/orientation-runtime.ts:108-116, v0.21.32:packages/kernel/src/success-text.ts:1-3
F6 A successful reply is JSON-RPC {jsonrpc:"2.0", id, result:{ok:true, data}} src/agent-device/shared/rpc.ts:125-128, src/agent-device/shared/rpc.ts:164-170
F7 The front's error reply is {error:{code:-32000, data:{code, details?, message}, message}, id, jsonrpc}; failure() is COMMAND_FAILED 502; workerUnreachable() is the try-again reply src/agent-device/shared/replies.ts:33-38, src/agent-device/shared/replies.ts:55-82
F8 A command with a lease id goes checkRequest → routeCall → runCommand, which begins a renewal and forwards to agent-device src/agent-device/front/front.ts:114-176
F9 The lease map entry holds platform, model, target, the identity, no physical; allocate writes it from the grant, where grant.device.spec.physical is available src/agent-device/front/front-map.ts:6-22, src/agent-device/front/allocate.ts:353-361
F10 An adopted lease (after a gateway restart) is restored with adopted: true and no grant spec src/agent-device/front/front.ts:365-379
F11 buildCheck exposes the map entry as leased only to the same principal src/agent-device/front/request-rules.ts:336-361
F12 The Simlock lease id equals the agent-device lease id (leaseId = requesterId = the CLI's lease id) src/agent-device/AGENTS.md:95
F13 The front calls contract ops with context.dispatch(op, input, buildHttpSession(identity)) src/agent-device/front/context.ts:113, src/agent-device/front/context.ts:167
F14 The gateway front and the worker's standalone front run the same rules src/agent-device/AGENTS.md:104-113
F15 The front refuses every token that is not an agent token src/agent-device/front/front.ts:381-386
F16 Batch steps are checked as units with isStep src/agent-device/front/request-rules.ts:305-319
F17 The front's gateway tests live in src/agent-device/gateway-front.test.ts src/agent-device/gateway-front.test.ts:1
F18 The map entry holds the granted model src/agent-device/front/allocate.ts:357

Modules touched

Searches: runCommand, checkRequest, commandLeaseId, context.map.add, DeviceFacts, context.dispatch( in src/agent-device.

  • src/agent-device/front/ — an orientation step before runCommand; front-map.ts and allocate.ts record physical; the alias parser and isRotatableModel from the contract. The front answers only when the entry is ios, not physical and isRotatableModel(model); an adopted entry (physical unknown) with such a model goes to device.rotate when the name parses and is forwarded otherwise; everything else is forwarded before any parse.
  • src/agent-device/shared/replies.ts — a success reply builder.
  • website/ — agent-device page.
sequenceDiagram
  participant A as agent-device CLI
  participant F as Simlock front
  participant D as device.rotate
  participant X as agent-device daemon
  A->>F: agent_device.command {command: orientation, positionals: [landscape-left]}
  alt map: ios, not physical (or adopted), iPhone/iPad model
    F->>D: {leaseId, orientation: landscape_left}
    alt ok
      F-->>A: result {ok, data: unconfirmed reply}
    else ROTATION_UNSUPPORTED, UNKNOWN_LEASE, FORBIDDEN
      F->>X: forward as today
    else INPUT_UNAVAILABLE or other error
      F-->>A: error COMMAND_FAILED
    else WORKER_UNREACHABLE
      F-->>A: worker-unreachable reply
    end
  else Android or physical
    F->>X: forward as today
  end
Loading

Contract and event changes

none: the front calls device.rotate as is; the reply shape is agent-device's (F5, F6). Searched src/contract for this task's names: no change.

Other code on the same state

Searches: renewals.begin (2 hits), context.map.get (4), context.map.add (2).

  • Command renewals (front.ts runCommand): an answered orientation begins and ends the lease's renewal like any command, including when device.rotate throws.
  • Front map: allocate now also writes physical; adopted entries leave it unset; every other reader ignores it.

Failure modes

Call Outcome What happens Limit, counted from
device.rotate ok unconfirmed reply (F5) the helper's 10 s, from the call
device.rotate ROTATION_UNSUPPORTED forward to agent-device —
device.rotate UNKNOWN_LEASE / FORBIDDEN forward to agent-device, which answers as today —
device.rotate INPUT_UNAVAILABLE COMMAND_FAILED, 502, its message —
device.rotate WORKER_UNREACHABLE the front's workerUnreachable() reply —
device.rotate any other error COMMAND_FAILED, 502, the error's message —
orientation parse auto, unknown, missing iPhone/iPad simulator lease: INVALID_ARGS; adopted lease: forward; any other lease is forwarded before the parse —

No state is written beyond the map's physical, set at allocate; a restart loses it with the map, as today.

Rules in play

  • ADR 0053 §3: "device.rotate … always on" — the front uses it with the input module off.
  • ADR 0046: the front's rules are the same on gateway and worker (F14).

Tests

Seam: the front's /rpc handler with a fake dispatch and a fake agent-device link, modelled on src/agent-device/gateway-front.test.ts.

  • 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; cases: 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.
  • 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; cases: 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.

Done when

  • The Tests lines pass.
  • A manual check the maintainer runs by hand on the worker Mac and records on this PR (no automated test; see the feature's Non-goals; an unattended delivery parks the PR with needs-hardware until it is recorded): 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 agent-device page says orientation on an iOS simulator goes through Simlock and replies unconfirmed, and that a batch step does not.

Out of scope

Depends on

Written by an agent.

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