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
47 changes: 37 additions & 10 deletions docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -779,11 +779,14 @@ why its Android catalog looks thin, trimmed to one worker:
},
"global": {"running": 0, "maxRunning": 8, "reserved": 0, "overLimit": false, "warm": 0}
},
"downloads": {"policy": "on-request"},
"downloads": {"policy": "on-request", "timeoutMs": 1200000},
"lease": {"maxTtlMs": 14400000},
"queueDepth": 0,
"leases": [],
"devices": [],
"installs": [
{"platform": "ios", "component": "26.4", "state": "downloading", "since": 1790864071200, "waiters": 1}
],
"catalog": [
{
"platform": "ios",
Expand Down Expand Up @@ -814,11 +817,18 @@ why its Android catalog looks thin, trimmed to one worker:
}
```

`downloads.policy` and `lease.maxTtlMs` are that worker's own effective
config, read when its uplink connects and again on every periodic refresh.
`downloads.policy`, `downloads.timeoutMs` and `lease.maxTtlMs` are that
worker's own effective config, read when its uplink connects, again on every
periodic refresh, and after the worker installs a component.
The policy is shown for reference; routing does not read it, since no
download is started through a gateway. `catalog` is what that
worker can lease, each model with the runtimes it pairs with. `host` is the
download is started through a gateway. `installs` lists the
component installs waiting or running on that worker, whoever started them,
in the shape [`simlock status`](#simlock-status) describes. It is re-read
when an install on that worker starts, finishes or fails, and on every
periodic refresh, so an install queued behind another may appear only then.
A disconnected or incompatible worker lists none. `catalog` is what that
worker can lease, each model with the runtimes it pairs with, and lists a
newly installed component as soon as its install ends. `host` is the
machine: operating system, its version, CPU architecture, and the version of
each platform tool its drivers use (`xcode` with its build; the Android
`emulator`, `platform-tools` and `cmdline-tools`). A tool the worker does not
Expand Down Expand Up @@ -976,10 +986,23 @@ platform), the RAM budget (`RAM budget: 4.50 GiB/12.00 GiB used`), every
managed device with its state and device mode
(`Device dev_7: ready, mode slim`), current leases (who — the agent
id, see [Agent identity](#agent-identity) — since when, and when each was last
renewed), and queue depth. `--json` for the structured equivalent. `overLimit`
renewed), the component installs in progress, and queue depth. `--json` for
the structured equivalent. `overLimit`
is true when a lowered limit cannot yet be met, for example because active
leases consume all running slots.

Each install in progress gets one line: platform, component, state, how long
since it was first asked for, and how many requests wait on it
(`Install ios 26.4: downloading for 42s, 2 waiters`). Every install is
listed, whoever started it, for example a lease request with
`--allow-download`. `downloading` means the platform's installer is running;
`waiting` means it is queued behind another install on the same platform, or
about to start. A line goes away as soon as its install ends, whether it
succeeded, failed or timed out. In `--json` the list is `installs`, oldest
first, at most 16 entries: `platform`, `component` (the version, or the word
the platform uses for its newest), `state`, `since` (milliseconds since the
epoch) and `waiters`. It is empty when nothing is installing.

The RAM budget line appears only under the `resource` capacity strategy
(see [CONFIGURATION.md](CONFIGURATION.md#capacity-strategies)); under
`fixed` there is none. In `--json` it is `capacity.ramBudget`:
Expand All @@ -994,10 +1017,12 @@ Against a **gateway** (`config.mode: "gateway"`) the same command
answers for the whole fleet, in the same shape: the daemon line reads
`running (gateway)`, capacity is summed across the connected workers (the RAM
budget over those that report one, over its limit when any worker is), one line
per worker precedes the devices, and every device and lease names the worker it
lives on (`Device dev_7 on wrk_a: leased, mode full`). `--json` gains a `workers` array of
per worker precedes the devices, and every device, lease and install names the
worker it lives on (`Device dev_7 on wrk_a: leased, mode full`,
`Install ios 26.4 on wrk_a: waiting for 3s, 1 waiter`). Installs are listed
for the connected workers, the 16 oldest across the fleet. `--json` gains a `workers` array of
[worker views](#simlock-worker-listdrainundrainremove) and a `workerId` on each
device and lease; `daemon.mode` says which kind of daemon answered.
device, lease and install; `daemon.mode` says which kind of daemon answered.

The daemon block carries `mode` (`"worker"` or `"gateway"`) — the one field
that tells a client which kind of daemon answered. Beside it, `host` says
Expand Down Expand Up @@ -1290,7 +1315,8 @@ operation **on a gateway**; against a worker they answer `UNKNOWN_REQUEST`
identity — stable across restarts, and not its label or host name), its
label if it set one, connection state, capacity, how many leases it
holds, and its host: operating system, version, architecture, and tool
versions. A worker the gateway cannot speak to shows `incompatible` with both
versions. Under each worker, one indented line per component install
waiting or running there, in the form `simlock status` prints. A worker the gateway cannot speak to shows `incompatible` with both
protocol ranges, which is what version skew looks like from here. `--json`
prints the raw worker views, which is what the console renders.
- `drain <worker-id>` / `undrain <worker-id>` — a drained worker keeps its
Expand All @@ -1311,6 +1337,7 @@ operation **on a gateway**; against a worker they answer `UNKNOWN_REQUEST`
```console
$ simlock worker list
wrk_9f2c (mac-mini-1): connected -- ios 1/2, android 0/1, 1 lease(s) -- macOS 15.5 arm64; xcode 16.4 (16F6), emulator 35.4.9
Install ios 26.4: downloading for 42s, 1 waiter
wrk_4a10 (ci-runner-3): disconnected, drained -- ios 0/4, android 0/2, 0 lease(s) -- macOS 14.7 x64; xcode 16.2 (16C5032a)
```

Expand Down
21 changes: 21 additions & 0 deletions docs/CLIENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,27 @@ const { host } = await client.getStatus();
drivers. Each worker's `host` is on its entry in `workers`, and on
`listWorkers()` from the admin client.

## What is installing: `getStatus().installs`

`getStatus()` lists the component installs waiting or running on the
machine, whoever started them, oldest first and at most 16:

```ts
const { installs = [] } = await client.getStatus();
// [{ platform: "ios", component: "26.4", state: "downloading", since: 1790864071200, waiters: 2 }]
```

- `state` is `downloading` while the platform's installer runs, and `waiting`
while the install is queued behind another one on the same platform or
about to start. `since` is when the first request for it arrived; `waiters`
is how many requests wait on it.
- An install leaves the list as soon as it ends, whether it succeeded,
failed or timed out. The field is absent only from an older daemon.
- On a gateway the list covers the connected workers, each entry with its
`workerId`, the 16 oldest across the fleet. Each worker's own list is on
its entry in `workers` and on `listWorkers()`, beside its
`downloads.timeoutMs`.

## One connection, no reconnect, no retry

This is the one thing to internalize before building anything on top of this
Expand Down
48 changes: 40 additions & 8 deletions docs/HTTP-API.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,31 @@ when the use exceeds the limit, for example after a restart with larger
per-device sizes; until a device is deleted, none is created, and no
shut-down slim device boots if its slim size is smaller than the full size.

**`installs`** lists the component installs waiting or running on the
machine, whoever started them (a lease request that allowed a download, for
example), oldest first and at most 16:

```json
"installs": [
{ "platform": "ios", "component": "26.4", "state": "downloading", "since": 1790864071200, "waiters": 2 },
{ "platform": "ios", "component": "26.5", "state": "waiting", "since": 1790864075000, "waiters": 1 }
]
```

`state` is `downloading` while the platform's installer runs, and `waiting`
while the install is queued behind another one on the same platform or about
to start. `component` is the version, or the word the platform uses for its
newest. `since` is when the first request for that install arrived, in
milliseconds since the epoch, and `waiters` is how many requests wait on it.
An install leaves the list as soon as it ends, whether it succeeded, failed
or timed out. A worker always sends the field, empty when nothing is
installing; an older daemon leaves it out.

On a **gateway** the numbers are the fleet's — capacity summed across connected
workers (`ramBudget` over the workers that report one, `overLimit` when any of
them is, absent when none does), every gateway-issued and local lease, every device, the gateway
queue's depth — every lease and device carries the **`workerId`** it lives
them is, absent when none does), every gateway-issued and local lease, every device, the
connected workers' installs (the 16 oldest across the fleet), the gateway
queue's depth — every lease, device and install carries the **`workerId`** it lives
on, and an additive **`workers`** array carries one
[worker view](#worker-routes) per worker:

Expand Down Expand Up @@ -691,11 +712,14 @@ simulated (hence the thin Android catalog), trimmed to one worker:
},
"global": {"running": 0, "maxRunning": 8, "reserved": 0, "overLimit": false, "warm": 0}
},
"downloads": {"policy": "on-request"},
"downloads": {"policy": "on-request", "timeoutMs": 1200000},
"lease": {"maxTtlMs": 14400000},
"queueDepth": 0,
"leases": [],
"devices": [],
"installs": [
{"platform": "ios", "component": "26.4", "state": "downloading", "since": 1790864071200, "waiters": 1}
],
"catalog": [
{
"platform": "ios",
Expand Down Expand Up @@ -726,13 +750,21 @@ simulated (hence the thin Android catalog), trimmed to one worker:
}
```

`downloads.policy` is that worker's own effective policy, read when its
uplink connects and again on every periodic refresh. It is shown for
reference; routing does not read it, since no download is started through a
gateway.
`downloads.policy` and `downloads.timeoutMs` are that worker's own effective
config, read when its uplink connects, again on every periodic refresh, and
after the worker installs a component. The policy is shown for reference;
routing does not read it, since no download is started through a gateway.

`installs` is the worker's own `installs` list from its
[`GET /v1/status`](#get-v1status). It is re-read when an install on that
worker starts, finishes or fails, and on every periodic refresh, so an
install queued behind another may appear only then. A worker that does not
send one shows an empty list; a disconnected or incompatible worker shows
none.

`catalog` is what that worker can lease, each model with the runtimes it
pairs with. `host` is the worker's machine, the same block its own
pairs with, and lists a newly installed component as soon as its install
ends. `host` is the worker's machine, the same block its own
`GET /v1/status` reports, as of the gateway's last refresh: a tool installed
or upgraded on the worker shows here without a restart of either side.

Expand Down
17 changes: 10 additions & 7 deletions docs/internal/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -457,13 +457,16 @@ manually-advanced `Clock`, exactly as the core's tests script drivers.
A **worker view** is what the gateway currently knows about one worker: its
id, `label`, daemon health and version, negotiated protocol range (only when
`incompatible`), capacity per platform, queue depth, leases, devices,
catalog, host facts, effective download policy and `lease.maxTtlMs`, and
drain state. On connect the gateway calls `status.get`, `list.get`,
`catalog.get`, `config.get`, and `events.subscribe` on the worker and builds
the view from the answers. It refreshes status and list on every worker event
that changes capacity or leases. A slow periodic tick refreshes all four
reads, catalog and config included, so a runtime installed on a worker
reaches its view without a restart of either side.
catalog, host facts, installs in progress, effective download policy and
timeout, `lease.maxTtlMs`, and drain state. On connect the gateway calls
`status.get`, `list.get`, `catalog.get`, `config.get`, and `events.subscribe`
on the worker and builds the view from the answers. It refreshes status and
list on every worker event that changes capacity or leases, and on
`component.install-started`, `component.installed` and
`component.install-failed` (ADR 0010 §7); after `component.installed` it
re-reads catalog and config too. A slow periodic tick refreshes all four
reads, catalog and config included, so a runtime installed on a worker by
other means still reaches its view without a restart of either side.

The **host facts** are the `host` block of the worker's `status.get`
(ADR 0008 §5-§8): operating system, version, architecture from the host
Expand Down
95 changes: 95 additions & 0 deletions e2e/installs-in-progress.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { describe, expect, it } from "vitest";

import { freeLoopbackPort, waitFor, withDaemon, type TestEnv } from "./helpers/index.js";

interface Install {
readonly platform: string;
readonly component: string;
readonly state: string;
}

interface WorkerView {
readonly connection: string;
readonly installs?: readonly Install[];
}

/** The installs a worker's own `simlock status --json` lists. */
async function workerInstalls(worker: TestEnv): Promise<readonly Install[]> {
const status = await worker.cli(["status", "--json"]);
expect(status.code, status.stderr).toBe(0);
return (status.json as { installs: readonly Install[] }).installs;
}

/** The installs the gateway's `simlock worker list --json` shows on its only worker's view. */
async function viewInstalls(gateway: TestEnv): Promise<readonly Install[] | undefined> {
const listed = await gateway.cli(["worker", "list", "--json"]);
expect(listed.code, listed.stderr).toBe(0);
return (listed.json as { workers: readonly WorkerView[] }).workers[0]?.installs;
}

describe("installs in progress", () => {
it("shows an install on the worker's status and on its gateway's worker list while it runs, and on neither after it ends", async () => {
const port = await freeLoopbackPort();
const gateway = await withDaemon({
configOverrides: { http: { enabled: true, host: "127.0.0.1", port }, mode: "gateway" },
driver: "none",
});
const minted = await gateway.cli(["token", "create", "--role", "worker"]);
expect(minted.code, minted.stderr).toBe(0);
const { secret } = minted.json as { secret: string };
const worker = await withDaemon({
configOverrides: { gateway: { token: secret, url: `ws://127.0.0.1:${port}` } },
driverScript: {
ios: {
availableOsVersions: ["18.4"],
knownModels: ["iPhone 16"],
// Held open long enough for both CLIs to look at it.
latencyMs: { installComponent: 8_000 },
},
},
});
await waitFor(
async () => {
const listed = await gateway.cli(["worker", "list", "--json"]);
const views = (listed.json as { workers?: readonly WorkerView[] } | undefined)?.workers;
return views?.[0]?.connection === "connected" && views[0].installs !== undefined;
},
{ label: "the worker joined the gateway and its first view arrived" },
);
expect(await workerInstalls(worker)).toEqual([]);
expect(await viewInstalls(gateway)).toEqual([]);

// Through the worker's own socket: a gateway never asks a worker to download.
const lease = worker.cliBackground([
"lease",
"--platform",
"ios",
"--device",
"iPhone 16",
"--os",
"19.0",
"--allow-download",
"--detach",
]);
const downloading = expect.objectContaining({
component: "19.0",
platform: "ios",
state: "downloading",
});
await waitFor(async () => (await workerInstalls(worker)).length === 1, {
label: "the worker's status lists the install",
});
expect(await workerInstalls(worker)).toEqual([downloading]);
await waitFor(async () => (await viewInstalls(gateway))?.length === 1, {
label: "the gateway's worker list shows the install",
});
expect(await viewInstalls(gateway)).toEqual([downloading]);

const granted = await lease.waitForExit(30_000);
expect(granted.code, granted.stderr).toBe(0);
expect(await workerInstalls(worker)).toEqual([]);
await waitFor(async () => (await viewInstalls(gateway))?.length === 0, {
label: "the gateway's worker list drops the install",
});
});
});
Loading
Loading