Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ command starts it again) to bring the platform up.
| 2 | `BAD_FRAME` | malformed request frame sent to the daemon |
| 2 | `BAD_REQUEST` | request payload failed validation |
| 2 | `UNSUPPORTED_IN_GATEWAY_MODE` | this command acts on one machine (its devices, or its installed components) and the daemon answering is a gateway; run it on the worker, or for `component install` name the workers with `--worker` or `--all-workers` |
| 2 | `UNSUPPORTED_IN_WORKER_MODE` | this command acts on a gateway's workers (`worker drain`, `undrain`, `remove`, or `component install --worker`/`--all-workers`) and the daemon answering is a single host; run it against the gateway, or for `component install` drop the worker flag to install on this host |
| 2 | `WORKER_CONNECTED` | `worker remove` on a worker whose uplink is still open; `drain` it and let it disconnect first |
| 2 | `UNKNOWN_REQUEST` | the daemon has no such operation — an operation this daemon's mode does not implement (`worker list` against a worker), or a client newer than the daemon |
| 2 | `UNKNOWN_REQUEST` | the daemon has no such operation — usually a client newer than the daemon |
| 2 | `PASSTHROUGH_REFUSED` | a `simctl`/`adb` verb simlock refuses, a caller-supplied `--set`/`-P`, or a bare `adb shell` where there is no terminal to give it |
| 2 | `UNKNOWN_PASSTHROUGH_TOOL` | a passthrough tool simlock does not wrap |
| 2 | `IDEMPOTENCY_CONFLICT` | a lease request reused an idempotency key its requester already sent for a different device; use a new key |
Expand Down Expand Up @@ -98,7 +99,7 @@ surfaced by `lease renew`) falls back to exit 1; the structured stderr line
still reports the specific code — a renew by a running `simlock lease` is the
exception, and exits `14`.

The five gateway-mode codes are placed on existing numbers rather than new
The six fleet codes are placed on existing numbers rather than new
ones, and the numbers are fixed by the contract's error table in the PRs that
implement them:

Expand All @@ -115,13 +116,16 @@ implement them:
later fleet-wide version. `component install` without a worker flag answers
it too; with `--worker` or `--all-workers` it installs on the workers you
name.
- `UNSUPPORTED_IN_WORKER_MODE` is the same refusal from the other side, and
exits `2` for the same reason: `worker drain`, `undrain` and `remove`, and
`component install` with a worker flag, act on a gateway's workers, and a
single host has none. It is permanent for that daemon.
- `UNKNOWN_WORKER` takes `12`, the number the table already gives to "the
thing you named cannot be resolved" (`UNKNOWN_MODEL`, `NO_DRIVER`), because
that is what it is: a worker id the gateway has no record of.
- `PASSTHROUGH_REFUSED`, `UNKNOWN_PASSTHROUGH_TOOL`, and `UNKNOWN_REQUEST`
are not new codes at all — they are already in the contract's table at exit
`2`, and they are listed here because `device.exec` and the `worker.*`
operations are new ways to reach them.
- `PASSTHROUGH_REFUSED` and `UNKNOWN_PASSTHROUGH_TOOL` are not new codes at
all — they are already in the contract's table at exit `2`, and they are
listed here because `device.exec` is a new way to reach them.
- `EXEC_TIMEOUT` joins `QUEUE_TIMEOUT` on `10`, the number that already means
"a deadline elapsed". The two can never be confused, since only `lease`
produces one and only `simctl`/`adb` produce the other. What *can* collide
Expand Down Expand Up @@ -808,10 +812,10 @@ gateway has rebuilt its index.

Operator commands for the workers connected to a **gateway**. All four need
the `admin` role (see [Admin credential
resolution](#admin-credential-resolution)). A worker has no workers of its
own, so it does not implement these operations at all and answers
`UNKNOWN_REQUEST` — they are not a gateway-mode refusal of something a worker
could otherwise do, they are simply not part of a worker's surface. `list`
resolution](#admin-credential-resolution)). A single host answers as a fleet
of one: `list` shows the host itself, and `drain`, `undrain` and `remove`
answer `UNSUPPORTED_IN_WORKER_MODE` (exit 2), because there is no gateway to
take the host out of rotation or forget it. `list`
prints one line per worker, or the views as JSON with `--json`; `drain`,
`undrain` and `remove` print JSON on stdout, unconditionally — `--json` is a
usage error (exit 2) for those three.
Expand Down Expand Up @@ -1274,7 +1278,8 @@ appears in `simlock catalog` at once.
Run the command again.
- **Gateway.** A gateway owns no components. Without a worker flag it
answers `UNSUPPORTED_IN_GATEWAY_MODE` (exit 2) and says to name workers;
see below.
see below. On a single host, a worker flag answers
`UNSUPPORTED_IN_WORKER_MODE` (exit 2); leave it out.

The command takes no `--json`: its output is already JSON, so the flag is a
usage error (exit 2), as is a missing or extra argument or a platform other
Expand Down Expand Up @@ -1696,8 +1701,12 @@ shows the current file with the immediately preceding one prepended.
## `simlock worker <list|drain|undrain|remove>`

The operator's view of a fleet. Every subcommand is an admin
operation **on a gateway**; against a worker they answer `UNKNOWN_REQUEST`
(exit 2), because a worker has no worker registry to answer from.
operation. On a single host, `list` prints one line for that host, with the
same fields a gateway shows for each of its workers: its id is the one it
presents to a gateway, its label is `gateway.label`, and it is always
`connected` and never drained. `drain`, `undrain` and `remove` answer
`UNSUPPORTED_IN_WORKER_MODE` (exit 2) on a single host, because there is no
gateway to take it out of rotation or forget it.

- `list [--json]` — one line per worker: its id (the worker's own instance
identity — stable across restarts, and not its label or host name), its
Expand Down
17 changes: 15 additions & 2 deletions docs/CLIENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ const { results } = await admin.installComponentOnWorkers(
resolves either way; read the outcomes.
- It rejects before any worker is asked with `UNKNOWN_WORKER` for an id the
gateway does not know, `WORKER_UNREACHABLE` for a named worker it cannot
ask, `FORBIDDEN` for an agent session, and `UNKNOWN_REQUEST` from a daemon
that is not a gateway.
ask, `FORBIDDEN` for an agent session, and `UNSUPPORTED_IN_WORKER_MODE`
from a single host. Use `installComponent` there instead.
- A worker's new component is in the gateway's `getCatalog()` by the time
the call resolves, unless the gateway could not read that worker's
catalog just then; its next read brings it in. Nothing is retried or kept
Expand Down Expand Up @@ -669,6 +669,19 @@ neither of which changes a call's shape:
the lease is not necessarily gone, you simply cannot reach it right now,
and it runs on the worker's TTL either way.

The fleet methods on the admin client work against a single host too, which
answers as a fleet of one:

- `listWorkers()` returns one entry, the host itself, with the same fields a
gateway gives each of its workers. Its `id` is the id the host presents to
a gateway, its `label` is `gateway.label`, and it is always `connected` and
never `drained`.
- `drainWorker`, `undrainWorker`, `removeWorker` and
`installComponentOnWorkers` reject with `UNSUPPORTED_IN_WORKER_MODE`, whose
`details.operation` names the operation. It mirrors
`UNSUPPORTED_IN_GATEWAY_MODE`: the operation exists, but not on this kind of
daemon. Do not retry it.

## What this client does not do

- It does not start or stop the daemon. `connectSimlock`/`connectSimlockAdmin`
Expand Down
38 changes: 29 additions & 9 deletions docs/HTTP-API.md
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,8 @@ installs the component itself under its own `downloads.policy`, Android
license setting, disk check and `downloads.timeoutMs`. A worker set to
`downloads.policy: "never"` refuses; the gateway has no download policy of
its own and stores or forwards no image. A drained worker is asked like any
other. `workers` on a daemon that is not a gateway is `400 UNKNOWN_REQUEST`.
other. `workers` on a single host is `501 UNSUPPORTED_IN_WORKER_MODE`; leave
it out to install on that host.

Before any worker is asked, these are JSON errors:

Expand Down Expand Up @@ -927,10 +928,12 @@ liveness signal — [`GET /v1/workers`](#worker-routes) is how you look at it.

### Worker routes

Role: `operator` for all four. They exist on a **gateway**; a worker has no
workers of its own and does not implement the underlying operations at all.
Role: `operator` for all four. They exist on a **gateway** and on a single
host. A single host answers as a fleet of one: `GET /v1/workers` lists the
host itself, and the other three answer `501 UNSUPPORTED_IN_WORKER_MODE`.

- `GET /v1/workers` — every worker view the gateway currently holds.
- `GET /v1/workers` — every worker view the gateway currently holds, or the
host's own view on a single host.
- `POST /v1/workers/{id}/drain` — stop dispatching new requests to this
worker; it keeps the leases it already has.
- `DELETE /v1/workers/{id}/drain` — undrain it, putting it back in rotation.
Expand Down Expand Up @@ -1062,9 +1065,21 @@ first. Unknown ids are the one place remove differs: `200 { "removed": false
gateway has already forgotten — the same reading `token.revoke` gives an
unknown token id.

On a **worker** daemon none of these routes exist: they are not registered at
all, so they answer `404` like any other unrouted path rather than a
gateway-mode refusal. There is nothing for them to act on.
On a **single host** (a daemon in `worker` mode), `GET /v1/workers` returns
one view, the host itself, with the same fields a gateway shows for each of
its workers. `id` is the id the host presents to a gateway, `label` is its
`gateway.label` (absent when unset), `connection` is `connected`, `drained`
is `false`, and `lastSeenAt` is the time of the request. Every other field
comes from the host's own status, devices, catalog and config. Status and
devices are read on every request. The catalog is read again every 30
seconds, and straight after a component is installed, as a gateway reads its
workers' catalogs; a removed component leaves it on the next read. A host that
has joined a gateway still answers about itself: its `drained` is `false`
even when the gateway has drained it, because that flag is the gateway's.

The drain, undrain and remove routes answer `501 UNSUPPORTED_IN_WORKER_MODE`
on a single host, with `operation` in the body: there is no gateway there to
take the host out of rotation or forget it.

### Operator routes

Expand Down Expand Up @@ -1116,11 +1131,11 @@ Every failure is the same shape the daemon protocol uses:
| 404 | `UNKNOWN_WORKER` (`POST`/`DELETE /v1/workers/{id}/drain` naming a worker the gateway does not know), `UNKNOWN_LEASE_REQUEST` (unknown request id), `UNKNOWN_LEASE` (unknown lease id, expired/released, **or `GET /v1/leases/{id}`/`GET /v1/leases/{id}/events` naming another requester's lease** — see [`GET /v1/leases/{id}`](#get-v1leasesid)) |
| 409 | `REQUESTER_ALREADY_LEASED` (body names the existing lease id; fleet-wide on a gateway), `IDEMPOTENCY_CONFLICT` (an `Idempotency-Key` repeated with a different device), `REQUEST_NOT_CANCELLABLE` (body names the lease id if the request had already been granted), `WORKER_CONNECTED` (`DELETE /v1/workers/{id}` while its uplink is open), `COMPONENT_NOT_OWNED`, `COMPONENT_IN_USE` (body carries `devices` and `foreignDevices`), `COMPONENT_BUSY` (the three refusals of `DELETE /v1/components/{platform}/{version}`) |
| 422 | `UNKNOWN_MODEL`, `RUNTIME_MISSING`, `NO_DRIVER`, `PASSTHROUGH_REFUSED` (a refused `exec` verb, a caller-supplied `--set`/`-P`, a bare `adb shell`), `UNKNOWN_PASSTHROUGH_TOOL` |
| 501 | `UNSUPPORTED_IN_GATEWAY_MODE` (an operation that acts on one machine, asked of a gateway: `POST /v1/components/install`, `GET /v1/components`, `DELETE /v1/components/{platform}/{version}`) |
| 501 | `UNSUPPORTED_IN_GATEWAY_MODE` (an operation that acts on one machine, asked of a gateway: `POST /v1/components/install`, `GET /v1/components`, `DELETE /v1/components/{platform}/{version}`), `UNSUPPORTED_IN_WORKER_MODE` (an operation on a gateway's workers, asked of a single host: `POST`/`DELETE /v1/workers/{id}/drain`, `DELETE /v1/workers/{id}`, `POST /v1/components/install` with `workers`) |
| 503 | `NO_CAPACITY` (only with `noWait: true`; response carries `Retry-After`), `WORKER_UNREACHABLE` (a gateway could not reach the worker holding this lease or request) |
| 504 | `EXEC_TIMEOUT` (a `device.exec` command outlived `exec.timeoutMs`), `DOWNLOAD_TIMEOUT` (a runtime download, waiting for another download included, outlived `downloads.timeoutMs`) |

Three notes on these codes.
Four notes on these codes.

`WORKER_UNREACHABLE` sits on `503` with `NO_CAPACITY` rather than on `502`,
because its `kind` is `transport` and every other `transport`-kind code in
Expand All @@ -1144,6 +1159,11 @@ and removals stay per-worker permanently rather than pending some later
fan-out. A component install through a gateway is a different request, one
that names its workers.

`UNSUPPORTED_IN_WORKER_MODE` is the same refusal from the other side: the
operation acts on a gateway's workers, and the daemon is a single host. It
is permanent for that daemon, so do not retry it. Both codes carry
`operation` in the body.

`EXEC_TIMEOUT`'s `504` is documented for completeness rather than for the
exec route: `POST /v1/leases/{id}/exec` has already answered `200` and begun
streaming by the time a command can outlive `exec.timeoutMs`, so on that
Expand Down
26 changes: 23 additions & 3 deletions docs/internal/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,25 @@ and `worker.remove` are the operator's edits to them. A **drained** worker
keeps its existing leases and receives no new dispatches — the tool for
taking a machine down without killing anyone's device.

A worker answers these operations as a **fleet of one** (ADR 0012).
`worker.list` returns one view, the worker itself: its instance id, its
`gateway.label`, `connected`, never drained, `lastSeenAt` the time of the
call. The reported fields come from its own `status.get`, `list.get`,
`catalog.get` and `config.get`, turned into view fields by
`workerViewFields` in `src/contract/worker-view.ts` — the same pure function
`WorkerLink` builds a gateway's views with, so the two cannot disagree about
a field. The catalog is the one read the worker keeps: `catalog.get` runs
each driver's catalog read (`simctl list` on iOS), and the console polls
`GET /v1/workers` every second, so the dispatcher re-reads it only once
`WORKER_VIEW_REFRESH_INTERVAL_MS` (the gateway's own refresh tick) has
passed, or after one of `WORKER_VIEW_CATALOG_EVENTS`. Both constants live
in `src/contract/worker-view.ts`, and `WorkerLink` reads the same two, so a
host's view of itself and a gateway's view of it re-read the catalog on the
same rhythm. The dispatcher's subscriptions end when `DaemonServer` stops. `worker.drain`, `worker.undrain`, `worker.remove` and
`worker.install-component` answer `UNSUPPORTED_IN_WORKER_MODE` (`501`, exit
`2`), the mirror of `UNSUPPORTED_IN_GATEWAY_MODE`. The `/v1/workers*` routes
are registered in both modes.

Drain is the one piece of worker state the gateway *decides* rather than
observes, and it is why the **worker registry** and the worker *view* are two
different things. The view is the observation: rebuilt on every connect,
Expand Down Expand Up @@ -1601,9 +1620,10 @@ last count are not seen; see KNOWN-PITFALLS.md.

#### Through a gateway

`worker.install-component` (ADR 0010 §7) is gateway-only: it is in
`GATEWAY_ONLY_OPERATIONS`, so a worker answers `UNKNOWN_REQUEST`, and no
worker ever receives it, which is why it moves no protocol version. Its input
`worker.install-component` (ADR 0010 §7) only installs through a gateway: a
worker refuses it with `UNSUPPORTED_IN_WORKER_MODE` (ADR 0012 §2), and no
worker ever receives it over an uplink, which is why it moves no protocol
version. Its input
is `{ platform, version, workers }`; `version` runs `component.install`'s own
schema and `workers` is `"all"` or 1 to 64 distinct ids. One function,
`relayComponentInstall` in `src/gateway/component-relay.ts`, does the
Expand Down
19 changes: 5 additions & 14 deletions e2e/contract-surface.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";

import { GATEWAY_ONLY_OPERATIONS, OPERATIONS, type OperationName } from "../src/contract/index.js";
import { OPERATIONS, type OperationName } from "../src/contract/index.js";
import { NodeIpcTransport } from "../src/ports/index.js";
import { SimlockWire, WireCallError } from "../src/simlock-client/wire.js";
import { freeLoopbackPort, withDaemon } from "./helpers/index.js";
Expand Down Expand Up @@ -92,20 +92,11 @@ describe("contract surface", () => {
expect(probedOperations()).toContain("component.install");

// Asserted as one object rather than per operation so a failure names every unreachable
// operation at once, instead of stopping at the first. The gateway-only operations
// (ADR 0005 §23) are the one deliberate exception: a worker has no worker registry, so
// `UNKNOWN_REQUEST` -- "this daemon does not implement that operation" -- is the honest
// answer rather than a routing mistake. The gateway's own sweep below is what proves they
// are reachable somewhere.
// operation at once, instead of stopping at the first. The `worker.*` operations are
// included: a worker answers them as a fleet of one (ADR 0012), so they parse their input
// here too, even the ones it then refuses with `UNSUPPORTED_IN_WORKER_MODE`.
expect(await sweep(env)).toEqual(
Object.fromEntries(
probedOperations().map((name) => [
name,
(GATEWAY_ONLY_OPERATIONS as readonly string[]).includes(name)
? "UNKNOWN_REQUEST"
: "BAD_REQUEST",
]),
),
Object.fromEntries(probedOperations().map((name) => [name, "BAD_REQUEST"])),
);
});

Expand Down
Loading
Loading