Skip to content
17 changes: 15 additions & 2 deletions docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ a timer and releasing it when it exits.

```
simlock lease --platform <ios|android> [--device <model> | --class <class>]
[--os <version>] [--mode <slim|full>] [--image-tag <tag>] [--agent-id <id>]
[--os <version|range>] [--mode <slim|full>] [--image-tag <tag>] [--agent-id <id>]
[--timeout <duration>]
[--no-wait] [--detach] [--ttl <duration>] [--allow-download]
[--export-env] [--bind-pid <pid>]
Expand All @@ -191,6 +191,18 @@ granted.
or `desktop`); with neither, the lease asks for a `phone`. Naming both is a
`BAD_REQUEST` (exit 2). `--os` defaults to the newest runtime already
installed for that platform. See [What a lease asks for](#what-a-lease-asks-for).
- `--os <version|range>` — an exact version (`18.4`), or a range: one or more
of `>=`, `>`, `<=`, `<` followed by a version, joined by single spaces
(`>=18 <26`), or a hyphen range (`18 - 26`). A short version covers
everything under it: `>=18` is 18.0 and newer, `<=26` includes every 26.x,
`>26` excludes them, `18 - 26` is `>=18 <=26`. Anything written like
a range but outside these forms (`^18`, `~18`, `18.x`, `*`, `||`) is
`BAD_REQUEST` (exit 2) and the message names these forms; any other string,
such as the Android runtimes `Baklava` or `34-ext12`, is an exact version.
A range is served by a fitting idle device first, or else by a new device
on the newest installed runtime in the range; when no installed runtime is
in the range the lease fails at once with `RUNTIME_MISSING` (exit 12), with
or without `--allow-download`, because a range never downloads.
- `--class <class>` — the kind of device to lease, in place of a model. See
[What a lease asks for](#what-a-lease-asks-for).
- `--agent-id` — this invocation's requester identity; see
Expand Down Expand Up @@ -445,7 +457,8 @@ A class lease is served by the first of these that applies: an idle device
that is already running and fits, then an idle device that is shut down and
fits (it is booted), then a new device. A device fits when its platform,
class, OS, mode and image tag all satisfy the request: with no `--os` a class
lease fits a device on any installed runtime, `--mode full` and `--image-tag`
lease fits a device on any installed runtime, with `--os` a device whose OS
satisfies it, `--mode full` and `--image-tag`
are never relaxed, and a lease that names no mode fits only the worker's
default mode. When several devices fit, which one is granted is not promised.

Expand Down
11 changes: 10 additions & 1 deletion docs/CLIENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,16 @@ type to create the device from, such as `"google_apis_playstore"`, as
`getCatalog()` lists it under each image's `tag`. Without it Simlock picks the
image itself (`google_apis` for the host's ABI when installed). With it the
device comes from an installed image of that tag, and without `osVersion` from
the newest API level that has one. A request with `imageTag` never downloads:
the newest API level that has one.

`osVersion` is an exact version (`"18.4"`) or a range: one or more of `>=`,
`>`, `<=`, `<` followed by a version, joined by single spaces (`">=18 <26"`),
or a hyphen range (`"18 - 26"`). A short version covers everything under it, so
`">=18"` is 18.0 and newer. Anything written like a range but outside those forms (`^18`, `~18`, `18.x`, `*`, `||`) is `BAD_REQUEST`; any other string, such as `Baklava` or `34-ext12`, is an exact version. A range is served
by an idle device whose OS satisfies it or by a new device on the newest
installed runtime in it, and when none is installed it fails at once with
`RUNTIME_MISSING`, whatever `allowDownload` says. Through a gateway a range is
`BAD_REQUEST` for now. A request with `imageTag` never downloads:
when no image of that tag is installed for the API level it fails with
`RUNTIME_MISSING`, whatever `allowDownload` says. On iOS it is a
`BAD_REQUEST`, and so is a tag that is not 1 to 64 letters, digits, `_`, `.`
Expand Down
4 changes: 2 additions & 2 deletions docs/EVENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ through `simlock events` and `simlock events --follow`.

| Event | Payload (key fields) | Emitted when | Emitter | Status |
|---|---|---|---|---|
| `lease.requested` | request id, request spec (platform, model when the request named one, device class when the request named one, os version, device mode when the request named one, image tag when the request named one), requester, wait policy | a lease request is accepted by the daemon and stored; the request id is the stored request's, so an observer can match this event to it | LeaseAcquisitionCoordinator (worker) / FleetLeaseCoordinator (gateway — its own fleet queue's admission, before any worker is chosen) | implemented |
| `lease.requested` | request id, request spec (platform, model when the request named one, device class when the request named one, os version, as an exact version or a range as typed, device mode when the request named one, image tag when the request named one), requester, wait policy | a lease request is accepted by the daemon and stored; the request id is the stored request's, so an observer can match this event to it | LeaseAcquisitionCoordinator (worker) / FleetLeaseCoordinator (gateway — its own fleet queue's admission, before any worker is chosen) | implemented |
| `lease.queued` | request id, queue position | no capacity; request entered the wait queue | LeaseAcquisitionCoordinator (worker) / FleetLeaseCoordinator (gateway) | implemented |
| `lease.granted` | lease id, device id, requester, request id (the `lease.requested` it answers), source (`warm`: a ready device handed over; `booted`: a shut-down device booted for it; `provisioned`: a device created for it) | a device was assigned and handed out | LeaseLifecycle | implemented |
| `lease.renewed` | lease id, new deadline | a `lease.renew` succeeded — whether it came from `simlock lease renew`, `POST /v1/leases/{id}/renew`, or the renew timer a running `simlock lease` / MCP session keeps over its own lease. There is one renew path and this is it | LeaseLifecycle | implemented |
| `lease.released` | lease id, device id, reason (explicit/killed/device-lost), owner id | an explicit `lease.release` (which is what a `simlock lease` holder does on its way out), (killed) an operator `release --all` or `nuke`, or (device-lost) a leased device could not be recovered after it stopped running outside simlock. Closing a connection is not a release and never emits this | LeaseLifecycle | implemented |
| `lease.expired` | lease id, device id, owner id | the lease's deadline passed with no `lease.renew` behind it — the grant-time TTL, or the TTL of the last renew, simply ran out. This is the one way a lease ends without somebody asking, and the only bound on a holder that was killed outright | LeaseLifecycle | implemented |
| `lease.rejected` | request id, requester, request spec (as on `lease.requested`: a request that named a class or nothing has no model), reason (timeout/no-wait/unresolvable-spec/no-worker/already-leased/boot-timeout/killed/cancelled/daemon-restarted) | a request ended without a grant. A request refused before it was stored (`killed`, `already-leased`) emits no `lease.requested`, and its `lease.rejected` carries the id it would have been stored under; on a gateway, `no-worker` is a request no worker that takes requests can serve, `NO_CAPACITY` at once, and `unresolvable-spec` is one no known worker has the platform, model, or runtime for, and such a request emits no `lease.queued`. A request a worker refused as unable to serve (`RUNTIME_MISSING`, `UNKNOWN_MODEL`, `NO_DRIVER`) while another worker was busy waits in the gateway queue, unless it is a `noWait` request, which is rejected at once with reason `no-wait` and emits no `lease.queued`; a request that did queue and then finds no worker left emits `unresolvable-spec` after its `lease.queued`, and one that never queued gets only the refusing worker's own `lease.rejected`; `daemon-restarted` is a request still waiting when the daemon stopped, settled as failed when it starts again. The reason list can grow: a consumer must tolerate a reason it does not know; `cancelled` is an explicit single-request cancel (backing `DELETE /v1/lease-requests/{id}`) of a still-queued waiter — one with device work already in flight is reported `not-cancellable` instead, the same envelope the queue timeout already uses | LeaseAcquisitionCoordinator / WaitQueue / StartupConverger (worker) / FleetLeaseCoordinator (gateway) | implemented |
| `lease.rejected` | request id, requester, request spec (as on `lease.requested`: a request that named a class or nothing has no model, and one that named an OS range carries it as typed), reason (timeout/no-wait/unresolvable-spec/no-worker/already-leased/boot-timeout/killed/cancelled/daemon-restarted) | a request ended without a grant. A request refused before it was stored (`killed`, `already-leased`) emits no `lease.requested`, and its `lease.rejected` carries the id it would have been stored under; on a gateway, `no-worker` is a request no worker that takes requests can serve, `NO_CAPACITY` at once, and `unresolvable-spec` is one no known worker has the platform, model, or runtime for, and such a request emits no `lease.queued`. A request a worker refused as unable to serve (`RUNTIME_MISSING`, `UNKNOWN_MODEL`, `NO_DRIVER`) while another worker was busy waits in the gateway queue, unless it is a `noWait` request, which is rejected at once with reason `no-wait` and emits no `lease.queued`; a request that did queue and then finds no worker left emits `unresolvable-spec` after its `lease.queued`, and one that never queued gets only the refusing worker's own `lease.rejected`; `daemon-restarted` is a request still waiting when the daemon stopped, settled as failed when it starts again. The reason list can grow: a consumer must tolerate a reason it does not know; `cancelled` is an explicit single-request cancel (backing `DELETE /v1/lease-requests/{id}`) of a still-queued waiter — one with device work already in flight is reported `not-cancellable` instead, the same envelope the queue timeout already uses | LeaseAcquisitionCoordinator / WaitQueue / StartupConverger (worker) / FleetLeaseCoordinator (gateway) | implemented |

On a **gateway**, the first three of these are its own fleet queue's facts,
emitted by `FleetLeaseCoordinator` and never by the worker whose device is
Expand Down
12 changes: 10 additions & 2 deletions docs/HTTP-API.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,16 @@ class's preference list that the machine lists (see
with no listed model fails with `422 UNKNOWN_MODEL`, naming the config key, and
one whose listed models pair with no installed runtime fails with `RUNTIME_MISSING`.
The granted lease's `device`, `os`, `mode` and `imageTag` always name the device
you got. Through a gateway a request that names no `device` is `400 BAD_REQUEST`
for now. `os` defaults to the newest installed runtime; `ttlMs` defaults to `lease.defaultTtlMs` and is `400 BAD_REQUEST`
you got. Through a gateway a request that names no `device`, or whose `os` is a
range, is `400 BAD_REQUEST` for now. `os` is an exact version (`"18.4"`) or a
range: one or more of `>=`, `>`, `<=`, `<` followed by a version, joined by single
spaces (`">=18 <26"`), or a hyphen range (`"18 - 26"`); a short version covers
everything under it, so `">=18"` is 18.0 and newer and `"<=26"` includes every
26.x. Anything written like a range but outside those forms (`^18`, `~18`, `18.x`, `*`, `||`) is `400 BAD_REQUEST`, and the message names these forms; any other string, such as `Baklava` or `34-ext12`, is an exact version. A
range is granted an idle device whose OS satisfies it, or else a new device on the
newest installed runtime in it; one no installed runtime satisfies fails at once
with `422 RUNTIME_MISSING`, `downloadable: false` and the range as `osVersion`,
whatever `allowDownload` says. `os` defaults to the newest installed runtime; `ttlMs` defaults to `lease.defaultTtlMs` and is `400 BAD_REQUEST`
above `lease.maxTtlMs`; `timeoutMs` (optional) is enforced daemon-side so a
vanished client can't hold a queue slot forever. `mode` (optional, `"slim"`
or `"full"`) is the device mode the request asks for; without it the request
Expand Down
12 changes: 12 additions & 0 deletions docs/internal/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1937,6 +1937,18 @@ still names pool identity for the warm pool, reclaim and the idempotency
check. A class is read from the catalog entry (`modelClasses`) at the moment
a fit is decided; a device record stores none.

`osVersion` is an exact version or an OS range (ADR 0015 §2). The one grammar
is `src/contract/os-range.ts`: the contract schema refines `osVersion`
through its parser (a refinement over the request object, so the MCP SDK's own
field validation never answers first), so a malformed range is `BAD_REQUEST` on
every transport; a string that is not range-like is a bare version and stays
exact, as `Baklava` or `34-ext12` on Android,
and the core and the gateway import `satisfies` and `compareVersions` from it.
For a range the coordinator picks the newest `modelRuntimes` entry in range
(of the requested image tag) for the exact model, or for the first class
candidate that has one, and hands the driver that exact version; none is
`RUNTIME_MISSING` with `downloadable: false`, and a range never installs.

For an exact model: **platform + device model + OS version**.
OS defaults to the newest runtime already installed on the machine that can
actually run the requested model — for iOS specifically, the newest
Expand Down
Loading
Loading