Skip to content

Admission respects the host's real memory pressure #1355

Closed
5 of 5 issues completed
Closed

Description

@V3RON

Request: #1246

Problem

In the reporter's words: "A worker kept admitting and warm-booting iOS simulators while its host was swapping hard. simlock status saw the pressure but capacity ignored it." The RAM budget is "total RAM minus 4 GiB" and counts only Simlock's own devices. On a host where most memory goes to other work (Xcode builds, local stacks, agents), it reports room and keeps creating and booting devices. On a 16 GiB worker the same shape showed up as repeated BootTimeoutError while the queue kept retrying. Nothing gives way as the host fills up.

Who it is for

An operator whose workers share their machines with builds and other agents, and the agents leasing from those workers, directly or through a gateway.

Outcome

When the host runs short of memory, a worker stops adding load, in two steps:

  • Warming paused (lower step): the warm pool starts nothing, and gives memory back by shutting down one idle device per reading. Leases are still served as today.
  • New devices paused (higher step): on top of that, no new device is created or booted for a lease. A request that needs one waits and says why. A request for a device that is already booted and idle is still served. Running leases are never touched.

A step lifts after a minute with no reading that meets it. The operator sees the step in simlock status, simlock worker list, the console and an alert. A gateway sends a request elsewhere before it sends one to a worker whose new devices are paused.

How it works for the user

flowchart TD
  R[Reading every 15 s] --> L{Meets which step?}
  L -- neither, for 1 min --> N[No step: as today]
  L -- lower: macOS warn, or under 20% available --> W[Warming paused: pool starts nothing, sheds one idle device per reading]
  L -- higher: macOS critical, or under 10% available --> P[New devices paused: also no create or boot for a lease]
  P --> A{Request}
  A -- an idle booted device fits --> G[Granted]
  A -- needs a new device --> Q[Waits: Full: host memory pressure]
  A -- --no-wait --> E[NO_CAPACITY, capacityReason memory-pressure]
  X[No reading, host load off, or reading over 60 s old] --> N
Loading

Before, on the reporter's 32 GiB Mac:

$ simlock status
Load: CPU 100% busy (12 cores) · memory 10.9 GiB of 32.0 GiB available · swap 14.0 GiB used · pressure warn · disk ... · read 4s ago
Capacity ios: managed 2/6, running 2 + 0 reserved/6, warm 2
RAM budget: 3.00 GiB/28.00 GiB used

After, at the lower step (one warm device already shed):

$ simlock status
Load: CPU 100% busy (12 cores) · memory 10.9 GiB of 32.0 GiB available · swap 14.0 GiB used · pressure warn · disk ... · read 4s ago
Memory pressure: warming paused since 09:12 (pressure warn)
Capacity ios: managed 2/6, running 1 + 0 reserved/6, warm 1
RAM budget: 1.50 GiB/28.00 GiB used

At the higher step, on a 16 GiB Linux host with no pressure level:

$ simlock status
Memory pressure: new devices paused since 09:40 (8% available, floor 10%)

$ simlock list --requests
Request req_1: agent-7, ios iPhone 17, queued at 1, waiting 120s — full: host memory pressure

$ simlock lease --platform ios --no-wait
{"error":{"code":"NO_CAPACITY","message":"..."}}        # details.capacityReason: "memory-pressure"

Through a gateway:

$ simlock worker list
mini-3: connected -- ios 2/6, android 0/0, 2 leases ... -- memory: new devices paused
mini-4: connected -- ios 1/6, android 0/0, 1 lease ...

$ simlock list --requests        # a fleet request no worker took yet
Request req_2: agent-9, ios iPhone 17, queued at 1, waiting 30s
  mini-3: full: host memory pressure
  mini-4: busy with its own queue

Examples

The defaults (pauseWarming at warn or 20%, pauseNewDevices at critical or 10%):

Reading Today After
macOS, pressure normal, 34% available admitted no step
macOS, pressure warn, 34% available admitted warming paused
macOS, pressure critical, 30% available admitted new devices paused
macOS, pressure normal, 8% available admitted new devices paused (floor)
Linux, 25% available admitted no step
Linux, 15% available admitted warming paused
Linux, 9.9% available admitted new devices paused (prints 9% available)
Linux cgroup limit 8 GiB, 1 GiB available under it (12.5%) admitted warming paused
Read failed (no memory part) admitted no step, at once
Last reading 61 s old admitted no step, at once
Host load off (hostLoadProbe: null) admitted no step; status shows no line
memoryPressure.enabled: false admitted no step
critical at 09:00, normal from 09:00:15 admitted new devices paused until 09:01:15, then none
critical at 09:00, warn from 09:00:15 to 09:05, normal from 09:05:15 admitted new devices paused until 09:01:15, warming paused until 09:06:15

What could go wrong

  • A Mac that sits at warn for hours stops warming: leases still work but pay a boot each. Likely on small Macs; the operator raises pauseWarming.level to critical or sets it off.
  • A step that does not lift leaves requests waiting with "host memory pressure" while the host looks fine. Unlikely; status shows the cause and its time.
  • Shedding shuts down a device a request was about to take. Unlikely: a device a waiting request would be granted is never shed.
  • A gateway keeps sending to a paused worker for one view refresh. Rare; the step-change event refreshes the view at once.

Words used

  • step: how far a worker has backed off under memory pressure: none, warming-paused or new-devices-paused. Example: Memory pressure: warming paused since 09:12.
  • pressure level: macOS's own judgement of memory, normal, warn or critical, already shown on the Load line as pressure warn. Linux and Windows have none.
  • available percent: available memory as a share of total memory (or of a cgroup limit), as the Load line's memory 10.9 GiB of 32.0 GiB available reads (34%).
  • floor: a step's minAvailablePercent; available under it meets the step. 0 turns it off.
  • meets: a reading meets a step when its pressure level is at or above the step's level, or its available percent is under the step's floor.
  • hold: clearAfterMs, how long a step stays on after the first reading that no longer meets it (default 60 s); a meeting reading meanwhile restarts it.
  • shed: shut down one idle warm device to give its memory back; its disk stays until the usual idle cleanup deletes it.
  • idle device: a virtual device that is booted (ready), not leased and not being worked on.

Non-goals

  • Stopping, killing or slowing a running lease, or a leased device's crash reboot.
  • Using swap as a signal: macOS keeps swap used long after pressure ends.
  • Gateway-side thresholds or routing on raw load: the gateway reads the worker's step.
  • A pressure level on Linux or Windows (PSI or similar): there the floor is the signal.
  • Changing a setting live: the section takes effect at the next start, like most keys today.
  • CPU or disk as admission signals.

Completion conditions

  • On a worker whose probe reports pressure warn, simlock status shows Memory pressure: warming paused since <time> (pressure warn), the warm pool boots and creates nothing, and each reading shuts down one idle device until none is idle.
  • On a worker at critical (or under 10% available), a lease that needs a new device waits with full: host memory pressure in simlock list --requests, a --no-wait one fails NO_CAPACITY with capacityReason: "memory-pressure", and a lease that fits an idle booted device is granted.
  • A minute after the first calm reading the step lifts, and a waiting request is served without any other event.
  • With no reading, a stale reading, host load off or enabled: false, admission is as today.
  • One memory.pressure-changed event per step change, listable by a gateway alert destination.
  • A gateway picks a worker that is not paused over one whose new devices are paused, unless the paused one has an idle fitting device; simlock worker list and the console show each worker's step.

Open questions

none

Decisions

Shared values

Value or state Rule Written by Read by Source
Step none | warming-paused | new-devices-paused; each step is on from the first reading meeting it until clearAfterMs after the first reading that does not, if none meets it meanwhile; the worker's step is the highest on; no reading (host load off, enabled: false, no memory part, reading older than 60 s) is none at once #1361 #1362, #1363, #1364, #1365 ADR 0068 §1
Core read port memoryPressure { current, onReading }: current() answers { step, since, cause, readingAt } or undefined (host load off); onReading(listener) calls after each reading, once the step is updated; readingAt lets a reader act once per reading #1361 #1362, #1363 ADR 0068 §2
status.get capacity.memoryPressure { step, since, cause }: since epoch ms of the current step's start; cause { trigger: "level" | "floor", availablePercent: integer 0-100, level?, floorPercent? } is the reading that turned the current step on, fixed while it holds (each step keeps its own); both absent at none; clamped and fitted on the worker; availablePercent is available ÷ total × 100 rounded down (a floor compares the exact value); absent when host load is off or while starting #1361 #1364, #1365 ADR 0068 §6
Event memory.pressure-changed { from, to, cause? }, once per step change, never per reading; cause the new step's, absent to none #1361 #1361 (alert), #1362 (core wakes the queue), #1363 (a warm pool trigger), #1364 (gateway refresh), #1365 (console stale) ADR 0068 §5
Config memoryPressure enabled (true), pauseWarming {level warn, minAvailablePercent 20}, pauseNewDevices {level critical, minAvailablePercent 10}, clearAfterMs 60000; level normal | warn | critical | off; percent a number 0-100; worker only #1361 #1362, #1363 ADR 0068 §1
Refusal reason memory-pressure a capacity refusal (CapacityRefusalReason), a waiting reason, NO_CAPACITY capacityReason, a gateway full capacityReason (routing's CapacityReason); the values come with #1361; only #1362 refuses with it, before the strategy #1361 (values), #1362 (refuses) #1363, #1364 ADR 0068 §4
Waiting text Full: host memory pressure (lower-cased after a request or worker name), in the CLI and the console #1361 #1362, #1364 ADR 0068 §6
Warm target short memory-pressure a configured or learned target left short while warming is paused; also warm-pool.target-missed reason; the wire value comes with #1361 #1361 (value), #1363 (reports it) the console prints short as given ADR 0068 §3
Protocol version only #1361 changes contract shapes and bumps it by one; #1362 to #1365 change none #1361 all toolchain "Contract shapes"
Alert event memory.pressure-changed in ALERT_EVENTS, with its Slack message #1361 gateway alerts ADR 0068 §5

Behaviours

Behaviour (invoker, action, what it sees) Seam Cases Task
An operator's worker reads memory and status.get reports the step it meets startDaemon with FakeHostLoadProbe (src/daemon/main-host-load.test.ts) macOS normal/warn/critical at 34%, the last two trigger: "level"; macOS warn at 8% → new-devices-paused, trigger: "floor", floorPercent: 10; macOS critical at 8% → trigger: "level"; macOS normal at 8%; no level at 25%, 15%, 9.9%; level off and floor 0; enabled: false #1361
A step lifts only after clearAfterMs with no meeting reading startDaemon with FakeHostLoadProbe and FakeClock calm 45 s after the first calm reading still on; 60 s after it lifted; a meeting reading at 30 s restarts the hold; new-devices-paused falls to warming-paused while only the lower step meets, reporting warming's own since and cause; a later, different meeting reading keeps since and cause #1361
No usable reading is no step, at once startDaemon; the 60 s case at MemoryPressureTracker host load off (no memoryPressure field); a failed read; no reading for 60 s (at the tracker); each while a step held, since and cause absent after #1361
The worker emits memory.pressure-changed once per step change startDaemon, events subscription none→warming; warming→new devices; new devices→warming; warming→none, each with the new step's cause (none to none); a second meeting reading emits nothing #1361
An operator's memoryPressure config is defaulted and checked loadConfig (src/core/config.test.ts) defaults; level: "bogus"; minAvailablePercent 101 and -1; clearAfterMs -1; a gateway's config with the section warns worker-only #1361
An operator's simlock status prints the Memory pressure line runCli (src/cli/index.test.ts) warming by level; new devices by floor; 9.9% prints 9% available; macOS warn at 8% tripped by the floor prints the floor; step none prints no line; no field prints no line #1361
An operator's simlock list --requests names host memory pressure runCli (src/cli/index.test.ts) a worker's own waiting request full: host memory pressure; a gateway request's worker entry full with capacityReason: "memory-pressure" #1361
An operator's console waiting list names host memory pressure waiting.ts builder (ui/src/model/waiting.test.ts) reason memory-pressure reads Full: host memory pressure #1361
A gateway alert destination listing memory.pressure-changed gets one message per change createAlerts (src/alerts/alerts.test.ts) Slack to new devices paused by level; to warming paused by floor; to none; generic JSON envelope #1361
At new-devices-paused a lease that needs a new device waits or is refused, and one that fits an idle booted device is granted worker Dispatcher (src/daemon/dispatcher-leases.test.ts) create; boot of a shut-down device; idle ready device granted; an --except lease that needs reboot-ready waits; noWait gets NO_CAPACITY capacityReason: "memory-pressure", also when the strategy would refuse too and under fixed; at the platform running limit an idle device of another kind is not evicted #1362
A request waiting on memory pressure is served when the step lifts, with no other event worker Dispatcher lifts to none; lifts to warming-paused; the waiter's reason reads memory-pressure before the lift #1362
At warming-paused the warm pool starts nothing and reports why evaluate (src/core/warm-pool/policy.test.ts), the event at WarmPool configured target short; learned kind short; a queued request's creation not proposed; a queued request's boot of a shut-down device not proposed; targets report short: "memory-pressure", also when also short for reserve, and a runtime-missing target keeps runtime-missing (at the WarmPool seam); warm-pool.target-missed reason memory-pressure #1363
Each reading while warming is paused shuts down one idle device, in order WarmPool with a fake port (src/core/warm-pool/converger.test.ts) through the port's onReading, one per reading, a device no target keeps (least recently used first), then a kept configured one; a device a waiter would take skipped; a device whose shutdown just failed skipped; two passes on one reading shed one; a reading before start() sheds nothing; nothing idle sheds nothing; step none sheds nothing #1363
When warming resumes the pool fills its targets again WarmPool memory.pressure-changed to none runs a pass that boots or creates for a short target, with no tick #1363
A gateway ranks a worker whose new devices are paused below one that is not createRoutingPolicy (src/gateway/routing.test.ts) paused vs calm picks calm; paused with a warm hit picks paused; every worker paused still picks one; explain gives full with capacityReason: "memory-pressure"; warming-paused ranks as calm #1364
A gateway refreshes a worker's view at once on its memory.pressure-changed GatewayService (src/gateway/service.test.ts) the event refreshes; a refusal held against the old view is asked again after the step lifts #1364
An operator's simlock worker list shows each worker's step runCli (src/cli/index.test.ts) memory: warming paused; memory: new devices paused; none prints nothing #1364
An operator's console shows a worker's step on its card and page src/model/fleet.ts and worker-page.ts builders (ui/src/model/fleet.test.ts) new-devices-paused error tone with words; warming-paused warn tone; warming-paused beside memory pressure warn reads warming paused; new-devices-paused beside memory pressure critical reads new devices paused; none nothing #1365
A memory.pressure-changed event marks the console's workers stale staleKeys (ui/src/model/stale-keys.ts; a new test file modelled on ui/src/model/fleet.test.ts) the event marks workers; an unrelated event does not #1365

Tasks

flowchart LR
  X[#1331, #1356, #1357: other features] --> T1[#1361 step and wire values]
  Y[#1330, another feature] --> T2
  T1 --> T2[#1362 new devices wait]
  T1 --> T3[#1363 warm pool pauses and sheds]
  T1 --> T4[#1364 gateway and worker list]
  X --> T4
  T1 --> T5[#1365 console]
Loading

Completion conditions:

Open work in the same area:

Written by an agent.

Sub-issues

Sub-issues

5 of 5 Issues completed
Loading 5 sub-issues

Activity

  1. added
    feature:spec
    on Nov 6, 2026
  2. V3RON commented on Nov 6, 2026

    @V3RON
    ContributorAuthor

    Spec updated: every section written (business sections, Decisions with ADR 0068 on #1359, Shared values, Behaviours, Tasks), and tasks #1361 to #1365 added as sub-issues.

    Written by an agent.

  3. added
    feature:planned
    and removed
    feature:spec
    on Nov 6, 2026
  4. github-actions commented on Nov 6, 2026

    @github-actions
    Contributor

    Closing: all 5 sub-issues are closed. The PR that closed the last one walks the completion conditions (delivery rule 9); reopen this if one does not hold on main. Flip its ADRs to Accepted if delivery has not.

  5. V3RON commented on Nov 6, 2026

    @V3RON
    ContributorAuthor

    Delivery run

    Merged: #1359 (ADR 0068), #1398 (#1361), #1401 (#1362), #1400 (#1363), #1402 (#1364), #1403 (#1365)
    Parked: none
    Waiting: none
    Decided: #1361 — where the memory-pressure config type lives, given host-load may not import core → host-load's step tracker declares its own options type, core owns the memoryPressure section, the daemon passes it in (pending the maintainer; see the "Decision taken" comment on #1359)
    Asleep: 20 min

    Written by an agent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature:planned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions