Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
783d701
test: a worker's status.get reports the memory pressure step its read…
V3RON Nov 6, 2026
77d17fb
feat(host-load): status.get reports the memory pressure step a readin…
V3RON Nov 6, 2026
3d9d2d0
docs(config): list the memoryPressure keys (#1361)
V3RON Nov 6, 2026
59ae41e
test: an operator's memoryPressure config is defaulted and checked (#…
V3RON Nov 6, 2026
053c082
feat(config): the memoryPressure section is checked on load (#1361)
V3RON Nov 6, 2026
96e5358
test: status.get reports each level, floor and off case of the memory…
V3RON Nov 6, 2026
488f5b1
test: a memory pressure step lifts only after clearAfterMs with no me…
V3RON Nov 6, 2026
a8eaa14
feat(host-load): a memory pressure step lifts clearAfterMs after the …
V3RON Nov 6, 2026
09d3e1c
test: no usable memory reading is no step, at once (#1361)
V3RON Nov 6, 2026
af4226e
feat(host-load): a reading with no memory drops the memory pressure s…
V3RON Nov 6, 2026
49407e5
test: a tracker with no reading for 60 s drops its step (#1361)
V3RON Nov 6, 2026
3421161
feat(host-load): a tracker with no reading for 60 s drops its step (#…
V3RON Nov 6, 2026
a0ec5c0
test: the worker emits memory.pressure-changed once per step change (…
V3RON Nov 6, 2026
1972d7c
feat(bus): memory.pressure-changed is emitted once per step change (#…
V3RON Nov 6, 2026
075ac4a
test: simlock status prints the Memory pressure line (#1361)
V3RON Nov 6, 2026
e06b550
feat(cli): simlock status prints the Memory pressure line (#1361)
V3RON Nov 6, 2026
0b75633
test: simlock list --requests names host memory pressure (#1361)
V3RON Nov 6, 2026
7699520
feat(cli): simlock list --requests names host memory pressure (#1361)
V3RON Nov 6, 2026
c58b03d
test: the console's waiting list names host memory pressure (#1361)
V3RON Nov 6, 2026
933d14b
test: the console's waiting list names host memory pressure (#1361)
V3RON Nov 6, 2026
baec6ab
feat(alerts): memory.pressure-changed is an alert event with a Slack …
V3RON Nov 6, 2026
8106376
feat(core): createCore takes the worker's memory pressure reader (#1361)
V3RON Nov 6, 2026
1fdee6b
docs(memory-pressure): the status line, the full reasons and the host…
V3RON Nov 6, 2026
c25c888
refactor(host-load): export only what is used (#1361)
V3RON Nov 6, 2026
0c1d1c8
Merge remote-tracking branch 'origin/feature/1355-adr' into HEAD
V3RON Nov 6, 2026
ea85a2e
test: audit probes for memory pressure (planner row, wire bounds, sta…
V3RON Nov 6, 2026
8932aab
fix(host-load): a floor cause on macOS carries the level; CLI test co…
V3RON Nov 6, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/internal/EVENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ left behind (#79), each when there is one.
| `daemon.update-started` | from, to, forced | an update began: `daemon.update` resolved the version and entered `waiting` or `installing` (ADR 0042 §11); `forced` is whether it was asked with `force` at the start | UpdateCoordinator | implemented |
| `daemon.update-failed` | stage (`installing` or `restarting`), from, to, message (at most 2000 characters) | an update ended without a new daemon: the updater reported a failed line or exited non-zero while this daemon runs (it serves again), or a rolled back update's result file was read at start (ADR 0042 §7, §8) | UpdateCoordinator | implemented |
| `disk.pressure-detected` | free bytes, threshold | free disk crossed under the configured threshold (edge-triggered: once per crossing, not once per tick while it persists) | CleanupReaper | implemented |
| `memory.pressure-changed` | from, to (`none`, `warming-paused`, `new-devices-paused`), cause (the new step's reading: trigger `level` or `floor`, availablePercent, level on macOS, floorPercent for a floor trigger; absent to `none`) | a worker's memory pressure step changed: once per change, never per reading; no usable reading drops the step at once (ADR 0068 §5) | MemoryPressureTracker | implemented |
| `cleanup.executed` | rule name, action, target, reason | cleanup executor committed a proposed action | CleanupExecutor | implemented |
| `doctor.reconciled` | drift findings | daemon reconciliation completed | Doctor | implemented |
| `driver.root-rejected` | platform, root path, reason (not-absolute/missing-marker/invalid-marker/wrong-instance/symlink/wrong-owner/wrong-permissions/non-empty-unowned-root/unreadable/invalid-device-set/device-set-changed) | a driver's device root failed ownership validation at startup, or (iOS) `drivers.ios.deviceSet` was not `simlock` or `default`, conflicted with `drivers.ios.deviceRoot` or with `ios.simulator.headless: false`, or was switched with simulators left in the set being given up (ADR 0048; `root` is then the configured value or the set holding them), so that platform's driver did not start | DaemonServer | implemented |
Expand Down
41 changes: 39 additions & 2 deletions src/alerts/alerts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,26 @@ describe("alerts", () => {
module: "quarantine",
});

const pressure = (h: Harness) =>
h.eventBus.republish({
id: "evt_pressure",
timestamp: 43,
event: "memory.pressure-changed",
payload: { from: "none", to: "warming-paused", workerId: "wrk_8" } as never,
module: "host-load",
});

it.each([
["a gateway-own worker.connected", gatewayOwn, "wrk_1"],
["a republished device.quarantine-abandoned", relayed, "wrk_9"],
["a republished memory.pressure-changed", pressure, "wrk_8"],
])(
"posts a listed event to a generic destination as the envelope with Content-Type, User-Agent, X-Simlock-Event, X-Simlock-Delivery and a signature that verifies with the secret (%s)",
async (_name, emitEnvelope, workerId) => {
const h = harness([
destination({ events: ["worker.connected", "device.quarantine-abandoned"] }),
destination({
events: ["worker.connected", "device.quarantine-abandoned", "memory.pressure-changed"],
}),
]);
const envelope = emitEnvelope(h);
await settle();
Expand Down Expand Up @@ -157,7 +169,7 @@ describe("alerts", () => {
});
});

it("each of the eleven events posts its message word for word", async () => {
it("each of the twelve events posts its message word for word", async () => {
const rows: [EventName, Record<string, unknown>, string][] = [
[
"worker.connected",
Expand Down Expand Up @@ -221,6 +233,31 @@ describe("alerts", () => {
{ workerId: "wrk_1", platform: "ios", componentId: "runtime-18", error: "no space" },
"❌ Installing ios runtime-18 on wrk_1 failed: no space.",
],
[
"memory.pressure-changed",
{
workerId: "wrk_1",
from: "none",
to: "new-devices-paused",
cause: { trigger: "level", availablePercent: 8, level: "critical" },
},
"🧠 Worker wrk_1 paused new devices: memory pressure critical.",
],
[
"memory.pressure-changed",
{
workerId: "wrk_1",
from: "none",
to: "warming-paused",
cause: { trigger: "floor", availablePercent: 15, floorPercent: 20 },
},
"🧠 Worker wrk_1 paused warming: 15% of memory available (floor 20%).",
],
[
"memory.pressure-changed",
{ workerId: "wrk_1", from: "warming-paused", to: "none" },
"✅ Worker wrk_1 is no longer under memory pressure.",
],
];
const events = [...new Set(rows.map(([event]) => event))] as AlertDestination["events"];
const h = harness([slackDestination({ events })]);
Expand Down
12 changes: 12 additions & 0 deletions src/alerts/formats/slack/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ function more(count: unknown): string {
: "";
}

function pressureCause(cause: unknown): string {
const fields = (typeof cause === "object" && cause !== null ? cause : {}) as Payload;
return fields.trigger === "level"
? `memory pressure ${part(fields.level)}`
: `${part(fields.availablePercent)}% of memory available (floor ${part(fields.floorPercent)}%)`;
}

export const SLACK_MESSAGES: Record<AlertEventName | "alerts.test-sent", Message> = {
"worker.connected": (p, worker) =>
p.version === undefined
Expand All @@ -35,6 +42,11 @@ export const SLACK_MESSAGES: Record<AlertEventName | "alerts.test-sent", Message
`⏳ Device ${part(p.deviceId)} on ${worker} has been ${part(p.state)} for ${formatAge(p.ageMs)}.`,
"disk.pressure-detected": (p, worker) =>
`💾 Worker ${worker} is low on disk: ${formatBytes(p.freeBytes)} free (threshold ${formatBytes(p.threshold)}).`,
"memory.pressure-changed": (p, worker) => {
if (p.to === "none") return `✅ Worker ${worker} is no longer under memory pressure.`;
const paused = p.to === "new-devices-paused" ? "new devices" : "warming";
return `🧠 Worker ${worker} paused ${paused}: ${pressureCause(p.cause)}.`;
},
"component.install-failed": (p, worker) =>
`❌ Installing ${part(p.platform)} ${part(p.componentId)} on ${worker} failed: ${part(p.error)}.`,
"alerts.test-sent": (p) =>
Expand Down
1 change: 1 addition & 0 deletions src/bus/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const EVENT_NAMES: Record<EventName, true> = {
"daemon.update-failed": true,
"daemon.update-started": true,
"disk.pressure-detected": true,
"memory.pressure-changed": true,
"cleanup.executed": true,
"doctor.reconciled": true,
"driver.root-rejected": true,
Expand Down
10 changes: 10 additions & 0 deletions src/bus/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,16 @@ export interface EventMap {
readonly forced: boolean;
};
"disk.pressure-detected": { readonly freeBytes: number; readonly threshold: number };
"memory.pressure-changed": {
readonly from: "none" | "warming-paused" | "new-devices-paused";
readonly to: "none" | "warming-paused" | "new-devices-paused";
readonly cause?: {
readonly trigger: "level" | "floor";
readonly availablePercent: number;
readonly level?: "normal" | "warn" | "critical";
readonly floorPercent?: number;
};
};
"device.foreign-provenance-detected": {
readonly deviceId: string;
readonly platform: string;
Expand Down
1 change: 1 addition & 0 deletions src/cli/commands/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const WAITING_REASON_TEXT: Readonly<Record<WaitingReasonWord, (platform: string)
"no-free-physical": () => "Every matching device is leased or absent",
"platform-running-limit": (platform) =>
`Full: running limit for ${platform === "ios" ? "iOS" : "Android"}`,
"memory-pressure": () => "Full: host memory pressure",
"ram-budget": () => "Full: RAM budget",
"waiting-for-device": () => "A matching device is starting",
};
Expand Down
15 changes: 15 additions & 0 deletions src/cli/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,20 @@ function formatLoadLine(
return `Load: ${[...cpuPart, ...memoryParts, ...diskPart, age].join(" · ")}`;
}

function memoryPressureLines(status: StatusGetOutput): string[] {
const pressure = status.capacity?.memoryPressure;
if (pressure === undefined || pressure.step === "none") return [];
const { cause, since } = pressure;
const words = pressure.step === "warming-paused" ? "warming paused" : "new devices paused";
const at = new Date(since ?? 0);
const pad = (value: number): string => String(value).padStart(2, "0");
const why =
cause?.trigger === "floor"
? `${cause.availablePercent}% available, floor ${cause.floorPercent}%`
: `pressure ${cause?.level}`;
return [`Memory pressure: ${words} since ${pad(at.getHours())}:${pad(at.getMinutes())} (${why})`];
}

function loadLines(status: StatusGetOutput): string[] {
return status.load === undefined
? []
Expand Down Expand Up @@ -295,6 +309,7 @@ export function formatStatus(status: StatusGetOutput, now: number, cliVersion?:
...daemonLines(daemon, cliVersion),
`Host: ${formatHost(host)}`,
...loadLines(status),
...memoryPressureLines(status),
...historyLines(status.history),
globalLine,
...capacityLines,
Expand Down
45 changes: 45 additions & 0 deletions src/cli/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6098,6 +6098,49 @@ describe("CLI: status renders the fleet a gateway reports (ADR 0005 §20)", () =
expect(await print(EMPTY_STATUS)).not.toContain("Load:");
expect(await print(STARTING)).not.toContain("Load:");
});

it("simlock status prints the Memory pressure line with the step, when it began and why, and none when there is no step", async () => {
const line = async (memoryPressure: unknown) =>
(
await print({
...EMPTY_STATUS,
capacity: { ...EMPTY_STATUS.capacity, memoryPressure },
load: LOAD,
} as StatusGetOutput)
)
.split("\n")
.find((row) => row.startsWith("Memory pressure:"));
const since = new Date(2026, 10, 6, 9, 12).getTime();
const warn = { availablePercent: 34, level: "warn", trigger: "level" };
const floor = (availablePercent: number, extra = {}) =>
line({
cause: { availablePercent, floorPercent: 10, trigger: "floor", ...extra },
since,
step: "new-devices-paused",
});

expect(await line({ cause: warn, since, step: "warming-paused" })).toBe(
"Memory pressure: warming paused since 09:12 (pressure warn)",
);
const floored = "Memory pressure: new devices paused since 09:12 (8% available, floor 10%)";
expect(await floor(8)).toBe(floored);
expect(await floor(8, { level: "warn" })).toBe(floored);
expect(await floor(9)).toBe(floored.replace("8%", "9%"));
expect(await line({ step: "none" })).toBeUndefined();
expect(await line(undefined)).toBeUndefined();

const stdout = await print({
...EMPTY_STATUS,
capacity: {
...EMPTY_STATUS.capacity,
memoryPressure: { cause: warn, since, step: "warming-paused" },
},
load: LOAD,
} as StatusGetOutput);
expect(stdout).toContain(
`${FULL_LINE}Memory pressure: warming paused since 09:12 (pressure warn)\nRunning global`,
);
});
});

it("simlock status prints the console address when HTTP is enabled", async () => {
Expand Down Expand Up @@ -9524,6 +9567,7 @@ describe("simlock list --requests", () => {
["behind-earlier-request", "ios", "behind an earlier request"],
["device-limit", "ios", "full: device limit"],
["ram-budget", "ios", "full: RAM budget"],
["memory-pressure", "ios", "full: host memory pressure"],
["global-running-limit", "ios", "full: running limit"],
["platform-running-limit", "ios", "full: running limit for iOS"],
["platform-running-limit", "android", "full: running limit for Android"],
Expand Down Expand Up @@ -9640,6 +9684,7 @@ describe("simlock list --requests", () => {
["full", "ios", undefined, "full"],
["full", "ios", "device-limit", "full: device limit"],
["full", "ios", "ram-budget", "full: RAM budget"],
["full", "ios", "memory-pressure", "full: host memory pressure"],
["full", "ios", "global-running-limit", "full: running limit"],
["full", "ios", "platform-running-limit", "full: running limit for iOS"],
["full", "android", "platform-running-limit", "full: running limit for Android"],
Expand Down
11 changes: 11 additions & 0 deletions src/contract/config-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ const proxyAuthSchema = z.object({
signOutUrl: z.string().optional(),
});

const memoryPressureRuleSchema = z.object({
level: z.enum(["normal", "warn", "critical", "off"]),
minAvailablePercent: z.number(),
});

export const configSchema = z.object({
mode: z.enum(["worker", "gateway"]),
capabilities: z.record(
Expand Down Expand Up @@ -108,6 +113,12 @@ export const configSchema = z.object({
}),
exec: z.object({ timeoutMs: z.number() }),
diskPressure: z.object({ freeBytesThreshold: z.number() }),
memoryPressure: z.object({
enabled: z.boolean(),
pauseWarming: memoryPressureRuleSchema,
pauseNewDevices: memoryPressureRuleSchema,
clearAfterMs: z.number(),
}),
eventBuffer: z.object({ capacity: z.number() }),
log: z.object({
level: z.enum(["debug", "info", "warn", "error"]),
Expand Down
1 change: 1 addition & 0 deletions src/contract/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface ErrorDetailsMap {
readonly capacityReason?:
| "device-limit"
| "ram-budget"
| "memory-pressure"
| "global-running-limit"
| "platform-running-limit";
};
Expand Down
2 changes: 2 additions & 0 deletions src/contract/lease-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const waitingReasonSchema = z.enum([
"behind-earlier-request",
"device-limit",
"ram-budget",
"memory-pressure",
"global-running-limit",
"platform-running-limit",
"waiting-for-device",
Expand All @@ -103,6 +104,7 @@ const waitingReasonSchema = z.enum([
export const capacityReasonSchema = z.enum([
"device-limit",
"ram-budget",
"memory-pressure",
"global-running-limit",
"platform-running-limit",
]);
Expand Down
71 changes: 71 additions & 0 deletions src/contract/operations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,65 @@ describe("operation input/output round trips", () => {
expect(OPERATIONS["status.get"].output.parse(status)).toBeDefined();
});

describe("status.get memoryPressure", () => {
const host = { os: "macOS", osVersion: "15.5", arch: "arm64", tools: [] };
const entry = {
atRamBudget: false,
limit: 1,
maxRunning: 1,
overLimit: false,
reserved: 0,
running: 0,
used: 0,
warm: 0,
};
const parse = (memoryPressure: unknown) =>
OPERATIONS["status.get"].output.safeParse({
capacity: {
android: entry,
global: { maxRunning: 2, overLimit: false, reserved: 0, running: 0, warm: 0 },
ios: entry,
memoryPressure,
},
daemon: {
health: "running",
lastUpdateFailure: null,
latestVersion: null,
mode: "worker",
update: null,
version: "0.0.0-test",
},
devices: [],
host,
leases: [],
queueDepth: 0,
}).success;
const floor = { availablePercent: 8, floorPercent: 10, trigger: "floor" };

it("a worker's block is bounded: the percent a whole number from 0 to 100, the floor 0 to 100, the time not negative", () => {
expect(parse({ step: "none" })).toBe(true);
expect(parse({ cause: floor, since: 0, step: "new-devices-paused" })).toBe(true);
expect(
parse({ cause: { ...floor, availablePercent: 100 }, since: 1, step: "warming-paused" }),
).toBe(true);
for (const cause of [
{ ...floor, availablePercent: 101 },
{ ...floor, availablePercent: -1 },
{ ...floor, availablePercent: 8.5 },
{ ...floor, floorPercent: 101 },
{ ...floor, floorPercent: -1 },
{ ...floor, level: "bogus" },
{ ...floor, trigger: "other" },
]) {
expect(parse({ cause, since: 1, step: "warming-paused" })).toBe(false);
}
for (const since of [-1, Number.POSITIVE_INFINITY, Number.NaN]) {
expect(parse({ cause: floor, since, step: "warming-paused" })).toBe(false);
}
expect(parse({ step: "paused" })).toBe(false);
});
});

describe("status.get warmPool", () => {
const host = { os: "macOS", osVersion: "15.5", arch: "arm64", tools: [] };
const warmPool = {
Expand Down Expand Up @@ -1322,6 +1381,12 @@ describe("operation input/output round trips", () => {
},
exec: { timeoutMs: 1 },
diskPressure: { freeBytesThreshold: 1 },
memoryPressure: {
clearAfterMs: 60_000,
enabled: true,
pauseNewDevices: { level: "critical", minAvailablePercent: 10 },
pauseWarming: { level: "warn", minAvailablePercent: 20 },
},
drivers: {},
eventBuffer: { capacity: 1 },
log: { level: "info", rotateBytes: 1 },
Expand Down Expand Up @@ -1402,6 +1467,12 @@ describe("operation input/output round trips", () => {
exec: { timeoutMs: 1 },
drivers: {},
diskPressure: { freeBytesThreshold: 1 },
memoryPressure: {
clearAfterMs: 60_000,
enabled: true,
pauseNewDevices: { level: "critical", minAvailablePercent: 10 },
pauseWarming: { level: "warn", minAvailablePercent: 20 },
},
eventBuffer: { capacity: 1 },
log: { level: "info", rotateBytes: 1 },
http: { enabled: false, host: "127.0.0.1", port: 4700 },
Expand Down
2 changes: 1 addition & 1 deletion src/contract/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface ProtocolRange {
const protocolRangeSchema = z.object({ min: z.number().int(), max: z.number().int() });

/** Widen only once a second version is kept alive side by side with the first; a bump that leaves no shim behind moves both ends. */
export const PROTOCOL_VERSION_RANGE: ProtocolRange = { min: 82, max: 82 };
export const PROTOCOL_VERSION_RANGE: ProtocolRange = { min: 83, max: 83 };

const LEGACY_DAEMON_PROTOCOL_VERSION = 2;

Expand Down
Loading
Loading