Skip to content
Merged
1 change: 1 addition & 0 deletions docs/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ edit yourself keeps the mode you give it until the next `config set`; run
| `gateway.token` | **Worker side.** The join token (`simlock token create --role worker`, minted on the gateway) this worker presents when it opens its uplink. Required whenever `gateway.url` is set. `simlock config` shows it; the daemon log and the `daemon.started` event show `[redacted]`. It is stored in plain text in `config.json`, which `simlock config set` writes owner-only. | unset |
| `gateway.label` | **Worker side.** Display name for this worker in `simlock worker list`, `status`, the console, and on the lease's `worker` block. Display-only: nothing routes on it and it need not be unique. | the worker's own id |
| `agentDevice.enabled` | **Worker side.** Run one agent-device daemon on this worker, started and watched by Simlock. It sees Simlock's devices and no others, refuses `boot` and `shutdown`, and keeps its files in `~/.simlock/agent-device`. If agent-device is missing, older than 0.21.25, speaks another RPC protocol or needs a newer Node than Simlock runs on, it is not started and Simlock runs on without it. A daemon a killed Simlock left behind is stopped at the next start. With `http.enabled` also `true`, the agent-device CLI reaches it at `/v1/agent-device` (see [HTTP-API.md](HTTP-API.md#v1agent-device)). | `false` |
| `agentDevice.leaseTtlCapMs` | **Worker side.** Caps the TTL of the leases the agent-device CLI makes and renews through Simlock: a longer `ttlMs` is lowered to it, and a lease that sends none gets it. A whole number of milliseconds from `5000` to `lease.maxTtlMs`; a value outside that range stops the daemon at start. Used only when `agentDevice.enabled` is `true`. | unset (no cap) |
| `agentDevice.command` | **Worker side.** The agent-device executable: a name looked up on `PATH`, or a path. Used only when `agentDevice.enabled` is `true`. | `agent-device` |
| `exec.timeoutMs` | **Worker side.** How long one `device.exec` command (`simlock simctl` / `simlock adb` against a gateway or over HTTP) may run before the worker kills it and the operation fails with `EXEC_TIMEOUT`. Authoritative: it bounds the process that actually runs. | `10 minutes` |
| `gateway.routing` | **Gateway side.** Which routing policy places a queued request on a worker. `warm-then-free` is the only policy in v1. Among the workers that can serve the request, in order: a worker whose health is not `running`, or that has requests of its own waiting, is left out; a worker holding a ready device that fits goes first (the device's mode must fit the request, a request with no mode fits a device that serves the worker's default mode, and its runtime must be the one requested or, with none requested, the one the worker would pick: its default runtime if the model pairs with it, otherwise the only runtime the model pairs with); otherwise a worker with no free running slot for the platform or overall is left out (a running device that is not leased counts as free: the worker shuts it down to make room), a worker under its RAM budget for the platform is preferred over one at it (a worker at its budget is still asked when it is the only one left), and the one with the most free running capacity for the platform wins. A worker that is left out is busy, not unable: the request waits for it. Ties go to the lowest worker id. | `warm-then-free` |
Expand Down
25 changes: 20 additions & 5 deletions docs/HTTP-API.md
Original file line number Diff line number Diff line change
Expand Up @@ -1481,9 +1481,21 @@ URL answers `404`.
token's principal, and the lease ID is the 32-hex ID the CLI chose. `close`
ends the agent-device lease and then frees the Simlock lease, so Simlock
wipes the device for the next agent.
- **Heartbeats** reach agent-device unchanged. They do not renew the Simlock
lease yet, so a Simlock lease ends at its own TTL; pass `ttlMs` on `open`
for a longer one.
- **Heartbeats keep the lease.** The CLI sends one before every command except
`devices`. Once agent-device answers it, Simlock renews the lease to now plus
its TTL, unless the lease already runs longer (a longer renewal by the agent
stands). A heartbeat's `ttlMs` changes that TTL, at least 5 seconds and at
most `agentDevice.leaseTtlCapMs` when that is set. While a command runs, the
lease is renewed every third of its TTL, and once more when the command ends.
An agent that stops sending heartbeats loses the device one TTL later.
- **A lease Simlock ended is not replaced quietly.** When the lease is gone
because Simlock ended it (`simlock release`, `release --all`, expiry, a lost
device, a restart of the agent-device daemon or of Simlock), the next
heartbeat answers `lease ended by simlock; run disconnect, then open`, as an
`UNAUTHORIZED` error with `details.reason` `LEASE_ENDED_BY_HOST`. A lease the
agent ended through `close` or `disconnect` answers agent-device's own
`LEASE_NOT_FOUND`, so `close` then `open` works. A heartbeat Simlock cannot
renew for another reason answers `COMMAND_FAILED` with Simlock's message.

What `open` asks Simlock for:

Expand All @@ -1492,7 +1504,7 @@ What `open` asks Simlock for:
| `--platform ios` or `android` | that platform, any device Simlock grants |
| `--target mobile`, `tv`, `desktop` | the class `phone`, `tv`, `desktop` |
| `--device "iPhone 17 Pro"` | that model, and no class: the model wins over `--target` |
| `ttlMs` | that TTL, at least 5 seconds; none sent means `lease.defaultTtlMs` |
| `ttlMs` | that TTL, at least 5 seconds and at most `agentDevice.leaseTtlCapMs` when set; none sent means that cap, or `lease.defaultTtlMs` without one |

Messages the route prints. The agent-device CLI reads the message in the body
(a JSON-RPC error on `/rpc`, `{ "ok": false, "error", "code" }` elsewhere), not
Expand All @@ -1510,7 +1522,10 @@ the status.
sent no lease ID.
- `refused: send lease calls as lease RPCs`: a lease call inside
`agent_device.command`.
- `refused: ttlMs must be a positive number of milliseconds`.
- `refused: ttlMs must be a positive number of milliseconds`: on `open` and on
a heartbeat.
- `lease ended by simlock; run disconnect, then open`: a heartbeat for a lease
Simlock ended.
- `refused: simlock leases only plain devices`: `backend`,
`retainOnClose: true`, a `provider*` or `aws*` key, or a `leaseProvider`
other than `proxy`.
Expand Down
2 changes: 1 addition & 1 deletion docs/internal/COMPONENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ modules with.
| `AgentDeviceSupervisor` | `src/agent-device/host/agent-device-supervisor.ts` | Starting, watching and stopping the one agent-device daemon: reaping one a killed simlock left (by a pid record and an identity check), the private state dir and policy file, the daemon's environment, readiness through `daemon.json`, the port and `/health`, restart on death, and the availability state (`off`, `starting`, `running`, `unavailable` with a reason and remedy). | Serve agent-device traffic; report to `simlock doctor`; decide which devices exist (the drivers' environments do). |
| Install lookup, compatibility, daemon environment | `src/agent-device/host/install.ts`, `src/agent-device/shared/` | Finding the agent-device install and its daemon entry; the minimum versions and RPC protocol; the environment and policy data. | Run a process. |
| `AgentDeviceHealthProbe` | `src/agent-device/host/health.ts` | The `GET /health` read, with a time limit. | Judge the answer. |
| Front | `src/agent-device/front/` | The `/v1/agent-device/*` mount: the role check, the `/rpc` body check, turning an agent-device `allocate` into a simlock `lease.request` (and its cancel when the CLI leaves) and a `release` into a `lease.release`, and the front map of the leases it made. | Check a token (the app does); run the proxy; renew leases (#473). |
| Front | `src/agent-device/front/` | The `/v1/agent-device/*` mount: the role check, the `/rpc` body check, turning an agent-device `allocate` into a simlock `lease.request` (and its cancel when the CLI leaves) and a `release` into a `lease.release`, the front map of the leases it made, and who ended each; the heartbeat, which renews the simlock lease after agent-device answers, and the renewals while a command runs. | Check a token (the app does); run the proxy. |
| `AgentDeviceHost`, `AgentDeviceUpstream` | `src/agent-device/host/host.ts`, `host/upstream.ts` | `@agent-device/proxy` in front of the daemon, one proxy per daemon start; the tenant each request acts as; the port the daemon is reached through and its supervisor adapter. | Know simlock leases. |
| Wire rules | `src/agent-device/shared/` | The path prefixes, the `/rpc` body reader, the call classifier, the lease-call field reader, the reply reader and the front's replies. | Decide what a call means. |
| `FakeAgentDevice` | `src/agent-device/testing.ts` | The in-memory agent-device daemon the proxy sits in front of in tests. | Appear in production code. |
Expand Down
Loading
Loading