Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
65cdd2d
test: a client leases slim with except and is granted a device report…
V3RON Nov 6, 2026
1927c02
feat(leasing): a slim lease with except boots the new device with it …
V3RON Nov 6, 2026
11d612f
test: a client leases slim with except and a warm ready device is shu…
V3RON Nov 6, 2026
3445650
feat(leasing): a ready warm device is rebooted with the except list a…
V3RON Nov 6, 2026
270f529
test: a client's except request is refused with BAD_REQUEST and the r…
V3RON Nov 6, 2026
4f93804
feat(leasing): an except request is refused unless it is a slim iOS s…
V3RON Nov 6, 2026
97478a9
test: an except list reaches the lease request from the CLI and HTTP,…
V3RON Nov 6, 2026
9664448
feat(cli): simlock lease --except, the HTTP body and lease reply carr…
V3RON Nov 6, 2026
cf05d71
test: a failed except boot is never granted (#1330)
V3RON Nov 6, 2026
9d80102
feat(leasing): a failed warm reboot destroys the device and counts to…
V3RON Nov 6, 2026
2f867b7
test: a replay with another except is a conflict, and a failed boot o…
V3RON Nov 6, 2026
4bd1302
feat(leasing): a replay naming another except is a conflict, and the …
V3RON Nov 6, 2026
6b91d9d
docs(leasing): except on the CLI, errors, events and manuals, and its…
V3RON Nov 6, 2026
5714585
refactor(leasing): keep the request comparison and the HTTP dispatch …
V3RON Nov 6, 2026
f04eeef
refactor(leasing): the acquisition's timing and request helpers move …
V3RON Nov 6, 2026
8592d50
docs(leasing): list the acquisition parts and the dispatcher test hel…
V3RON Nov 6, 2026
069bf8f
test(daemon): the warm reboot's new address reaches the granted devic…
V3RON Nov 6, 2026
9c12ffb
fix(leasing): a slim baseline's except names reach the driver, and a …
V3RON Nov 6, 2026
2de21c7
test(leasing): a slim except boot granted full, the retry count of a …
V3RON Nov 6, 2026
1a83811
chore(merge): bring main up to ff11319 into the branch (#1330)
V3RON Nov 6, 2026
cc473a7
chore(merge): bring task/1329 into the branch (#1330)
V3RON Nov 6, 2026
0718248
refactor(daemon): drop the test-dispatcher helpers no test uses after…
V3RON Nov 6, 2026
8c2a41f
fix(contract): the slim except shapes bump the protocol past main's 7…
V3RON Nov 6, 2026
49122bd
chore(stack): merge task/1329 into the slim-except wiring branch, exc…
V3RON Nov 6, 2026
bf1b920
docs(leasing): restore the crash-mid-reboot known gap dropped in the …
V3RON Nov 6, 2026
2f54f9f
Merge remote-tracking branch 'origin/task/1329' into HEAD
V3RON Nov 6, 2026
5241a10
Merge remote-tracking branch 'origin/task/1329' into HEAD
V3RON Nov 6, 2026
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
6 changes: 3 additions & 3 deletions docs/internal/EVENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ in short: `subject.past-tense-fact`, emitted post-commit, facts not commands.

| Event | Payload (key fields) | Emitted when | Emitter | Status |
|---|---|---|---|---|
| `lease.requested` | request id, request spec (platform, `model` only when the request named one, `class` when it named one -- a request naming neither carries neither, ADR 0015 §9, os version -- an exact version or an OS range as typed, ADR 0015 §2, device `mode` as the request named it -- absent when it named none, since the worker's default is applied after this event, ADR 0007 §2; `imageTag` when the request named one, #214, additive; `physical: true` when the request asked for an enrolled physical device, ADR 0022, additive; `baseline`, the name, when the request named one, #1207, additive), requester, wait policy, `fleetRequestId` on a worker's event for a gateway's dispatch (a probe; ADR 0021 §3, additive, events rule 6) | 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 (#72 added the id; additive, events rule 6) | LeaseAcquisitionCoordinator (worker) / FleetLeaseCoordinator (gateway, ADR 0005 §11 — its own fleet queue's admission, before any worker is chosen) | implemented |
| `lease.requested` | request id, request spec (platform, `model` only when the request named one, `class` when it named one -- a request naming neither carries neither, ADR 0015 §9, os version -- an exact version or an OS range as typed, ADR 0015 §2, device `mode` as the request named it -- absent when it named none, since the worker's default is applied after this event, ADR 0007 §2; `imageTag` when the request named one, #214, additive; `physical: true` when the request asked for an enrolled physical device, ADR 0022, additive; `baseline`, the name, when the request named one, #1207, additive; `except`, the list as the request named it, when it named one, ADR 0066 §1, additive), requester, wait policy, `fleetRequestId` on a worker's event for a gateway's dispatch (a probe; ADR 0021 §3, additive, events rule 6) | 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 (#72 added the id; additive, events rule 6) | LeaseAcquisitionCoordinator (worker) / FleetLeaseCoordinator (gateway, ADR 0005 §11 — its own fleet queue's admission, before any worker is chosen) | implemented |
| `lease.queued` | request id, queue position (counted in the request's own line, ADR 0022 §3: a physical request waits apart from simulator and emulator requests) | no capacity; request entered the wait queue | LeaseAcquisitionCoordinator (worker) / FleetLeaseCoordinator (gateway) | implemented |
| `lease.granted` | lease id, device id, requester, request id, source (`warm`/`booted`/`provisioned`, ADR 0016 §2: the kind of the plan that granted it -- an eviction never grants by itself, so the plan made after it decides; a physical grant is `warm`, ADR 0022 §3), `fleetRequestId` when the grant served a probe (ADR 0021 §3, additive), the device's `platform` (`ios` or `android`), `baseline: { name, version }` when the device is a copy of a baseline (#1207, additive) | a device was assigned and handed out | LeaseLifecycle | implemented (payload per ADR 0004 pending) |
| `lease.granted` | lease id, device id, requester, request id, source (`warm`/`booted`/`provisioned`, ADR 0016 §2: the kind of the plan that granted it -- an eviction never grants by itself, so the plan made after it decides; a physical grant is `warm`, ADR 0022 §3; a ready warm device shut down and booted again for a request with `except` is `booted`, because the requester waited for a boot, ADR 0066 §2), `fleetRequestId` when the grant served a probe (ADR 0021 §3, additive), the device's `platform` (`ios` or `android`), `baseline: { name, version }` when the device is a copy of a baseline (#1207, additive) | a device was assigned and handed out | LeaseLifecycle | implemented (payload per ADR 0004 pending) |
| `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 (payload per ADR 0004 pending) |
| `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, or a daemon start found its device not running, or (device-lost, ADR 0022 §7) a physical device was not present for the grace period (`health.stableObservations` reads in a row, `health.probeIntervalMs` apart; emitted by the `PhysicalDeviceWatcher` through `LeaseReleaseCoordinator.endForAbsentDevice`; the device becomes `absent` in the same write and nothing is wiped), and the device of that lease was wiped and returned to the pool, left waiting in `reclaiming` on a platform the daemon could not list, or marked missing. Closing a connection is not a release and never emits this | LeaseLifecycle | implemented (payload per ADR 0004 pending) |
| `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 (payload per ADR 0004 pending) |
Expand Down Expand Up @@ -84,7 +84,7 @@ worker is ever contacted. `lease-id-taken` (ADR 0020; widens a published vocabul
| `device.quarantine-recovered` | device id, attempts, reclaim strategy (erase/snapshot/wipe/uninstall), `missingApps` for a physical device (additive), the device's `platform` (`ios` or `android`) | a quarantined device's retried purge succeeded; it returned to `ready`/`shutdown` and rejoined the warm pool. Never emitted for a spent `fresh` device (`mayBeGranted` false): its retry is a delete, and a successful one emits `device.deleted` with initiator `lease-end` (`lease-engine` for a device that never served a lease) | QuarantineCoordinator | implemented |
| `device.quarantine-abandoned` | device id, attempts, the device's `platform` (`ios` or `android`) | a quarantined device exhausted its configured retry budget (`warmPool.quarantine.maxRetries`) — purge retries, or delete retries for a spent `fresh` device — and was destroyed, or, for a physical device, unenrolled: Simlock never destroys one (safety rule 2, ADR 0022 §4) | QuarantineCoordinator | implemented |
| `device.quarantine-stranded` | device id, attempts, stable error summary, the device's `platform` (`ios` or `android`) | a quarantined device exhausted its retry budget (purge or delete retries) and the destroy that should have retired it also failed; it stays `quarantined` with no further retry until an operator intervenes | QuarantineCoordinator | implemented |
| `device.shutdown` | device id, initiator (rule/command; `daemon-stop` when a stopping daemon shut down an idle device, #1056; `warm-pool` when the warm pool shut an idle device down, over the running limit, with `warmPool.enabled: false`, to keep `warmPool.reserveRunning` running slots free, or because a ready device that never served a lease and that no `warmPool.targets` entry and no kind the pool learned from a lease keeps has been idle past `idle.shutdownAfterMs`, or to displace it: an idle device shut down so a newer learned kind, or a configured target, can boot into its slot) | device stopped, still on disk | Registry; ReclaimCoordinator for interrupted reclaim recovery | implemented |
| `device.shutdown` | device id, initiator (rule/command; `daemon-stop` when a stopping daemon shut down an idle device, #1056; `warm-pool` when the warm pool shut an idle device down, over the running limit, with `warmPool.enabled: false`, to keep `warmPool.reserveRunning` running slots free, or because a ready device that never served a lease and that no `warmPool.targets` entry and no kind the pool learned from a lease keeps has been idle past `idle.shutdownAfterMs`, or to displace it: an idle device shut down so a newer learned kind, or a configured target, can boot into its slot; `lease-engine` when a ready warm device failed the reboot a lease with `except` asked of it, ADR 0066 §2) | device stopped, still on disk | Registry; ReclaimCoordinator for interrupted reclaim recovery | implemented |
| `device.deleted` | device id, initiator (`lease-end` when a `fresh` device's lease ended and its delete completed — from ReclaimCoordinator, at startup convergence, or retried from quarantine; #75. `doctor` when `doctor --fix` marked a missing device, or startup's lease reconciler found a leased device absent from a platform it could read and ended the lease in the same write, ADR 0019 §2. `operator` when `device remove` unenrolled a physical device, ADR 0022 §2. `quarantine` when a physical device's quarantine retries ran out and it was unenrolled, ADR 0022 §4; `lease-engine` when a device that failed to boot for a lease was destroyed in cleanup, or when quarantine's delete retry removed a device that never served a lease; `cleanup-reaper` when the cleanup reaper destroyed a device; `nuke` when `nuke` destroyed it; `baseline-save` when `baseline save` kept a copy of the device and deleted it; `baseline-remove` when `baseline remove` deleted an idle device made from the baseline; `baseline-replaced` when a newer baseline version replaced the one an idle device was made from and the device was deleted), physical (the record's own flag: `true` for an enrolled physical device, `false` for a simulator or emulator; additive, events rule 6) | device removed from the registry, and from disk for a virtual device; a physical device is only forgotten and nothing is sent to it | Registry | implemented |
| `device.enrolled` | device id, platform, driver device id (the canonical ID), model, OS version, class (phone/tablet), app count, reenrolled | an admin's `device add` wrote a physical device `ready` (ADR 0022 §2). `reenrolled` is `true` when the device already had a `ready`, `quarantined` or `absent` record, which kept its registry ID and took a fresh read of model, OS version, class and apps | Registry | implemented |
| `device.absence-detected` | device id, previous state (ready/leased/reclaiming), absent reason (locked/untrusted/not-present) | an enrolled physical device became `absent` (ADR 0022 §2, §7, §8): the `PhysicalDeviceWatcher` read it not present `health.stableObservations` times in a row (a leased device's lease ends first, `lease.released` device-lost, in the same write), or `ReclaimCoordinator` found it not present after a failed reclaim (`reclaiming → absent`, no `device.purge-failed`, no `device.quarantined`). Emitted after the commit | Registry (the watcher's writes, the reclaim's failure path) | implemented |
Expand Down
133 changes: 132 additions & 1 deletion e2e/slow-ios-slim.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ interface LeaseGrant {
readonly lease: string;
readonly udid: string;
readonly mode: "slim" | "full";
/** why: the categories the grant says the lease kept running; absent for a lease with no `--except`. */
readonly except?: readonly string[];
/** The device set the grant says the device lives in; no simctl call reaches it without. */
readonly deviceSet: string;
}
Expand Down Expand Up @@ -103,6 +105,23 @@ async function catalogModelAndOs(env: TestEnv): Promise<{ model: string; os: str
return { model: model as string, os: os as string };
}

/** why: a runtime is picked by version, not by being the newest installed (ADR 0066): the first model the catalog pairs with a runtime `pick` accepts. */
async function catalogModelWithOs(
env: TestEnv,
pick: (versions: readonly string[]) => string | undefined,
): Promise<{ model: string; os: string }> {
const catalog = await env.cli(["catalog", "--json", "--platform", "ios"]);
expect(catalog.code, `catalog failed: ${catalog.stderr}`).toBe(0);
const iosCatalog = (catalog.json as { platforms: CatalogPlatform[] }).platforms.find(
(platform) => platform.platform === "ios",
);
for (const model of iosCatalog?.models ?? []) {
const os = pick([...(iosCatalog?.modelRuntimes[model] ?? [])].sort(compareVersionsDescending));
if (os !== undefined) return { model, os };
}
throw new Error("simlock catalog pairs no iOS model with the runtime this case needs");
}

async function leaseDetached(
env: TestEnv,
model: string,
Expand All @@ -128,14 +147,15 @@ async function leaseDetached(
);
expect(lease.code, `lease failed: ${lease.stderr}`).toBe(0);
const grant = lease.json as {
device: { driverDeviceId: string; mode: "slim" | "full" };
device: { driverDeviceId: string; except?: readonly string[]; mode: "slim" | "full" };
environment: Record<string, string>;
lease: { id: string };
};
const deviceSet = grant.environment.SIMLOCK_IOS_DEVICE_SET;
expect(deviceSet, "an iOS grant must name the device set its device lives in").toBeDefined();
return {
deviceSet: deviceSet as string,
...(grant.device.except === undefined ? {} : { except: grant.device.except }),
lease: grant.lease.id,
mode: grant.device.mode,
udid: grant.device.driverDeviceId,
Expand Down Expand Up @@ -311,6 +331,117 @@ describe.skipIf(process.platform !== "darwin")(
},
);

it.each([
["iOS 18.5", (versions: readonly string[]) => versions.find((v) => v === "18.5")],
[
"the newest iOS 26.x",
(versions: readonly string[]) => versions.find((v) => v.startsWith("26.")),
],
])(
"a lease of --mode slim --except store,other on %s finds every store and other label enabled",
{ timeout: 900_000 },
async (_label, pick) => {
const env = await withRealDaemon();
const { model, os } = await catalogModelWithOs(env, pick);
const except = ["store", "other"];

const grant = await leaseDetached(env, model, os, "slim-except", [
"--mode",
"slim",
"--except",
except.join(","),
]);

await expectSlim(env, grant.mode, "a --mode slim lease with --except must be slim");
expect(grant.except).toEqual(except);
const disabled = await printDisabled(grant);
const kept = labelsFor(
SLIM_CATEGORIES.filter((category) => except.includes(category.name)),
);
expect(
kept.filter((label) => disabled.has(label)),
"a label of an excepted category is still disabled",
).toEqual([]);
await env.cli(["nuke", "--delete-devices", "--yes"], { timeout: 180_000 });
},
);

it(
"on the newest iOS 26.x, excepting each category in turn finds its labels enabled",
{ timeout: 7_200_000 },
async () => {
const env = await withRealDaemon();
const { model, os } = await catalogModelWithOs(env, (versions) =>
versions.find((version) => version.startsWith("26.")),
);
for (const category of SLIM_CATEGORIES) {
const grant = await leaseDetached(env, model, os, `slim-except-${category.name}`, [
"--mode",
"slim",
"--except",
category.name,
]);
await expectSlim(
env,
grant.mode,
`a --mode slim lease excepting ${category.name} must be slim`,
);
expect(grant.except).toEqual([category.name]);
const disabled = await printDisabled(grant);
expect(
labelsFor([category]).filter((label) => disabled.has(label)),
`a label of the excepted category ${category.name} is still disabled`,
).toEqual([]);
await env.cli(["release", grant.lease]);
}
await env.cli(["nuke", "--delete-devices", "--yes"], { timeout: 180_000 });
},
);

it(
"a warm slim device is rebooted with the smaller list and granted",
{ timeout: 1_200_000 },
async () => {
const env = await withRealDaemon({ ios: { defaultMode: "slim" } });
const { model, os } = await catalogModelWithOs(env, (versions) =>
versions.find((version) => version.startsWith("26.")),
);
// why: the pool learns the kind of a lease and boots a warm replacement once it is released.
const taught = await leaseDetached(env, model, os, "slim-teach");
await env.cli(["release", taught.lease]);
let warmUdid: string | undefined;
await waitFor(
async () => {
const rows = (await env.cli(["list", "--devices"])).json as {
driverDeviceId: string;
mode: string;
state: string;
}[];
warmUdid = rows.find(
(row) => row.state === "ready" && row.mode === "slim",
)?.driverDeviceId;
return warmUdid !== undefined;
},
{ timeout: 600_000, label: "a warm slim device is ready" },
);

const grant = await leaseDetached(env, model, os, "slim-warm-except", [
"--except",
"store",
]);

expect(grant.udid, "the warm device is the one granted").toBe(warmUdid);
expect(grant.except).toEqual(["store"]);
const disabled = await printDisabled(grant);
expect(
labelsFor(SLIM_CATEGORIES.filter((category) => category.name === "store")).filter(
(label) => disabled.has(label),
),
).toEqual([]);
await env.cli(["nuke", "--delete-devices", "--yes"], { timeout: 180_000 });
},
);

it(
"no simulator from this file's device sets is still running after its flows",
{ timeout: 60_000 },
Expand Down
4 changes: 3 additions & 1 deletion src/cli/commands/lease.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ async function runLease(
detach: { type: "boolean" },
device: { type: "string" },
"export-env": { type: "boolean" },
except: { type: "string" },
help: { type: "boolean", short: "h" },
"image-tag": { type: "string" },
"lease-id": { type: "string" },
Expand All @@ -64,7 +65,7 @@ async function runLease(
environment.stdout.write(
"Usage: simlock lease --platform <ios|android> [--device <model> | --class <class>]\n" +
" [--os <version|range>] [--mode <slim|full>] [--image-tag <tag>] [--agent-id <id>]\n" +
" [--baseline <name>]\n" +
" [--except <category,...>] [--baseline <name>]\n" +
" [--timeout <duration>] [--lease-id <id>] [--physical]\n" +
" [--no-wait] [--detach] [--ttl <duration>] [--allow-download]\n" +
" [--export-env] [--bind-pid <pid>]\n",
Expand Down Expand Up @@ -202,6 +203,7 @@ async function runLease(
...(values.physical === true ? { physical: true } : {}),
platform,
...(typeof values.mode === "string" ? { mode: values.mode as "slim" | "full" } : {}),
...(typeof values.except === "string" ? { except: values.except.split(",") } : {}),
...(typeof values["image-tag"] === "string" ? { imageTag: values["image-tag"] } : {}),
...(baseline === undefined ? {} : { baseline }),
...(typeof values["lease-id"] === "string" ? { leaseId: values["lease-id"] } : {}),
Expand Down
Loading
Loading