diff --git a/docs/internal/adr/0068-a-worker-pauses-warming-and-new-devices-under-host-memory-pressure.md b/docs/internal/adr/0068-a-worker-pauses-warming-and-new-devices-under-host-memory-pressure.md index 5de8a9670..15e0a6634 100644 --- a/docs/internal/adr/0068-a-worker-pauses-warming-and-new-devices-under-host-memory-pressure.md +++ b/docs/internal/adr/0068-a-worker-pauses-warming-and-new-devices-under-host-memory-pressure.md @@ -1,6 +1,6 @@ # 0068. A worker pauses warming and new devices under host memory pressure -- **Status:** Accepted — not yet implemented +- **Status:** Accepted - **Date:** 2026-11-06 - **Issue:** [#1355](https://github.com/callstackincubator/simlock/issues/1355) (from request [#1246](https://github.com/callstackincubator/simlock/issues/1246)) diff --git a/docs/internal/adr/README.md b/docs/internal/adr/README.md index bc382d092..b98aa0007 100644 --- a/docs/internal/adr/README.md +++ b/docs/internal/adr/README.md @@ -103,4 +103,4 @@ the status is stale. | [0065](0065-a-driver-owns-its-config-keys-and-a-module-takes-the-sections-it-reads.md) | A driver owns its config keys, and a module takes the config sections it reads | Accepted | | [0066](0066-a-slim-lease-may-keep-named-categories-running.md) | A slim lease may keep named categories running | Accepted; narrows 0007 §8, §9, 0008 §4, §9, 0009 §2, §4 and 0060 §1, §2, §6 | | [0067](0067-a-lease-has-a-file-folder-on-its-worker-that-http-callers-fill-and-read.md) | A lease has a file folder on its worker that HTTP callers fill and read | Accepted; narrows 0005 Non-goals (file transfer) and §19b′, 0026 §1 (a core relay target) and 0028 §4 (a file PUT's deadline) | -| [0068](0068-a-worker-pauses-warming-and-new-devices-under-host-memory-pressure.md) | A worker pauses warming and new devices under host memory pressure | Accepted — not yet implemented; narrows 0029, adds a rank stage to 0009 | +| [0068](0068-a-worker-pauses-warming-and-new-devices-under-host-memory-pressure.md) | A worker pauses warming and new devices under host memory pressure | Accepted; narrows 0029, adds a rank stage to 0009 | diff --git a/ui/src/model/fleet.test.ts b/ui/src/model/fleet.test.ts index 9fa0c7466..69f6f7ecb 100644 --- a/ui/src/model/fleet.test.ts +++ b/ui/src/model/fleet.test.ts @@ -80,6 +80,28 @@ describe("a worker's health square", () => { }); }); +describe("a worker's memory-pressure step", () => { + it("shows on the square as its own word, ahead of the pressure it comes with", () => { + const stepped = (step: string, pressure?: "warn" | "critical") => + worker({ + capacity: { + ...capacity(4, 4), + memoryPressure: { step }, + } as unknown as NonNullable, + ...(pressure === undefined ? {} : { load: load(30, 40, pressure) }), + }); + const cases: readonly [WorkerView, string, string][] = [ + [stepped("new-devices-paused"), "error", "new devices paused"], + [stepped("warming-paused"), "warn", "warming paused"], + [stepped("warming-paused", "warn"), "warn", "warming paused"], + [stepped("new-devices-paused", "critical"), "error", "new devices paused"], + [stepped("none"), "ok", "connected"], + [{ ...stepped("new-devices-paused"), connection: "disconnected" }, "error", "disconnected"], + ]; + for (const [w, tone, word] of cases) expect(workerHealth(w), word).toEqual({ tone, word }); + }); +}); + describe("a worker with an issue", () => { it("is one that is lost, failed, drained, starting, over its RAM budget, under memory pressure, or at 85% of CPU, disk or memory", () => { const budget = { ...capacity(4, 4), ramBudget: { overLimit: true } }; diff --git a/ui/src/model/fleet.ts b/ui/src/model/fleet.ts index fe0dab132..2ad3830d3 100644 --- a/ui/src/model/fleet.ts +++ b/ui/src/model/fleet.ts @@ -16,7 +16,7 @@ const RANK: Readonly> = { error: 3, idle: 0, ok: 1, warn: 2 // why: a list row has room for one square, so of everything wrong with a worker the worst is // shown and its word goes in the square's name; a worker with nothing wrong reads "connected". export function workerHealth(worker: WorkerView): Toned { - return [...stateFindings(worker), ...loadFindings(worker)].reduce( + return [...stateFindings(worker), ...stepFindings(worker), ...loadFindings(worker)].reduce( (worst, finding) => (RANK[finding.tone] > RANK[worst.tone] ? finding : worst), { tone: "ok", word: "connected" }, ); @@ -42,6 +42,20 @@ function stateFindings(worker: WorkerView): Toned[] { return findings; } +// why: the step comes before the pressure and figure findings so that, at equal tone, the square +// names what the worker refuses rather than the reading behind it. A worker not connected needs no +// guard: its error finding comes first and wins. +function stepFindings(worker: WorkerView): Toned[] { + switch (worker.capacity?.memoryPressure?.step) { + case "new-devices-paused": + return [{ tone: "error", word: "new devices paused" }]; + case "warming-paused": + return [{ tone: "warn", word: "warming paused" }]; + default: + return []; + } +} + // why: a reading from a worker that is not connected is stale, so it says nothing about the worker // now; where memory reports a pressure, that word judges memory instead of its fill. function loadFindings(worker: WorkerView): Toned[] { diff --git a/ui/src/model/stale-keys.test.ts b/ui/src/model/stale-keys.test.ts new file mode 100644 index 000000000..b3d9f87f2 --- /dev/null +++ b/ui/src/model/stale-keys.test.ts @@ -0,0 +1,10 @@ +import { describe, expect, it } from "vitest"; + +import { staleKeys } from "./stale-keys"; + +describe("a memory.pressure-changed event", () => { + it("marks the console's workers stale, and an unrelated event does not", () => { + expect(staleKeys("memory.pressure-changed", {})).toContainEqual(["workers"]); + expect(staleKeys("something.unrelated", {})).toEqual([]); + }); +}); diff --git a/ui/src/model/stale-keys.ts b/ui/src/model/stale-keys.ts index 5f427d8b4..c0388d160 100644 --- a/ui/src/model/stale-keys.ts +++ b/ui/src/model/stale-keys.ts @@ -28,6 +28,7 @@ export function staleKeys(name: string, payload: unknown): readonly StaleKey[] { case "queue.changed": return REQUESTS; case "capacity.changed": + case "memory.pressure-changed": return WORKERS; case "baseline.saved": case "baseline.removed": diff --git a/ui/src/model/worker-page.test.ts b/ui/src/model/worker-page.test.ts index 0c1c18e32..e5aa67ecc 100644 --- a/ui/src/model/worker-page.test.ts +++ b/ui/src/model/worker-page.test.ts @@ -312,6 +312,30 @@ describe("a worker's load figures", () => { expect(inspector.overview.read).toBe("12 s ago"); }); + it("lists a Paused row on the Memory card while the worker's memory-pressure step pauses something", () => { + const paused = (step: string | undefined) => + figure( + inspect( + worker({ + capacity: { + ...CAPACITY, + ...(step === undefined ? {} : { memoryPressure: { step } }), + } as unknown as WorkerView["capacity"], + load: LOAD, + }), + ), + "Memory", + )?.details.find((detail) => detail.label === "Paused"); + expect(paused("new-devices-paused")).toEqual({ + label: "Paused", + text: "new devices", + tone: "error", + }); + expect(paused("warming-paused")).toEqual({ label: "Paused", text: "warming", tone: "warn" }); + expect(paused("none")).toBeUndefined(); + expect(paused(undefined)).toBeUndefined(); + }); + it("fills each meter to the figure's own percent", () => { const inspector = inspect(worker({ load: LOAD })); diff --git a/ui/src/model/worker-page.ts b/ui/src/model/worker-page.ts index 53ea838fc..0f20b551c 100644 --- a/ui/src/model/worker-page.ts +++ b/ui/src/model/worker-page.ts @@ -199,6 +199,18 @@ function limited(text: string, isLimited: boolean): string { return isLimited ? `${text} (limit)` : text; } +// why: the step names what the worker refuses to start, so the row is there only while it refuses. +function pausedDetail(worker: WorkerView): readonly LoadDetail[] { + switch (worker.capacity?.memoryPressure?.step) { + case "new-devices-paused": + return [{ label: "Paused", text: "new devices", tone: "error" }]; + case "warming-paused": + return [{ label: "Paused", text: "warming", tone: "warn" }]; + default: + return []; + } +} + function figureCards(worker: WorkerView): readonly FigureCard[] { const { load } = worker; if (load === undefined) return []; @@ -243,6 +255,7 @@ function figureCards(worker: WorkerView): readonly FigureCard[] { tone: pressureStatus(memory.pressure).tone, }, ]), + ...pausedDetail(worker), ], label: "Memory", text: limited( diff --git a/website/src/content/docs/docs/worker/console.mdx b/website/src/content/docs/docs/worker/console.mdx index c3a83a384..03d1751f3 100644 --- a/website/src/content/docs/docs/worker/console.mdx +++ b/website/src/content/docs/docs/worker/console.mdx @@ -103,8 +103,8 @@ The square shows the worst thing wrong with the worker, and always has a word be | Colour | When | | --- | --- | -| Red | The worker's health is `failed`, its memory pressure is `critical`, or its CPU, memory or disk is 95% full or more. | -| Amber | The worker is `starting` or `over RAM budget`, its memory pressure is `warn`, or a figure is 85% full or more. | +| Red | The worker's health is `failed`, its memory pressure is `critical`, it has `new devices paused`, or its CPU, memory or disk is 95% full or more. | +| Amber | The worker is `starting` or `over RAM budget`, its memory pressure is `warn`, it has `warming paused`, or a figure is 85% full or more. | | Green | Nothing is wrong. The word is `connected`. | **Issues** shows only workers whose square is not green. **Busy** shows workers using three quarters of their device slots or more.