diff --git a/docs/internal/EVENTS.md b/docs/internal/EVENTS.md index c5e7a8f72..cde25fb50 100644 --- a/docs/internal/EVENTS.md +++ b/docs/internal/EVENTS.md @@ -70,7 +70,7 @@ worker is ever contacted. `lease-id-taken` (ADR 0020; widens a published vocabul |---|---|---|---|---| | `capacity.changed` | per platform (`ios`, `android`) and `global`: running, max running, reserved, warm; `ramBudget` (used bytes, limit bytes) only under the `resource` capacity strategy | a worker's capacity figures differ from the last ones emitted: after a registry commit, or after a provisioning or boot reservation is taken or released. Emitted once when the daemon has started, so every run begins with a step; two consecutive events never carry equal figures. The figures are the ones `simlock status` reports | CapacityObserver (worker) | implemented | | `queue.changed` | depth, `physical: true` when the physical line changed (ADR 0022 §3, additive, events rule 6) | the number of requests waiting in a queue changed: a request joined it or left it. A queue has two lines; `depth` is the changed line's, and the event without `physical` is the virtual line's. Emitted once when the daemon has started. A worker emits it for its own queue and a gateway for its fleet queue; a worker's events a gateway relays carry `workerId`, and the gateway's own do not | WaitQueue (worker) / FleetLeaseCoordinator (gateway) | implemented | -| `warm-pool.target-missed` | `{ platform, model, osVersion?, mode, count, ready, reason }` — `osVersion` is the resolved one, or the configured one for a target that did not resolve, and absent when it names none and did not resolve; `reason` is the one reason the pool records for the target (`warm-pool/policy.ts` for one that resolved, `warm-pool/converger.ts` for one the resolver refused), the one `short` carries in `status.get` (the one reason `simlock status` shows as the target's `short`, but never `disabled`, since a pool that is off reports no target: `no-driver`, `runtime-missing`, `unknown-model`, `unresolvable`, `boot-failed`, `device-limit`, `running-limit`, `reserve` or `ram-budget`) | a warm pool target went short: after a pass the pool could do nothing for a target that has fewer ready devices than its count, and it was not already missed (ADR 0017 §7). Emitted once the pass's actions have run (events rule 3), once per report on that edge (targets that resolve to one spec are one report and emit one event between them, with their counts added; each target the resolver refuses emits its own), not on each short pass after, nor when a retry or a boot fills it and it is short again; the edge is kept per configured target, and only ready devices reaching its count end the miss, so a target met in between and missed again emits again. A target that is filling, held by `warmPool.maxConcurrentBoots` or waiting behind a queued request the pool could not serve is not short | WarmPool (worker) | implemented | +| `warm-pool.target-missed` | `{ platform, model, osVersion?, mode, origin, count, ready, reason }` — `origin` is always `configured`: the event is for the `warmPool.targets` entries, never for a kind the pool learned, and `count` is the configured count (ADR 0038 §8); `osVersion` is the resolved one, or the configured one for a target that did not resolve, and absent when it names none and did not resolve; `reason` is the one reason the pool records for the target (`warm-pool/policy.ts` for one that resolved, `warm-pool/converger.ts` for one the resolver refused), the one `short` carries in `status.get` (the one reason `simlock status` shows as the target's `short`, but never `disabled`, since a pool that is off reports no target: `no-driver`, `runtime-missing`, `unknown-model`, `unresolvable`, `boot-failed`, `device-limit`, `running-limit`, `reserve` or `ram-budget`) | a warm pool target went short: after a pass the pool could do nothing for a target that has fewer ready devices than its count, and it was not already missed (ADR 0017 §7). Emitted once the pass's actions have run (events rule 3), once per report on that edge (targets that resolve to one spec are one report and emit one event between them, with their counts added; each target the resolver refuses emits its own), not on each short pass after, nor when a retry or a boot fills it and it is short again; the edge is kept per configured target, and only ready devices reaching its count end the miss, so a target met in between and missed again emits again. A target that is filling, held by `warmPool.maxConcurrentBoots` or waiting behind a queued request the pool could not serve is not short | WarmPool (worker) | implemented | ## Device lifecycle diff --git a/src/bus/index.ts b/src/bus/index.ts index 1125f9996..ae9e996bc 100644 --- a/src/bus/index.ts +++ b/src/bus/index.ts @@ -297,6 +297,7 @@ export interface EventMap { /** Absent for a target that names none and did not resolve. */ readonly osVersion?: string; readonly mode: "slim" | "full"; + readonly origin: "configured"; readonly count: number; readonly ready: number; /** why: one reason, not all: the first of the reasons the target is short that applies. */ diff --git a/src/cli/format.ts b/src/cli/format.ts index c837800d5..11ec2f694 100644 --- a/src/cli/format.ts +++ b/src/cli/format.ts @@ -256,11 +256,11 @@ function formatWarmPool(warmPool: NonNullable): str return [ `warm pool: ${enabled ? "enabled" : "disabled"}, reserve ios ${reserveRunning.ios} android ${reserveRunning.android}`, ...targets.map((target) => { - const name = [target.model, target.osVersion, target.mode] + const name = [target.model, target.osVersion, target.mode, target.imageTag] .filter((part) => part !== undefined) .join(" / "); const short = target.short === undefined ? "" : ` short: ${target.short}`; - return ` ${name} wanted ${target.count} ready ${target.ready} booting ${target.booting}${short}`; + return ` ${name} ${target.origin} wanted ${target.count} ready ${target.ready} booting ${target.booting}${short}`; }), ]; } diff --git a/src/cli/index.test.ts b/src/cli/index.test.ts index 61e8bcae0..fe4f4cff0 100644 --- a/src/cli/index.test.ts +++ b/src/cli/index.test.ts @@ -4112,6 +4112,7 @@ describe("CLI: status renders the fleet a gateway reports (ADR 0005 §20)", () = count: 2, mode: "full" as const, model: "iPhone 17", + origin: "configured" as const, osVersion: "26.0", platform: "ios" as const, ready: 1, @@ -4121,17 +4122,29 @@ describe("CLI: status renders the fleet a gateway reports (ADR 0005 §20)", () = count: 1, mode: "full" as const, model: "iPhone 17", + origin: "learned" as const, osVersion: "27.0", platform: "ios" as const, ready: 0, short: "runtime-missing" as const, }, + { + booting: 0, + count: 1, + imageTag: "google_apis_playstore", + mode: "full" as const, + model: "Pixel 8", + origin: "learned" as const, + osVersion: "35", + platform: "android" as const, + ready: 1, + }, ], }; const statusWith = (block: StatusGetOutput["warmPool"]) => fakeClient({ getStatus: () => Promise.resolve({ ...EMPTY_STATUS, warmPool: block }) }); - it("simlock status prints whether the pool is on, the reserve, and each target with how many are wanted, ready and booting, and why it is short", async () => { + it("simlock status prints the origin word on every warm pool line, learned lines included, the tag in the name, and a learned line's short:", async () => { const output = outputCapture(); await runCli( @@ -4141,8 +4154,9 @@ describe("CLI: status renders the fleet a gateway reports (ADR 0005 §20)", () = expect(output.stdout).toContain( "warm pool: enabled, reserve ios 1 android 0\n" + - " iPhone 17 / 26.0 / full wanted 2 ready 1 booting 1\n" + - " iPhone 17 / 27.0 / full wanted 1 ready 0 booting 0 short: runtime-missing\n", + " iPhone 17 / 26.0 / full configured wanted 2 ready 1 booting 1\n" + + " iPhone 17 / 27.0 / full learned wanted 1 ready 0 booting 0 short: runtime-missing\n" + + " Pixel 8 / 35 / full / google_apis_playstore learned wanted 1 ready 1 booting 0\n", ); }); @@ -4157,6 +4171,7 @@ describe("CLI: status renders the fleet a gateway reports (ADR 0005 §20)", () = count: 1, mode: "slim" as const, model: "iPhone 17", + origin: "configured" as const, platform: "ios" as const, ready: 0, }, @@ -4170,7 +4185,7 @@ describe("CLI: status renders the fleet a gateway reports (ADR 0005 §20)", () = expect(output.stdout).toContain( "warm pool: enabled, reserve ios 0 android 0\n" + - " iPhone 17 / slim wanted 1 ready 0 booting 0\n", + " iPhone 17 / slim configured wanted 1 ready 0 booting 0\n", ); }); @@ -4194,7 +4209,7 @@ describe("CLI: status renders the fleet a gateway reports (ADR 0005 §20)", () = expect(output.stdout).toContain( "warm pool: disabled, reserve ios 0 android 0\n" + - " iPhone 17 / 26.0 / full wanted 2 ready 0 booting 0 short: disabled\n", + " iPhone 17 / 26.0 / full configured wanted 2 ready 0 booting 0 short: disabled\n", ); }); diff --git a/src/contract/AGENTS.md b/src/contract/AGENTS.md index 715684d66..4b4715889 100644 --- a/src/contract/AGENTS.md +++ b/src/contract/AGENTS.md @@ -55,7 +55,7 @@ Three identities: ## Protocol version -- `PROTOCOL_VERSION_RANGE` in `protocol.ts` holds it, now `{ min: 52, max: 52 }`. `DAEMON_PROTOCOL_VERSION` (`src/daemon-protocol/`) is its `max`. +- `PROTOCOL_VERSION_RANGE` in `protocol.ts` holds it, now `{ min: 53, max: 53 }`. `DAEMON_PROTOCOL_VERSION` (`src/daemon-protocol/`) is its `max`. - Every change to a contract shape bumps it by one in the same PR. Move `min` too, unless a compatibility path stays side by side. `.agents/scripts/protocol-bump-check.mjs` checks it on push and in CI; it counts every file here as a shape but tests, `index.ts` and the diff --git a/src/contract/operations.test.ts b/src/contract/operations.test.ts index f5b17ef62..65e15ba87 100644 --- a/src/contract/operations.test.ts +++ b/src/contract/operations.test.ts @@ -537,6 +537,7 @@ describe("operation input/output round trips", () => { count: 2, mode: "full", model: "iPhone 17", + origin: "configured", osVersion: "26.0", platform: "ios", ready: 1, @@ -546,6 +547,7 @@ describe("operation input/output round trips", () => { count: 1, mode: "full", model: "iPhone 17", + origin: "learned", osVersion: "27.0", platform: "ios", ready: 0, @@ -594,7 +596,7 @@ describe("operation input/output round trips", () => { ).toEqual({ daemon: { health: "starting", mode: "worker" }, host }); }); - it("rejects a short outside the ten reasons, and a target list longer than 256", () => { + it("rejects a short outside the ten reasons, and a target list longer than 320", () => { const target = warmPool.targets[0]; expect(() => OPERATIONS["status.get"].output.parse({ @@ -605,7 +607,7 @@ describe("operation input/output round trips", () => { expect(() => OPERATIONS["status.get"].output.parse({ ...running, - warmPool: { ...warmPool, targets: Array.from({ length: 257 }, () => target) }, + warmPool: { ...warmPool, targets: Array.from({ length: 321 }, () => target) }, }), ).toThrow(); }); @@ -628,6 +630,7 @@ describe("operation input/output round trips", () => { count: 1, mode: "full", model: "iPhone 17", + origin: "configured", platform: "ios", ready: 0, short, diff --git a/src/contract/protocol.ts b/src/contract/protocol.ts index d537902ce..34403ac17 100644 --- a/src/contract/protocol.ts +++ b/src/contract/protocol.ts @@ -10,7 +10,7 @@ export interface ProtocolRange { const protocolRangeSchema = z.object({ min: z.number().int(), max: z.number().int() }); /** Widen only once a second version is kept alive side by side with the first; a bump that leaves no shim behind moves both ends. */ -export const PROTOCOL_VERSION_RANGE: ProtocolRange = { min: 52, max: 52 }; +export const PROTOCOL_VERSION_RANGE: ProtocolRange = { min: 53, max: 53 }; const LEGACY_DAEMON_PROTOCOL_VERSION = 2; diff --git a/src/contract/schemas.test.ts b/src/contract/schemas.test.ts index 83e6323d5..ce77ce6df 100644 --- a/src/contract/schemas.test.ts +++ b/src/contract/schemas.test.ts @@ -14,6 +14,7 @@ import { leaseGrantSchema, leaseRequestRecordSchema, platformCatalogSchema, + statusWarmPoolSchema, statusDeviceSchema, waitingRequestSchema, workerViewSchema, @@ -1006,3 +1007,45 @@ describe("waitingRequestSchema's workers", () => { ).toBe(false); }); }); + +describe("statusWarmPoolSchema", () => { + const entry = { + booting: 0, + count: 1, + mode: "full", + model: "Pixel 8", + origin: "learned", + osVersion: "35", + platform: "android", + ready: 1, + }; + const block = (targets: readonly unknown[]) => ({ + enabled: true, + reserveRunning: { android: 0, ios: 0 }, + targets, + }); + const { origin: _origin, ...withoutOrigin } = entry; + + it("accepts origin configured and learned, an optional imageTag, and 320 entries, and refuses an entry without origin or with another word, a tag imageTagSchema refuses, and 321 entries", () => { + const cases: readonly { name: string; targets: readonly unknown[]; accepted: boolean }[] = [ + { accepted: true, name: "learned", targets: [entry] }, + { accepted: true, name: "configured", targets: [{ ...entry, origin: "configured" }] }, + { accepted: true, name: "a tag", targets: [{ ...entry, imageTag: "google_apis_playstore" }] }, + { accepted: true, name: "320 entries", targets: Array.from({ length: 320 }, () => entry) }, + { accepted: false, name: "no origin", targets: [withoutOrigin] }, + { accepted: false, name: "another word", targets: [{ ...entry, origin: "remembered" }] }, + { accepted: false, name: "a bad tag", targets: [{ ...entry, imageTag: "no spaces" }] }, + { accepted: false, name: "321 entries", targets: Array.from({ length: 321 }, () => entry) }, + ]; + + expect( + cases.map(({ name, targets }) => [ + name, + statusWarmPoolSchema.safeParse(block(targets)).success, + ]), + ).toEqual(cases.map(({ accepted, name }) => [name, accepted])); + expect( + statusWarmPoolSchema.parse(block([{ ...entry, imageTag: "google_apis" }])).targets[0], + ).toMatchObject({ imageTag: "google_apis", origin: "learned" }); + }); +}); diff --git a/src/contract/schemas.ts b/src/contract/schemas.ts index 148a03e1b..c469c5069 100644 --- a/src/contract/schemas.ts +++ b/src/contract/schemas.ts @@ -517,9 +517,11 @@ export const statusCapacitySchema = z.object({ }); /** Bounds on the warm pool block: a gateway parses it off the wire from every worker. */ -/** The most targets the block carries, and the longest model or OS version it names. The config load enforces the same. */ +/** why: the most configured targets the config load accepts (the block itself takes `WARM_POOL_ENTRIES_MAX`), and the longest model or OS version the block names. */ export const WARM_POOL_TARGETS_MAX = 256; export const WARM_POOL_NAME_MAX = 256; +/** why: the configured targets plus the learned kinds, 32 per platform, the pool keeps. */ +const WARM_POOL_ENTRIES_MAX = WARM_POOL_TARGETS_MAX + 64; /** Why a warm target is short, in the order the first that applies is the one reported. */ const warmPoolShortSchema = z.enum([ @@ -540,6 +542,8 @@ const warmPoolTargetSchema = z.object({ model: z.string().max(WARM_POOL_NAME_MAX), osVersion: z.string().max(WARM_POOL_NAME_MAX).optional(), mode: z.enum(["slim", "full"]), + imageTag: imageTagSchema.optional(), + origin: z.enum(["configured", "learned"]), count: z.number().int().nonnegative(), ready: z.number().int().nonnegative(), booting: z.number().int().nonnegative(), @@ -553,7 +557,7 @@ export const statusWarmPoolSchema = z.object({ ios: z.number().int().nonnegative(), android: z.number().int().nonnegative(), }), - targets: z.array(warmPoolTargetSchema).max(WARM_POOL_TARGETS_MAX), + targets: z.array(warmPoolTargetSchema).max(WARM_POOL_ENTRIES_MAX), }); export const daemonHealthSchema = z.enum(["starting", "running", "failed"]); diff --git a/src/core/doctor.test.ts b/src/core/doctor.test.ts index 13264ed21..844811742 100644 --- a/src/core/doctor.test.ts +++ b/src/core/doctor.test.ts @@ -2387,6 +2387,7 @@ describe("Doctor: optional module findings", () => { count: 1, mode: "full" as const, model: "iPhone 17", + origin: "configured" as const, osVersion: "27.0", platform: "ios" as const, ready: 0, @@ -2957,6 +2958,7 @@ describe("Doctor: warm pool targets", () => { const figuresOf = ( targets: readonly { model: string; + origin?: "configured" | "learned"; osVersion?: string; platform?: "ios" | "android"; short?: "runtime-missing" | "unknown-model" | "ram-budget"; @@ -2968,6 +2970,7 @@ describe("Doctor: warm pool targets", () => { booting: 0, count: 1, mode: "full" as const, + origin: "configured" as const, platform: "ios" as const, ready: 0, ...target, @@ -3010,11 +3013,13 @@ describe("Doctor: warm pool targets", () => { return report.findings.filter((finding) => finding.kind === "warm-pool-target-unreachable"); } - it("reports a target short with runtime-missing as unreachable, naming the install command", async () => { + it("reports a configured target short with runtime-missing as unreachable, naming the install command, and no learned entry, even one short runtime-missing", async () => { const found = await findings({ figures: figuresOf([ { model: "iPhone 17", osVersion: "26.0" }, { model: "iPhone 17", osVersion: "27.0", short: "runtime-missing" }, + { model: "iPhone 16", origin: "learned", osVersion: "27.0", short: "runtime-missing" }, + { model: "iPhone 15", origin: "learned", osVersion: "26.0", short: "unknown-model" }, ]), }); diff --git a/src/core/doctor.ts b/src/core/doctor.ts index 5575b0a02..b910ea1a9 100644 --- a/src/core/doctor.ts +++ b/src/core/doctor.ts @@ -599,7 +599,7 @@ export class Doctor { } /** - * The warm pool's targets that cannot be met as configured: those the last pass found a runtime + * why: the warm pool's configured targets (a learned kind is never a finding) that cannot be met: 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 @@ -610,7 +610,7 @@ export class Doctor { const { enabled, targets } = this.options.config.warmPool; if (warmPool === undefined || !enabled) return []; const limits = warmPool.runningCapacity(); - const figures = warmPool.figures().targets; + const figures = warmPool.figures().targets.filter((target) => target.origin === "configured"); const catalogs = await this.#catalogsOfMissingRuntimes(figures); const findings = figures.flatMap((target) => unreachableTarget(target, catalogs.get(target.platform)), diff --git a/src/core/warm-pool/AGENTS.md b/src/core/warm-pool/AGENTS.md index 25ac27e1f..bd185a543 100644 --- a/src/core/warm-pool/AGENTS.md +++ b/src/core/warm-pool/AGENTS.md @@ -76,16 +76,17 @@ every call, so cancellation removes this protection. The reaper's `idle-shutdown these devices. With no pass yet, it resolves the targets first. With the pool off it returns none. Figures (`figures()`, read by `status.get`, doctor's `warm-pool-target-unreachable`, the console): -`enabled`, `reserveRunning`, and per kind `platform`, `model`, `osVersion`, `mode`, `count`, `ready`, -`booting`, `short`. Before the first pass, or with the pool off, they come from config. +`enabled`, `reserveRunning`, and per kind `platform`, `model`, `osVersion`, `mode`, `imageTag`, `origin` +(`configured` or `learned`), `count`, `ready`, `booting`, `short`; learned kinds included, a merged kind once +with the larger count. Before the first pass, or with the pool off, they are the configured targets from config. `short`, the first that applies: `disabled`; set in the converger `no-driver`, `runtime-missing`, `unknown-model`, `unresolvable`; set in the policy `boot-failed`, `device-limit`, `running-limit`, `reserve`, `ram-budget`. None while filling or waiting behind a queued request the pass could not serve. `warm-pool.target-missed`: once per report that is short now and whose configured targets have not -missed since they were last met (ready ≥ count). Payload: platform, model, osVersion, mode, count, -ready, reason. +missed since they were last met (ready ≥ count). Configured targets only, by the configured count. Payload: +platform, model, osVersion, mode, origin (`configured`), count, ready, reason. Stop: `close()` at stop start; `drain()` finishes the pass and running boots, starts nothing; `dispose()` cancels the timers. diff --git a/src/core/warm-pool/converger.test.ts b/src/core/warm-pool/converger.test.ts index 3f231eae3..6d4cf8970 100644 --- a/src/core/warm-pool/converger.test.ts +++ b/src/core/warm-pool/converger.test.ts @@ -1823,6 +1823,7 @@ describe("warm pool targets", () => { const wanted = { mode: "full", model: "iPhone 17", + origin: "configured", osVersion: "26.0", platform: "ios", } as const; @@ -1976,6 +1977,7 @@ describe("warm pool targets", () => { count: 1, mode: "full", model: "iPhone 17", + origin: "configured", platform: "ios", ready: 0, short: "no-driver", @@ -2006,6 +2008,7 @@ describe("warm pool targets", () => { count: 1, mode: "full", model: "iPhone 17", + origin: "configured", osVersion: "27.0", platform: "ios", ready: 0, @@ -2048,6 +2051,7 @@ describe("warm pool targets", () => { count: 1, mode: "full", model: "iPhone 17", + origin: "configured", platform: "ios", ready: 0, reason: "no-driver", @@ -2546,43 +2550,72 @@ describe("warm pool learned kinds", () => { ).toEqual([{ deviceId: "d1", reason: "displaced" }]); }); - it("lists configured targets only in figures() and the short log, with a learned kind short in the same pass", async () => { - const short = harness([], { limit: 0, state: await withLearned([1]), targets: [phone] }); - await short.pool.pass(); - await short.pool.settle(); - const met = harness([device("d1", "ready", 0)], { - limit: 1, - state: await withLearned([1, 2]), + it("lists a learned kind in figures() with its origin, count, image tag and short, a merged kind once with the larger count, and drops a forgotten kind on the next pass", async () => { + const pixel = { ...device("d2", "ready", 0, "android").spec, imageTag: "google_apis" }; + const state = await openMemoryState([warmPoolOwner]); + const learned = new LearnedKinds(state); + learned.learn(ipad, "pad", now - minute); + learned.learn(pixel, "pixel", now - 3 * minute); + learned.learn(device("d1", "ready", 0).spec, "phone-0", now - 2 * minute); + learned.learn(device("d1", "ready", 0).spec, "phone-1", now - 2 * minute); + const androidListing: PlatformCatalog = { + ...iosListing, + images: [{ abi: "arm64", runtime: "35", tag: "google_apis" }], + modelRuntimes: { "Pixel 8": ["35"] }, + models: ["Pixel 8"], + platform: "android", + runtimes: ["35"], + }; + const rig = harness([], { + catalog: async () => [iosListing, androidListing], + limit: 0, + state, targets: [phone], }); - await met.pool.pass(); - await met.pool.settle(); + const summary = () => + rig.pool.figures().targets.map((target) => ({ + count: target.count, + imageTag: target.imageTag, + model: target.model, + origin: target.origin, + short: target.short, + })); - expect(short.pool.figures().targets).toEqual([ + await rig.pool.pass(); + await rig.pool.settle(); + + expect(summary()).toEqual([ + { count: 2, model: "iPhone 15", origin: "configured", short: "running-limit" }, + { count: 1, model: "iPad Pro", origin: "learned", short: "running-limit" }, { - booting: 0, count: 1, - mode: "full", - model: "iPhone 15", - osVersion: "26.0", - platform: "ios", - ready: 0, + imageTag: "google_apis", + model: "Pixel 8", + origin: "learned", short: "running-limit", }, ]); - const shortLogs = short.sink.records.filter( + const shortLogs = rig.sink.records.filter( (record) => record.message === "a warm pool target is short", ); expect(shortLogs.map((record) => record.fields?.target)).toEqual(["ios iPhone 15 26.0"]); - expect( - met.pool.figures().targets.map((target) => [target.model, target.ready, target.short]), - ).toEqual([["iPhone 15", 1, undefined]]); - expect( - met.sink.records.filter((record) => record.message === "a warm pool target is short"), - ).toEqual([]); + + learned.forget(ipad); + await rig.pool.pass(); + await rig.pool.settle(); + + expect(summary().map((entry) => entry.model)).toEqual(["iPhone 15", "Pixel 8"]); + const off = harness([], { enabled: false, state, targets: [phone] }); + expect(off.pool.figures().targets.map((target) => [target.model, target.origin])).toEqual([ + ["iPhone 15", "configured"], + ]); + const fresh = harness([], { state, targets: [phone] }); + expect(fresh.pool.figures().targets.map((target) => [target.model, target.origin])).toEqual([ + ["iPhone 15", "configured"], + ]); }); - it("emits warm-pool.target-missed for a merged entry by its configured count", async () => { + it("emits warm-pool.target-missed with origin configured and the configured count, and for no learned kind however short it is", async () => { const payloads = (rig: ReturnType): unknown[] => { const seen: unknown[] = []; rig.eventBus.subscribe("warm-pool.target-missed", (envelope) => @@ -2598,17 +2631,29 @@ describe("warm pool learned kinds", () => { const metPayloads = payloads(met); await met.pool.pass(); await met.pool.settle(); - const empty = harness([], { limit: 0, state: await withLearned([1, 2]), targets: [phone] }); + const empty = harness([], { + catalog: async () => [iosListing], + limit: 0, + state: await withLearned([1, 2]), + targets: [phone], + }); const emptyPayloads = payloads(empty); await empty.pool.pass(); await empty.pool.settle(); + expect( + empty.pool + .figures() + .targets.filter((target) => target.origin === "learned") + .map((target) => [target.model, target.short]), + ).toEqual([["iPad Pro", "running-limit"]]); expect(metPayloads).toEqual([]); expect(emptyPayloads).toEqual([ { count: 1, mode: "full", model: "iPhone 15", + origin: "configured", osVersion: "26.0", platform: "ios", ready: 0, diff --git a/src/core/warm-pool/converger.ts b/src/core/warm-pool/converger.ts index 3aa93f018..3ff75251d 100644 --- a/src/core/warm-pool/converger.ts +++ b/src/core/warm-pool/converger.ts @@ -134,6 +134,8 @@ export class WarmPool { readonly #lastSpecs = new Map(); /** Every target's state as the last pass left it. */ #reports: readonly TargetReport[] = []; + /** why: every report of the last pass, learned kinds included, which `figures()` lists and the log and the event leave out. */ + #figured: readonly TargetReport[] = []; /** Whether a pass has left its reports yet: until one has, the figures come from the config. */ #passed = false; /** @@ -300,7 +302,7 @@ export class WarmPool { }); } - /** Every report as the last pass left it: how many are ready, and why not more. Targets that resolved to one spec are one report. */ + /** why: every configured target's report as the last pass left it: how many are ready, and why not more. Targets that resolved to one spec are one report. */ targets(): readonly TargetReport[] { return this.#reports; } @@ -314,7 +316,7 @@ export class WarmPool { const { enabled, reserveRunning, targets } = this.options.config; const reports = enabled && this.#passed - ? this.#reports + ? this.#figured : targets.map((target): TargetReport => { const kind = this.#kindOfTarget(target); return { @@ -394,7 +396,9 @@ export class WarmPool { try { const refused = await this.#resolveEnabled(); const plan = await this.options.decisions.run(() => evaluate(this.#view())); - const reports = configuredOnly([...refused, ...plan.targets]); + const everyReport = [...refused, ...plan.targets]; + const reports = configuredOnly(everyReport); + this.#figured = everyReport; this.#note(reports); for (const proposal of plan.proposals) { if (this.#draining) break; @@ -529,6 +533,7 @@ export class WarmPool { count: report.count, mode: report.kind.mode, model: report.kind.model, + origin: "configured", platform: report.kind.platform, ready: report.ready, reason: report.short, @@ -830,8 +835,7 @@ function shutDownIn(devices: readonly VirtualDevice[], down: ReadonlySet } /** - * why: status, the short log and `warm-pool.target-missed` describe the operator's targets only in - * this version, so a learned kind's report is left out and a merged entry is judged by the + * why: the short log and `warm-pool.target-missed` describe the operator's targets only, so a learned kind's report is left out and a merged entry is judged by the * configured count: a configured target that is met is not short however short the learned count is. */ function configuredOnly(reports: readonly TargetReport[]): TargetReport[] { @@ -853,7 +857,9 @@ function figureOf(report: TargetReport): WarmTargetFigures { ...report.kind, booting: report.booting, count: report.count, + origin: report.origin, ready: report.ready, + ...(report.spec?.imageTag === undefined ? {} : { imageTag: report.spec.imageTag }), ...(report.short === undefined ? {} : { short: report.short }), }; } diff --git a/src/core/warm-pool/figures.ts b/src/core/warm-pool/figures.ts index 54bdeddea..c3cd09fab 100644 --- a/src/core/warm-pool/figures.ts +++ b/src/core/warm-pool/figures.ts @@ -2,6 +2,8 @@ import type { TargetKind, TargetShort } from "./policy.js"; /** One warm target as `status` reports it: its kind, how many it wants, and how it stands. */ export interface WarmTargetFigures extends TargetKind { + readonly origin: "configured" | "learned"; + readonly imageTag?: string; readonly count: number; readonly ready: number; readonly booting: number; diff --git a/src/daemon-protocol/index.test.ts b/src/daemon-protocol/index.test.ts index 6ceef37ca..104b5766e 100644 --- a/src/daemon-protocol/index.test.ts +++ b/src/daemon-protocol/index.test.ts @@ -9,7 +9,7 @@ import { describe("daemon protocol", () => { it("keeps the current protocol version and newline framing", () => { - expect(DAEMON_PROTOCOL_VERSION).toBe(52); + expect(DAEMON_PROTOCOL_VERSION).toBe(53); expect(serializeFrame({ id: 1, type: "hello" })).toBe('{"id":1,"type":"hello"}\n'); }); diff --git a/src/daemon/AGENTS.md b/src/daemon/AGENTS.md index f386f1cc2..1a8ff5610 100644 --- a/src/daemon/AGENTS.md +++ b/src/daemon/AGENTS.md @@ -52,7 +52,7 @@ An HTTP bind failure after a good start stops the daemon (`http-start-failed`). Principal: `hello.principal`, else `SIMLOCK_AGENT_ID`, else the daemon's pid. Both are fixed for the connection's life. 3. **Version** — ranges overlap → highest common version. `PROTOCOL_VERSION_RANGE` - is `{ min: 52, max: 52 }` (`src/contract/protocol.ts`). No overlap → the + is `{ min: 53, max: 53 }` (`src/contract/protocol.ts`). No overlap → the connection stays open, and every request but `daemon.stop` gets `PROTOCOL_VERSION_UNSUPPORTED`. 4. **Request** — one frame → one `dispatch()` call. While stopping: `DAEMON_STOPPING`. diff --git a/src/daemon/dispatcher.test.ts b/src/daemon/dispatcher.test.ts index 54e586397..966827e26 100644 --- a/src/daemon/dispatcher.test.ts +++ b/src/daemon/dispatcher.test.ts @@ -1707,6 +1707,7 @@ describe("Dispatcher: device mode on every surface", () => { count: 1, mode: "full", model: "iPhone 17", + origin: "configured", osVersion: "27.0", platform: "ios", ready: 0, @@ -1739,6 +1740,7 @@ describe("Dispatcher: device mode on every surface", () => { count: 2, mode: "full", model: "iPhone 17", + origin: "configured", osVersion: "26.5", platform: "ios", ready: 0, @@ -1749,6 +1751,7 @@ describe("Dispatcher: device mode on every surface", () => { count: 1, mode: "slim", model: "Pixel 8", + origin: "configured", platform: "android", ready: 0, short: "disabled", diff --git a/src/daemon/server.test.ts b/src/daemon/server.test.ts index 5cb7a0077..1cce587bd 100644 --- a/src/daemon/server.test.ts +++ b/src/daemon/server.test.ts @@ -231,7 +231,7 @@ describe("DaemonServer", () => { [48, "cannot read config.get's gateway.alerts"], [51, "cannot page events.replay with beforeId or limit"], ])( - "answers PROTOCOL_VERSION_UNSUPPORTED, naming protocol 52, to a client on protocol %i, which %s", + "answers PROTOCOL_VERSION_UNSUPPORTED, naming protocol 53, to a client on protocol %i, which %s", async (version) => { const harness = await createHarness(); const previous = await createClient(harness.socketPath); @@ -241,7 +241,7 @@ describe("DaemonServer", () => { ).resolves.toMatchObject({ error: { code: "PROTOCOL_VERSION_UNSUPPORTED", - details: { client: { min: version, max: version }, daemon: { min: 52, max: 52 } }, + details: { client: { min: version, max: version }, daemon: { min: 53, max: 53 } }, }, ok: false, }); diff --git a/src/gateway/dispatcher.test.ts b/src/gateway/dispatcher.test.ts index c7de7879f..bc48cfbb1 100644 --- a/src/gateway/dispatcher.test.ts +++ b/src/gateway/dispatcher.test.ts @@ -376,6 +376,7 @@ describe("GatewayDispatcher", () => { count: 1, mode: "full" as const, model: "iPhone 17", + origin: "configured" as const, osVersion: "27.0", platform: "ios" as const, ready: 0, diff --git a/ui/src/model/worker-page.test.ts b/ui/src/model/worker-page.test.ts index e8cce67af..3b6bc1d63 100644 --- a/ui/src/model/worker-page.test.ts +++ b/ui/src/model/worker-page.test.ts @@ -576,13 +576,14 @@ describe("a worker's warm pool tab", () => { count: 1, mode: "full" as const, model: "iPhone 17", + origin: "configured" as const, osVersion: "27.0", platform: "ios" as const, ready: 0, short: "runtime-missing" as const, }; - it("lists each kind the pool keeps with its wanted, ready and booting numbers and the reason it is short, a dash where there is none", () => { + it("lists each kind the pool keeps with its origin, its image tag, its wanted, ready and booting numbers and the reason it is short, a dash where there is none, and gives two kinds that differ by tag two keys", () => { const { warm } = inspect( worker({ warmPool: { @@ -590,7 +591,14 @@ describe("a worker's warm pool tab", () => { reserveRunning: { android: 0, ios: 1 }, targets: [ { ...target, booting: 1, count: 2, osVersion: "26.0", ready: 1, short: undefined }, - { ...target, osVersion: undefined }, + { ...target, origin: "learned" as const, osVersion: undefined }, + { ...target, imageTag: "google_apis", model: "Pixel 8", platform: "android" as const }, + { + ...target, + imageTag: "google_apis_playstore", + model: "Pixel 8", + platform: "android" as const, + }, ], }, }), @@ -600,6 +608,7 @@ describe("a worker's warm pool tab", () => { expect( warm?.targets.map((row) => [ row.model, + row.origin, row.runtime, row.wanted, row.ready, @@ -607,8 +616,16 @@ describe("a worker's warm pool tab", () => { row.short, ]), ).toEqual([ - ["iPhone 17", "26.0", 2, 1, 1, "—"], - ["iPhone 17", "—", 1, 0, 0, "runtime-missing"], + ["iPhone 17", "configured", "26.0", 2, 1, 1, "—"], + ["iPhone 17", "learned", "—", 1, 0, 0, "runtime-missing"], + ["Pixel 8 / google_apis", "configured", "27.0", 1, 0, 0, "runtime-missing"], + ["Pixel 8 / google_apis_playstore", "configured", "27.0", 1, 0, 0, "runtime-missing"], + ]); + expect(warm?.targets.map((row) => row.key)).toEqual([ + "ios-iPhone 17-26.0-full#0", + "ios-iPhone 17-undefined-full#0", + "android-Pixel 8-27.0-full-google_apis#0", + "android-Pixel 8-27.0-full-google_apis_playstore#0", ]); }); diff --git a/ui/src/model/worker-page.ts b/ui/src/model/worker-page.ts index 52ae32795..905e55d8e 100644 --- a/ui/src/model/worker-page.ts +++ b/ui/src/model/worker-page.ts @@ -507,6 +507,7 @@ function hostTabOf(worker: WorkerView): HostTab { export interface WarmRow { readonly key: string; readonly model: string; + readonly origin: string; readonly runtime: string; readonly mode: string; readonly wanted: number; @@ -535,7 +536,8 @@ function warmRow(row: WarmPoolRow): WarmRow { booting: row.booting, key: row.key, mode: row.mode, - model: row.model, + model: row.imageTag === undefined ? row.model : `${row.model} / ${row.imageTag}`, + origin: row.origin, ready: row.ready, runtime: row.osVersion ?? "—", short: row.short ?? "—", diff --git a/ui/src/model/workers.test.ts b/ui/src/model/workers.test.ts index ca0f5a5ce..e6ef48ea3 100644 --- a/ui/src/model/workers.test.ts +++ b/ui/src/model/workers.test.ts @@ -7,6 +7,7 @@ const REFUSED: WarmTarget = { count: 1, mode: "full", model: "iPhone 17", + origin: "configured", osVersion: "27.0", platform: "ios", ready: 0, diff --git a/ui/src/model/workers.ts b/ui/src/model/workers.ts index b20756c71..cf1168d19 100644 --- a/ui/src/model/workers.ts +++ b/ui/src/model/workers.ts @@ -71,7 +71,8 @@ export type WarmPoolRow = WarmTarget & { readonly key: string }; export function warmPoolRows(targets: readonly WarmTarget[]): WarmPoolRow[] { const seen = new Map(); return targets.map((target) => { - const kind = `${target.platform}-${target.model}-${target.osVersion}-${target.mode}`; + const tag = target.imageTag === undefined ? "" : `-${target.imageTag}`; + const kind = `${target.platform}-${target.model}-${target.osVersion}-${target.mode}${tag}`; const occurrence = seen.get(kind) ?? 0; seen.set(kind, occurrence + 1); return { ...target, key: `${kind}#${occurrence}` }; diff --git a/ui/src/screens/fleet/fleet.test.tsx b/ui/src/screens/fleet/fleet.test.tsx index 65a8cfc85..1148aa0ba 100644 --- a/ui/src/screens/fleet/fleet.test.tsx +++ b/ui/src/screens/fleet/fleet.test.tsx @@ -309,6 +309,7 @@ describe("a worker's host and warm pool tabs", () => { count: 2, mode: "full", model: "iPhone 17", + origin: "configured", osVersion: "26.0", platform: "ios", ready: 1, @@ -318,10 +319,22 @@ describe("a worker's host and warm pool tabs", () => { count: 1, mode: "full", model: "iPhone 17", + origin: "learned", platform: "ios", ready: 0, short: "runtime-missing", }, + { + booting: 0, + count: 1, + imageTag: "google_apis_playstore", + mode: "full", + model: "Pixel 8", + origin: "learned", + osVersion: "35", + platform: "android", + ready: 1, + }, ], }, }; @@ -331,8 +344,10 @@ describe("a worker's host and warm pool tabs", () => { expect(shown).toContain("Pool On"); expect(shown).toContain("Reserved running slots iOS 1, Android 0"); - expect(shown).toContain("iPhone 17 26.0 full 2 1 1 —"); - expect(shown).toContain("iPhone 17 — full 1 0 0 runtime-missing"); + expect(shown).toContain("Origin"); + expect(shown).toContain("iPhone 17 26.0 full configured 2 1 1 —"); + expect(shown).toContain("iPhone 17 — full learned 1 0 0 runtime-missing"); + expect(shown).toContain("Pixel 8 / google_apis_playstore 35 full learned 1 1 0 —"); expect(shown).toContain("iOS 19.0 downloading for 7 s , 1 waiter"); expect(markup).toContain('2'); }); diff --git a/ui/src/screens/fleet/worker-page.tsx b/ui/src/screens/fleet/worker-page.tsx index 1b25e0b77..15b74d975 100644 --- a/ui/src/screens/fleet/worker-page.tsx +++ b/ui/src/screens/fleet/worker-page.tsx @@ -374,6 +374,7 @@ const WARM_COLUMNS: readonly Column[] = [ { cell: (target) => target.model, header: "Model" }, { cell: (target) => target.runtime, header: "Runtime", mono: true }, { cell: (target) => target.mode, header: "Mode" }, + { cell: (target) => target.origin, header: "Origin" }, { cell: (target) => target.wanted, header: "Wanted", numeric: true }, { cell: (target) => target.ready, header: "Ready", numeric: true }, { cell: (target) => target.booting, header: "Booting", numeric: true }, diff --git a/website/src/content/docs/docs/reference/events.mdx b/website/src/content/docs/docs/reference/events.mdx index e8c55be69..72a5ab79d 100644 --- a/website/src/content/docs/docs/reference/events.mdx +++ b/website/src/content/docs/docs/reference/events.mdx @@ -124,7 +124,7 @@ release and records nothing. | --- | --- | --- | --- | | `capacity.changed` | The worker's running figures changed, and once at start. | `ios`, `android`, `global`, each with `running`, `maxRunning`, `reserved`, `warm`; `ramBudget` (`usedBytes`, `limitBytes`) under the `resource` strategy | Relayed | | `queue.changed` | A request joined or left the queue, and once at start. | `depth` (requests waiting in that line), `physical: true` when the physical line changed | Own and relayed | -| `warm-pool.target-missed` | A `warmPool.targets` entry went short and the pool could do nothing about it. Once per time it goes short. | `platform`, `model`, `osVersion`, `mode`, `count`, `ready`, `reason` (`no-driver`, `runtime-missing`, `unknown-model`, `unresolvable`, `boot-failed`, `device-limit`, `running-limit`, `reserve`, `ram-budget`) | Relayed | +| `warm-pool.target-missed` | A `warmPool.targets` entry went short and the pool could do nothing about it. Once per time it goes short. | `platform`, `model`, `osVersion`, `mode`, `origin` (always `configured`), `count`, `ready`, `reason` (`no-driver`, `runtime-missing`, `unknown-model`, `unresolvable`, `boot-failed`, `device-limit`, `running-limit`, `reserve`, `ram-budget`) | Relayed | ## Devices diff --git a/website/src/content/docs/docs/worker/capacity.mdx b/website/src/content/docs/docs/worker/capacity.mdx index 7a7cf0cf2..ac0b3a5d6 100644 --- a/website/src/content/docs/docs/worker/capacity.mdx +++ b/website/src/content/docs/docs/worker/capacity.mdx @@ -192,14 +192,17 @@ Other settings: ### Read the warm pool in `simlock status` -Each target gets a line under `warm pool`. Learned kinds are not listed. +Each target and each learned kind gets a line under `warm pool`. The word after the name says where the line came from: `configured` for a `warmPool.targets` entry, `learned` for a kind the worker leased. A kind that is both is one `configured` line, wanted the larger of the two counts. An Android kind with an image tag shows the tag after the mode. A learned kind the pool forgets leaves the list on the next pass. With the warm pool off, nothing is learned and only the targets are listed. ```text warm pool: enabled, reserve ios 1 android 0 - iPhone 16 / 26.0 / full wanted 2 ready 1 booting 1 - Pixel 8 / 35 / full wanted 1 ready 0 booting 0 short: runtime-missing + iPhone 16 / 26.0 / full configured wanted 2 ready 1 booting 1 + iPhone 15 / 18.4 / full learned wanted 1 ready 1 booting 0 + Pixel 8 / 35 / full / google_apis_playstore learned wanted 1 ready 0 booting 0 short: running-limit ``` +`simlock status --json` carries the same in `warmPool.targets[]`: `origin` (`configured` or `learned`) and, when the kind names one, `imageTag`. `simlock doctor` and the `warm-pool.target-missed` event cover the configured targets only. + `short` says why the last pass could do nothing for a target: | Reason | What to do | diff --git a/website/src/content/docs/docs/worker/console.mdx b/website/src/content/docs/docs/worker/console.mdx index 42e44c2cc..939a34329 100644 --- a/website/src/content/docs/docs/worker/console.mdx +++ b/website/src/content/docs/docs/worker/console.mdx @@ -127,7 +127,7 @@ Select the worker to see three tabs: - **Overview**: CPU, memory and disk, each with a bar; how many leases it holds; a square per device slot for iOS and Android (leased, ready, booting, quarantined or free); and every device, with its state, model, runtime, whether it is physical or virtual, and the lease holding it. - **Host**: the worker's id, health, operating system, CPU architecture, the version of each platform tool, each optional module (such as screen streaming) as `available`, `off` or `unavailable` with a reason, and the catalog of models and runtimes it can lease. -- **Warm pool**: whether the worker keeps devices warm, the running slots it holds back, and per target how many devices it wants, how many are ready and how many are booting. A target it cannot fill shows the reason, such as `runtime-missing`. Under it, **Installs in progress** lists runtimes and system images being downloaded. See [Capacity and the warm pool](/simlock/docs/worker/capacity). +- **Warm pool**: whether the worker keeps devices warm, the running slots it holds back, and per target and learned kind its origin (`configured` or `learned`), how many devices it wants, how many are ready and how many are booting. A target it cannot fill shows the reason, such as `runtime-missing`. Under it, **Installs in progress** lists runtimes and system images being downloaded. See [Capacity and the warm pool](/simlock/docs/worker/capacity). While the daemon is still starting, devices, capacity and the warm pool are left out. They appear once startup finishes. diff --git a/website/src/content/docs/docs/worker/monitoring.mdx b/website/src/content/docs/docs/worker/monitoring.mdx index 177f0e194..d7c937d99 100644 --- a/website/src/content/docs/docs/worker/monitoring.mdx +++ b/website/src/content/docs/docs/worker/monitoring.mdx @@ -29,7 +29,7 @@ Capacity ios: managed 4/8, running 3 + 1 reserved/4, warm 1 Capacity android: managed 0/4, running 0 + 0 reserved/2, warm 0 RAM budget: 11.50 GiB/22.00 GiB used warm pool: enabled, reserve ios 0 android 0 - iPhone 16 / 18.4 / full wanted 1 ready 1 booting 0 + iPhone 16 / 18.4 / full configured wanted 1 ready 1 booting 0 Device dev_6f1c2a9e-3b7d-4e0a-9c55-2d8f1e4a7b10: leased, mode full, serves default mode: yes Device dev_0b93d4c1-8a2e-4f6b-b1d7-5e9c3a2f8d64: ready, mode full, serves default mode: yes Lease lse_9d2e7b14-6c3a-4f81-a0e5-7b1c9d4e2f36: claude-code:5f0e8a3c-1b2d-4c6e-9f7a-0d3b8e1c4a92 since 1761036720000, last renewed 1761037320000 @@ -48,7 +48,7 @@ What each line means: | `Running global` | Devices running now, plus slots held for devices that are booting, out of the most that may run at once, and how many of the running ones are warm. | | `Capacity ios` / `Capacity android` | Per platform: `managed` is devices that exist out of the device limit; `running` is as above. `(over limit)` means more devices exist than the limit allows, for example after you lowered it. `(at RAM budget)` means no more devices fit in the memory set aside for them. | | `RAM budget` | Memory the running devices use out of the budget. Shown only with the `resource` capacity strategy. | -| `warm pool` | Whether the warm pool is on, the running slots it keeps free per platform, and one row per target: how many devices you want ready, how many are ready, how many are booting, and why a target is short. | +| `warm pool` | Whether the warm pool is on, the running slots it keeps free per platform, and one row per target and learned kind, with where it came from (`configured` or `learned`): how many devices you want ready, how many are ready, how many are booting, and why a target is short. | | `Device` | One line per device: its id, state, and its device mode, or `physical` and its class for an enrolled physical device. Markers in brackets flag a problem, such as `quarantined (purge retry 2, ...)` or `stalled`. | | `Lease` | One line per lease: its id, the requester holding it, and when it was granted and last renewed, in milliseconds since 1970. | | `Install` | A runtime or system image being downloaded, how long for, and how many requests wait on it. |