Repository navigation
Description
Part of #1355.
Scope
A worker works out its memory-pressure step from each host-load reading and reports it. An operator sees it in simlock status and in status.get, gets one memory.pressure-changed event per change, and sets it up through the new memoryPressure config section. Nothing acts on the step yet: admission and the warm pool are as today until #1362 and #1363. This task also adds every wire value the later tasks use, with the words each surface prints for it: the memory-pressure refusal and waiting reason, the warm pool's memory-pressure short reason, and the event in the alert list with its Slack message. So it is the only task of #1355 that bumps the protocol. Until #1362 lands, nothing refuses with the new reason.
In short
A new memoryPressure section (on by default) decides, from each 15 s reading, whether the worker is at none, warming-paused or new-devices-paused (Words used and Examples in #1355). A step comes on at the first reading that meets it. It lifts clearAfterMs (60 s) after the first reading that no longer meets it, on a Clock timer, unless a reading meets it again meanwhile: critical at 09:00 and calm from 09:00:15 lifts at 09:01:15. No usable reading is none at once. Each step keeps the time and the reading that turned it on, and the worker reports those of its current step: falling from new-devices-paused to warming-paused reports when and why warming was paused. At none there is no since and no cause. availablePercent is available ÷ total × 100 rounded down to a whole number; meeting a floor compares the exact value, so 9.9% meets a 10% floor and prints 9% available.
flowchart LR
S[sampler reading] -->|each recorded reading| T[step tracker *new*]
T --> P[core read port memoryPressure *new*]
T -->|step changed| E[memory.pressure-changed *new*]
P --> D[status.get capacity.memoryPressure *new*]
D --> C[simlock status: Memory pressure line *new*]
# before
$ simlock status
Load: ... · memory 10.9 GiB of 32.0 GiB available · swap 14.0 GiB used · pressure warn · ...
Capacity ios: managed 2/6, running 2 + 0 reserved/6, warm 2
# after
$ simlock status
Load: ... · memory 10.9 GiB of 32.0 GiB available · swap 14.0 GiB used · pressure warn · ...
Memory pressure: warming paused since 09:12 (pressure warn)
Capacity ios: managed 2/6, running 2 + 0 reserved/6, warm 2
The line is Memory pressure: <warming paused | new devices paused> since <HH:MM> (<cause>). <HH:MM> is since in the CLI's local time, 24-hour, zero-padded. <cause> is pressure <level> when cause.trigger is level, else <availablePercent>% available, floor <floorPercent>%. A reading that meets a step by both its level and its floor is a level trigger. At none, or with no field, there is no line.
The new wire values print as:
| Value | Where | Text |
|---|---|---|
waiting reason memory-pressure |
simlock list --requests, the console's waiting list |
Full: host memory pressure (lower-cased after a request or worker name) |
gateway worker entry full, capacityReason: "memory-pressure" |
simlock list --requests |
<worker>: full: host memory pressure |
memory.pressure-changed to new-devices-paused |
Slack alert | 🧠 Worker <worker> paused new devices: <cause>. |
to warming-paused |
Slack alert | 🧠 Worker <worker> paused warming: <cause>. |
to none |
Slack alert | ✅ Worker <worker> is no longer under memory pressure. |
<cause> in the alert is memory pressure <level> when cause.trigger is level, else <availablePercent>% of memory available (floor <floorPercent>%). To none the event carries no cause.
If this goes wrong, an operator sees a step that does not match the Load line, or one that never lifts.
Technical spec
Facts
Commit 6674ad0.
| # | Fact | Source |
|---|---|---|
| F1 | macOS memory comes from one sysctl; pressure maps 1/2/4 to normal/warn/critical; available is hw.memsize × kern.memorystatus_level / 100 |
src/ports/host-load.ts:81-85, src/ports/host-load.ts:194 |
| F2 | Linux reads MemAvailable with no pressure; under a cgroup limit, available and total are against the limit (limited: true); Windows reads os.freemem() with no pressure |
src/ports/host-load.ts:268, src/ports/host-load.ts:416-417, src/ports/host-load.ts:148-153 |
| F3 | The sampler reads every 15 s; a failed read records a reading with no parts; current() answers the parts plus ageMs; it has no per-reading listener |
src/host-load/sampler.ts:32, src/host-load/sampler.ts:138-146, src/host-load/sampler.ts:68-71 |
| F4 | The worker builds the sampler only when hostLoadProbe is not null, then createCore, and passes hostLoad and load to the server |
src/daemon/worker-composition.ts:240-243, src/daemon/worker-composition.ts:257, src/daemon/worker-composition.ts:475 |
| F5 | Core, leasing, drivers, gateway and contract may not import host-load | .dependency-cruiser.mjs:166-169 |
| F6 | status.get's capacity is buildCapacityFigures over the snapshot, built in the worker dispatcher; the schema is statusCapacitySchema (ios, android, global, optional ramBudget) |
src/daemon/dispatcher.ts:387, src/contract/status-schemas.ts:29-43 |
| F7 | capacity.changed is built from the capacity figures and emitted only when they differ |
src/bus/index.ts:89-94, src/core/capacity/observer.ts:39 |
| F8 | diskPressure is typed, defaulted and validated in core config, and declared again in the contract's configSchema |
src/core/config.ts:341, src/core/config.ts:996, src/core/config.ts:1147, src/contract/config-schemas.ts:110 |
| F9 | Unknown config keys are warned and dropped; a gateway warns on worker-only keys from lists given to warnWorkerOnlyKeys |
src/core/validation.ts:31-47, src/core/config.ts:729, src/core/config.ts:795-802 |
| F10 | Every key the validator accepts must be a row of the website's configuration reference | src/core/config-reference.test.ts:81, website/src/content/docs/docs/reference/configuration.mdx:159 |
| F11 | An event is added in EventMap, EVENT_NAMES in the bus test, EVENTS.md and the website's events reference; a test fails when the catalog's names differ |
src/bus/index.ts:272, src/bus/index.test.ts:54, docs/internal/EVENTS.md:159, website/src/content/docs/docs/reference/events.mdx:197 |
| F12 | simlock status prints the Load line, then the Capacity lines with (at RAM budget), then the RAM budget line |
src/cli/format.ts:145-147, src/cli/format.ts:259-266 |
| F13 | The model test starts a daemon with FakeHostLoadProbe and a fake clock, and reads status.get |
src/daemon/main-host-load.test.ts:90, src/daemon/main-host-load.test.ts:109, src/daemon/main-host-load.test.ts:132 |
| F14 | The protocol range is one number, and a contract shape change bumps it | src/contract/protocol.ts:13 |
| F15 | CapacityRefusalReason has four members; the planner maps each to a waiting reason in a Record, so a missing row fails to compile |
src/core/capacity/strategy.ts:30-34, src/leasing/acquisition-planner.ts:53-64 |
| F16 | The wire enums: waiting reasons, capacityReasonSchema, NO_CAPACITY details, the warm pool's short |
src/contract/lease-schemas.ts:94-108, src/contract/errors.ts:37-39, src/contract/status-schemas.ts:53-64 |
| F17 | The gateway's routing keeps its own CapacityReason union, and keeps a worker's refusal reason only when it parses |
src/gateway/routing/pipeline.ts:17-21, src/gateway/fleet-refusals.ts:141-144 |
| F18 | The CLI's and the console's waiting texts are Records over the waiting reasons; a gateway entry full uses the CLI's text for its capacityReason |
src/cli/commands/list.ts:50-58, src/cli/commands/list.ts:100-104, ui/src/model/waiting.ts:60-70 |
| F19 | ALERT_EVENTS lists the events a destination may name; the Slack messages are a Record over it; the alerts test emits an event and reads the text posted |
src/core/config.ts:95-107, src/alerts/formats/slack/messages.ts:36-37, src/alerts/alerts.test.ts:333-343 |
| F20 | The CLI test holds a reason → text table for a worker's and a gateway's entry | src/cli/index.test.ts:9518, src/cli/index.test.ts:9634 |
| F21 | The load block is fitted on the worker before the daemon's own output check; a gateway's client parses status.get strictly, so an out-of-bounds field fails the whole read |
src/daemon/worker-composition.ts:475, src/contract/status-schemas.ts:229-234, src/simlock-client/client.ts:1019 |
| F22 | Under a cgroup limit available is limit - (used - inactive), which can pass the limit |
src/ports/host-load.ts:416 |
| F23 | Host-load may not import core, leasing, gateway, drivers, contract, http, cli, mcp or daemon; bus and ports are allowed | .dependency-cruiser.mjs:154-158 |
| F24 | A hung read records a failed reading after 10 s, so through startDaemon a reading never gets 60 s old |
src/host-load/sampler.ts:33, src/host-load/sampler.ts:104-108 |
| F25 | The server starts the sampler before converge and disposes it at stop | src/daemon/server.ts:414, src/daemon/server.ts:653 |
Modules touched
Searches: HostLoadSampler, hostLoad, diskPressure, statusCapacitySchema, buildCapacityFigures, formatLoadLine, disk.pressure-detected, EVENT_NAMES, CapacityRefusalReason, capacityReasonSchema, waitingReasonSchema, warmPoolShortSchema, CapacityReason, WAITING_REASON_TEXT, WHY_TEXT, ALERT_EVENTS across src/, ui/, website/.
flowchart LR
DC[daemon/worker-composition *] --> HL[host-load: sampler listener *, step tracker *]
DC --> CO[core: create-core read port *, config *]
DD[daemon/dispatcher status.get *] --> CO
DD --> CT[contract: status-schemas *, config-schemas *, protocol *]
CLI[cli/format *] --> CT
HL --> BUS[bus: EventMap *]
src/host-load/: the sampler calls an optional listener with each recorded reading; a new step tracker (index.tsexports it) fed by it, holding the hold and 60 s staleness timers on theClock, emitting the event. The tracker declares its own options type for the thresholds it reads (asHostLoadSamplerOptionsdoes) and never imports core; core owns thememoryPressuresection's type, anddaemon/worker-composition.tspassesconfig.memoryPressurein. Tests: the dependency check (host-load-imports-ports-only) stays green (decided in delivery, approved by the maintainer 2026-11-06)src/core/config.ts,src/contract/config-schemas.ts: thememoryPressuresection (Shared values in Admission respects the host's real memory pressure #1355), its defaults and validator, worker-only on a gateway.src/core/create-core.ts,src/core/core-ports.ts: an optionalmemoryPressureoption oncreateCore({ current, onReading }); absent,current()answersundefinedandonReadingnever calls. Held for Memory pressure: new devices wait while a worker's new devices are paused #1362 and Memory pressure: the warm pool pauses and sheds idle devices #1363.src/daemon/worker-composition.ts: builds the tracker beside the sampler when host load is on; passes it tocreateCoreand the dispatcher.src/daemon/dispatcher.ts:status.getaddscapacity.memoryPressureafterbuildCapacityFigures, socapacity.changedis unchanged (F7).src/contract/status-schemas.ts:memoryPressureoptional onstatusCapacitySchema, bounded.src/bus/index.ts,src/cli/format.ts.src/daemon/server.ts: amemoryPressureoption disposed withhostLoadat stop (server.ts:653).- The new values, with no caller acting on them yet:
src/core/capacity/strategy.ts(memory-pressureinCapacityRefusalReason),src/leasing/acquisition-planner.ts(its row),src/contract/lease-schemas.ts,src/contract/errors.ts,src/http/lease-declarations.ts,src/contract/status-schemas.ts(warmPoolShortSchema),src/gateway/routing/pipeline.ts(CapacityReason),src/cli/commands/list.tsandui/src/model/waiting.ts(the text),src/core/config.tsandsrc/contract/config-schemas.ts(ALERT_EVENTS),src/alerts/formats/slack/messages.ts. src/core/warm-pool/policy.tsshortOfkeeps mapping an unknown refusal torunning-limituntil Memory pressure: the warm pool pauses and sheds idle devices #1363.- Docs:
docs/internal/EVENTS.md, websitereference/events.mdx,reference/configuration.mdx,reference/errors.mdx(NO_CAPACITYreasons),gateway/alerts.mdx(the row),worker/console.mdx(the full-reason table), thesimlock statusoutput on the worker pages,src/host-load/AGENTS.md.
Surface and extension points
src/host-load/index.ts gains new MemoryPressureTracker({ clock, config, eventBus, logger }) with observe(reading) (fed by the sampler's listener), current() → { step, since, cause, readingAt } | undefined, onReading(listener) → unsubscribe (called after each observed reading, once the step is updated) and dispose(), which cancels its timers and emits nothing more; the server disposes it with the sampler (F25), before daemon.stopping's teardown ends. Core's read port is { current, onReading }; readingAt is the latest reading's time, absent before the first. Its config, step and cause types are declared in host-load (F23); the daemon hands it the memoryPressure section. No second implementation of anything.
Contract and event changes
This PR bumps the protocol by one.
statusCapacitySchema.memoryPressure, optional:stepenumnone|warming-paused|new-devices-paused;since(a finite non-negative number, epoch ms) andcause{ trigger: "level" | "floor", availablePercent: integer 0-100, level?: "normal" | "warn" | "critical", floorPercent?: number 0-100 (present whentriggerisfloor) }, both present unlessstepisnoneand absent then.availablePercentis clamped to 0-100 before rounding down (F22), and the block is fitted on the worker before the output check, as the load block is (F21).configSchema.memoryPressure: the section as in Admission respects the host's real memory pressure #1355's Shared values.memory-pressurejoinswaitingReasonSchema,capacityReasonSchema,NO_CAPACITY'scapacityReasonandwarmPoolShortSchema;memory.pressure-changedjoinsALERT_EVENTSand the contract'sconfigSchemalist of alert events.- Event
memory.pressure-changed{ from, to, cause? }(from,tostep enums;causeas above, the new step's, absent whentoisnone), a row inEVENTS.mdand the website's events reference; emitted by the step tracker, after the step changed, once per change.
Other code on the same state
Searches: current() on the sampler (2 hits: the server's load, the uplink's firstReading); capacity in status.get (1 hit, dispatcher.ts:387); diskPressure (5 hits, the reaper's own disk read, unrelated state).
- The
loadfield ofstatus.getand the tracker read the same reading; the tracker never changes it. - Tasks 2 and 3 read the core port; Memory pressure: a gateway ranks a paused worker last, and worker list shows the step #1364 and Memory pressure: the console shows a worker's step #1365 read
capacity.memoryPressureand the event (Shared values in Admission respects the host's real memory pressure #1355). Only this task writes the step. - A gateway routes an except lease by each worker's slim set and default mode #1331 (task:ready, another feature) edits the routing reason unions in
routing/pipeline.tsand the reason texts inlist.tsandwaiting.ts, and bumps the protocol: this task depends on it and takes its base. - Lease files on a worker: upload, download, list and delete a lease's files #1356 and exec takes stdinFile and runs in the lease folder #1357 (task:ready, lease files) both bump the protocol and edit
src/contract/errors.ts,src/daemon/worker-composition.tsandsrc/daemon/dispatcher.ts, which this task changes: it depends on both.
Failure modes
| Call | Outcome | What happens | Limit, counted from |
|---|---|---|---|
| sampler → tracker listener | reading with memory | step worked out, event on change | each reading, every 15 s |
| sampler → tracker listener | reading without memory (failed read) | step none at once, event if it changed |
that reading |
| sampler → tracker listener | no reading for 60 s | step none, event if it changed; unreachable through startDaemon (F24), tested on the tracker |
60 s from the last reading |
| server stop | tracker disposed | timers cancelled, no event | none |
| sampler → tracker listener | listener throws | logged, the sampler goes on | none |
status.get |
host load off | no memoryPressure field |
none |
The step is memory only: a restart starts with no step until the first reading; no file is written. One tracker per worker, fed one reading at a time.
Rules in play
- ADR 0068 §1: "No reading is no step"; the tracker drops every step at once on a reading with no memory part or after 60 s with none.
- ADR 0068 §2: "Core stays clear of host-load"; core takes a read function, never the tracker's module (F5).
- ADR 0029 §7 as narrowed by 0068 §5: one event per step change, "never per reading".
- Events rule (bus manual): "Emit only after the commit that made it true"; the tracker emits after it stored the new step.
- ADR 0065 §1:
createCoretakes the slice it reads; the tracker takesmemoryPressureonly. - Dependency rule
host-load-imports-ports-only(F23): host-load "imports no other component" among core, contract, daemon and the rest; the tracker declares its own config and step types, and takes theEventBustype from bus, which the rule allows.
Tests
The seam is startDaemon with FakeHostLoadProbe and a fake clock, modelled on src/daemon/main-host-load.test.ts; the 60 s case drives MemoryPressureTracker in a new src/host-load/memory-pressure.test.ts modelled on src/host-load/sampler.test.ts; config and CLI lines use src/core/config.test.ts and src/cli/index.test.ts.
- An operator's worker reads memory and
status.getreports the step it meets: macOSnormal/warn/criticalat 34% →none/warming-paused/new-devices-paused, the last two withtrigger: "level"; macOSwarnat 8% →new-devices-pausedwithtrigger: "floor",floorPercent: 10; macOScriticalat 8% (level and floor both) →trigger: "level"; macOSnormalat 8% →new-devices-paused; no level at 25%, 15%, 9.9% →none,warming-paused,new-devices-paused; leveloffand floor 0 →none;enabled: false→none. - A step lifts only after
clearAfterMswith no meeting reading: 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-pausedfalls towarming-pausedwhile only the lower step meets, reporting warming's ownsinceandcause; a later, different meeting reading keepssinceandcause. - No usable reading is no step, at once: host load off (no
memoryPressurefield); a failed read; no reading for 60 s (at the tracker); each while a step held,sinceandcauseabsent after. - The worker emits
memory.pressure-changedonce per step change: none→warming, warming→new devices, new devices→warming, warming→none, each withfrom,toand the new step'scause(none tonone); a second meeting reading emits nothing. - An operator's
memoryPressureconfig is defaulted and checked: the defaults;level: "bogus"refused naming the key;minAvailablePercent101 and -1 refused;clearAfterMs-1 refused; a gateway's config with the section warns it is worker-only. - An operator's
simlock statusprints the Memory pressure line: warming by levelMemory pressure: warming paused since 09:12 (pressure warn); new devices by floorMemory pressure: new devices paused since 09:40 (8% available, floor 10%); 9.9% prints9% available; macOSwarnat 8% tripped by the floor prints the floor; stepnoneprints no line; no field prints no line. - An operator's
simlock list --requestsnames host memory pressure: a worker's own waiting requestfull: host memory pressure; a gateway request's worker entryfullwithcapacityReason: "memory-pressure". - An operator's console waiting list names host memory pressure: reason
memory-pressurereadsFull: host memory pressure. - A gateway alert destination listing
memory.pressure-changedgets one message per change: Slack to new devices paused by level; to warming paused by floor; to none; generic JSON envelope.
Done when
pnpm exec vitest run --project unit src/daemon/main-host-load.test.ts src/core/config.test.ts src/cli/index.test.ts src/bus/index.test.ts src/core/config-reference.test.ts src/alerts/alerts.test.ts ui/src/model/waiting.test.ts src/contract/schemas.test.ts src/host-load/memory-pressure.test.tspasses.pnpm lintpasses, the boundary rulesnot-host-loadandhost-load-imports-ports-onlyincluded.- The website's configuration and events references list
memoryPressure.*andmemory.pressure-changed.
Out of scope
- Refusing with
memory-pressure(Memory pressure: new devices wait while a worker's new devices are paused #1362), the warm pool's pause and shed (Memory pressure: the warm pool pauses and sheds idle devices #1363), the gateway's rank, refresh andsimlock worker list(Memory pressure: a gateway ranks a paused worker last, and worker list shows the step #1364), the console's step display (Memory pressure: the console shows a worker's step #1365). - Changing the section live (Settings: change a setting through the daemon, live where it can #1154).
Depends on
- A gateway routes an except lease by each worker's slim set and default mode #1331
- Lease files on a worker: upload, download, list and delete a lease's files #1356
- exec takes stdinFile and runs in the lease folder #1357
Written by an agent.
Activity
test: an operator's memoryPressure config is defaulted and checked (#…
feat(config): the memoryPressure section is checked on load (#1361)
test: status.get reports each level, floor and off case of the memory…
test: a memory pressure step lifts only after clearAfterMs with no me…
feat(host-load): a memory pressure step lifts clearAfterMs after the …
test: no usable memory reading is no step, at once (#1361)
feat(host-load): a reading with no memory drops the memory pressure s…
test: a tracker with no reading for 60 s drops its step (#1361)
feat(host-load): a tracker with no reading for 60 s drops its step (#…
test: the worker emits memory.pressure-changed once per step change (#…
feat(bus): memory.pressure-changed is emitted once per step change (#…
test: simlock status prints the Memory pressure line (#1361)
feat(cli): simlock status prints the Memory pressure line (#1361)
test: simlock list --requests names host memory pressure (#1361)
feat(cli): simlock list --requests names host memory pressure (#1361)
test: the console's waiting list names host memory pressure (#1361)
test: the console's waiting list names host memory pressure (#1361)
feat(alerts): memory.pressure-changed is an alert event with a Slack …
feat(core): createCore takes the worker's memory pressure reader (#1361)
docs(memory-pressure): the status line, the full reasons and the host…
refactor(host-load): export only what is used (#1361)
test: audit probes for memory pressure (planner row, wire bounds, sta…
fix(host-load): a floor cause on macOS carries the level; CLI test co…
feat(host-load): a worker works out its memory pressure step and repo…