Skip to content

Memory pressure: new devices wait while a worker's new devices are paused #1362

Closed

Description

@V3RON

Part of #1355.

Scope

At new-devices-paused, a worker creates and boots no device for a lease. A request that needs a new device waits with reason memory-pressure, and a --no-wait one fails with NO_CAPACITY and capacityReason: "memory-pressure". A request that fits an idle booted device is still granted, unless granting it means rebooting it (#1330's reboot-ready for an --except slim lease): that reboot waits like a boot. When the step lifts, the waiting request is served without any other event. The reason, its wire value and its text came with #1361; this task is the first to refuse with it.

In short

The step from #1361 now stops new devices. CapacityCoordinator refuses every reservation that adds RAM with reason memory-pressure, before the strategy is asked, under every strategy. Leasing and the warm pool both reserve through it.

flowchart LR
  R[lease.request] --> P[planner]
  P -->|ready idle device| G[grant, as today]
  P -->|create or boot| C{CapacityCoordinator}
  C -- step new-devices-paused *new* --> W[wait: memory-pressure, or NO_CAPACITY under noWait]
  C -- otherwise --> S[strategy, as today]
  E[memory.pressure-changed] -->|*new* core kicks the queue| P
Loading
# before (16 GiB host at 8% available)
$ simlock list --requests
No requests are waiting.            # the worker boots one more simulator, which times out

# after
$ 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" }

If this goes wrong, requests wait on a calm host, or a paused worker still boots devices.

Technical spec

Facts

Commit 6674ad0.

# Fact Source
F1 tryReserveProvisioning, tryReserveBoot and tryReserveRewarm are the reservations that add a device or RAM; each asks the strategy (canProvision, canBoot) first src/core/capacity/coordinator.ts:61-65, src/core/capacity/coordinator.ts:84-88, src/core/capacity/coordinator.ts:114-118
F2 atRamBudget asks canProvision and reads only ram-budget src/core/capacity/coordinator.ts:139-140
F3 CapacityRefusalReason has four members; WaitingReason includes it; a Record over it maps each to a waiting reason, so the compiler fails on a missing one src/core/capacity/strategy.ts:30-34, src/leasing/acquisition-planner.ts:53-64
F4 A refusal evicts only for a running limit; noWait turns a blocked plan into no-capacity src/leasing/acquisition-planner.ts:242, src/leasing/acquisition-planner.ts:261
F5 The worker dispatcher sets details.capacityReason only for a reason capacityReasonOf knows src/daemon/dispatcher.ts:548-551, src/leasing/acquisition-planner.ts:66-71
F6 The wire enums: waiting reasons and capacityReasonSchema; NO_CAPACITY details type the four reasons; a gateway keeps only a parsing value src/contract/lease-schemas.ts:94-108, src/contract/errors.ts:37-39, src/gateway/fleet-refusals.ts:141-144
F8 notifyAvailability kicks acquisition and passes the warm pool; core already reaches it as a port src/leasing/create-leasing.ts:189-192, src/core/create-core.ts:169
F9 The model test drives lease.request through buildDispatcher and checks details.capacityReason per reason src/daemon/dispatcher-leases.test.ts:1007-1013, src/daemon/test-dispatcher.ts:143
F11 tryReserveRewarm has no caller outside tests today rg -n "tryReserveRewarm" src --glob '!*.test.ts' printed only src/core/capacity/coordinator.ts:114

Modules touched

Searches: tryReserve, canProvision, canBoot, notifyAvailability, memory.pressure-changed, "ram-budget" across src/, ui/, website/.

flowchart LR
  L[leasing planner] --> CC[core capacity coordinator *]
  WP[warm pool] --> CC
  CC --> MP[core memoryPressure port, #1361]
  CORE[core create-core: on memory.pressure-changed *] --> NA[notifyAvailability]
Loading
  • src/core/capacity/coordinator.ts: the check before the strategy in the three reservations (F1); canProvision and canBoot stay the strategy's own answer, so atRamBudget is unchanged (F2).
  • src/core/create-core.ts: hands the memoryPressure port to the CapacityCoordinator constructor (create-core.ts:184-187), and on memory.pressure-changed calls notifyAvailability (F8). Memory pressure: the warm pool pauses and sheds idle devices #1363 edits the WarmPool construction in the same file (create-core.ts:295), elsewhere: they run at once.
  • src/leasing/acquisition-planner.ts: reboot-ready (from A slim lease keeps named categories running (--except) #1330) is not chosen at new-devices-paused; the plan blocks with memory-pressure.
  • src/leasing/testing.ts: TestEngineOptions carries the port to createCore, since buildDispatcher builds core through createTestEngine (src/daemon/test-dispatcher.ts:239).
  • src/daemon/test-dispatcher.ts: a memoryPressure option, a step the test sets.
  • Docs: the website's worker/capacity.mdx, its section "What happens when the machine is full" (Memory pressure: the warm pool pauses and sheds idle devices #1363 writes the warm pool section), src/core/capacity/AGENTS.md.

Contract and event changes

none: the reason is on the wire from #1361 (F6). No event changes; EVENTS.md is unchanged.

Other code on the same state

Searches: callers of tryReserveProvisioning and tryReserveBoot (4 hits: the planner's two, the warm pool's two); readers of CapacityRefusalReason (planner map, warm pool shortOf, gateway fleet-refusals).

  • The warm pool plans with canBoot and canProvision directly (src/core/warm-pool/converger.ts:633-646), which stay blind to the step, then reserves through tryReserveBoot and tryReserveProvisioning (converger.ts:781, :819). So at new-devices-paused the pool still proposes boots and creations, the reservation refuses them, and they end "not attempted" (converger.ts:787, :824): nothing boots, nothing retries in a loop, but a target that never fills reads as not short and raises no warm-pool.target-missed, and a displacement may shut an idle device down for a boot then refused. Accepted until Memory pressure: the warm pool pauses and sheds idle devices #1363 lands: there the pool proposes nothing at warming-paused or higher, so either order is safe.
  • A leased device's crash reboot (recoverLeased) takes no reservation and stays unchecked (ADR 0068 §4).
  • A grant of a ready device takes no reservation, so it goes on.
  • A slim lease keeps named categories running (--except) #1330 (task:ready, another feature) adds the plan reboot-ready: it reboots a ready device for an --except lease under a boot claim with no capacity reservation (A slim lease keeps named categories running (--except) #1330 body, step 1). At new-devices-paused that plan waits with reason memory-pressure, as a boot does: the planner asks the coordinator's step check before choosing it. This task depends on A slim lease keeps named categories running (--except) #1330 and adds that check to its plan.

Failure modes

Call Outcome What happens Limit, counted from
coordinator → memoryPressure() port new-devices-paused refused memory-pressure none
coordinator → memoryPressure() port other step, or undefined the strategy decides, as today none
memory.pressure-changed → notifyAvailability delivered queue plans again at once none

No state is written: a reservation refused takes nothing. A restart starts with no step (#1361).

Rules in play

  • ADR 0068 §4: "before the strategy is asked"; under fixed too.
  • Capacity manual: "A boot refused for RAM evicts nothing; the request waits."; memory-pressure evicts nothing (F4).
  • Capacity manual: "Status and the planner ask the same questions"; the step check sits in the reservations, and status reports the step itself (Memory pressure: a worker works out its step and reports it #1361), so atRamBudget keeps meaning RAM.
  • Leasing manual: "A waiting reason is never stored"; the reason lives on the waiter only.

Tests

The seam is the worker Dispatcher from buildDispatcher with a settable step, modelled on src/daemon/dispatcher-leases.test.ts.

  • 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: 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.
  • A request waiting on memory pressure is served when the step lifts, with no other event: lifts to none; lifts to warming-paused; the waiter's reason reads memory-pressure before the lift. The test changes the settable step, then emits memory.pressure-changed on the harness's eventBus, in that order.

Done when

  • pnpm exec vitest run --project unit src/daemon/dispatcher-leases.test.ts src/core/capacity/coordinator.test.ts passes.

Out of scope

Depends on

Written by an agent.

Activity

  1. added
    task:draft
    on Nov 6, 2026
  2. added
    task:ready
    and removed
    task:draft
    on Nov 6, 2026
  3. self-assigned this
    on Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

task:ready

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions