@smoothbricks/nx-plugin 0.7.4 → 0.7.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/README.md +59 -30
  2. package/dist/.build-inputs.json +15 -8
  3. package/dist/executors/bounded-exec/cpu-pool-thread.d.ts +3 -2
  4. package/dist/executors/bounded-exec/cpu-pool-thread.d.ts.map +1 -1
  5. package/dist/executors/bounded-exec/cpu-pool-thread.js +1 -1
  6. package/dist/executors/bounded-exec/cpu-pool.d.ts +24 -10
  7. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
  8. package/dist/executors/bounded-exec/cpu-pool.js +96 -52
  9. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  10. package/dist/executors/bounded-exec/executor.js +192 -82
  11. package/dist/executors/bounded-exec/host-memory.d.ts +47 -0
  12. package/dist/executors/bounded-exec/host-memory.d.ts.map +1 -0
  13. package/dist/executors/bounded-exec/host-memory.darwin.d.ts +3 -0
  14. package/dist/executors/bounded-exec/host-memory.darwin.d.ts.map +1 -0
  15. package/dist/executors/bounded-exec/host-memory.darwin.js +40 -0
  16. package/dist/executors/bounded-exec/host-memory.js +29 -0
  17. package/dist/executors/bounded-exec/host-memory.linux.d.ts +14 -0
  18. package/dist/executors/bounded-exec/host-memory.linux.d.ts.map +1 -0
  19. package/dist/executors/bounded-exec/host-memory.linux.js +104 -0
  20. package/dist/executors/bounded-exec/leaf-peak.d.ts +55 -0
  21. package/dist/executors/bounded-exec/leaf-peak.d.ts.map +1 -0
  22. package/dist/executors/bounded-exec/leaf-peak.js +146 -0
  23. package/dist/executors/bounded-exec/mbx-pool.d.ts +17 -9
  24. package/dist/executors/bounded-exec/mbx-pool.d.ts.map +1 -1
  25. package/dist/executors/bounded-exec/mbx-pool.js +29 -11
  26. package/dist/executors/bounded-exec/mbx-reservations.d.ts +41 -0
  27. package/dist/executors/bounded-exec/mbx-reservations.d.ts.map +1 -0
  28. package/dist/executors/bounded-exec/mbx-reservations.js +372 -0
  29. package/dist/executors/bounded-exec/peak-waiter.d.ts +2 -0
  30. package/dist/executors/bounded-exec/peak-waiter.d.ts.map +1 -0
  31. package/dist/executors/bounded-exec/peak-waiter.js +53 -0
  32. package/dist/executors/bounded-exec/pool-admission.d.ts +38 -0
  33. package/dist/executors/bounded-exec/pool-admission.d.ts.map +1 -0
  34. package/dist/executors/bounded-exec/pool-admission.js +31 -0
  35. package/dist/executors/bounded-exec/run-cpu-pool.d.ts +6 -4
  36. package/dist/executors/bounded-exec/run-cpu-pool.d.ts.map +1 -1
  37. package/dist/executors/bounded-exec/run-cpu-pool.js +20 -7
  38. package/dist/executors/bounded-exec/runner-sizing.d.ts +5 -5
  39. package/dist/executors/bounded-exec/runner-sizing.d.ts.map +1 -1
  40. package/dist/executors/bounded-exec/runner-sizing.js +6 -6
  41. package/dist/executors/bounded-exec/verdict.d.ts +21 -2
  42. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
  43. package/dist/executors/bounded-exec/verdict.js +27 -4
  44. package/dist/index.d.ts +1 -1
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +4 -1
  47. package/package.json +1 -1
  48. package/src/executors/bounded-exec/cpu-pool-thread.ts +4 -3
  49. package/src/executors/bounded-exec/cpu-pool.ts +111 -49
  50. package/src/executors/bounded-exec/executor.ts +202 -77
  51. package/src/executors/bounded-exec/host-memory.darwin.ts +44 -0
  52. package/src/executors/bounded-exec/host-memory.linux.ts +115 -0
  53. package/src/executors/bounded-exec/host-memory.ts +70 -0
  54. package/src/executors/bounded-exec/leaf-peak.ts +151 -0
  55. package/src/executors/bounded-exec/mbx-pool.ts +33 -13
  56. package/src/executors/bounded-exec/mbx-reservations.ts +300 -0
  57. package/src/executors/bounded-exec/peak-waiter.ts +82 -0
  58. package/src/executors/bounded-exec/pool-admission.ts +64 -0
  59. package/src/executors/bounded-exec/run-cpu-pool.ts +20 -6
  60. package/src/executors/bounded-exec/runner-sizing.ts +6 -6
  61. package/src/executors/bounded-exec/verdict.ts +40 -6
  62. package/src/index.ts +4 -1
  63. package/test-timings.json +134 -131
@@ -2,8 +2,9 @@ import { BUN_TEST, GO_TEST_RUNNER, NEXTEST_RUN } from './verdict.js';
2
2
  /** Every budgeted command learns its grant here, so a script that starts a runner can size it. */
3
3
  export const CPU_TOKENS_ENV = 'BOUNDED_EXEC_CPU_TOKENS';
4
4
  /**
5
- * The cores mbx granted the reservation a leaf runs under: `mbx reserve --cpus N` names at most N to its command, as many
6
- * as were free once one was.
5
+ * The cores mbx granted the reservation a leaf runs under: its run's mbx reservation endpoint grants at most the N the
6
+ * leaf asks for, as many as were free once one was, and the leaf's shell reads that count into this variable
7
+ * (mbx-pool.ts, `reservation`), the one `mbx reserve --cpus N` names to its own command.
7
8
  */
8
9
  export const GRANTED_CPUS_ENV = 'MBX_RESERVE_CPUS';
9
10
  /**
@@ -262,13 +263,12 @@ export function sizeRunner(demand, command, tokens) {
262
263
  /**
263
264
  * The shell statements that run first in a reserved leaf's reservation and size its runner to the grant, which only
264
265
  * the command learns as it starts: `CPU_TOKENS_ENV` becomes the cores mbx granted (`GRANTED_CPUS_ENV`), never more
265
- * than the leaf asked for (`WANT_ENV`, set before it reserved), which also stands in under an mbx that grants a
266
- * reservation whole and names none. The test-thread variables a sizing sets follow from it, under their inherited
267
- * ceilings, outranking the target's own as a numeric grant's do (`sizeRunner`).
266
+ * than the leaf asked for (`WANT_ENV`, set before it reserved). The test-thread variables a sizing sets follow from it,
267
+ * under their inherited ceilings, outranking the target's own as a numeric grant's do (`sizeRunner`).
268
268
  */
269
269
  export function grantedSizing(demand) {
270
270
  const asked = `$${WANT_ENV}`;
271
- const named = `\${${GRANTED_CPUS_ENV}:-${asked}}`;
271
+ const named = `$${GRANTED_CPUS_ENV}`;
272
272
  const tokens = `$${CPU_TOKENS_ENV}`;
273
273
  const atMost = (ceiling) => ceiling === null ? `"${tokens}"` : `"$(( ${tokens} < ${ceiling} ? ${tokens} : ${ceiling} ))"`;
274
274
  const statements = [`export ${CPU_TOKENS_ENV}="$(( ${named} < ${asked} ? ${named} : ${asked} ))"`];
@@ -20,8 +20,9 @@ import type { NativeTestResult } from './test-result-writer.js';
20
20
  * - `no-space`: the run failed and its output said a write found no space (ENOSPC). Whatever its tests then reported,
21
21
  * they failed on the disk, not on their own: the verdict names the line that said so and, when the task held one,
22
22
  * its RAM temp volume as it stood when that line arrived.
23
- * - `queued`: the command failed before any admission after a live task PID was explicitly seen waiting in mbx.
24
- * Its observed wait and public queue positions describe admission pressure, never a wedged test.
23
+ * - `queued`: the command failed before any admission after a live task PID was explicitly seen waiting in mbx, or
24
+ * while its reserved leaf's request waited on its run's mbx reservation endpoint. Its observed wait, and any public
25
+ * queue positions, describe admission pressure, never a wedged test.
25
26
  * - `failed`: anything else that did not pass. That includes an assertion named in the report,
26
27
  * or a non-zero exit with no report to say why.
27
28
  */
@@ -103,6 +104,13 @@ export interface BoundedExecRecord {
103
104
  * expired; written for the reader of a refused run, never read back.
104
105
  */
105
106
  readonly cpuWait?: CpuWaitRow;
107
+ /**
108
+ * The command's memory peak in bytes when it ended (specs/cowshed/13_telemetry.md, "Job resource peaks"): its rusage
109
+ * `ru_maxrss`, the largest resident set any one process of its tree reached, as its waiter read it (`leaf-peak.ts`).
110
+ * Null when it was not measured: the command never ran, the waiter ended before it, or no Bun waited on it; never
111
+ * zero for that. The task's next run is charged it in its run's pool (`readLastPeak`).
112
+ */
113
+ readonly peakBytes: number | null;
106
114
  }
107
115
  /** The Nx task a run executes as. Nx gives an executor no task id, only its parts. */
108
116
  export interface BoundedExecTask {
@@ -222,6 +230,17 @@ export declare function clearTaskDirectory(directory: string): Promise<void>;
222
230
  export declare function writeRecord(directory: string, record: BoundedExecRecord): Promise<void>;
223
231
  /** The record in `directory`, or `null` when there is none. A malformed record throws. */
224
232
  export declare function readRecord(directory: string): Promise<BoundedExecRecord | null>;
233
+ /**
234
+ * The peak the task's last record in `directory` names: its charge in its run's pool. Null when the task has no record
235
+ * or its record no peak; a record that cannot be read is an error naming it, never a charge of nothing.
236
+ */
237
+ export declare function readLastPeak(directory: string): Promise<{
238
+ ok: true;
239
+ peakBytes: number | null;
240
+ } | {
241
+ ok: false;
242
+ error: string;
243
+ }>;
225
244
  /** The JUnit report a command wrote into `directory`, or `null` when it wrote none. */
226
245
  export declare function readJunitReport(directory: string, bunClosed?: (results: readonly NativeTestResult[]) => void): Promise<JunitFailures | null>;
227
246
  /** A failed task of an Nx run, and whether its bounded-exec record shows only a bound. */
@@ -1 +1 @@
1
- {"version":3,"file":"verdict.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/verdict.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAmB,KAAK,QAAQ,EAAe,MAAM,gBAAgB,CAAC;AAC7E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAGhE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,MAAM,kBAAkB,GAC1B;IAAE,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAA;CAAE,GAC9B,CAAC;IAAE,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,kBAAkB,CAAC,GAChF;IACE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,CAAC;IACpC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B,GACD;IAAE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE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gB,eAAe,CAAC,OAAO,EAAE,kBAAkB,GAAG,MAAM,CA2BnE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,eAAe,GAAG,MAAM,CAgBjE"}
@@ -321,6 +321,21 @@ export async function readRecord(directory) {
321
321
  }
322
322
  return parseRecord(JSON.parse(text));
323
323
  }
324
+ /**
325
+ * The peak the task's last record in `directory` names: its charge in its run's pool. Null when the task has no record
326
+ * or its record no peak; a record that cannot be read is an error naming it, never a charge of nothing.
327
+ */
328
+ export async function readLastPeak(directory) {
329
+ try {
330
+ return { ok: true, peakBytes: (await readRecord(directory))?.peakBytes ?? null };
331
+ }
332
+ catch (error) {
333
+ return {
334
+ ok: false,
335
+ error: `the task's last record ${join(directory, VERDICT_FILE)} cannot be read: ${error instanceof Error ? error.message : String(error)}`,
336
+ };
337
+ }
338
+ }
324
339
  /** The JUnit report a command wrote into `directory`, or `null` when it wrote none. */
325
340
  export async function readJunitReport(directory, bunClosed) {
326
341
  try {
@@ -341,7 +356,12 @@ function parseRecord(value) {
341
356
  if (!isObject(value) || typeof value.task !== 'string' || !(typeof value.hash === 'string' || value.hash === null)) {
342
357
  throw new Error(`not a bounded-exec record: ${JSON.stringify(value)}`);
343
358
  }
344
- return { task: value.task, hash: value.hash, verdict: parseVerdict(value.verdict) };
359
+ // A record written before peaks were recorded carries none.
360
+ const peakBytes = value.peakBytes ?? null;
361
+ if (!(peakBytes === null || (typeof peakBytes === 'number' && Number.isSafeInteger(peakBytes) && peakBytes >= 0))) {
362
+ throw new Error(`not a bounded-exec record: ${JSON.stringify(value)}`);
363
+ }
364
+ return { task: value.task, hash: value.hash, verdict: parseVerdict(value.verdict), peakBytes };
345
365
  }
346
366
  function parseVerdict(value) {
347
367
  if (isObject(value)) {
@@ -489,9 +509,12 @@ export async function failedTasksOfRun(runJson, workspaceData) {
489
509
  }
490
510
  /** The same honest admission diagnostic in live output and a terminal verdict. */
491
511
  export function describeAdmissionQueue(wait) {
492
- return `queued for admission ${(wait.waitedMs / 1_000).toFixed(1)} s; mbx ${wait.requests
493
- .map((request) => `pid=${request.pid} ticket=${request.ticket} queue position=${request.queuePosition}`)
494
- .join(', ')}`;
512
+ const where = wait.requests.length === 0
513
+ ? "on its run's mbx reservation endpoint"
514
+ : `mbx ${wait.requests
515
+ .map((request) => `pid=${request.pid} ticket=${request.ticket} queue position=${request.queuePosition}`)
516
+ .join(', ')}`;
517
+ return `queued for admission ${(wait.waitedMs / 1_000).toFixed(1)} s; ${where}`;
495
518
  }
496
519
  export function describeVerdict(verdict) {
497
520
  switch (verdict.outcome) {
package/dist/index.d.ts CHANGED
@@ -37,7 +37,7 @@ export declare const createNodesV2: CreateNodesV2;
37
37
  * hint and the opt-in producer completion receipts. Each sees the same options and run context; neither reads the
38
38
  * other's output. The hint is recorded first so a producer-receipt bug cannot cost the controller its evidence. The
39
39
  * pair also serves a run that inherits no CPU pool its own, which every task inherits (`run-cpu-pool.ts`), and closes
40
- * it when the run ends. Last, once every task has finished, the post hook starts the reclaim of the
40
+ * it when the run ends, and a run with mbx's pool its mbx reservation endpoint (`mbx-reservations.ts`), which it ends then too. Last, once every task has finished, the post hook starts the reclaim of the
41
41
  * superseded Cargo unit generations of each Cargo workspace the run built into, in a process of its own, never on
42
42
  * Nx's thread (`@smoothbricks/cargo-retain`).
43
43
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EAGnB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EAGtB,KAAK,mBAAmB,EACzB,MAAM,0BAA0B,CAAC;AAmElC,OAAO,EACL,KAAK,uBAAuB,EAG7B,MAAM,wBAAwB,CAAC;AAoBhC,gEAAgE;AAChE,eAAO,MAAM,aAAa,WAAW,CAAC;AACtC,uEAAuE;AACvE,eAAO,MAAM,mBAAmB,iBAAiB,CAAC;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CROSS_LINT_COMMAND, CARGO_CROSS_LINT_TARGET, CARGO_FETCH_COMMAND,
18
18
  import { eslintConfigClosure } from './eslint-config-closure.js';
19
19
  import { ESLINT_SOURCES_GLOB, eslintSources } from './eslint-sources.js';
20
20
  import { ALL_VERDICTS_EXECUTOR, ESLINT_SOURCES_TOKEN, } from './executors/all-verdicts/schema.js';
21
+ import { closeRunReservations, serveRunReservations } from './executors/bounded-exec/mbx-reservations.js';
21
22
  import { closeRunCpuPool, serveRunCpuPool } from './executors/bounded-exec/run-cpu-pool.js';
22
23
  import { ffiPathProblem } from './executors/scriptc-native/ffi-paths.js';
23
24
  import { hashVersionlessCrateManifests } from './manifest-hash.js';
@@ -954,7 +955,7 @@ function isBuildOutputPackageJson(packageJsonPath) {
954
955
  * hint and the opt-in producer completion receipts. Each sees the same options and run context; neither reads the
955
956
  * other's output. The hint is recorded first so a producer-receipt bug cannot cost the controller its evidence. The
956
957
  * pair also serves a run that inherits no CPU pool its own, which every task inherits (`run-cpu-pool.ts`), and closes
957
- * it when the run ends. Last, once every task has finished, the post hook starts the reclaim of the
958
+ * it when the run ends, and a run with mbx's pool its mbx reservation endpoint (`mbx-reservations.ts`), which it ends then too. Last, once every task has finished, the post hook starts the reclaim of the
958
959
  * superseded Cargo unit generations of each Cargo workspace the run built into, in a process of its own, never on
959
960
  * Nx's thread (`@smoothbricks/cargo-retain`).
960
961
  */
@@ -965,11 +966,13 @@ export const preTasksExecution = async (options, context) => {
965
966
  preTaskResults(options, context);
966
967
  await preProducerReceipts(options, context);
967
968
  await serveRunCpuPool(context);
969
+ await serveRunReservations(context);
968
970
  };
969
971
  export const postTasksExecution = async (options, context) => {
970
972
  await postTaskResults(options, context);
971
973
  await postProducerReceipts(options, context);
972
974
  await closeRunCpuPool(context);
975
+ await closeRunReservations(context);
973
976
  await postCargoRetention(options, context);
974
977
  };
975
978
  /** The lock-scope nodes' edges: each bun node's to the packages and members its manifest resolves. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smoothbricks/nx-plugin",
3
- "version": "0.7.4",
3
+ "version": "0.7.6",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "main": "./loader.js",
@@ -9,13 +9,14 @@ import { type CloseOutcome, createCpuPool } from './cpu-pool.js';
9
9
  * jobserver fifo and heartbeat share an event loop that runs nothing else, so the heartbeat proves that the actor which
10
10
  * admits and grants is turning.
11
11
  *
12
- * The thread is started with the pool's count. It says once that the pool serves, with the environment a task inherits,
12
+ * The thread is started with the pool's count and the run's memory. It says once that the pool serves, with the environment a task inherits,
13
13
  * or why it cannot; the host's one message is its close, after which the thread says how the pool closed.
14
14
  */
15
15
 
16
- /** What the thread is started with. */
16
+ /** What the thread is started with: the run's count, and the run's memory in bytes its grants are charged against. */
17
17
  export interface CpuPoolThreadData {
18
18
  readonly tokens: number;
19
+ readonly memory: number;
19
20
  }
20
21
 
21
22
  /** What the thread says, in order: the pool serves or failed; after the host's close, how the pool closed. */
@@ -31,7 +32,7 @@ if (host === null) {
31
32
  const report = (message: CpuPoolThreadReport): void => host.postMessage(message);
32
33
  const data: CpuPoolThreadData = workerData;
33
34
  // The pool lives until its host closes it, or with the thread.
34
- const made = await createCpuPool(data.tokens, new Promise<void>(() => {}));
35
+ const made = await createCpuPool(data.tokens, new Promise<void>(() => {}), data.memory);
35
36
  if (made.ok) {
36
37
  const { pool } = made;
37
38
  host.once('message', () => {
@@ -8,6 +8,7 @@ import typia from 'typia';
8
8
  import { ownedSocketDirectory } from '../../testing.js';
9
9
  import { holdLease, type Unleased } from './gateway-lease.js';
10
10
  import { type CpuLeaseProgress, type CpuLeaseQueued, CpuLeaseWait, HEARTBEAT_MS } from './lease-wait.js';
11
+ import { admit } from './pool-admission.js';
11
12
  import { CPU_TOKENS_ENV, parseInheritedTokens } from './runner-sizing.js';
12
13
 
13
14
  /**
@@ -23,6 +24,11 @@ import { CPU_TOKENS_ENV, parseInheritedTokens } from './runner-sizing.js';
23
24
  * lasts while its connection does, so a child that dies returns its tokens with its socket. A pool
24
25
  * grants only from its own count, and a pool whose upstream grant has gone grants nothing.
25
26
  *
27
+ * A run's own pool also charges memory (`pool-admission.ts`; specs/cowshed/05_gateway.md, "Without mbx, every Nx run
28
+ * budgets itself"). A request names its task's last recorded peak as `memory`, in bytes, and is granted only while
29
+ * the charges of the leaves holding grants and its own fit the run's memory; a request that names none is charged
30
+ * nothing, as mbx's omitted `--memory` is. A sub-pool charges no memory: its holder's charge covers its tree.
31
+ *
26
32
  * The same count is a GNU make jobserver fifo beside the socket, mode 0600, which Cargo, its build
27
33
  * scripts and every nested `cargo` read through `CARGO_MAKEFLAGS`/`MAKEFLAGS` (specs/cowshed/05_gateway.md,
28
34
  * "Cargo reads its holder's jobserver"). A pool of `g` holds `g − 1` token bytes there; the holder's own
@@ -55,17 +61,26 @@ export interface CpuPool {
55
61
 
56
62
  export type CloseOutcome = { ok: true } | { ok: false; error: string };
57
63
 
58
- /** The one line a child sends: a count of whole tokens, at least one. */
64
+ /**
65
+ * The one line a child sends: a count of whole tokens, at least one, and the bytes it is charged, its task's last
66
+ * recorded memory peak. A child whose task has no recorded peak names none: it is charged nothing.
67
+ */
59
68
  interface CpuPoolRequest {
60
69
  op: 'cpu-pool';
61
70
  want: number & typia.tags.Type<'uint32'> & typia.tags.Minimum<1>;
71
+ memory?: number & typia.tags.Type<'uint64'>;
72
+ }
73
+
74
+ /** A grant whose charge alone exceeds the run's memory, made while nothing else held memory: the run's memory. */
75
+ export interface Oversized {
76
+ readonly memory: number & typia.tags.Type<'uint64'>;
62
77
  }
63
78
 
64
79
  /** The pool's answers, in `holdLease`'s framing. */
65
80
  type CpuPoolReply =
66
81
  | CpuLeaseProgress
67
82
  | CpuLeaseQueued
68
- | { ok: true; lease: 'granted'; tokens: number }
83
+ | { ok: true; lease: 'granted'; tokens: number; oversized?: Oversized }
69
84
  | { ok: false; code: 'invalid-request'; error: string };
70
85
 
71
86
  /** Exactly a request's fields: any other field is an invalid request. */
@@ -94,7 +109,7 @@ const run = promisify(execFile);
94
109
  type Phase =
95
110
  | { readonly kind: 'reading' }
96
111
  | { readonly kind: 'queued' }
97
- | { readonly kind: 'holding'; readonly bytes: number; readonly slot: boolean }
112
+ | { readonly kind: 'holding'; readonly bytes: number; readonly slot: boolean; readonly memory: number }
98
113
  | { readonly kind: 'done' };
99
114
 
100
115
  /** A child connection and what the pool owes it. Its grant, or its place in line, ends with the connection. */
@@ -103,10 +118,11 @@ interface Child {
103
118
  phase: Phase;
104
119
  }
105
120
 
106
- /** A queued child and the count it asked for. */
121
+ /** A queued child, the count it asked for and the bytes it is charged. */
107
122
  interface Waiter {
108
123
  readonly child: Child;
109
124
  readonly want: number;
125
+ readonly memory: number;
110
126
  }
111
127
 
112
128
  /** One framed reply line. The newline is the framing; every reply goes through here. */
@@ -127,21 +143,34 @@ export function readInheritedCpuPool(environment: Readonly<NodeJS.ProcessEnv>):
127
143
  }
128
144
 
129
145
  /**
130
- * Tokens a parent pool lent, held until released, or why there are none. `closed` resolves when the grant's
131
- * connection closes, however it closes, so a sub-pool built on the grant ends with it.
146
+ * Tokens a parent pool lent, held until released, or why there are none. `oversized` names the run's memory when the
147
+ * child's charge alone exceeds it and it was granted because nothing else held memory. `closed` resolves when the
148
+ * grant's connection closes, however it closes, so a sub-pool built on the grant ends with it.
132
149
  */
133
- export type TokenGrant = { granted: true; tokens: number; release: () => void; closed: Promise<void> } | Unleased;
150
+ export type TokenGrant =
151
+ | { granted: true; tokens: number; oversized: Oversized | null; release: () => void; closed: Promise<void> }
152
+ | Unleased;
153
+
154
+ const isOversized = typia.createEquals<Oversized>();
134
155
 
135
156
  /**
136
- * Ask the immediate parent pool for `want` tokens. The inherited count does not bound the ask: a pool grants at
137
- * most what it holds. A granted lease is the child's local allocation: its connection is the grant, and closing it
138
- * returns only that allocation. An absent endpoint grants nothing and refuses nothing; a connected endpoint's refusal
139
- * or protocol failure must fail admission rather than run the child beside its parent's count.
157
+ * Ask the immediate parent pool for `want` tokens, charged `memory` bytes: the task's last recorded peak, or null when
158
+ * it has none. The inherited count does not bound the ask: a pool grants at most what it holds. A granted lease is the
159
+ * child's local allocation: its connection is the grant, and closing it returns only that allocation. An absent
160
+ * endpoint grants nothing and refuses nothing; a connected endpoint's refusal or protocol failure must fail admission
161
+ * rather than run the child beside its parent's count.
140
162
  */
141
- export async function takeParentCpuTokens(parent: InheritedCpuPool, want: number): Promise<TokenGrant> {
163
+ export async function takeParentCpuTokens(
164
+ parent: InheritedCpuPool,
165
+ want: number,
166
+ memory: number | null,
167
+ ): Promise<TokenGrant> {
142
168
  if (!Number.isSafeInteger(want) || want < 1) {
143
169
  throw new RangeError(`a child asks its parent pool for a positive count, not ${want} (pool ${parent.tokens})`);
144
170
  }
171
+ if (memory !== null && (!Number.isSafeInteger(memory) || memory < 0)) {
172
+ throw new RangeError(`a child is charged a whole number of bytes, not ${memory}`);
173
+ }
145
174
  if (parent.socket.length === 0 || parent.socket.includes('\0')) {
146
175
  return {
147
176
  granted: false,
@@ -149,11 +178,12 @@ export async function takeParentCpuTokens(parent: InheritedCpuPool, want: number
149
178
  reason: `the parent CPU pool's endpoint ${JSON.stringify(parent.socket)} is not a socket path`,
150
179
  };
151
180
  }
152
- const lease = await holdLease(parent.socket, { op: 'cpu-pool', want }, 'the parent CPU pool', new CpuLeaseWait());
181
+ const request = memory === null ? { op: 'cpu-pool', want } : { op: 'cpu-pool', want, memory };
182
+ const lease = await holdLease(parent.socket, request, 'the parent CPU pool', new CpuLeaseWait());
153
183
  if (!lease.granted) {
154
184
  return lease;
155
185
  }
156
- const tokens = lease.answer.tokens;
186
+ const { tokens, oversized } = lease.answer;
157
187
  if (typeof tokens !== 'number' || !Number.isInteger(tokens) || tokens < 1 || tokens > want) {
158
188
  lease.release();
159
189
  return {
@@ -162,7 +192,15 @@ export async function takeParentCpuTokens(parent: InheritedCpuPool, want: number
162
192
  reason: `the parent CPU pool granted ${JSON.stringify(tokens)} tokens for ${want}`,
163
193
  };
164
194
  }
165
- return { granted: true, tokens, release: lease.release, closed: lease.closed };
195
+ if (oversized !== undefined && !isOversized(oversized)) {
196
+ lease.release();
197
+ return {
198
+ granted: false,
199
+ cause: 'other',
200
+ reason: `the parent CPU pool named its memory ${JSON.stringify(oversized)} in a grant, which is no byte count`,
201
+ };
202
+ }
203
+ return { granted: true, tokens, oversized: oversized ?? null, release: lease.release, closed: lease.closed };
166
204
  }
167
205
 
168
206
  /** A thrown value's message. */
@@ -315,12 +353,14 @@ function watchFifo(
315
353
 
316
354
  /**
317
355
  * Make a pool of `tokens` that lives while `closed` does: when `closed` resolves the pool refuses
318
- * grants, ends its child connections, drains its jobserver fifo and removes its directory. Setup
319
- * failures are values; a non-positive or unsafe count is a programmer bug and throws.
356
+ * grants, ends its child connections, drains its jobserver fifo and removes its directory. A run's own
357
+ * pool charges its grants against `memory`, the run's memory in bytes; a sub-pool charges none (null).
358
+ * Setup failures are values; a non-positive or unsafe count is a programmer bug and throws.
320
359
  */
321
360
  export async function createCpuPool(
322
361
  tokens: number,
323
362
  closed: Promise<void>,
363
+ memory: number | null,
324
364
  ): Promise<{ ok: true; pool: CpuPool } | { ok: false; error: string }> {
325
365
  if (!Number.isSafeInteger(tokens) || tokens < 1) {
326
366
  throw new RangeError(`a CPU pool holds a positive safe integer of tokens, not ${tokens}`);
@@ -347,6 +387,8 @@ export async function createCpuPool(
347
387
  const scratch = Buffer.allocUnsafe(tokens);
348
388
  // The holder's implicit first token, while a socket child holds it.
349
389
  let slotLent = false;
390
+ // The bytes the children holding grants are charged, against `memory`.
391
+ let heldMemory = 0;
350
392
  // The readability wait while the queue's head finds no token, else undefined.
351
393
  let watch: FifoWatch | undefined;
352
394
  let closing = false;
@@ -404,46 +446,62 @@ export async function createCpuPool(
404
446
  }
405
447
  };
406
448
 
407
- // FIFO: the head takes `min(want, available)` as one grant once any token is available, where available is the
408
- // fifo bytes it can read without blocking plus the implicit slot while no child holds it. `arrived` is bytes the
409
- // readability wait already took. A waiting child holds nothing, so no child waits while it holds tokens another
410
- // child needs. Whatever bytes are in hand when no head can use them go straight back to the fifo.
449
+ // FIFO (`admit`): the head takes `min(want, available)` as one grant once any token is available and, in a run's
450
+ // pool, its charge fits beside the holders'; available is the fifo bytes it can read without blocking plus the
451
+ // implicit slot while no child holds it. `arrived` is bytes the readability wait already took. A waiting child holds
452
+ // nothing, so no child waits while it holds tokens another child needs. Whatever bytes are in hand when no head can
453
+ // use them go straight back to the fifo. A head that waits for memory watches the fifo for nothing: only a holder's
454
+ // close frees memory, and that close drains again.
411
455
  function drain(arrived: number): void {
456
+ if (closing) {
457
+ stopWatching();
458
+ return;
459
+ }
460
+ // A child that half-closed or failed while queued leaves the line. Its `close` finds it gone from the queue.
461
+ for (let at = queue.length - 1; at >= 0; at -= 1) {
462
+ if (queue[at]?.child.socket.writable === false) queue.splice(at, 1);
463
+ }
412
464
  let inHand = arrived;
413
- while (!closing) {
414
- const waiter = queue[0];
415
- if (waiter === undefined) {
416
- break;
417
- }
418
- if (!waiter.child.socket.writable) {
419
- // A child that half-closed or failed while queued. Its `close` finds it gone from the queue.
420
- queue.shift();
421
- continue;
422
- }
423
- if (inHand < waiter.want) {
424
- try {
425
- inHand += readTokens(jobserver, scratch, waiter.want - inHand);
426
- } catch (error) {
427
- fail(`its jobserver fifo could not be read: ${describe(error)}`);
428
- return;
429
- }
430
- }
431
- const granted = Math.min(waiter.want, inHand + (slotLent ? 0 : 1));
432
- if (granted === 0) {
433
- watchForTokens();
465
+ const wanted = Math.min(
466
+ queue.reduce((sum, waiter) => sum + waiter.want, 0),
467
+ scratch.length,
468
+ );
469
+ if (inHand < wanted) {
470
+ try {
471
+ inHand += readTokens(jobserver, scratch, wanted - inHand);
472
+ } catch (error) {
473
+ fail(`its jobserver fifo could not be read: ${describe(error)}`);
434
474
  return;
435
475
  }
436
- queue.shift();
476
+ }
477
+ const admission = admit(
478
+ queue,
479
+ inHand + (slotLent ? 0 : 1),
480
+ memory === null ? null : { capacity: memory, held: heldMemory },
481
+ );
482
+ queue.splice(0, admission.grants.length);
483
+ for (const { request, tokens: granted, oversized } of admission.grants) {
437
484
  // Fifo bytes first, the implicit slot last.
438
485
  const bytes = Math.min(granted, inHand);
439
486
  inHand -= bytes;
440
487
  const slot = granted > bytes;
441
488
  if (slot) slotLent = true;
442
- waiter.child.phase = { kind: 'holding', bytes, slot };
443
- waiter.child.socket.write(frame({ ok: true, lease: 'granted', tokens: granted }));
489
+ heldMemory += request.memory;
490
+ request.child.phase = { kind: 'holding', bytes, slot, memory: request.memory };
491
+ request.child.socket.write(
492
+ frame(
493
+ oversized && memory !== null
494
+ ? { ok: true, lease: 'granted', tokens: granted, oversized: { memory } }
495
+ : { ok: true, lease: 'granted', tokens: granted },
496
+ ),
497
+ );
498
+ }
499
+ if (admission.waiting === 'cpu') {
500
+ watchForTokens();
501
+ } else {
502
+ stopWatching();
444
503
  }
445
- stopWatching();
446
- if (!closing) returnTokens(inHand);
504
+ returnTokens(inHand);
447
505
  }
448
506
 
449
507
  const refuse = (child: Child, error: string): void => {
@@ -471,6 +529,7 @@ export async function createCpuPool(
471
529
  } else if (child.phase.kind === 'holding') {
472
530
  // A closing pool drains its fifo whole; until then the bytes go back for the next holder.
473
531
  if (child.phase.slot) slotLent = false;
532
+ heldMemory -= child.phase.memory;
474
533
  if (!closing) returnTokens(child.phase.bytes);
475
534
  }
476
535
  child.phase = { kind: 'done' };
@@ -523,12 +582,15 @@ export async function createCpuPool(
523
582
  parsed = undefined;
524
583
  }
525
584
  if (!isRequest(parsed)) {
526
- refuse(child, 'a request is {"op":"cpu-pool","want":<a whole number of tokens, at least 1>}');
585
+ refuse(
586
+ child,
587
+ 'a request is {"op":"cpu-pool","want":<a whole number of tokens, at least 1>,"memory"?:<bytes it is charged>}',
588
+ );
527
589
  return;
528
590
  }
529
591
  const request = parsed;
530
592
  child.phase = { kind: 'queued' };
531
- queue.push({ child, want: request.want });
593
+ queue.push({ child, want: request.want, memory: request.memory ?? 0 });
532
594
  socket.write(frame({ ok: true, lease: 'queued', server: process.pid }));
533
595
  drain(0);
534
596
  });