diff --git a/docs/CONFIGURATION.md b/docs/CONFIGURATION.md index be27dc777..3e33a58c7 100644 --- a/docs/CONFIGURATION.md +++ b/docs/CONFIGURATION.md @@ -458,6 +458,13 @@ is why `ios.slim.bootTimeoutMs` defaults higher than the normal boot timeout, especially on slower CI runners. The `ios.slim.*` keys apply to every slim device the worker makes, whatever its default mode. +An iOS simulator is ready after boot completes and `simctl listapps` succeeds. +Boot completion and installer polling share a 120-second deadline for a full +device and for crash recovery, or `ios.slim.bootTimeoutMs` for each preparation +boot of a supported slim device. +If the deadline expires, readiness fails and Simlock attempts to shut the +simulator down. + **`full` is a guarantee; `slim` is best effort.** A `full` request never receives a slim device. A `slim` request on a runtime that cannot be slimmed -- an iOS runtime older than 18.5, or any Android device -- is granted a full diff --git a/docs/EVENTS.md b/docs/EVENTS.md index 61f1b1005..ea1cf6525 100644 --- a/docs/EVENTS.md +++ b/docs/EVENTS.md @@ -39,7 +39,7 @@ the gateway's own lease index before any worker is ever contacted. `lease-id-tak | Event | Payload (key fields) | Emitted when | Emitter | Status | |---|---|---|---|---| | `device.provisioned` | device id, spec (platform, model, os version, `physical: false`, `mode: "slim"` for a device planned slim, and `imageTag` for a device whose request named one), driver, duration | driver `provision` committed to registry | Registry | implemented | -| `device.ready` | device id, boot duration | readiness probe passed | Registry | implemented | +| `device.ready` | device id, boot duration | readiness probe passed (on iOS simulators, boot completion and a successful installer probe) | Registry | implemented | | `device.reclaimed` | device id, strategy (erase/snapshot/wipe/uninstall), duration, `missingApps` for a physical device (the apps on its enrollment list that were no longer installed; they are reported, not reinstalled) | fresh-state reclaim finished. Never emitted for a device created under `lease.identity` `fresh`: nothing is reclaimed, the device is deleted instead | Registry | implemented | | `device.purge-failed` | device id, lease id, attempted strategy (erase/snapshot/wipe/delete/uninstall), duration, stable error summary | release-time purge failed (including the wipe of a device a daemon start put off; a physical device that reads not present emits nothing and becomes absent), or (strategy `delete`) the shutdown or delete that ends a `fresh` device's lease failed; the device enters `quarantined` (see below) rather than rejoining the pool. The strategy list can grow: a consumer must tolerate a strategy it does not know | Reclaim coordinator | implemented | | `device.quarantined` | device id, max retries, next retry deadline | a device committed to `quarantined` — present in the registry, still counted as running when it is a virtual device, not eligible for a grant. Fires immediately after `device.purge-failed` for a release-time purge or delete failure, or on its own for a stalled-transition timeout (see `device.stalled-transition-detected`) or for a returned physical device whose reclaim failed while it was present | QuarantineCoordinator | implemented | diff --git a/docs/internal/EVENTS.md b/docs/internal/EVENTS.md index 768583e69..ea25c74b9 100644 --- a/docs/internal/EVENTS.md +++ b/docs/internal/EVENTS.md @@ -77,7 +77,7 @@ worker is ever contacted. `lease-id-taken` (ADR 0020; widens a published vocabul | Event | Payload (key fields) | Emitted when | Emitter | Status | |---|---|---|---|---| | `device.provisioned` | device id, spec (`physical: false`, always, ADR 0022 §1: a physical device never emits this event, additive; `mode: "slim"` for a device planned slim, absent for a full one -- the one place the planned mode is visible, ADR 0007 §9; `imageTag` for a device whose request named one, #214, additive), driver, duration | driver `provision` committed to registry | Registry | implemented | -| `device.ready` | device id, boot duration | readiness probe passed | Registry | implemented | +| `device.ready` | device id, boot duration | readiness probe passed (on iOS simulators, boot completion and a successful installer probe) | Registry | implemented | | `device.reclaimed` | device id, strategy (erase/snapshot/wipe/uninstall, ADR 0022 §4), duration, `missingApps` for a physical device (enrollment-list apps no longer installed: reported, not reinstalled; additive) | fresh-state reclaim finished. Never emitted for a device created under `lease.identity` `fresh` (#75): nothing is reclaimed, the device is deleted instead | Registry | implemented | | `device.purge-failed` | device id, lease id, attempted strategy (erase/snapshot/wipe/delete/uninstall), duration, stable error summary | release-time purge failed (including the deferred wipe a daemon start runs in the background, ADR 0019 §2; a physical device read not present emits nothing and becomes `absent`), or (strategy `delete`, #75) the shutdown or delete that ends a `fresh` device's lease failed; the device enters `quarantined` (see below) rather than rejoining the pool. `delete` widens a published vocabulary (events rule 6 allows additive changes): a consumer must tolerate a strategy it does not know | ReclaimCoordinator (strategy `delete`: ReclaimCoordinator's spent-device path) | implemented | | `device.quarantined` | device id, max retries, next retry deadline | a device committed to `quarantined` — present in the registry, still counted as running when it is a virtual device, not eligible for a grant. Fires immediately after `device.purge-failed` for a release-time purge or delete failure (`reclaiming`/`shutdown → quarantined`), or on its own for a stalled-transition timeout (see `device.stalled-transition-detected`) or for a returned physical device whose reclaim failed while it was present (ADR 0022 §8: there is no lease for `device.purge-failed` to name) | QuarantineCoordinator | implemented | @@ -96,13 +96,13 @@ worker is ever contacted. `lease-id-taken` (ADR 0020; widens a published vocabul | `device.recovered` | device id, lease id, attempts, duration | a crashed leased device was rebooted under its existing lease and passed readiness | LeaseHealthMonitor | implemented | | `device.recovery-failed` | device id, lease id, attempts, reason, error | recovery could not restore a leased device (absent from driver reality, provenance drift, or attempts exhausted) and its lease was released | LeaseHealthMonitor | implemented | | `device.orphan-purged` | driver device id, platform, device root | `simlock doctor --purge-orphans` destroyed a device that sat inside a validly-marked Simlock device root with no registry record — see [ADR 0001](adr/0001-simlock-owned-device-roots.md) | Doctor | implemented | -| `device.slimmed` | device id, address, platform (ios), categories, label count, duration, signature, unknown labels | *after* the post-slim reboot's `bootstatus` succeeded -- i.e. once the `launchctl disable` overrides applied via `simctl spawn` are actually in force on the simulator | driver-diagnostics | implemented | +| `device.slimmed` | device id, address, platform (ios), categories, label count, duration, signature, unknown labels | *after* the post-slim reboot's `bootstatus` and installer probe succeeded -- i.e. once the `launchctl disable` overrides applied via `simctl spawn` are actually in force on the simulator | driver-diagnostics | implemented | `device.slimmed` reports a fact committed to the *simulator's own launchd database*, not to the Simlock registry (ADR 0002, `docs/internal/adr/0002-opt-in-slim-ios-simulators.md`) -- so events rule 3 ("emit post-commit only") is satisfied by waiting for that commit to become observable, not by waiting on a registry write: the driver applies the `launchctl disable` overrides, reboots the device, and only fires -`onSlimmed` once the second `bootstatus` has passed, proving the overrides survived the reboot and +`onSlimmed` once the second `bootstatus` and installer probe have passed, proving the overrides survived the reboot and are actually in force. The registry's own `device.ready` for that same boot is a separate, later event, emitted through the normal readiness path once the driver call returns. A slim request on a runtime older than iOS 18.5 is resolved to a full spec before planning (ADR 0007 diff --git a/docs/internal/adr/0002-opt-in-slim-ios-simulators.md b/docs/internal/adr/0002-opt-in-slim-ios-simulators.md index 113a58e5a..bdf86b849 100644 --- a/docs/internal/adr/0002-opt-in-slim-ios-simulators.md +++ b/docs/internal/adr/0002-opt-in-slim-ios-simulators.md @@ -73,15 +73,15 @@ is enabled, the driver: 1. applies the disable list through `simctl spawn launchctl disable`, 2. shuts the device down, -3. boots it again and waits for `bootstatus -b`, +3. boots it again and waits for `bootstatus -b` and a successful `simctl listapps` installer probe, 4. records what it did in `driverData` (see 3), -5. emits `device.slimmed` after the registry commit. +5. emits `device.slimmed` after the overrides have survived the reboot and the installer probe has passed. `makeReady` is the single choke point because it is the only operation that already holds the safety guarantees this needs: it runs on registry-owned -devices, it never runs on a leased device (the crash-recovery exception in -`ManagedDeviceLifecycle.recoverLeased` reboots an already-provisioned device -and is precisely the case where re-slimming is correct), and it downloads +devices, it never runs on a leased device except for crash recovery in +`ManagedDeviceLifecycle.recoverLeased`, which reboots an already-provisioned +device without reapplying the slim pass, and it downloads nothing. Slimming from a cleanup rule, from `doctor`, or from the CLI directly would each have to re-derive those guarantees. @@ -155,7 +155,7 @@ worse than no slim pass. ### 8. The boot deadline accounts for the second boot `ios.slim.bootTimeoutMs` (default ten minutes, matching simslim on CI -runners) replaces the ordinary `bootstatus` deadline, but only for a boot +runners) replaces the ordinary combined `bootstatus` and installer-probe deadline, but only for a boot that will actually slim: a `--full` device, a runtime below the floor, or a recovery boot keeps the normal deadline. `Driver.estimate` quotes the double-boot cost for the same boots so `doctor` does not read a slim boot @@ -165,7 +165,7 @@ as a stalled transition. `device.slimmed` is bridged from the driver's `onSlimmed` callback in the daemon, exactly like `component.install-*`, and fires only once the -post-slim `bootstatus` has passed. The fact it reports is committed to the +post-slim `bootstatus` and installer probe have passed. The fact it reports is committed to the simulator's launchd database, not the registry, which is why the bridge does not wait on a registry write. A skipped or failed slim is a warning log line, not an event. diff --git a/e2e/slow-ios-smoke.test.ts b/e2e/slow-ios-smoke.test.ts index 439dcd1d0..5921dafbf 100644 --- a/e2e/slow-ios-smoke.test.ts +++ b/e2e/slow-ios-smoke.test.ts @@ -2,7 +2,7 @@ import { execFile } from "node:child_process"; import { promisify } from "node:util"; import { describe, expect, it } from "vitest"; -import { withDaemon } from "./helpers/index.js"; +import { IOS, withDaemon } from "./helpers/index.js"; import { iosDeviceSet, setDevices, @@ -221,7 +221,7 @@ describe.skipIf(process.platform !== "darwin")( ); it( - "a platform-only lease grants the first listed phone model booted in Simlock's device set, and the same request after release gets that device back without a second boot", + "a platform-only lease grants the first listed phone model and accepts an immediate install, including after erase and reuse", { timeout: 300_000 }, async () => { await sweepStaleDeviceSets(); @@ -239,6 +239,8 @@ describe.skipIf(process.platform !== "darwin")( expect(first.code, `lease failed: ${first.stderr}`).toBe(0); const firstGrant = first.json as Grant; const udid = firstGrant.device.driverDeviceId; + const firstInstall = await env.cli(["simctl", "install", udid, IOS.app]); + expect(firstInstall.code, `first install failed: ${firstInstall.stderr}`).toBe(0); expect(firstGrant.device.spec.model).toBe(phone); const bootedDevice = (await setDevices(deviceSet)).find((device) => device.udid === udid); expect(bootedDevice?.state).toBe("Booted"); @@ -259,6 +261,13 @@ describe.skipIf(process.platform !== "darwin")( const second = await env.cli(request, { timeout: 120_000 }); expect(second.code, `second lease failed: ${second.stderr}`).toBe(0); const secondGrant = second.json as Grant; + const secondInstall = await env.cli([ + "simctl", + "install", + secondGrant.device.driverDeviceId, + IOS.app, + ]); + expect(secondInstall.code, `install after erase failed: ${secondInstall.stderr}`).toBe(0); expect( secondGrant.device.driverDeviceId, "the same request must reuse the idle device", diff --git a/src/drivers/ios/AGENTS.md b/src/drivers/ios/AGENTS.md index 4dde270ed..9cc088415 100644 --- a/src/drivers/ios/AGENTS.md +++ b/src/drivers/ios/AGENTS.md @@ -37,12 +37,14 @@ Provision — `simctl create simlock- ` → UDID, then Boot — `makeReady`: -1. `simctl boot`, then `simctl bootstatus -b`. Timeout → shut down, `BootTimeoutError`. +1. `simctl boot`, then `simctl bootstatus -b`, then poll `simctl listapps` until it succeeds. + Bootstatus and installer polling share one deadline; each probe is capped at 30 s and + failures retry after 1 s. Deadline expiry → best-effort shutdown, `BootTimeoutError`. 2. Slim pass only for `prepare` + mode `slim` + runtime 18.5+. Too old → skipped, returned `full`. 3. Already slim: `driverData.slimSignature` and `slimMarkToken` match the categories and the current mark → return `slim`, no work. 4. Else `simctl spawn /bin/sh -c` running `launchctl disable system/