From 0e519b6c337871ead6c6e93d7061a6bb1192b606 Mon Sep 17 00:00:00 2001 From: Xavier Date: Fri, 30 Oct 2026 23:06:55 -0300 Subject: [PATCH 1/5] docs(adr): 0053 the daemon owns each lease's device input, and device.rotate uses it Co-Authored-By: Claude Opus 5.5 --- ...he-daemon-owns-each-leases-device-input.md | 99 +++++++++++++++++++ docs/internal/adr/README.md | 1 + 2 files changed, 100 insertions(+) create mode 100644 docs/internal/adr/0053-the-daemon-owns-each-leases-device-input.md diff --git a/docs/internal/adr/0053-the-daemon-owns-each-leases-device-input.md b/docs/internal/adr/0053-the-daemon-owns-each-leases-device-input.md new file mode 100644 index 000000000..673cf9b0d --- /dev/null +++ b/docs/internal/adr/0053-the-daemon-owns-each-leases-device-input.md @@ -0,0 +1,99 @@ +# 0053. The daemon owns each lease's device input, and `device.rotate` uses it + +- **Status:** Proposed +- **Date:** 2026-10-30 +- **Issue:** [#1105](https://github.com/callstackincubator/simlock/issues/1105) +- **Narrows:** [ADR 0049](0049-a-lease-holder-watches-and-drives-its-devices-screen.md) + §2 (the optional `input` module owns a lease's device input) and + [ADR 0052](0052-an-ios-simulator-takes-serve-sims-rotation.md) §1 (rotation + is an input-socket message only). + +## Context + +ADR 0052 lets an iOS simulator take serve-sim's rotation, but only as `0x07` +on the lease's input WebSocket. That socket belongs to the optional `input` +module, which is off unless `capabilities.input.enabled` is on, on the +worker and on the gateway. An agent using the CLI, MCP, plain HTTP or +agent-device cannot send it (#1098). + +The one device input per lease, an iOS input helper process +(`simlock-screen-capture --input`), is opened and shared inside the +input module today (`src/input/sessions.ts`): the first socket opens it, +the last one leaving closes it, and lease reclaim closes it through the +module's `beforeDeviceReclaim` hook. A rotation that does not go through a +socket needs the same helper, whether or not the module is loaded. Two +helpers on one simulator at once are untested, and nothing needs them. + +```mermaid +flowchart LR + subgraph Before + S1[input socket] --> M1[input module: per-lease helper] --> H1[iOS helper] + end + subgraph After + S2[input socket] --> M2[input module] + M2 --> D2[daemon: per-lease device input] + R2[device.rotate] --> D2 + D2 --> H2[iOS helper] + end +``` + +## Decision + +1. The daemon keeps one device input per lease, opened through the driver + catalog on first use and shared by every user. Users are the input + module's sockets and an in-flight `device.rotate`. It closes when no + socket holds it and no rotate is in flight, and at lease reclaim. +2. The input module takes the lease's device input from the daemon through + its context instead of opening its own. Its socket behaviour (limits, + close codes, `0x82`, failure handling) does not change. +3. `device.rotate {leaseId, orientation}` is a core contract operation, role + `agent`, authorized as `device.exec` is. It is always on, independent of + `capabilities.input.enabled`. On an iOS simulator lease it takes the + lease's device input, sends `0x07 {orientation}` and answers + `{leaseId, orientation}` once the message is written, then lets the input + go. It reports no new orientation and does not wait for the screen. +4. Any other lease is refused with `ROTATION_UNSUPPORTED` before a device + input is opened. A device input that cannot open is `INPUT_UNAVAILABLE`. +5. A gateway forwards `device.rotate` to the lease's worker, as it forwards + `device.exec`. + +```mermaid +sequenceDiagram + participant C as Caller (CLI, MCP, HTTP, front) + participant G as Gateway + participant W as Worker daemon + participant H as iOS helper + C->>G: device.rotate {leaseId, landscape_left} + G->>W: device.rotate {workerLeaseId, landscape_left} + alt not an iOS simulator + W-->>C: ROTATION_UNSUPPORTED + else helper cannot open + W-->>C: INPUT_UNAVAILABLE + else + W->>H: 0x07 {orientation} + W-->>C: {leaseId, orientation} + end +``` + +## Consequences + +- An agent rotates an iOS simulator from any surface with the input module + off. +- The daemon gains a small per-lease registry it did not have; the input + module loses one. Lease reclaim closes the device input in the daemon, not + only through the module's hook. +- A rotate with no socket open pays the helper's start each time (bounded at + 10 s). +- The contract grows one operation and two error codes, and the protocol is + bumped. + +## Alternatives considered + +- **A rotate route inside the input module, gated by + `capabilities.input.enabled`.** Rejected: modules add HTTP routes, not + contract operations, so the CLI and MCP could not reach it, and the + setting is off by default. +- **A second helper for each rotate, outside the module.** Rejected: two + helpers on one simulator at once are untested, and sharing costs little. +- **Keep a rotate's helper until the lease ends.** Rejected: an idle process + per rotated lease for a call that is rare. diff --git a/docs/internal/adr/README.md b/docs/internal/adr/README.md index 4026b7bb0..d64e9c745 100644 --- a/docs/internal/adr/README.md +++ b/docs/internal/adr/README.md @@ -91,3 +91,4 @@ the status is stale. | [0050](0050-an-operator-can-forget-a-learned-warm-kind.md) | An operator can forget a learned warm kind | Accepted | | [0051](0051-configured-warm-targets-come-first-and-learning-can-be-turned-off.md) | Configured warm targets come first, and learning can be turned off | Accepted | | [0052](0052-an-ios-simulator-takes-serve-sims-rotation.md) | An iOS simulator takes serve-sim's rotation | Accepted; narrows 0049 §3 on iOS simulators | +| [0053](0053-the-daemon-owns-each-leases-device-input.md) | The daemon owns each lease's device input, and `device.rotate` uses it | Proposed; narrows 0049 §2 and 0052 §1 | From 63142901d3c37a3cd2e177d854ce02775e0824c5 Mon Sep 17 00:00:00 2001 From: Xavier Date: Fri, 30 Oct 2026 23:28:06 -0300 Subject: [PATCH 2/5] =?UTF-8?q?docs(adr):=200053=20cites=200049=20=C2=A74,?= =?UTF-8?q?=20awaits=20the=20write,=20rewrites=20gateway=20ids?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- ...he-daemon-owns-each-leases-device-input.md | 78 ++++++++++++------- docs/internal/adr/README.md | 2 +- 2 files changed, 50 insertions(+), 30 deletions(-) diff --git a/docs/internal/adr/0053-the-daemon-owns-each-leases-device-input.md b/docs/internal/adr/0053-the-daemon-owns-each-leases-device-input.md index 673cf9b0d..e4a128c75 100644 --- a/docs/internal/adr/0053-the-daemon-owns-each-leases-device-input.md +++ b/docs/internal/adr/0053-the-daemon-owns-each-leases-device-input.md @@ -4,9 +4,11 @@ - **Date:** 2026-10-30 - **Issue:** [#1105](https://github.com/callstackincubator/simlock/issues/1105) - **Narrows:** [ADR 0049](0049-a-lease-holder-watches-and-drives-its-devices-screen.md) - §2 (the optional `input` module owns a lease's device input) and - [ADR 0052](0052-an-ios-simulator-takes-serve-sims-rotation.md) §1 (rotation - is an input-socket message only). + §4 ("A lease has one device input", held by the optional `input` module, + which is off by default) and + [ADR 0052](0052-an-ios-simulator-takes-serve-sims-rotation.md) §1 + (`0x07` is an input message: a rotation can now also be sent without the + input socket). ## Context @@ -19,10 +21,14 @@ agent-device cannot send it (#1098). The one device input per lease, an iOS input helper process (`simlock-screen-capture --input`), is opened and shared inside the input module today (`src/input/sessions.ts`): the first socket opens it, -the last one leaving closes it, and lease reclaim closes it through the -module's `beforeDeviceReclaim` hook. A rotation that does not go through a -socket needs the same helper, whether or not the module is loaded. Two -helpers on one simulator at once are untested, and nothing needs them. +the last one leaving closes it, a failed one is dropped, and lease end +closes it through the module's `beforeDeviceReclaim` hook. A rotation that +does not go through a socket needs the same helper, whether or not the +module is loaded. Two helpers on one simulator at once are untested, and +nothing needs them. + +A device input's `send` returns nothing today: a failed write is reported +later, through `onFailed`. A caller that answers "sent" cannot know. ```mermaid flowchart LR @@ -39,23 +45,31 @@ flowchart LR ## Decision -1. The daemon keeps one device input per lease, opened through the driver - catalog on first use and shared by every user. Users are the input - module's sockets and an in-flight `device.rotate`. It closes when no - socket holds it and no rotate is in flight, and at lease reclaim. +1. The daemon keeps one device input per lease, keyed by lease id, opened + through the driver catalog on first use and shared by every user. Users + are the input module's sockets and an in-flight `device.rotate`. It + closes when no socket holds it and no rotate is in flight, and when the + lease ends. One that fails is dropped, and the next user opens a fresh + one. 2. The input module takes the lease's device input from the daemon through its context instead of opening its own. Its socket behaviour (limits, close codes, `0x82`, failure handling) does not change. -3. `device.rotate {leaseId, orientation}` is a core contract operation, role - `agent`, authorized as `device.exec` is. It is always on, independent of - `capabilities.input.enabled`. On an iOS simulator lease it takes the - lease's device input, sends `0x07 {orientation}` and answers - `{leaseId, orientation}` once the message is written, then lets the input - go. It reports no new orientation and does not wait for the screen. -4. Any other lease is refused with `ROTATION_UNSUPPORTED` before a device - input is opened. A device input that cannot open is `INPUT_UNAVAILABLE`. -5. A gateway forwards `device.rotate` to the lease's worker, as it forwards - `device.exec`. +3. `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; a failed write still reaches them through `onFailed`. +4. `device.rotate {leaseId, orientation, requesterId?}` is a core contract + operation, role `agent`, authorized as `device.exec` is. It is always on, + independent of `capabilities.input.enabled`. On a lease of an iOS + simulator of class `phone` or `tablet` it takes the lease's device input, + sends `0x07 {orientation}`, awaits the write and answers + `{leaseId, orientation}`, then lets the input go. It reports no new + orientation and does not wait for the screen. +5. Any other lease is refused with `ROTATION_UNSUPPORTED` before a device + input is opened. A device input that cannot open, or a write that fails, + is `INPUT_UNAVAILABLE`. +6. A gateway forwards `device.rotate` to the lease's worker, as it forwards + `device.exec`, and answers with the caller's own lease id in the output + and in both errors. ```mermaid sequenceDiagram @@ -63,15 +77,18 @@ sequenceDiagram participant G as Gateway participant W as Worker daemon participant H as iOS helper - C->>G: device.rotate {leaseId, landscape_left} - G->>W: device.rotate {workerLeaseId, landscape_left} - alt not an iOS simulator - W-->>C: ROTATION_UNSUPPORTED - else helper cannot open - W-->>C: INPUT_UNAVAILABLE + C->>G: device.rotate {w1.3f9c, landscape_left} + G->>W: device.rotate {3f9c, landscape_left, requesterId} + alt not an iOS phone or tablet simulator + W-->>G: ROTATION_UNSUPPORTED (3f9c) + G-->>C: ROTATION_UNSUPPORTED (w1.3f9c) + else helper cannot open, or the write fails + W-->>G: INPUT_UNAVAILABLE (3f9c) + G-->>C: INPUT_UNAVAILABLE (w1.3f9c) else W->>H: 0x07 {orientation} - W-->>C: {leaseId, orientation} + W-->>G: {3f9c, orientation} + G-->>C: {w1.3f9c, orientation} end ``` @@ -80,8 +97,9 @@ sequenceDiagram - An agent rotates an iOS simulator from any surface with the input module off. - The daemon gains a small per-lease registry it did not have; the input - module loses one. Lease reclaim closes the device input in the daemon, not + module loses one. Lease end closes the device input in the daemon, not only through the module's hook. +- Every driver's `send` returns a promise; the change is internal. - A rotate with no socket open pays the helper's start each time (bounded at 10 s). - The contract grows one operation and two error codes, and the protocol is @@ -97,3 +115,5 @@ sequenceDiagram helpers on one simulator at once are untested, and sharing costs little. - **Keep a rotate's helper until the lease ends.** Rejected: an idle process per rotated lease for a call that is rare. +- **Answer once `send` is called, without awaiting the write.** Rejected: a + rotate could report success for a write that failed. diff --git a/docs/internal/adr/README.md b/docs/internal/adr/README.md index d64e9c745..67bd42f78 100644 --- a/docs/internal/adr/README.md +++ b/docs/internal/adr/README.md @@ -91,4 +91,4 @@ the status is stale. | [0050](0050-an-operator-can-forget-a-learned-warm-kind.md) | An operator can forget a learned warm kind | Accepted | | [0051](0051-configured-warm-targets-come-first-and-learning-can-be-turned-off.md) | Configured warm targets come first, and learning can be turned off | Accepted | | [0052](0052-an-ios-simulator-takes-serve-sims-rotation.md) | An iOS simulator takes serve-sim's rotation | Accepted; narrows 0049 §3 on iOS simulators | -| [0053](0053-the-daemon-owns-each-leases-device-input.md) | The daemon owns each lease's device input, and `device.rotate` uses it | Proposed; narrows 0049 §2 and 0052 §1 | +| [0053](0053-the-daemon-owns-each-leases-device-input.md) | The daemon owns each lease's device input, and `device.rotate` uses it | Proposed; narrows 0049 §4 and 0052 §1 | From f1b2bfaf418207ff55b425aa985cd65538630bd9 Mon Sep 17 00:00:00 2001 From: Xavier Date: Fri, 30 Oct 2026 23:32:28 -0300 Subject: [PATCH 3/5] docs(adr): 0053 decides rotatable simulators by model family Co-Authored-By: Claude Opus 5.5 --- .../adr/0053-the-daemon-owns-each-leases-device-input.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/internal/adr/0053-the-daemon-owns-each-leases-device-input.md b/docs/internal/adr/0053-the-daemon-owns-each-leases-device-input.md index e4a128c75..a198df7e4 100644 --- a/docs/internal/adr/0053-the-daemon-owns-each-leases-device-input.md +++ b/docs/internal/adr/0053-the-daemon-owns-each-leases-device-input.md @@ -60,7 +60,8 @@ flowchart LR 4. `device.rotate {leaseId, orientation, requesterId?}` is a core contract operation, role `agent`, authorized as `device.exec` is. It is always on, independent of `capabilities.input.enabled`. On a lease of an iOS - simulator of class `phone` or `tablet` it takes the lease's device input, + simulator whose model is an iPhone or iPad (its name starts with `iPhone` + or `iPad`, the iOS driver's phone and tablet families) it takes the lease's device input, sends `0x07 {orientation}`, awaits the write and answers `{leaseId, orientation}`, then lets the input go. It reports no new orientation and does not wait for the screen. @@ -79,7 +80,7 @@ sequenceDiagram participant H as iOS helper C->>G: device.rotate {w1.3f9c, landscape_left} G->>W: device.rotate {3f9c, landscape_left, requesterId} - alt not an iOS phone or tablet simulator + alt not an iPhone or iPad simulator W-->>G: ROTATION_UNSUPPORTED (3f9c) G-->>C: ROTATION_UNSUPPORTED (w1.3f9c) else helper cannot open, or the write fails From 4f7e80df747a05a3f46e2cffedd91a668f238ddf Mon Sep 17 00:00:00 2001 From: Xavier Date: Fri, 30 Oct 2026 23:34:15 -0300 Subject: [PATCH 4/5] docs(adr): accept 0053, not yet implemented Co-Authored-By: Claude Opus 5.5 --- .../adr/0053-the-daemon-owns-each-leases-device-input.md | 2 +- docs/internal/adr/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/internal/adr/0053-the-daemon-owns-each-leases-device-input.md b/docs/internal/adr/0053-the-daemon-owns-each-leases-device-input.md index a198df7e4..170f3bb73 100644 --- a/docs/internal/adr/0053-the-daemon-owns-each-leases-device-input.md +++ b/docs/internal/adr/0053-the-daemon-owns-each-leases-device-input.md @@ -1,6 +1,6 @@ # 0053. The daemon owns each lease's device input, and `device.rotate` uses it -- **Status:** Proposed +- **Status:** Accepted — not yet implemented - **Date:** 2026-10-30 - **Issue:** [#1105](https://github.com/callstackincubator/simlock/issues/1105) - **Narrows:** [ADR 0049](0049-a-lease-holder-watches-and-drives-its-devices-screen.md) diff --git a/docs/internal/adr/README.md b/docs/internal/adr/README.md index 67bd42f78..154740d6e 100644 --- a/docs/internal/adr/README.md +++ b/docs/internal/adr/README.md @@ -91,4 +91,4 @@ the status is stale. | [0050](0050-an-operator-can-forget-a-learned-warm-kind.md) | An operator can forget a learned warm kind | Accepted | | [0051](0051-configured-warm-targets-come-first-and-learning-can-be-turned-off.md) | Configured warm targets come first, and learning can be turned off | Accepted | | [0052](0052-an-ios-simulator-takes-serve-sims-rotation.md) | An iOS simulator takes serve-sim's rotation | Accepted; narrows 0049 §3 on iOS simulators | -| [0053](0053-the-daemon-owns-each-leases-device-input.md) | The daemon owns each lease's device input, and `device.rotate` uses it | Proposed; narrows 0049 §4 and 0052 §1 | +| [0053](0053-the-daemon-owns-each-leases-device-input.md) | The daemon owns each lease's device input, and `device.rotate` uses it | Accepted — not yet implemented; narrows 0049 §4 and 0052 §1 | From 6641a755b7425fce4cea9abce4a71e327fa28dd4 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Sat, 31 Oct 2026 23:10:49 +0100 Subject: [PATCH 5/5] docs(adr): 0053 is implemented, so its status is Accepted (#1105) --- .../adr/0053-the-daemon-owns-each-leases-device-input.md | 2 +- docs/internal/adr/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/internal/adr/0053-the-daemon-owns-each-leases-device-input.md b/docs/internal/adr/0053-the-daemon-owns-each-leases-device-input.md index 170f3bb73..e07133637 100644 --- a/docs/internal/adr/0053-the-daemon-owns-each-leases-device-input.md +++ b/docs/internal/adr/0053-the-daemon-owns-each-leases-device-input.md @@ -1,6 +1,6 @@ # 0053. The daemon owns each lease's device input, and `device.rotate` uses it -- **Status:** Accepted — not yet implemented +- **Status:** Accepted - **Date:** 2026-10-30 - **Issue:** [#1105](https://github.com/callstackincubator/simlock/issues/1105) - **Narrows:** [ADR 0049](0049-a-lease-holder-watches-and-drives-its-devices-screen.md) diff --git a/docs/internal/adr/README.md b/docs/internal/adr/README.md index 154740d6e..15f21a096 100644 --- a/docs/internal/adr/README.md +++ b/docs/internal/adr/README.md @@ -91,4 +91,4 @@ the status is stale. | [0050](0050-an-operator-can-forget-a-learned-warm-kind.md) | An operator can forget a learned warm kind | Accepted | | [0051](0051-configured-warm-targets-come-first-and-learning-can-be-turned-off.md) | Configured warm targets come first, and learning can be turned off | Accepted | | [0052](0052-an-ios-simulator-takes-serve-sims-rotation.md) | An iOS simulator takes serve-sim's rotation | Accepted; narrows 0049 §3 on iOS simulators | -| [0053](0053-the-daemon-owns-each-leases-device-input.md) | The daemon owns each lease's device input, and `device.rotate` uses it | Accepted — not yet implemented; narrows 0049 §4 and 0052 §1 | +| [0053](0053-the-daemon-owns-each-leases-device-input.md) | The daemon owns each lease's device input, and `device.rotate` uses it | Accepted; narrows 0049 §4 and 0052 §1 |