Repository navigation
Description
Part of #1355.
Scope
At warming-paused (and above), the warm pool starts nothing and gives memory back. It proposes no boot and no creation for configured targets, learned kinds or queued requests. On each reading while the step holds, it shuts down one idle device. A target left short reports memory-pressure. When the step lifts, the pool runs a pass at once and fills again. Leasing's own creates and boots are as today at this step.
In short
flowchart LR
R[reading while warming paused] -->|*new* port onReading, after start| P[warm pool pass]
L[memory.pressure-changed] -->|*new* trigger| P
P --> F{plan}
F -- boots, creations --> N[none proposed *new*]
F -- shed *new* --> S[shut down one idle device: no configured count keeps it first, then configured; least recently used first; never one a waiter would take]
P --> T[targets short: memory-pressure *new*]
An idle device is a virtual device that is ready, unleased and unclaimed. Shed means shut it down; the disk stays until the reaper's idle rules delete it, as today. One shed per reading means at most one per 15 s, however many passes run in between; the reading counts as used when the shed is proposed.
The order: first every idle device no configured target keeps (a configured target keeps its oldest count ready devices, by createdAt, as it does today, F13), then the kept ones, the devices of spared targets among them; least recently used first within each group. Never a device a waiting request would be granted. A device whose shutdown failed in the last 30 s is skipped, so the next reading takes the next one. While warming is paused, a short target reports memory-pressure in place of any reason evaluate decides (boot-failed, running-limit, device-limit, ram-budget, reserve). A target that does not resolve keeps its own reason (no-driver, runtime-missing, unknown-model, unresolvable, set by the converger, src/core/warm-pool/converger.ts:527): a pause would not fill it either.
# before, at pressure warn
$ simlock status
Capacity ios: managed 3/6, running 3 + 0 reserved/6, warm 3
# after, three readings later
$ simlock status
Memory pressure: warming paused since 09:12 (pressure warn)
Capacity ios: managed 3/6, running 0 + 0 reserved/6, warm 0
If this goes wrong, the pool sheds a device a request was about to take, or keeps booting while memory is short.
Technical spec
Facts
Commit 6674ad0.
| # | Fact | Source |
|---|---|---|
| F1 | evaluate is pure over a WarmPolicyView: devices, leases, waiting demand, capacity, config, now, targets, learned kinds |
src/core/warm-pool/policy.ts:92-117 |
| F2 | Over budget, the policy proposes shutdowns of the least recently used running devices, never one a non-in-flight waiter is served by, reason over-budget |
src/core/warm-pool/policy.ts:268-285 |
| F3 | TargetShort lists the short reasons; a capacity refusal maps to one through shortOf, ram-budget and device-limit kept, the rest running-limit |
src/core/warm-pool/policy.ts:53-60, src/core/warm-pool/policy.ts:589-591 |
| F4 | The wire's short is warmPoolShortSchema |
src/contract/status-schemas.ts:53-64, src/contract/status-schemas.ts:77 |
| F5 | warm-pool.target-missed carries a free reason string; the website lists its values |
src/bus/index.ts:298-307, website/src/content/docs/docs/reference/events.mdx:128 |
| F6 | The pool boots under tryReserveBoot and creates under tryReserveProvisioning |
src/core/warm-pool/converger.ts:781, src/core/warm-pool/converger.ts:819 |
| F7 | A pass runs on bus facts (capacity.changed among them), a 30 s tick and core.passWarmPool() |
src/core/warm-pool/converger.ts:941, src/core/warm-pool/converger.ts:98, src/core/create-core.ts:423 |
| F8 | The policy test asserts the over-budget shutdown order and waiter shield | src/core/warm-pool/policy.test.ts:412 |
| F9 | The converger test drives proposals into actions with the warm-pool initiator under the cleanup claim | src/core/warm-pool/converger.test.ts:103 |
| F10 | The pool boots for a waiter through bootForWaiter and creates through createForWaiter, two paths |
src/core/warm-pool/policy.ts:365-383, src/core/warm-pool/policy.ts:385-409 |
| F11 | The pool's bus triggers do not include memory.pressure-changed; it starts only inside core.converge, and the sampler starts before converge |
src/core/warm-pool/converger.ts:932-943, src/core/create-core.ts:416-420, src/daemon/server.ts:414, src/daemon/server.ts:427 |
| F12 | The pool is built in createCore and in its test fixtures |
src/core/create-core.ts:295, src/core/warm-pool/test-fixtures.ts:362 |
| F13 | A target keeps its oldest count ready devices |
src/core/warm-pool/policy.ts:476-493 |
Modules touched
Searches: TargetShort, shortOf, overBudget, warmPoolShortSchema, WarmPolicyView, passWarmPool, "over-budget" across src/, ui/, website/.
flowchart LR
CC[core create-core *] --> WC[warm-pool converger *]
WC --> WP[warm-pool policy *]
WC --> MP[core memoryPressure port, #1361]
src/core/warm-pool/policy.ts: the view gains the step, whether this pass may shed (a new reading since the last shed) and the devices whose shutdown failed in the last 30 s; paused, no boot or creation is proposed, and at most oneshutdownwith reasonmemory-pressurein the order of the Scope; targets shortmemory-pressure;shortOfmapsmemory-pressure(the refusal type from Memory pressure: a worker works out its step and reports it #1361, refused by Memory pressure: new devices wait while a worker's new devices are paused #1362) to the shortmemory-pressure.src/core/warm-pool/converger.ts: readscurrent()each pass; instart()(so never before converge, F11) subscribesonReadingand asks a pass on each reading atwarming-pausedor higher; unsubscribes inclose(); addsmemory.pressure-changedto its triggers; keeps thereadingAtof its last shed; emitswarm-pool.target-missedwith the new reason.src/core/create-core.ts,src/core/warm-pool/test-fixtures.ts: pass the port toWarmPool(F12). Memory pressure: new devices wait while a worker's new devices are paused #1362 editscreate-core.tselsewhere; they run at once.- Docs: website
reference/events.mdx(the reason list),worker/capacity.mdx's section "Keep devices booted: the warm pool" (Memory pressure: new devices wait while a worker's new devices are paused #1362 writes the full-machine section),src/core/warm-pool/AGENTS.md.
Contract and event changes
none: memory-pressure is in warmPoolShortSchema from #1361. warm-pool.target-missed gains the reason value memory-pressure (its payload's reason is a free string, F5); its EVENTS.md row and the website's list name it.
Other code on the same state
Searches: proposals of action: "shutdown" in policy.ts (3 hits: disabled, over budget, never-leased idle, displacement); readers of idle ready devices (targeted(), the reaper's idle-shutdown).
- A pass that is over budget proposes its own shutdowns first; the shed is one more and counts toward the same device set, so one device is never shut down twice.
- The reaper's
idle-shutdownandidle-destroyact on the same devices; the pool'scleanupclaim keeps them apart, as today. - Leasing grants a ready device under the lock; a device the pool proposed is revalidated before it is shut down, so a device leased meanwhile is left alone (F9).
- Memory pressure: a worker works out its step and reports it #1361 adds
memory-pressuretoCapacityRefusalReason; this task maps it inshortOf. Memory pressure: new devices wait while a worker's new devices are paused #1362 is the one that refuses with it. - Runtime warm-pool targets: warm.set and warm.list, kept in state.db #1143 (another feature's draft) edits the proposal reason union and the pass code in the same files; whichever lands second rebases. No Depends on: it is not ready.
Failure modes
| Call | Outcome | What happens | Limit, counted from |
|---|---|---|---|
pass → memoryPressure() port |
warming-paused or higher |
no boot or creation; one shed per new reading | each pass |
pass → memoryPressure() port |
none or undefined |
as today | each pass |
shed → lifecycle.shutdown |
fails | logged, the pool's failed-shutdown pause, as today; that device is skipped by the next sheds | 30 s from the failure |
port onReading |
a reading before start() |
nothing: not subscribed yet | none |
The last-shed readingAt is memory only; a restart may shed once on its first reading, which is the same cadence.
Rules in play
- ADR 0068 §3: "never a device a waiting request would be granted"; the shed skips the devices the over-budget shield skips (F2).
- Warm pool manual: "Only displacement shuts a device down for a target or learned kind"; the shed is a pressure shutdown, not for a target, and ADR 0068 §3 puts configured targets' devices last.
- Warm pool manual: "
policy.tsis pure"; the shed decision reads the step and the last shed from the view. - ADR 0017: the pool acts beside the lease transaction; a shed takes no lease-path lock beyond the existing
cleanupclaim.
Tests
The seam is evaluate for what is proposed, modelled on src/core/warm-pool/policy.test.ts, and WarmPool with a fake port and the bus for the cadence and the event, modelled on src/core/warm-pool/converger.test.ts.
- At
warming-pausedthe warm pool starts nothing and reports why: 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 reportshort: "memory-pressure", also when also short forreserve, and aruntime-missingtarget keepsruntime-missing(at theWarmPoolseam);warm-pool.target-missedreasonmemory-pressure(at theWarmPoolseam). - Each reading while warming is paused shuts down one idle device, in order: 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 beforestart()sheds nothing; nothing idle sheds nothing; step none sheds nothing. - When warming resumes the pool fills its targets again:
memory.pressure-changedto none runs a pass that boots or creates for a short target, with no tick.
Done when
pnpm exec vitest run --project unit src/core/warm-pool/policy.test.ts src/core/warm-pool/converger.test.tspasses.
Out of scope
- Lease creates and boots at the higher step (Memory pressure: new devices wait while a worker's new devices are paused #1362).
- Deleting shed devices sooner: the reaper's rules stay.
Depends on
Written by an agent.
Activity
test: at warming-paused the warm pool starts nothing and reports why (#…
feat(warm-pool): at warming-paused the pool proposes no boot or creat…
test: a capacity refusal for memory pressure reports the target short…
feat(warm-pool): a memory-pressure capacity refusal is the short memo…
test: a paused pool reports memory-pressure and keeps a target's own …
test: a shed takes a device no configured target keeps first, never o…
feat(warm-pool): a shed takes unkept devices first and spares waiters…
test: the waiter in the shed test asks for the iPad Pro by model (#1363)
test: a shed skips a device whose shutdown just failed and none runs …
feat(warm-pool): a shed skips a device whose shutdown failed in the l…
test: when warming resumes the pool fills its targets again on memory…
feat(warm-pool): memory.pressure-changed asks for a pass (#1363)
docs(warm-pool): the pool pauses and sheds at memory pressure; memory…
refactor(warm-pool): the pressure hold of a target is one helper (#1363)
test(warm-pool): a shed never repeats a device the budget shuts down (#…
docs(capacity): restore the warm-pool memory-pressure row; #1363 owns…
test(warm-pool): memory-pressure also replaces boot-failed (#1363)
docs(warm-pool): the manual no longer copies the shutdown-failure del…
refactor(warm-pool): fillTarget's early holds move to holdFill (#1363)
feat(host-load): a worker works out its memory pressure step and repo…
feat(warm-pool): the warm pool starts nothing and sheds a device at w…