From a56c6fea4117f1ab2c86accd3a111a9cc85c6470 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Fri, 6 Nov 2026 18:55:28 +0100 Subject: [PATCH 1/5] test: at new-devices-paused a lease needing a new device waits or is refused, one fitting an idle booted device is granted (#1362) --- src/core/index.ts | 1 + src/daemon/dispatcher-except.test.ts | 40 +-------- src/daemon/dispatcher-leases.test.ts | 121 ++++++++++++++++++++++++++- src/daemon/test-dispatcher.ts | 53 ++++++++++++ src/leasing/testing.ts | 3 + 5 files changed, 178 insertions(+), 40 deletions(-) diff --git a/src/core/index.ts b/src/core/index.ts index 37ab84623..a88d0e4d3 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -193,6 +193,7 @@ export { export { SerializedDecision } from "./serialized-decision.js"; export { type CapacityReader, + type MemoryPressureReader, type CatalogReader, type LeaseExpirer, type PassthroughResolver, diff --git a/src/daemon/dispatcher-except.test.ts b/src/daemon/dispatcher-except.test.ts index 287eb6748..982ced7c3 100644 --- a/src/daemon/dispatcher-except.test.ts +++ b/src/daemon/dispatcher-except.test.ts @@ -1,9 +1,8 @@ import { describe, expect, it, vi } from "vitest"; -import { readyTransitionUpdate } from "../core/testing.js"; import { DriverCrashError } from "../core/index.js"; import { classifyError } from "./error-code.js"; -import { buildDispatcher, session } from "./test-dispatcher.js"; +import { buildDispatcher, seedSlimDevice, session } from "./test-dispatcher.js"; /** why: the answer of a request that must settle by itself once the event loop has run to rest; a hang fails here, on a named assertion, rather than by the test's timeout. */ async function grantedOnceSettled(request: Promise): Promise { @@ -16,43 +15,6 @@ async function grantedOnceSettled(request: Promise): Promise { return answer as T; } -/** why: a slim device a worker already holds, ready or shut down, as the warm pool or an earlier lease leaves one. */ -async function seedSlimDevice( - built: Awaited>, - state: "ready" | "shutdown", -) { - const spec = { - mode: "slim", - model: "iPhone 17 Pro", - osVersion: "26.5", - physical: false, - platform: "ios", - } as const; - const driverDevice = await built.driver.provision(spec); - const driven = await built.driver.makeReady(driverDevice, { mode: "slim", purpose: "prepare" }); - // why: the seed is a slim device whatever the fake reports on its boot, so a test whose driver answers `full` still starts from slim. - const ready = { ...driven, mode: "slim" as const }; - const registered = await built.registry.registerDevice({ - driverData: driverDevice.driverData, - driverDeviceId: driverDevice.deviceId, - provisionDuration: 0, - spec, - }); - await built.registry.transitionDevice( - registered.id, - "ready", - { event: "device.ready", payload: { bootDuration: 0, deviceId: registered.id } }, - readyTransitionUpdate(ready), - ); - if (state === "ready") return registered; - await built.driver.shutdown(driverDevice); - await built.registry.transitionDevice(registered.id, "shutdown", { - event: "device.shutdown", - payload: { deviceId: registered.id, initiator: "test" }, - }); - return registered; -} - describe("Dispatcher: lease.request with an except list", () => { it("a client leases slim with except and is granted a device reporting it", async () => { const except = ["store", "other"]; diff --git a/src/daemon/dispatcher-leases.test.ts b/src/daemon/dispatcher-leases.test.ts index 7628a4aec..fe4122598 100644 --- a/src/daemon/dispatcher-leases.test.ts +++ b/src/daemon/dispatcher-leases.test.ts @@ -6,7 +6,14 @@ import type { DispatcherOptions } from "./dispatcher.js"; import { classifyError } from "./error-code.js"; import { UnknownLeaseError } from "../core/index.js"; import { RequestCancelledError } from "../leasing/index.js"; -import { HOST_SYSTEM, buildDispatcher, flush, gibibyte, session } from "./test-dispatcher.js"; +import { + HOST_SYSTEM, + buildDispatcher, + flush, + gibibyte, + seedSlimDevice, + session, +} from "./test-dispatcher.js"; describe("Dispatcher: ownership", () => { async function grantLease(dispatcher: Awaited>["dispatcher"]) { @@ -1295,3 +1302,115 @@ describe("Dispatcher: lease.request requires", () => { expect(JSON.stringify(requested?.payload)).not.toContain("requires"); }); }); + +describe("Dispatcher: lease.request at new-devices-paused", () => { + const slimmable = { slimmableOsVersions: ["26.5"] }; + const ask = { model: "iPhone 17 Pro", osVersion: "26.5", platform: "ios" } as const; + const slim = { ...ask, mode: "slim" } as const; + const asker = () => session({ principal: "tok_asker" }); + const waiting = (built: Awaited>) => + built.dispatcher.dispatch("list.get", { kind: "requests" }, session({ role: "admin" })); + const fixed: Config["capacity"] = { strategy: "fixed", config: { maxRunning: 4 } }; + + it.each([ + { name: "needs a new device", seed: undefined, input: ask, options: {} }, + { name: "boots a shut-down device", seed: "shutdown", input: slim, options: {} }, + { + name: "needs the reboot of an idle device for its except list", + seed: "ready", + input: { ...slim, except: ["store"] }, + options: {}, + }, + { + name: "is refused for RAM too", + seed: undefined, + input: ask, + options: { + capacity: { + strategy: "resource", + config: { + limits: { + android: { maxDevices: 1, maxRunning: 1 }, + ios: { maxDevices: 4, maxRunning: 4 }, + maxRunning: 6, + }, + ramBudget: { androidBytesPerDevice: 4 * gibibyte, iosBytesPerDevice: 30 * gibibyte }, + }, + }, + }, + }, + { + name: "runs under the fixed strategy", + seed: undefined, + input: ask, + options: { capacity: fixed }, + }, + ] as const)( + "a request that $name waits, or gets NO_CAPACITY under noWait, with memory-pressure", + async (row) => { + const built = await buildDispatcher({ + driverOptions: slimmable, + memoryPressureStep: "new-devices-paused", + ...row.options, + }); + if (row.seed !== undefined) await seedSlimDevice(built, row.seed); + const seededCalls = built.driver.calls.length; + + const request = built.dispatcher.dispatch("lease.request", row.input, asker()); + void request.catch(() => undefined); + await flush(); + const listed = await waiting(built); + await expect( + built.dispatcher.dispatch( + "lease.request", + { ...row.input, noWait: true }, + session({ principal: "tok_second" }), + ), + ).rejects.toMatchObject({ + code: "NO_CAPACITY", + details: { capacityReason: "memory-pressure" }, + }); + + expect(listed).toMatchObject([{ reason: "memory-pressure", stage: "queued" }]); + expect( + built.driver.calls + .slice(seededCalls) + .filter((call) => ["provision", "makeReady", "shutdown"].includes(call.operation)), + ).toEqual([]); + }, + ); + + it("grants a request that fits an idle booted device, and does not evict an idle device of another kind", async () => { + const granted = await buildDispatcher({ + driverOptions: slimmable, + memoryPressureStep: "new-devices-paused", + }); + const registered = await seedSlimDevice(granted, "ready"); + await expect( + granted.dispatcher.dispatch("lease.request", slim, asker()), + ).resolves.toMatchObject({ device: { id: registered.id } }); + + const limited = await buildDispatcher({ + capacity: { + strategy: "resource", + config: { + limits: { + android: { maxDevices: 1, maxRunning: 1 }, + ios: { maxDevices: 4, maxRunning: 1 }, + maxRunning: 6, + }, + ramBudget: { androidBytesPerDevice: 4 * gibibyte, iosBytesPerDevice: gibibyte }, + }, + }, + driverOptions: slimmable, + memoryPressureStep: "new-devices-paused", + }); + const idle = await seedSlimDevice(limited, "ready"); + await expect( + limited.dispatcher.dispatch("lease.request", { ...ask, mode: "full", noWait: true }, asker()), + ).rejects.toMatchObject({ details: { capacityReason: "memory-pressure" } }); + expect(limited.registry.snapshot.virtualDevices.find((d) => d.id === idle.id)?.state).toBe( + "ready", + ); + }); +}); diff --git a/src/daemon/test-dispatcher.ts b/src/daemon/test-dispatcher.ts index fb59a8485..5103c80b2 100644 --- a/src/daemon/test-dispatcher.ts +++ b/src/daemon/test-dispatcher.ts @@ -3,6 +3,7 @@ import { testConfig as configWithDefaults } from "../core/testing.js"; import { FakeDriver, loadTestRegistry, + readyTransitionUpdate, openTestState, testComponentWiring, type FakeDriverOptions, @@ -22,8 +23,11 @@ import { Nuke, PassthroughRefusedError, type CatalogReader, + type MemoryPressureReader, type PassthroughResolver, } from "../core/index.js"; + +type MemoryPressureStep = "none" | "warming-paused" | "new-devices-paused"; import { CryptoTokenSecrets, FakeClock, @@ -166,6 +170,8 @@ export async function buildDispatcher( readonly withoutBaselines?: boolean; readonly hostFacts?: () => HostFacts; readonly capacity?: Config["capacity"]; + /** why: the worker's memory pressure step at the start; a test changes it with `setMemoryPressure`. */ + readonly memoryPressureStep?: MemoryPressureStep; readonly warmPool?: Partial; /** why: the `ios.defaultMode` `catalog.get` reports. */ readonly iosDefaultMode?: "slim" | "full"; @@ -194,6 +200,12 @@ export async function buildDispatcher( ) { const clock = overrides.clock ?? new FakeClock(1_000); const eventBus = new EventBus(clock); + let pressureStep = overrides.memoryPressureStep; + const memoryPressure: MemoryPressureReader = { + current: () => + pressureStep === undefined ? undefined : { readingAt: clock.now(), step: pressureStep }, + onReading: () => () => undefined, + }; const filesystem = new MemoryFilesystem(); const state = await openTestState(); seedPhysicalDevices(state, overrides.physicalDevices ?? []); @@ -251,6 +263,7 @@ export async function buildDispatcher( drivers: [driver, ...(overrides.extraDrivers ?? [])], eventBus, idGenerator: sequence(), + memoryPressure, registry, state: testStateOf(registry), systemStats: new FakeSystemStats({ @@ -338,11 +351,51 @@ export async function buildDispatcher( engine, eventBus, registry, + setMemoryPressure: (step: MemoryPressureStep) => { + pressureStep = step; + }, state, tokens, }; } +/** why: a slim device a worker already holds, ready or shut down, as the warm pool or an earlier lease leaves one. */ +export async function seedSlimDevice( + built: Awaited>, + state: "ready" | "shutdown", +) { + const spec = { + mode: "slim", + model: "iPhone 17 Pro", + osVersion: "26.5", + physical: false, + platform: "ios", + } as const; + const driverDevice = await built.driver.provision(spec); + const driven = await built.driver.makeReady(driverDevice, { mode: "slim", purpose: "prepare" }); + // why: the seed is a slim device whatever the fake reports on its boot, so a test whose driver answers `full` still starts from slim. + const ready = { ...driven, mode: "slim" as const }; + const registered = await built.registry.registerDevice({ + driverData: driverDevice.driverData, + driverDeviceId: driverDevice.deviceId, + provisionDuration: 0, + spec, + }); + await built.registry.transitionDevice( + registered.id, + "ready", + { event: "device.ready", payload: { bootDuration: 0, deviceId: registered.id } }, + readyTransitionUpdate(ready), + ); + if (state === "ready") return registered; + await built.driver.shutdown(driverDevice); + await built.registry.transitionDevice(registered.id, "shutdown", { + event: "device.shutdown", + payload: { deviceId: registered.id, initiator: "test" }, + }); + return registered; +} + export function session(overrides: Partial = {}): DispatchSession { return { manageEventSubscription: () => undefined, diff --git a/src/leasing/testing.ts b/src/leasing/testing.ts index f7f63b335..ece1674a1 100644 --- a/src/leasing/testing.ts +++ b/src/leasing/testing.ts @@ -14,6 +14,7 @@ import { type Driver, type LeaseExpirer, type LeaseRequestFailure, + type MemoryPressureReader, type ModelPreferences, type NukeExecutor, type PassthroughResolver, @@ -47,6 +48,7 @@ export interface TestEngineOptions { readonly eventBus: EventBus; readonly idGenerator: IdGenerator; readonly logger?: Logger | undefined; + readonly memoryPressure?: MemoryPressureReader | undefined; readonly registry: Registry; readonly state: StateDatabase; readonly systemStats: SystemStats; @@ -94,6 +96,7 @@ export function createTestEngine(options: TestEngineOptions): TestEngine { drivers: options.drivers, eventBus: options.eventBus, logger: options.logger, + ...(options.memoryPressure === undefined ? {} : { memoryPressure: options.memoryPressure }), modelPreferences: options.modelPreferences, registry: options.registry, state: options.state, From 7ecbd004a8204db5da411c8dd0719d14a0c5fb41 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Fri, 6 Nov 2026 18:57:11 +0100 Subject: [PATCH 2/5] feat(capacity): at new-devices-paused no reservation adds a device and the request waits (#1362) --- src/core/capacity/AGENTS.md | 1 + src/core/capacity/coordinator.ts | 16 +++++++ src/core/create-core.ts | 4 +- src/core/device-provisioner.test.ts | 3 ++ src/daemon/dispatcher-leases.test.ts | 46 ++++++++++--------- src/leasing/acquisition-planner.ts | 2 + .../src/content/docs/docs/worker/capacity.mdx | 4 +- 7 files changed, 52 insertions(+), 24 deletions(-) diff --git a/src/core/capacity/AGENTS.md b/src/core/capacity/AGENTS.md index 88575a845..2440bbd74 100644 --- a/src/core/capacity/AGENTS.md +++ b/src/core/capacity/AGENTS.md @@ -11,6 +11,7 @@ Does: how many virtual devices may exist and run at once — limits, RAM budget, - Until its reservation is released, a device being booted counts `full` and no longer `shutdown`, so it holds RAM in every decision. - `ramBudget` reads devices only; reservations are left out. - Running slots ignore mode; RAM does not. A `quarantined` device holds a running slot. Physical devices are never read. +- At `new-devices-paused` (the memory pressure port) every reservation that adds a device or RAM is refused `memory-pressure` before the strategy is asked, under every strategy; it evicts nothing. `canProvision` and `canBoot` stay the strategy's answer. - A boot refused for RAM evicts nothing; the request waits. - Over the RAM limit (sizes raised by a restart), every create and every boot that adds RAM is refused. Nothing is stopped or reclaimed for it. - Release is idempotent. Every take and release calls the observer. diff --git a/src/core/capacity/coordinator.ts b/src/core/capacity/coordinator.ts index ef19e5293..c9a75d292 100644 --- a/src/core/capacity/coordinator.ts +++ b/src/core/capacity/coordinator.ts @@ -10,6 +10,13 @@ import type { RunningCapacity, } from "./strategy.js"; +/** why: the one thing capacity reads of a worker's memory pressure, so it never names host-load. */ +export interface MemoryPressureStepReader { + current(): { readonly step: "none" | "warming-paused" | "new-devices-paused" } | undefined; +} + +const NEW_DEVICES_PAUSED: CapacityRefusal = { ok: false, reason: "memory-pressure" }; + /** A releasable capacity reservation. Releasing it more than once is safe. */ export interface CapacityReservation { release(): void; @@ -51,8 +58,14 @@ export class CapacityCoordinator { constructor( private readonly strategy: CapacityStrategy, private readonly onReservationsChanged: () => void = () => undefined, + private readonly memoryPressure?: MemoryPressureStepReader, ) {} + /** why: checked before the strategy is asked, under every strategy (ADR 0068 §4). */ + newDevicesPaused(): boolean { + return this.memoryPressure?.current()?.step === "new-devices-paused"; + } + /** * Reserves both a future device slot and its future running slot. * Provisioning counts against the strategy's device budget and running limits @@ -62,6 +75,7 @@ export class CapacityCoordinator { device: PlannedCapacityDevice, devices: readonly CapacityDevice[], ): CapacityReservationAttempt { + if (this.newDevicesPaused()) return NEW_DEVICES_PAUSED; const provision = this.canProvision(device, devices); if (!provision.ok) return provision; @@ -85,6 +99,7 @@ export class CapacityCoordinator { device: RegisteredCapacityDevice, devices: readonly CapacityDevice[], ): CapacityReservationAttempt { + if (this.newDevicesPaused()) return NEW_DEVICES_PAUSED; const boot = this.canBoot(device, devices); if (!boot.ok) return boot; const running = this.canReserveRunning(device.platform, devices); @@ -115,6 +130,7 @@ export class CapacityCoordinator { device: RegisteredCapacityDevice, devices: readonly CapacityDevice[], ): CapacityReservationAttempt { + if (this.newDevicesPaused()) return NEW_DEVICES_PAUSED; const boot = this.canBoot(device, devices); if (!boot.ok) return boot; diff --git a/src/core/create-core.ts b/src/core/create-core.ts index 75f296091..cdd996edf 100644 --- a/src/core/create-core.ts +++ b/src/core/create-core.ts @@ -170,6 +170,7 @@ const NO_MEMORY_PRESSURE: MemoryPressureReader = { export function createCore(options: CoreOptions): Core { const { decisions, registry } = options; + const memoryPressure = options.memoryPressure ?? NO_MEMORY_PRESSURE; let ports: CorePorts | undefined; const port = (name: Name): CorePorts[Name] => { if (ports === undefined) throw new CorePortMissingError(name); @@ -193,6 +194,7 @@ export function createCore(options: CoreOptions): Core { const capacity = new CapacityCoordinator( createCapacityStrategy(options.config.capacity, options.systemStats), () => capacityObserver.changed(), + memoryPressure, ); const devices = () => capacityDevices(registry.snapshot.virtualDevices); const capacityReader: CapacityReader = { @@ -400,7 +402,7 @@ export function createCore(options: CoreOptions): Core { return { capacity, capacityReader, - memoryPressure: options.memoryPressure ?? NO_MEMORY_PRESSURE, + memoryPressure, warmPoolReader: warmPool, warmKinds: { forget: (match) => warmPool.forgetKinds(match) }, baselines, diff --git a/src/core/device-provisioner.test.ts b/src/core/device-provisioner.test.ts index 9bbda6eb6..a6675dd12 100644 --- a/src/core/device-provisioner.test.ts +++ b/src/core/device-provisioner.test.ts @@ -448,6 +448,8 @@ describe("DeviceProvisioner and a component removal (ADR 0010 §8)", () => { [join("core", "test-registry.ts")]: 1, // why: the harness the lease-acquisition coordinator tests split out of one file share (ADR 0063). [join("leasing", "test-lease-acquisition.ts")]: 1, + // why: the dispatcher tests' seeded warm device, shared by the files that start from one. + [join("daemon", "test-dispatcher.ts")]: 1, }); expect(callSites(/\.provision\(/g)).toEqual({ // The driver call itself. @@ -462,6 +464,7 @@ describe("DeviceProvisioner and a component removal (ADR 0010 §8)", () => { [join("drivers", "android", "testing.ts")]: 2, // why: the harness's fixture devices, as for registerDevice above. [join("leasing", "test-lease-acquisition.ts")]: 1, + [join("daemon", "test-dispatcher.ts")]: 1, }); }); diff --git a/src/daemon/dispatcher-leases.test.ts b/src/daemon/dispatcher-leases.test.ts index fe4122598..d96c0fcc5 100644 --- a/src/daemon/dispatcher-leases.test.ts +++ b/src/daemon/dispatcher-leases.test.ts @@ -1348,35 +1348,37 @@ describe("Dispatcher: lease.request at new-devices-paused", () => { ] as const)( "a request that $name waits, or gets NO_CAPACITY under noWait, with memory-pressure", async (row) => { - const built = await buildDispatcher({ - driverOptions: slimmable, - memoryPressureStep: "new-devices-paused", - ...row.options, - }); - if (row.seed !== undefined) await seedSlimDevice(built, row.seed); - const seededCalls = built.driver.calls.length; - - const request = built.dispatcher.dispatch("lease.request", row.input, asker()); - void request.catch(() => undefined); + const start = async () => { + const built = await buildDispatcher({ + driverOptions: slimmable, + memoryPressureStep: "new-devices-paused", + ...row.options, + }); + if (row.seed !== undefined) await seedSlimDevice(built, row.seed); + return { built, seededCalls: built.driver.calls.length }; + }; + const driven = (world: Awaited>) => + world.built.driver.calls + .slice(world.seededCalls) + .filter((call) => ["provision", "makeReady", "shutdown"].includes(call.operation)); + + const waiter = await start(); + void waiter.built.dispatcher + .dispatch("lease.request", row.input, asker()) + .catch(() => undefined); await flush(); - const listed = await waiting(built); + const listed = await waiting(waiter.built); + const refused = await start(); + await expect( - built.dispatcher.dispatch( - "lease.request", - { ...row.input, noWait: true }, - session({ principal: "tok_second" }), - ), + refused.built.dispatcher.dispatch("lease.request", { ...row.input, noWait: true }, asker()), ).rejects.toMatchObject({ code: "NO_CAPACITY", details: { capacityReason: "memory-pressure" }, }); - expect(listed).toMatchObject([{ reason: "memory-pressure", stage: "queued" }]); - expect( - built.driver.calls - .slice(seededCalls) - .filter((call) => ["provision", "makeReady", "shutdown"].includes(call.operation)), - ).toEqual([]); + expect(driven(waiter)).toEqual([]); + expect(driven(refused)).toEqual([]); }, ); diff --git a/src/leasing/acquisition-planner.ts b/src/leasing/acquisition-planner.ts index d3ca1f34f..9aa3eb65f 100644 --- a/src/leasing/acquisition-planner.ts +++ b/src/leasing/acquisition-planner.ts @@ -175,6 +175,8 @@ export class AcquisitionPlanner { // why: no capacity reservation: the device keeps its running slot and RAM, because its record stays `ready` through the reboot. #planReady(input: AcquisitionPlannerInput, ready: DeviceRecord): AcquisitionPlan { if (input.rebootReady !== true || ready.physical) return { device: ready, kind: "grant-ready" }; + // why: a reboot boots a device as a new one does, so the pause that stops new devices stops it. + if (this.capacity.newDevicesPaused()) return blocked(input.noWait, "memory-pressure"); const claim = this.claims.tryClaim(ready.id, "boot", input.owner); if (claim === undefined) return blocked(input.noWait, "waiting-for-device"); return { claim, device: ready, kind: "reboot-ready" }; diff --git a/website/src/content/docs/docs/worker/capacity.mdx b/website/src/content/docs/docs/worker/capacity.mdx index a3887fe42..3cb49207e 100644 --- a/website/src/content/docs/docs/worker/capacity.mdx +++ b/website/src/content/docs/docs/worker/capacity.mdx @@ -50,6 +50,8 @@ When a lease needs a device, Simlock tries these in order: 5. At the running limit, shut down an idle device to make room. 6. Otherwise, wait in the queue until a device frees up. With `--no-wait`, the request fails at once with `NO_CAPACITY`. +When the host is short of memory enough to pause new devices, steps 2 and 3 are skipped and so is rebooting a ready device for an `--except` lease: the request waits, and is served when the pressure lifts. A ready device that fits is still handed over, and nothing is shut down for the wait. + A leased device is never shut down or deleted to make room. When RAM is the only thing in the way, Simlock shuts nothing down for it; the request waits until RAM frees up, for example when an idle device shuts down on its own. Each simulator or emulator serves one lease and is deleted when that lease ends. The first lease of an iOS model and version takes longer; later ones of the same kind start faster. @@ -224,6 +226,6 @@ warm pool: enabled, reserve ios 1 android 0 | `device-limit` | The platform is at its device limit. | | `reserve` | The slot is held back by `warmPool.reserveRunning`. | | `ram-budget` | The device would not fit in the RAM budget. | -| `memory-pressure` | The host is short of memory and warming is paused (`memoryPressure.*`). | +| `memory-pressure` | The host is short of memory and the worker has paused new devices (`memoryPressure.*`). | A line that is filling, or waiting behind a queued lease, shows no reason. `simlock doctor` warns when your targets add up to more devices than the running limit allows. From ca9550ce079b5ae94c9557288969e4aac822f9f1 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Fri, 6 Nov 2026 18:59:08 +0100 Subject: [PATCH 3/5] test: a request waiting on memory pressure is served when the step lifts, with no other event (#1362) --- src/core/create-core.ts | 2 ++ src/daemon/dispatcher-leases.test.ts | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/core/create-core.ts b/src/core/create-core.ts index cdd996edf..bd7e04d78 100644 --- a/src/core/create-core.ts +++ b/src/core/create-core.ts @@ -272,6 +272,8 @@ export function createCore(options: CoreOptions): Core { ...(options.logger === undefined ? {} : { logger: options.logger }), registry, }); + // why: a waiting request is only planned again by an event; the step lifting is the one that frees it. + options.eventBus.subscribe("memory.pressure-changed", notifyAvailability); // why: removing a runtime or image is what makes a baseline stale, so the check follows it. options.eventBus.subscribe("component.removed", () => { baselines.checkStale().catch((error: unknown) => { diff --git a/src/daemon/dispatcher-leases.test.ts b/src/daemon/dispatcher-leases.test.ts index d96c0fcc5..b8818d0e5 100644 --- a/src/daemon/dispatcher-leases.test.ts +++ b/src/daemon/dispatcher-leases.test.ts @@ -1415,4 +1415,29 @@ describe("Dispatcher: lease.request at new-devices-paused", () => { "ready", ); }); + + it.each(["none", "warming-paused"] as const)( + "a request waiting on memory pressure reads memory-pressure, then is served when the step lifts to %s with no other event", + async (lifted) => { + const built = await buildDispatcher({ memoryPressureStep: "new-devices-paused" }); + let granted: unknown; + void built.dispatcher.dispatch("lease.request", ask, asker()).then((grant) => { + granted = grant; + }); + await flush(); + const before = await waiting(built); + + built.setMemoryPressure(lifted); + built.eventBus.emit( + "memory.pressure-changed", + { from: "new-devices-paused", to: lifted }, + "test", + ); + + await flush(); + + expect(before).toMatchObject([{ reason: "memory-pressure" }]); + expect(granted).toMatchObject({ lease: { ownerId: "tok_asker" } }); + }, + ); }); From e5032c31af49db0aa4e583590aca76a45241042d Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Fri, 6 Nov 2026 19:02:51 +0100 Subject: [PATCH 4/5] docs(leasing): reboot-ready waits at new-devices-paused (#1362) --- src/leasing/AGENTS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/leasing/AGENTS.md b/src/leasing/AGENTS.md index a579d7fb0..30807e35a 100644 --- a/src/leasing/AGENTS.md +++ b/src/leasing/AGENTS.md @@ -27,7 +27,7 @@ The queue: - A grant of a ready device wakes the queue, so the next waiter plans without another event. - A device made from an older baseline version is never granted: a copy that finishes after a save is deleted at the grant check, and its waiter plans again. - A request naming a baseline attempts no download. -- A request with `except` (ADR 0066) boots with the list. A ready warm device is shut down and prepared again under its `boot` claim, with no capacity reservation (plan `reboot-ready`, `ManagedDeviceLifecycle.rebootForLease`); the grant is `booted`. Any failure of that reboot or of a boot destroys the device and counts one failure with a failed provision. A request without `except` that fails to boot rejects `boot-timeout`. +- A request with `except` (ADR 0066) boots with the list. A ready warm device is shut down and prepared again under its `boot` claim, with no capacity reservation (plan `reboot-ready`, `ManagedDeviceLifecycle.rebootForLease`), except that at `new-devices-paused` the request waits `memory-pressure` instead; the grant is `booted`. Any failure of that reboot or of a boot destroys the device and counts one failure with a failed provision. A request without `except` that fails to boot rejects `boot-timeout`. - A slim baseline's `except` names go to `driver.resolveSpec` too, so an unknown name is `BAD_REQUEST`; a full baseline refuses `except`. Ending a lease: From c2f6c913a64b3cf62837b44224eb3052bd952155 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Fri, 6 Nov 2026 19:11:33 +0100 Subject: [PATCH 5/5] docs(capacity): restore the warm-pool memory-pressure row; #1363 owns it (#1362) --- website/src/content/docs/docs/worker/capacity.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/src/content/docs/docs/worker/capacity.mdx b/website/src/content/docs/docs/worker/capacity.mdx index 3cb49207e..413e4f63a 100644 --- a/website/src/content/docs/docs/worker/capacity.mdx +++ b/website/src/content/docs/docs/worker/capacity.mdx @@ -226,6 +226,6 @@ warm pool: enabled, reserve ios 1 android 0 | `device-limit` | The platform is at its device limit. | | `reserve` | The slot is held back by `warmPool.reserveRunning`. | | `ram-budget` | The device would not fit in the RAM budget. | -| `memory-pressure` | The host is short of memory and the worker has paused new devices (`memoryPressure.*`). | +| `memory-pressure` | The host is short of memory and warming is paused (`memoryPressure.*`). | A line that is filling, or waiting behind a queued lease, shows no reason. `simlock doctor` warns when your targets add up to more devices than the running limit allows.