Repository navigation
Description
Part of #1355.
Scope
A gateway steers requests away from a worker whose new devices are paused. It ranks that worker below one that is not, and a warm hit on the paused worker still wins. It refreshes the worker's view at once on its memory.pressure-changed, and explains it as full: host memory pressure. simlock worker list shows each worker's step. The alert message and the reason text came with #1361.
In short
The gateway reads the step each worker reports in status.get's capacity.memoryPressure (#1361) and applies no threshold of its own. warming-paused changes nothing in routing: that worker still takes leases.
flowchart LR
E[worker memory.pressure-changed] -->|*new* refresh at once| V[worker view]
V --> R[routing: ... warm-hit, free-slot, memory-pressure rank *new*, ram-budget, free-capacity]
R -->|zero score| X[explain: full, capacityReason memory-pressure]
# before
$ simlock worker list
mini-3: connected -- ios 2/6, android 0/0, 2 leases ...
# after
$ 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 ...
The worker's first line ends, after its capabilities, with -- memory: warming paused or -- memory: new devices paused; nothing at none, with no field, or for a worker not connected (its view keeps its last capacity, and its Load line already says no reading while disconnected).
If this goes wrong, a gateway keeps sending requests to a swapping worker while a calm one is free.
Technical spec
Facts
Commit 6674ad0.
| # | Fact | Source |
|---|---|---|
| F1 | The warm-then-free stages run in this order: … warmHit, freeSlot, ramBudget, freeCapacity |
src/gateway/routing.ts:71-84 |
| F2 | The ram-budget rank scores 0 for a worker at budget, and its zero reason is { capacityReason: "ram-budget", reason: "full" }; it skips physical requests |
src/gateway/routing/stages/ram-budget.ts:6-19 |
| F3 | A rank abstains when its best score is 0 or less; a settling rank (warm-hit) ends the walk |
src/gateway/routing/pipeline.ts:89-97 |
| F4 | A worker's status.capacity is copied whole into its view |
src/contract/worker-view.ts:110 |
| F5 | A refusal is held against viewLoadKey, which includes capacity, so a changed capacity.memoryPressure lets the worker be asked again |
src/gateway/routing/view-state.ts:7-16 |
| F6 | A relayed event refreshes the view only when changesCapacityOrLeases matches it (lease., device., installs, baselines, updates) |
src/gateway/worker-link.ts:629-637 |
| F7 | simlock worker list builds a worker's first line from label, state, capacity, leases, version, host and capabilities; load, baselines and installs follow as indented lines; a disconnected worker's Load line reads no reading while disconnected |
src/cli/format.ts:48, src/cli/format.ts:54-57 |
| F9 | The registered policy's tests: a worker at its RAM budget passed over unless it is the only one, still picked for a warm device, and the list of stages that skip a physical request | src/gateway/routing.test.ts:186, src/gateway/routing.test.ts:206, src/gateway/routing.test.ts:378 |
| F10 | The service test refreshes the view on a worker event that changes capacity or leases | src/gateway/service.test.ts:761 |
Modules touched
Searches: ramBudget, routingPolicies, changesCapacityOrLeases, viewLoadKey, the worker line in format.ts, across src/, ui/, website/.
flowchart LR
WL[gateway worker-link *] --> V[views]
RT[gateway routing.ts *] --> ST[routing stages: memory-pressure *]
ST --> V
CLI[cli format *] --> V
src/gateway/routing/stages/memory-pressure.ts(new),routing/index.ts,routing.ts: a rank afterfreeSlot, beforeramBudget, scoring 0 forcapacity.memoryPressure.step === "new-devices-paused", zero reason{ capacityReason: "memory-pressure", reason: "full" },appliesToPhysical: false.src/gateway/worker-link.ts:memory.pressure-changedrefreshes the view.src/cli/format.ts: the worker line.- Docs: website
gateway/routing.mdx(the stage list),gateway/managing-workers.mdx(the worker line),src/gateway/routing/AGENTS.md.
Contract and event changes
none: the stage reads capacity.memoryPressure, and capacityReason: "memory-pressure" is in routing's CapacityReason and on the wire, both from #1361. EVENTS.md is unchanged.
Other code on the same state
Searches: readers of view.capacity in src/gateway/ (stages free-slot, free-capacity, ram-budget, aggregate.ts, view-state.ts).
aggregateStatusbuilds the gateway's owncapacityfield by field (src/gateway/aggregate.ts:124-126), so a gateway's ownstatus.getcarries nomemoryPressure; each worker's view does.ram-budgetand the new rank both score.explaingives each worker its first zero-scoring rank in stage order, so a paused worker is explainedmemory-pressure(src/gateway/routing/pipeline.ts:135-139); the pick's reported stage is the last rank that removed a worker (pipeline.ts:95), unchanged.- A gateway routes an except lease by each worker's slim set and default mode #1331 (task:ready, another feature) edits the stage list in
routing.tswhere the new rank goes: this task depends on it. - A worker's
NO_CAPACITYwithcapacityReason: "memory-pressure"is memoized against the view key (F5), as any capacity refusal.
Failure modes
| Call | Outcome | What happens | Limit, counted from |
|---|---|---|---|
worker view without capacity.memoryPressure (older worker, host load off) |
absent | ranked as calm | none |
relayed memory.pressure-changed |
delivered | view refreshed, coalesced with other refreshes | one view read, 10 s |
No state is written.
Rules in play
- ADR 0068 §6: the gateway "applies no threshold of its own"; the stage reads only the step.
- Routing manual: "Stages read the view and the request only. No clock, no I/O, no state."
- Routing manual: "A filter returns its own reason and a rank its own zero reason."
- ADR 0009 §7: the RAM budget "is a rank"; the pressure step is a rank too, so a paused worker is still asked when it is the only one.
Tests
The seams are createRoutingPolicy (src/gateway/routing.test.ts, extending the RAM-budget tests and the physical-skip list at F9), GatewayService (src/gateway/service.test.ts) and runCli (src/cli/index.test.ts).
- A gateway ranks a worker whose new devices are paused below one that is not: paused vs calm picks calm; paused with a warm hit picks paused; every worker paused still picks one;
explaingivesfullwithcapacityReason: "memory-pressure";warming-pausedranks as calm. - A gateway refreshes a worker's view at once on its
memory.pressure-changed: the event refreshes; a refusal held against the old view is asked again after the step lifts. - An operator's
simlock worker listshows each worker's step:memory: warming paused;memory: new devices paused, each asserted as the whole first line; none prints nothing; a disconnected worker prints nothing.
Done when
pnpm exec vitest run --project unit src/gateway/routing.test.ts src/gateway/service.test.ts src/cli/index.test.tspasses.
Out of scope
- The console (Memory pressure: the console shows a worker's step #1365).
- Ranking a
warming-pausedworker down.
Depends on
- Memory pressure: a worker works out its step and reports it #1361
- A gateway routes an except lease by each worker's slim set and default mode #1331
Written by an agent.
Activity
test: a gateway refreshes a worker's view at once on its memory.press…
feat(gateway): memory.pressure-changed refreshes the worker's view (#…
test: an operator's simlock worker list shows each worker's memory st…
feat(cli): worker list shows a worker's memory step (#1364)
docs(gateway): routing ranks a memory-paused worker last; worker list…
test: a worker that refused a request is asked again once memory.pres…
fix: drop a restating manual line, raise the shrink-only size of cli/…
feat(gateway): a gateway ranks a memory-paused worker last and worker…