Skip to content
Merged
40 changes: 32 additions & 8 deletions docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,18 @@ granted.
leases for the same missing runtime share one download. The whole wait,
queued download included, counts against `downloads.timeoutMs`; running out
is `DOWNLOAD_TIMEOUT` (exit 10). Through a gateway the flag has no effect.
On Android it downloads only a level with no image installed at all, and
only when the `google_apis` image for the host would fit the model: a lease
for a TV at an uninstalled level, or for any model at an installed level
whose images do not fit it, fails with `RUNTIME_MISSING` (exit 12,
`downloadable` `false`) and downloads nothing. The message is `No installed
system image fits <model> at Android <level>: <reason>` (without ` at Android
<level>` when `--os` is not given). The reason is the first of these that rules
out every image: `it needs Android <n> or newer` (or `older`), `it needs a TV
image` (or Wear OS, automotive, desktop, XR, AI glasses, `phone or tablet`, or
`an image tagged <tag>`), `<model> does not take Play Store images`, `<model>
does not take tablet images`, else `none of the installed images fit it`; or
`Android <level> is not installed`, or `no system image is installed`.
- `--ttl <duration>` — the lease's initial TTL, replacing
`lease.defaultTtlMs` (15m) for this lease. Asking for more than
`lease.maxTtlMs` (4h) is a `BAD_REQUEST` (exit 2), not a silent clamp. See
Expand Down Expand Up @@ -298,8 +310,10 @@ granted.
the host's ABI first; without `--os` the lease gets the newest API level
that has one. A lease with `--image-tag` never downloads: if no image of that
tag is installed for the API level it fails with `RUNTIME_MISSING` (exit 12),
`--allow-download` or not. Install other image types with `sdkmanager`. A
lease only reuses an idle device created for the same tag, or for no tag
`--allow-download` or not. The image must also fit the model: if the image
of that tag does not, the lease fails with `RUNTIME_MISSING`, `downloadable`
`false`, saying `the <tag> image does not fit it` and why. Install other image
types with `sdkmanager`. A lease only reuses an idle device created for the same tag, or for no tag
when it names none. On iOS the flag is a `BAD_REQUEST` (exit 2). A tag is 1
to 64 letters, digits, `_`, `.` or `-`. Through a gateway, a lease whose tag
no worker lists for that API level, an iOS one included, fails at once with
Expand Down Expand Up @@ -495,7 +509,10 @@ forward) is gone whether or not recovery succeeds.
A lease names its device in one of three ways:

- `--device <model>` asks for exactly that model. It is granted an idle device
of that model, OS, mode and image tag, as always.
of that model, OS, mode and image tag, as always. On Android an idle device on
a level that no longer fits the model (a TV made on a phone image) is not
reused by a lease that names the model; a class or `--os` range lease can
still pick it until idle cleanup removes it.
- `--class <class>` asks for any model of that class.
- With neither, the lease asks for a `phone`.

Expand Down Expand Up @@ -892,9 +909,7 @@ matches when its model and runtime fit and its mode fits the request: with
`--mode full` it must be a `full` device, with `--mode slim` a `slim` one, and
with no `--mode` it must be one that `status` shows as serving the default mode
(see [`simlock status`](#simlock-status)). With no `--os`, the runtime must be the one
the worker would pick: its default runtime when the model pairs with it,
otherwise the model's only paired runtime. A worker whose model pairs with
several runtimes and no default has no warm match for such a request. A request
the worker would pick: the newest runtime the model pairs with. A request
with no warm match goes to a machine with free capacity, which boots a device.
Otherwise a
worker with no free running slot is passed over (a running device nobody has leased counts as free), a worker under its RAM budget
Expand Down Expand Up @@ -1564,8 +1579,17 @@ installed, which installed runtime is the default (the newest), and for each
model the installed runtimes it pairs with (`modelRuntimes`). A model and a
runtime that are both listed can still fail to pair — on iOS, a runtime can
drop an older model — so pick a pair from `modelRuntimes`. A model with an
empty list pairs with nothing installed. On Android every model pairs with
every installed API level.
empty list pairs with nothing installed. On Android a model pairs with an
installed API level only when an image there fits the model, as Android Studio
would offer it: the image is for the same kind of device (a TV takes `android-tv`
or `google-tv`, a phone takes none of the TV, Wear OS, automotive, desktop, XR
(except `android-xr-ost`), glasses or ChromeOS images), its API level is in the model's range (Pixel 9
needs Android 35 or newer), a Play Store image only goes with a model that
allows Play Store (Pixel 6 does not), and a `tablet` image only with a tablet
model. `runtimes`, `defaultRuntime` and `images` still list every installed
image, so a level can be listed there and absent from every `modelRuntimes`
list. A custom model made in Android Studio but not listed by `avdmanager` pairs
with every installed level for now.

`modelAliases` lists, for a model, the other names `--device` accepts for it
on that machine; a model with no other name has no entry. On Android a
Expand Down
2 changes: 1 addition & 1 deletion docs/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ edit yourself keeps the mode you give it until the next `config set`; run
| `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` |
| `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: the newest 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` |
| `gateway.disconnectedRetentionMs` | **Gateway side.** How long a disconnected worker is kept (greyed, never dispatched to) before the gateway forgets it. The clock is held while the gateway still knows of gateway-issued leases on that worker, and that hold ends when the last of those leases passes its deadline. | `24 hours` |
| `gateway.execTimeoutMs` | **Gateway side.** How long the gateway waits on a proxied `device.exec` before giving up. A backstop for a worker that never answers at all — deliberately longer than the worker's own `exec.timeoutMs`, which is authoritative because that side owns the process and can kill it, so an ordinary timeout surfaces as the worker's `EXEC_TIMEOUT` rather than racing this one. | `11 minutes` |
| `gateway.leaseRequestTimeoutMs` | **Gateway side.** How long the gateway waits on a forwarded `lease.request` before giving up on that worker for this request, answering `WORKER_UNREACHABLE`. Bounds the one uplink call that otherwise had no timeout of its own, so a wedged worker cannot park a request where neither a deadline nor `lease.cancel` could ever reach it again. Generous against a cold device provision-plus-boot; well below `gateway.execTimeoutMs`, since granting a lease should never take as long as a command run against the device afterward. | `5 minutes` |
Expand Down
4 changes: 1 addition & 3 deletions docs/internal/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -702,9 +702,7 @@ The v1 policy (`warm-then-free`) is eight stages:
worker's own catalog: its own name for an exact model, or the class with
the worker's `modelClasses` as `classOf`. The OS is the one requested or
the range requested; with none requested, an exact model needs the runtime
the worker would pick (the catalog's `defaultRuntime` when the model pairs
with it, otherwise its only paired runtime; none when several pair and no
default does) and a class accepts any installed runtime. The mode must
the worker would pick (the newest runtime the model pairs with) and a class accepts any installed runtime. The mode must
fit (ADR 0009 §6): `full` needs a device reporting `mode: "full"`, `slim` one
reporting `slim`, and a request naming none a device reporting
`servesDefaultMode`, which the worker computes in
Expand Down
50 changes: 49 additions & 1 deletion src/core/doctor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3335,6 +3335,7 @@ describe("Doctor: warm pool targets", () => {
readonly enabled?: boolean;
readonly limit?: { ios?: number; android?: number; global?: number };
readonly figures?: ReturnType<typeof figuresOf>;
readonly driver?: Omit<ConstructorParameters<typeof FakeDriver>[0], "clock">;
}): Promise<DoctorFinding[]> {
const clock = new FakeClock(10_000);
const eventBus = new EventBus(clock);
Expand All @@ -3352,7 +3353,7 @@ describe("Doctor: warm pool targets", () => {
targets: options.targets ?? [],
},
},
drivers: [new FakeDriver({ clock, platform: "ios" })],
drivers: [new FakeDriver({ clock, platform: "ios", ...options.driver })],
eventBus,
registry,
warmPool: {
Expand Down Expand Up @@ -3384,6 +3385,53 @@ describe("Doctor: warm pool targets", () => {
]);
});

it.each([
["ios", "iOS", "iPhone 17", ["18.0", "26.0"], "26.0"],
["android", "Android", "Television (1080p)", ["34", "35"], "35"],
] as const)(
"names simlock catalog, not component install, for an installed %s version the target's model does not pair with",
async (platform, name, model, runtimes, unpaired) => {
const found = await findings({
driver: {
availableOsVersions: [...runtimes],
knownModels: [model],
modelRuntimes: { [model]: runtimes.filter((runtime) => runtime !== unpaired) },
platform,
},
figures: figuresOf([{ model, osVersion: unpaired, platform, short: "runtime-missing" }]),
});

expect(found).toStrictEqual([
{
kind: "warm-pool-target-unreachable",
message: `${model} does not pair with ${name} ${unpaired}`,
platform,
reason: "runtime-missing",
remedy: `run simlock catalog --platform ${platform}`,
target: `${model} / ${unpaired} / full`,
},
]);
},
);

it("keeps the install text for a version the platform's catalog does not list", async () => {
const found = await findings({
driver: {
availableOsVersions: ["26.0"],
knownModels: ["iPhone 17"],
platform: "ios",
},
figures: figuresOf([{ model: "iPhone 17", osVersion: "27.0", short: "runtime-missing" }]),
});

expect(found).toStrictEqual([
expect.objectContaining({
message: "iOS 27.0 is not installed",
remedy: "run simlock component install ios 27.0",
}),
]);
});

it("reports a target short with unknown-model as unreachable", async () => {
const found = await findings({
figures: figuresOf([{ model: "iPhone 99", osVersion: "26.0", short: "unknown-model" }]),
Expand Down
57 changes: 52 additions & 5 deletions src/core/doctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type { DeviceOperationClaims } from "./device-operation-claims.js";
import type { StartupRead } from "./startup-read.js";
import {
type Driver,
type DriverCatalogEntry,
type DriverDevice,
type DriverRejection,
type DriverReality,
Expand Down Expand Up @@ -253,7 +254,7 @@ export class Doctor {
const remaining = [
...(purgeOrphans ? await this.#purgeOrphans(findings, driversByPlatform) : findings),
...(await this.#collectPrerequisites(prerequisites)),
...this.#warmPoolFindings(),
...(await this.#warmPoolFindings()),
...this.#optionalModuleFindings(),
];

Expand Down Expand Up @@ -578,19 +579,44 @@ export class Doctor {
}
}

async #catalogsOfMissingRuntimes(
targets: readonly WarmTargetFigures[],
): Promise<Map<Platform, DriverCatalogEntry>> {
const catalogs = new Map<Platform, DriverCatalogEntry>();
const platforms = new Set(
targets.filter((target) => target.short === "runtime-missing").map((t) => t.platform),
);
for (const driver of this.options.drivers) {
if (!platforms.has(driver.platform)) continue;
try {
catalogs.set(driver.platform, await driver.listCatalog());
} catch (error) {
this.#logger.warn("Could not read a catalog for a warm pool finding", {
error: errorMessage(error),
platform: driver.platform,
});
}
}
return catalogs;
}

/**
* The warm pool's targets that cannot be met as configured: those the last pass found a runtime
* or a model missing for, and the platforms (or the machine) whose targets add up to more than
* the running limit leaves once the reserve is held back. Read, never acted on, like
* `prerequisite-missing`. A target short for RAM, the device limit or a failed boot is no
* finding: those pass with time or with an operator's choice of machine. None with the pool off.
*/
#warmPoolFindings(): DoctorFinding[] {
async #warmPoolFindings(): Promise<DoctorFinding[]> {
const { warmPool } = this.options;
const { enabled, targets } = this.options.config.warmPool;
if (warmPool === undefined || !enabled) return [];
const limits = warmPool.runningCapacity();
const findings = warmPool.figures().targets.flatMap(unreachableTarget);
const figures = warmPool.figures().targets;
const catalogs = await this.#catalogsOfMissingRuntimes(figures);
const findings = figures.flatMap((target) =>
unreachableTarget(target, catalogs.get(target.platform)),
);
const reserves = reservedRunning(this.options.config.warmPool, limits);
let wanted = 0;
for (const platform of ["ios", "android"] as const) {
Expand Down Expand Up @@ -1075,8 +1101,11 @@ function isRange(osVersion: string): boolean {
return parsed.ok && parsed.constraint.kind === "range";
}

/** A warm target the last pass could find no runtime or no model for, as a finding. */
function unreachableTarget(target: WarmTargetFigures): DoctorFinding[] {
// fallow-ignore-next-line complexity -- one finding per short reason, each a fixed message.
function unreachableTarget(
target: WarmTargetFigures,
catalog: DriverCatalogEntry | undefined,
): DoctorFinding[] {
const { model, osVersion, platform, short } = target;
const named = [model, osVersion, target.mode].filter((part) => part !== undefined).join(" / ");
const name = PLATFORM_NAMES[platform];
Expand All @@ -1094,6 +1123,24 @@ function unreachableTarget(target: WarmTargetFigures): DoctorFinding[] {
},
];
}
if (
model !== undefined &&
osVersion !== undefined &&
catalog?.runtimes.includes(osVersion) === true &&
catalog.modelRuntimes[model] !== undefined &&
!catalog.modelRuntimes[model].includes(osVersion)
) {
return [
{
kind: "warm-pool-target-unreachable",
message: `${model} does not pair with ${name} ${osVersion}`,
platform,
reason: short,
remedy: `run simlock catalog --platform ${platform}`,
target: named,
},
];
}
return [
{
kind: "warm-pool-target-unreachable",
Expand Down
17 changes: 17 additions & 0 deletions src/drivers/android/device-profile-source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@ describe("BuiltinDeviceProfileSource", () => {
]);
});

it("keeps a profile's raw Tag value as tag, besides the class it maps to", async () => {
const runner = new ScriptedProcessRunner([
processResult(
`Available devices:\nid: 0 or "tv_sdk"\n Name: Sdk TV\n OEM : Google\n Tag : google-tv\n---------\n` +
`id: 1 or "glasses"\n Name: Glasses\n OEM : Google\n Tag : ai-glasses\n`,
),
]);
const source = new BuiltinDeviceProfileSource(avdmanager, runner);

const profiles = await source.profiles();

expect(profiles.map((profile) => [profile.name, "tag" in profile && profile.tag])).toEqual([
["Sdk TV", "google-tv"],
["Glasses", "ai-glasses"],
]);
});

it("marks a profile custom only when avdmanager lists it with OEM : User", async () => {
const runner = new ScriptedProcessRunner([
processResult(
Expand Down
Loading
Loading