Repository navigation
Description
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
# 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]
src/core/capacity/coordinator.ts: the check before the strategy in the three reservations (F1);canProvisionandcanBootstay the strategy's own answer, soatRamBudgetis unchanged (F2).src/core/create-core.ts: hands thememoryPressureport to theCapacityCoordinatorconstructor (create-core.ts:184-187), and onmemory.pressure-changedcallsnotifyAvailability(F8). Memory pressure: the warm pool pauses and sheds idle devices #1363 edits theWarmPoolconstruction 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 atnew-devices-paused; the plan blocks withmemory-pressure.src/leasing/testing.ts:TestEngineOptionscarries the port tocreateCore, sincebuildDispatcherbuilds core throughcreateTestEngine(src/daemon/test-dispatcher.ts:239).src/daemon/test-dispatcher.ts: amemoryPressureoption, 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
canBootandcanProvisiondirectly (src/core/warm-pool/converger.ts:633-646), which stay blind to the step, then reserves throughtryReserveBootandtryReserveProvisioning(converger.ts:781,:819). So atnew-devices-pausedthe 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 nowarm-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 atwarming-pausedor 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--exceptlease under abootclaim with no capacity reservation (A slim lease keeps named categories running (--except) #1330 body, step 1). Atnew-devices-pausedthat plan waits with reasonmemory-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
fixedtoo. - Capacity manual: "A boot refused for RAM evicts nothing; the request waits.";
memory-pressureevicts 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
atRamBudgetkeeps 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-pauseda 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--exceptlease that needsreboot-readywaits;noWaitgetsNO_CAPACITYcapacityReason: "memory-pressure", also when the strategy would refuse too and underfixed; 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 readsmemory-pressurebefore the lift. The test changes the settable step, then emitsmemory.pressure-changedon the harness'seventBus, in that order.
Done when
pnpm exec vitest run --project unit src/daemon/dispatcher-leases.test.ts src/core/capacity/coordinator.test.tspasses.
Out of scope
- The warm pool's own pause and shedding, and its
shortreason (Memory pressure: the warm pool pauses and sheds idle devices #1363). - Routing around a paused worker (Memory pressure: a gateway ranks a paused worker last, and worker list shows the step #1364).
Depends on
- Memory pressure: a worker works out its step and reports it #1361
- A slim lease keeps named categories running (--except) #1330
Written by an agent.
Activity
test: a request waiting on memory pressure is served when the step li…
docs(leasing): reboot-ready waits at new-devices-paused (#1362)
docs(capacity): restore the warm-pool memory-pressure row; #1363 owns…
feat(host-load): a worker works out its memory pressure step and repo…
feat(capacity): at new-devices-paused a worker creates and boots no d…