@smoothbricks/nx-plugin 0.7.5 → 0.7.7

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 (52) hide show
  1. package/README.md +20 -3
  2. package/dist/.build-inputs.json +12 -6
  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 +115 -62
  11. package/dist/executors/bounded-exec/host-memory.d.ts +54 -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 +115 -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 +137 -0
  20. package/dist/executors/bounded-exec/leaf-peak.d.ts +56 -0
  21. package/dist/executors/bounded-exec/leaf-peak.d.ts.map +1 -0
  22. package/dist/executors/bounded-exec/leaf-peak.js +147 -0
  23. package/dist/executors/bounded-exec/mbx-reservations.d.ts +22 -0
  24. package/dist/executors/bounded-exec/mbx-reservations.d.ts.map +1 -1
  25. package/dist/executors/bounded-exec/mbx-reservations.js +22 -0
  26. package/dist/executors/bounded-exec/peak-waiter.d.ts +2 -0
  27. package/dist/executors/bounded-exec/peak-waiter.d.ts.map +1 -0
  28. package/dist/executors/bounded-exec/peak-waiter.js +79 -0
  29. package/dist/executors/bounded-exec/pool-admission.d.ts +38 -0
  30. package/dist/executors/bounded-exec/pool-admission.d.ts.map +1 -0
  31. package/dist/executors/bounded-exec/pool-admission.js +31 -0
  32. package/dist/executors/bounded-exec/run-cpu-pool.d.ts +6 -4
  33. package/dist/executors/bounded-exec/run-cpu-pool.d.ts.map +1 -1
  34. package/dist/executors/bounded-exec/run-cpu-pool.js +20 -7
  35. package/dist/executors/bounded-exec/verdict.d.ts +18 -0
  36. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
  37. package/dist/executors/bounded-exec/verdict.js +21 -1
  38. package/managed/templates/github/actions/setup-devenv/action.yml +31 -2
  39. package/package.json +2 -2
  40. package/src/executors/bounded-exec/cpu-pool-thread.ts +4 -3
  41. package/src/executors/bounded-exec/cpu-pool.ts +111 -49
  42. package/src/executors/bounded-exec/executor.ts +121 -59
  43. package/src/executors/bounded-exec/host-memory.darwin.ts +147 -0
  44. package/src/executors/bounded-exec/host-memory.linux.ts +147 -0
  45. package/src/executors/bounded-exec/host-memory.ts +77 -0
  46. package/src/executors/bounded-exec/leaf-peak.ts +152 -0
  47. package/src/executors/bounded-exec/mbx-reservations.ts +30 -0
  48. package/src/executors/bounded-exec/peak-waiter.ts +115 -0
  49. package/src/executors/bounded-exec/pool-admission.ts +64 -0
  50. package/src/executors/bounded-exec/run-cpu-pool.ts +20 -6
  51. package/src/executors/bounded-exec/verdict.ts +30 -1
  52. package/test-timings.json +136 -132
package/README.md CHANGED
@@ -2276,9 +2276,9 @@ through its recorded handle, then archived whole, readonly tree and modes includ
2276
2276
  signalled), beside a dead lease that recorded no handle and one whose handle another live job holds (kept, then
2277
2277
  reclaimed once that job ends), a later dead lease whose archive rotates the oldest out and is deleted in the background,
2278
2278
  a failed run's own lease archived below the half-volume floor and so deleted with every other archive, and the final
2279
- detach. Its supervisor is a stand-in speaking the subtree verbs' wire shapes, whose tree is the root's process group
2280
- (`src/__tests__/stand-in-cowshed.ts`). Its volume uses a real private gateway served by `ram_fixture <ns>` on its
2281
- namespace's socket, with `recordedRamAttach` capturing every attached identity and `disk-command --gateway-socket`
2279
+ detach. Its supervisor is a stand-in speaking the subtree verbs' wire shapes, whose tree is the process group its root
2280
+ runs in (`src/__tests__/stand-in-cowshed.ts`). Its volume uses a real private gateway served by `ram_fixture <ns>` on
2281
+ its namespace's socket, with `recordedRamAttach` capturing every attached identity and `disk-command --gateway-socket`
2282
2282
  routing native admission. The helper is closed only after exact-owned teardown, which then removes the namespace root;
2283
2283
  no test asks the installed gateway. External symlink targets and held directory modes stay unchanged, without duplicate
2284
2284
  provision and teardown; its 60 s case bound is unchanged and its target has the progress bound.
@@ -2415,6 +2415,14 @@ instead of each sizing its runner to the whole host. Its scope is one run. A com
2415
2415
  as configured, sized only by the ceilings it inherits, and nothing is said; a cowshed job's own jobserver fifo still
2416
2416
  reaches it by Cargo's own rule ("Cargo reads its holder's jobserver").
2417
2417
 
2418
+ The run's pool charges memory too. Each task is charged its last recorded peak (`peakBytes` in its `verdict.json`,
2419
+ below), nothing while it has none, and is granted only while the charges of the tasks holding grants plus its own fit
2420
+ the run's memory: the least finite `memory.max` of the run's cgroup and its ancestors and the host's `MemTotal` on
2421
+ Linux, `hw.memsize` on macOS (`host-memory.ts`). A run whose memory cannot be read fails in `preTasksExecution`, naming
2422
+ the file or sysctl. A task whose own peak exceeds the run's memory is granted once nothing else holds memory, and its
2423
+ stderr says so; the wait line names the charge as `memory=<bytes>` or `memory=none`. A granted executor's sub-pool
2424
+ charges no memory.
2425
+
2418
2426
  The pool runs on a worker thread of its own (`cpu-pool-thread.ts`). The process that serves the run, the Nx daemon when
2419
2427
  installed plugins load in it or the Nx CLI without one, hashes tasks and builds the project graph in synchronous calls
2420
2428
  on its main thread; a pool on that thread wrote no heartbeat behind a 14.2 s `hashPlans`, and every runner queued on it
@@ -2480,6 +2488,15 @@ task id and the hash it ran at:
2480
2488
  - `failed`: a test failed on its own, or the command exited non-zero with no report naming a timeout.
2481
2489
  - `passed`.
2482
2490
 
2491
+ The record also holds `peakBytes`, the command's memory peak: the exited command's rusage `ru_maxrss`, the largest
2492
+ resident set any one process of its tree reached, in bytes. Node reaps a child without its rusage, so the command runs
2493
+ under a Bun waiter (`peak-waiter.ts`, on the executor's Bun or the first `bun` on its PATH) that reads it, passes the
2494
+ command its stdio and descriptors 3 to 5, and exits as the command did. The waiter leads the command's process group and
2495
+ names the command's pid when it starts it: that command is the runner a hang snapshot samples, never the waiter.
2496
+ `peakBytes` is null when nothing was measured: the command never ran, the waiter was killed before it reported, or no
2497
+ Bun was found; stderr then says why. The task's next run reads it before clearing the directory, and its run's pool
2498
+ charges it.
2499
+
2483
2500
  The report needs no target configuration. When the command runs exactly one `bun test` or `nextest run`, the executor
2484
2501
  asks that runner for a JUnit report in the task's directory: `bun test` through `--reporter=junit --reporter-outfile`,
2485
2502
  nextest through a one-key tool config (nextest takes the report path only from configuration). A `bun` is any unquoted
@@ -35,26 +35,32 @@
35
35
  "packages/nx-plugin/src/executors/all-verdicts/executor.ts": "4d3aac65aa2e03a2d24d149c412aa18f2e66a6a36a4e88993122b10e9355c8f0",
36
36
  "packages/nx-plugin/src/executors/all-verdicts/schema.ts": "2ca6bd8d2f19d851f291ab6a5227167399b9dc8ed0fda0248b69896d77e471f1",
37
37
  "packages/nx-plugin/src/executors/bounded-exec/bounds.ts": "fecc48ea66df1c2ba526dc0322ab7760cfc1a4e85d99a72a7a43f040448970f0",
38
- "packages/nx-plugin/src/executors/bounded-exec/cpu-pool-thread.ts": "4b914385f7ab73cfb3afdc75c0e3c462e7c103c5061f7f7720d7b95f6655e32d",
39
- "packages/nx-plugin/src/executors/bounded-exec/cpu-pool.ts": "a4be1280a0ea4b5aa0f04170ce75ce4b813631264c50fab5cdd05d34926fc890",
38
+ "packages/nx-plugin/src/executors/bounded-exec/cpu-pool-thread.ts": "bc7d113a044bb830e4db4c373c2f366fadfbb212353e34ef9a5e7dccf876aee6",
39
+ "packages/nx-plugin/src/executors/bounded-exec/cpu-pool.ts": "0f2085296486ebfc63b356fb92c4ec77670de5ac9877bbaf2772ea3aaabbf9f9",
40
40
  "packages/nx-plugin/src/executors/bounded-exec/disk-lease.ts": "1a3f6a6fa590d9a2550490bb6906dc91b6c05fbef235b025eaf257eb5310e92d",
41
- "packages/nx-plugin/src/executors/bounded-exec/executor.ts": "c84aa4b8f0fb53eb37123808f2c89a605f2919cfa924d22a6141970a602b8482",
41
+ "packages/nx-plugin/src/executors/bounded-exec/executor.ts": "49c29558c8b4f3db21a807d6c2e453ca5805ffd8b41f8f79d3837fde33a92396",
42
42
  "packages/nx-plugin/src/executors/bounded-exec/gateway-lease.ts": "f3f73bd92db30e4857f98fb8bd2b9a75b2a5a2a318f094e075ed803c1f9a0117",
43
43
  "packages/nx-plugin/src/executors/bounded-exec/hang-diagnostics.ts": "bcaa9e52384f6c481a9cc2835ba6e8ffe167afa3cb51623fdf8dc3493876f335",
44
+ "packages/nx-plugin/src/executors/bounded-exec/host-memory.darwin.ts": "c27868c1240ec9c782f80c7848f5eee1bc59146e3a56a6c8c0fc05bcf82b2931",
45
+ "packages/nx-plugin/src/executors/bounded-exec/host-memory.linux.ts": "d473dc8475066d4914c419b6b803b6937ebb2577348f0dda8f9ed9def60e8584",
46
+ "packages/nx-plugin/src/executors/bounded-exec/host-memory.ts": "cc7e94023adad2c3645c7a4ba18d07545426ae8d02840a2cf8117494d0915234",
47
+ "packages/nx-plugin/src/executors/bounded-exec/leaf-peak.ts": "0b1b94992b2cbb9e3759785424ceb202667053c5571edf3a79cdd0b206e54a1d",
44
48
  "packages/nx-plugin/src/executors/bounded-exec/lease-wait.ts": "59d8ac94d0b8b75858971c5bb28ee421fca4f7685577274fe8bbaf0c01ba462a",
45
49
  "packages/nx-plugin/src/executors/bounded-exec/lock-wait.ts": "b14a23b49759a777f4b3338ced003adaf76837c2c38462458f76a7fef1b95d9e",
46
50
  "packages/nx-plugin/src/executors/bounded-exec/mbx-pool.ts": "4ef48c1887c1fb29000cdc581686332db6fd503ee07ccdb5f0241fb033249097",
47
51
  "packages/nx-plugin/src/executors/bounded-exec/mbx-queue.ts": "ac309e28e5ee78fa08d628edb00e33532514f7572166770799ae86d468c12b4e",
48
- "packages/nx-plugin/src/executors/bounded-exec/mbx-reservations.ts": "65087d9fdb3f7e788a127d0a7261701b7cb18b0b520ca5cef4b8f7b6fc33d3c5",
52
+ "packages/nx-plugin/src/executors/bounded-exec/mbx-reservations.ts": "1d51ef403f1ea3606d570370265d21421add7d5ca48d74480e9cde12793d0786",
49
53
  "packages/nx-plugin/src/executors/bounded-exec/no-space.ts": "ec032968d89f9e853796012705a06c06cfc4da54bf6e6f10a526f98daca3d077",
50
54
  "packages/nx-plugin/src/executors/bounded-exec/owned-subtree.ts": "cb5edf2b5fe2c1b5b961f8c0ff16ec7bfae3c22ad75dfd671b74f1a4a865863f",
55
+ "packages/nx-plugin/src/executors/bounded-exec/peak-waiter.ts": "3d9a60f8e61d160cf4151746c160f836954f57aca896127a5ef9df4d09c26180",
56
+ "packages/nx-plugin/src/executors/bounded-exec/pool-admission.ts": "384819f66b486a4075685d9a5c240011a342966eeb5c39ecafe1656529f16c21",
51
57
  "packages/nx-plugin/src/executors/bounded-exec/progress.ts": "ed926f7b4991ebf7a7c8876ab0ea00295934d058c774e3f811963a85d209979b",
52
58
  "packages/nx-plugin/src/executors/bounded-exec/ram-attach.ts": "865eb5c277d9ab4b258013030938aeee762b731a7298fa8ad3c5eba3026df77a",
53
59
  "packages/nx-plugin/src/executors/bounded-exec/ram-detach.ts": "535d26114d14d0d94db76227ea7ba52b1ae0b590d7dbac22993b6796d255e666",
54
60
  "packages/nx-plugin/src/executors/bounded-exec/ram-temp-fixtures.ts": "075da4ecfd1cf7dd98fc8c894599dcf2720faba07ac30b8e5592964178849359",
55
61
  "packages/nx-plugin/src/executors/bounded-exec/ram-temp-held.ts": "7c32555bc6dab3f767925b55b68684d33a69393050342d06f055fb81e8e5332b",
56
62
  "packages/nx-plugin/src/executors/bounded-exec/ram-temp.ts": "8d66e6ac13c4ccf6172586b9857d5114b48e027bdcb305f94f6828076c1f7eb4",
57
- "packages/nx-plugin/src/executors/bounded-exec/run-cpu-pool.ts": "3fc4bfe04862a756d9f74743e399d902a6ce6052a0a3ff4e7edf17f875f33266",
63
+ "packages/nx-plugin/src/executors/bounded-exec/run-cpu-pool.ts": "180dc2b185e22c5280182115ca99d52debd2461e51f971ba284aa9a8bef634fb",
58
64
  "packages/nx-plugin/src/executors/bounded-exec/runner-hook.ts": "606eab5db826e571eb15df618315e01cc773d09fd647beb1c00f6434df58ffad",
59
65
  "packages/nx-plugin/src/executors/bounded-exec/runner-lifecycle.ts": "b2a7c901296bb6c139909297bbdbab5bd00e94319c022307d006b0e1293f6454",
60
66
  "packages/nx-plugin/src/executors/bounded-exec/runner-sizing.ts": "bffd2ba0f80758944ca682838832bdbe20ae12eb9a4f75084a3df82ae7786145",
@@ -62,7 +68,7 @@
62
68
  "packages/nx-plugin/src/executors/bounded-exec/schema.ts": "74eb04eaa8d90d966a98ca2b1b7fffc7d2205a55a1e38958effa641b72c680a3",
63
69
  "packages/nx-plugin/src/executors/bounded-exec/test-result-writer.ts": "df7668a11d105a1f88d2187ef8b0edff9db7ba56d8176b5bc35daf1359667637",
64
70
  "packages/nx-plugin/src/executors/bounded-exec/test-results.ts": "4f83dc3accd7892f45385796522267adad9401326d0cd9ce4d4e1145b9023577",
65
- "packages/nx-plugin/src/executors/bounded-exec/verdict.ts": "1614ba94e488629280215dee1e4182fe893342e1c3e3bb124d946addbf9c4e92",
71
+ "packages/nx-plugin/src/executors/bounded-exec/verdict.ts": "7ec4b86fbdacc3b6ef0829a19d76e32858f196c2e741f5e69e3b0e395a03a12f",
66
72
  "packages/nx-plugin/src/executors/cargo-zigbuild/executor.ts": "622a5f36897d9eb1f7465654e88f4291aedee9767603028d20c1e819b91d72f4",
67
73
  "packages/nx-plugin/src/executors/cargo-zigbuild/schema.ts": "e5cf3b0cc91a2d003a63ca0c9a93f1ec08263469b8a19dbe338b2dc0c0810747",
68
74
  "packages/nx-plugin/src/executors/scriptc-native/executor.ts": "4db61da4444d3a30acd3995b6cf53a4bc403a40fe856d88b2c30ce467badbea8",
@@ -7,12 +7,13 @@ import { type CloseOutcome } from './cpu-pool.js';
7
7
  * jobserver fifo and heartbeat share an event loop that runs nothing else, so the heartbeat proves that the actor which
8
8
  * admits and grants is turning.
9
9
  *
10
- * The thread is started with the pool's count. It says once that the pool serves, with the environment a task inherits,
10
+ * 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,
11
11
  * or why it cannot; the host's one message is its close, after which the thread says how the pool closed.
12
12
  */
13
- /** What the thread is started with. */
13
+ /** What the thread is started with: the run's count, and the run's memory in bytes its grants are charged against. */
14
14
  export interface CpuPoolThreadData {
15
15
  readonly tokens: number;
16
+ readonly memory: number;
16
17
  }
17
18
  /** What the thread says, in order: the pool serves or failed; after the host's close, how the pool closed. */
18
19
  export type CpuPoolThreadReport = {
@@ -1 +1 @@
1
- {"version":3,"file":"cpu-pool-thread.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/cpu-pool-thread.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,YAAY,EAAiB,MAAM,eAAe,CAAC;AAEjE;;;;;;;;;;GAUG;AAEH,uCAAuC;AACvC,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,8GAA8G;AAC9G,MAAM,MAAM,mBAAmB,GAC3B;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GAC1E;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACnD;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAA;CAAE,CAAC"}
1
+ {"version":3,"file":"cpu-pool-thread.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/cpu-pool-thread.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,YAAY,EAAiB,MAAM,eAAe,CAAC;AAEjE;;;;;;;;;;GAUG;AAEH,sHAAsH;AACtH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,8GAA8G;AAC9G,MAAM,MAAM,mBAAmB,GAC3B;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GAC1E;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACnD;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAA;CAAE,CAAC"}
@@ -7,7 +7,7 @@ if (host === null) {
7
7
  const report = (message) => host.postMessage(message);
8
8
  const data = workerData;
9
9
  // The pool lives until its host closes it, or with the thread.
10
- const made = await createCpuPool(data.tokens, new Promise(() => { }));
10
+ const made = await createCpuPool(data.tokens, new Promise(() => { }), data.memory);
11
11
  if (made.ok) {
12
12
  const { pool } = made;
13
13
  host.once('message', () => {
@@ -1,3 +1,4 @@
1
+ import typia from 'typia';
1
2
  import { type Unleased } from './gateway-lease.js';
2
3
  /**
3
4
  * A CPU pool: the tokens a process lends the runners it starts, held live rather than inherited as a
@@ -12,6 +13,11 @@ import { type Unleased } from './gateway-lease.js';
12
13
  * lasts while its connection does, so a child that dies returns its tokens with its socket. A pool
13
14
  * grants only from its own count, and a pool whose upstream grant has gone grants nothing.
14
15
  *
16
+ * A run's own pool also charges memory (`pool-admission.ts`; specs/cowshed/05_gateway.md, "Without mbx, every Nx run
17
+ * budgets itself"). A request names its task's last recorded peak as `memory`, in bytes, and is granted only while
18
+ * the charges of the leaves holding grants and its own fit the run's memory; a request that names none is charged
19
+ * nothing, as mbx's omitted `--memory` is. A sub-pool charges no memory: its holder's charge covers its tree.
20
+ *
15
21
  * The same count is a GNU make jobserver fifo beside the socket, mode 0600, which Cargo, its build
16
22
  * scripts and every nested `cargo` read through `CARGO_MAKEFLAGS`/`MAKEFLAGS` (specs/cowshed/05_gateway.md,
17
23
  * "Cargo reads its holder's jobserver"). A pool of `g` holds `g − 1` token bytes there; the holder's own
@@ -44,6 +50,10 @@ export type CloseOutcome = {
44
50
  ok: false;
45
51
  error: string;
46
52
  };
53
+ /** A grant whose charge alone exceeds the run's memory, made while nothing else held memory: the run's memory. */
54
+ export interface Oversized {
55
+ readonly memory: number & typia.tags.Type<'uint64'>;
56
+ }
47
57
  /**
48
58
  * The inherited descriptor, or null when malformed or absent. A missing or bare count, or an empty
49
59
  * or NUL-bearing endpoint, proves no allocation; the count is a positive whole number. A valid
@@ -51,28 +61,32 @@ export type CloseOutcome = {
51
61
  */
52
62
  export declare function readInheritedCpuPool(environment: Readonly<NodeJS.ProcessEnv>): InheritedCpuPool | null;
53
63
  /**
54
- * Tokens a parent pool lent, held until released, or why there are none. `closed` resolves when the grant's
55
- * connection closes, however it closes, so a sub-pool built on the grant ends with it.
64
+ * Tokens a parent pool lent, held until released, or why there are none. `oversized` names the run's memory when the
65
+ * child's charge alone exceeds it and it was granted because nothing else held memory. `closed` resolves when the
66
+ * grant's connection closes, however it closes, so a sub-pool built on the grant ends with it.
56
67
  */
57
68
  export type TokenGrant = {
58
69
  granted: true;
59
70
  tokens: number;
71
+ oversized: Oversized | null;
60
72
  release: () => void;
61
73
  closed: Promise<void>;
62
74
  } | Unleased;
63
75
  /**
64
- * Ask the immediate parent pool for `want` tokens. The inherited count does not bound the ask: a pool grants at
65
- * most what it holds. A granted lease is the child's local allocation: its connection is the grant, and closing it
66
- * returns only that allocation. An absent endpoint grants nothing and refuses nothing; a connected endpoint's refusal
67
- * or protocol failure must fail admission rather than run the child beside its parent's count.
76
+ * Ask the immediate parent pool for `want` tokens, charged `memory` bytes: the task's last recorded peak, or null when
77
+ * it has none. The inherited count does not bound the ask: a pool grants at most what it holds. A granted lease is the
78
+ * child's local allocation: its connection is the grant, and closing it returns only that allocation. An absent
79
+ * endpoint grants nothing and refuses nothing; a connected endpoint's refusal or protocol failure must fail admission
80
+ * rather than run the child beside its parent's count.
68
81
  */
69
- export declare function takeParentCpuTokens(parent: InheritedCpuPool, want: number): Promise<TokenGrant>;
82
+ export declare function takeParentCpuTokens(parent: InheritedCpuPool, want: number, memory: number | null): Promise<TokenGrant>;
70
83
  /**
71
84
  * Make a pool of `tokens` that lives while `closed` does: when `closed` resolves the pool refuses
72
- * grants, ends its child connections, drains its jobserver fifo and removes its directory. Setup
73
- * failures are values; a non-positive or unsafe count is a programmer bug and throws.
85
+ * grants, ends its child connections, drains its jobserver fifo and removes its directory. A run's own
86
+ * pool charges its grants against `memory`, the run's memory in bytes; a sub-pool charges none (null).
87
+ * Setup failures are values; a non-positive or unsafe count is a programmer bug and throws.
74
88
  */
75
- export declare function createCpuPool(tokens: number, closed: Promise<void>): Promise<{
89
+ export declare function createCpuPool(tokens: number, closed: Promise<void>, memory: number | null): Promise<{
76
90
  ok: true;
77
91
  pool: CpuPool;
78
92
  } | {
@@ -1 +1 @@
1
- {"version":3,"file":"cpu-pool.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/cpu-pool.ts"],"names":[],"mappings":"AAQA,OAAO,EAAa,KAAK,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAI9D;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,yGAAyG;AACzG,eAAO,MAAM,YAAY,0BAA0B,CAAC;AAEpD,6FAA6F;AAC7F,MAAM,WAAW,gBAAgB;IAC/B,QAAQ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AAQ,CAAC;AAIb;;;;;;GAMG;AACH,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,gBAAgB,EACxB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GAAG,IAAI,GACpB,OAAO,CAAC,UAAU,CAAC,CAqCrB;AAsJD;;;;;GAKG;AACH,wBAAsB,aAAa,CACjC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,EACrB,MAAM,EAAE,MAAM,GAAG,IAAI,GACpB,OAAO,CAAC;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CA4VrE"}
@@ -1,5 +1,7 @@
1
1
  import * as _isTypeUint32_1 from "typia/lib/internal/_isTypeUint32";
2
+ import * as _isTypeUint64_1 from "typia/lib/internal/_isTypeUint64";
2
3
  import * as _jsonStringifyNumber_1 from "typia/lib/internal/_jsonStringifyNumber";
4
+ import * as _jsonStringifyTail_1 from "typia/lib/internal/_jsonStringifyTail";
3
5
  import * as _jsonStringifyString_1 from "typia/lib/internal/_jsonStringifyString";
4
6
  import * as _throwTypeGuardError_1 from "typia/lib/internal/_throwTypeGuardError";
5
7
  import { execFile } from 'node:child_process';
@@ -12,6 +14,7 @@ import typia from 'typia';
12
14
  import { ownedSocketDirectory } from '../../testing.js';
13
15
  import { holdLease } from './gateway-lease.js';
14
16
  import { CpuLeaseWait, HEARTBEAT_MS } from './lease-wait.js';
17
+ import { admit } from './pool-admission.js';
15
18
  import { CPU_TOKENS_ENV, parseInheritedTokens } from './runner-sizing.js';
16
19
  /**
17
20
  * A CPU pool: the tokens a process lends the runners it starts, held live rather than inherited as a
@@ -26,6 +29,11 @@ import { CPU_TOKENS_ENV, parseInheritedTokens } from './runner-sizing.js';
26
29
  * lasts while its connection does, so a child that dies returns its tokens with its socket. A pool
27
30
  * grants only from its own count, and a pool whose upstream grant has gone grants nothing.
28
31
  *
32
+ * A run's own pool also charges memory (`pool-admission.ts`; specs/cowshed/05_gateway.md, "Without mbx, every Nx run
33
+ * budgets itself"). A request names its task's last recorded peak as `memory`, in bytes, and is granted only while
34
+ * the charges of the leaves holding grants and its own fit the run's memory; a request that names none is charged
35
+ * nothing, as mbx's omitted `--memory` is. A sub-pool charges no memory: its holder's charge covers its tree.
36
+ *
29
37
  * The same count is a GNU make jobserver fifo beside the socket, mode 0600, which Cargo, its build
30
38
  * scripts and every nested `cargo` read through `CARGO_MAKEFLAGS`/`MAKEFLAGS` (specs/cowshed/05_gateway.md,
31
39
  * "Cargo reads its holder's jobserver"). A pool of `g` holds `g − 1` token bytes there; the holder's own
@@ -37,8 +45,8 @@ import { CPU_TOKENS_ENV, parseInheritedTokens } from './runner-sizing.js';
37
45
  export const CPU_POOL_ENV = 'BOUNDED_EXEC_CPU_POOL';
38
46
  /** Exactly a request's fields: any other field is an invalid request. */
39
47
  const isRequest = (() => {
40
- const _io0 = (input, _exceptionable = true) => "cpu-pool" === input.op && ("number" === typeof input.want && (_isTypeUint32_1._isTypeUint32(input.want) && 1 <= input.want)) && (2 === Object.keys(input).length || Object.keys(input).every(key => {
41
- if (["op", "want"].some(prop => key === prop))
48
+ const _io0 = (input, _exceptionable = true) => "cpu-pool" === input.op && ("number" === typeof input.want && (_isTypeUint32_1._isTypeUint32(input.want) && 1 <= input.want)) && (undefined === input.memory || "number" === typeof input.memory && _isTypeUint64_1._isTypeUint64(input.memory)) && (2 === Object.keys(input).length || Object.keys(input).every(key => {
49
+ if (["op", "want", "memory"].some(prop => key === prop))
42
50
  return true;
43
51
  const value = input[key];
44
52
  if (undefined === value)
@@ -51,8 +59,9 @@ const stringifyReply = (() => {
51
59
  const _ip0 = input => true === input["ok"];
52
60
  const _so0 = input => `{"ok":${String(input.ok)},"progress":${String(_jsonStringifyNumber_1._jsonStringifyNumber(input.progress))}}`;
53
61
  const _so1 = input => `{"ok":${String(input.ok)},"lease":${"\"" + input.lease + "\""},"server":${String(_jsonStringifyNumber_1._jsonStringifyNumber(input.server))}}`;
54
- const _so2 = input => `{"ok":${String(input.ok)},"lease":${"\"" + input.lease + "\""},"tokens":${String(_jsonStringifyNumber_1._jsonStringifyNumber(input.tokens))}}`;
55
- const _so3 = input => `{"ok":${String(input.ok)},"code":${"\"" + input.code + "\""},"error":${_jsonStringifyString_1._jsonStringifyString(input.error)}}`;
62
+ const _so2 = input => `{${_jsonStringifyTail_1._jsonStringifyTail(`"ok":${String(input.ok)},"lease":${"\"" + input.lease + "\""},"tokens":${String(_jsonStringifyNumber_1._jsonStringifyNumber(input.tokens))},${undefined === input.oversized ? "" : `"oversized":${undefined !== input.oversized ? _so3(input.oversized) : undefined}`}`)}}`;
63
+ const _so3 = input => `{"memory":${String(_jsonStringifyNumber_1._jsonStringifyNumber(input.memory))}}`;
64
+ const _so4 = input => `{"ok":${String(input.ok)},"code":${"\"" + input.code + "\""},"error":${_jsonStringifyString_1._jsonStringifyString(input.error)}}`;
56
65
  const _su0 = input => (() => {
57
66
  if (undefined !== input.progress)
58
67
  return _so0(input);
@@ -61,18 +70,19 @@ const stringifyReply = (() => {
61
70
  else if ("granted" === input.lease)
62
71
  return _so2(input);
63
72
  else if (false === input.ok)
64
- return _so3(input);
73
+ return _so4(input);
65
74
  else
66
75
  _throwTypeGuardError_1._throwTypeGuardError({
67
76
  method: "typia.json.createStringify",
68
- expected: "(CpuLeaseProgress | CpuLeaseQueued | { ok: true; lease: \"granted\"; tokens: number; } | { ok: false; code: \"invalid-request\"; error: string; })",
77
+ expected: "(CpuLeaseProgress | CpuLeaseQueued | { ok: true; lease: \"granted\"; tokens: number; oversized?: Oversized | undefined; } | { ok: false; code: \"invalid-request\"; error: string; })",
69
78
  value: input
70
79
  });
71
80
  })();
72
81
  const _io0 = input => _ip0(input) && "number" === typeof input.progress;
73
82
  const _io1 = input => _ip0(input) && "queued" === input.lease && ("number" === typeof input.server && _isTypeUint32_1._isTypeUint32(input.server));
74
- const _io2 = input => _ip0(input) && "granted" === input.lease && "number" === typeof input.tokens;
75
- const _io3 = input => false === input.ok && "invalid-request" === input.code && "string" === typeof input.error;
83
+ const _io2 = input => _ip0(input) && "granted" === input.lease && "number" === typeof input.tokens && (undefined === input.oversized || "object" === typeof input.oversized && null !== input.oversized && _io3(input.oversized));
84
+ const _io3 = input => "number" === typeof input.memory && _isTypeUint64_1._isTypeUint64(input.memory);
85
+ const _io4 = input => false === input.ok && "invalid-request" === input.code && "string" === typeof input.error;
76
86
  return input => _su0(input);
77
87
  })();
78
88
  /** A request over this many bytes is refused as `invalid-request` (specs/cowshed/05_gateway.md, "Wire"). */
@@ -104,16 +114,31 @@ export function readInheritedCpuPool(environment) {
104
114
  }
105
115
  return { socket, tokens };
106
116
  }
117
+ const isOversized = (() => {
118
+ const _io0 = (input, _exceptionable = true) => "number" === typeof input.memory && _isTypeUint64_1._isTypeUint64(input.memory) && (1 === Object.keys(input).length || Object.keys(input).every(key => {
119
+ if (["memory"].some(prop => key === prop))
120
+ return true;
121
+ const value = input[key];
122
+ if (undefined === value)
123
+ return true;
124
+ return false;
125
+ }));
126
+ return (input, _exceptionable = true) => "object" === typeof input && null !== input && _io0(input, true);
127
+ })();
107
128
  /**
108
- * Ask the immediate parent pool for `want` tokens. The inherited count does not bound the ask: a pool grants at
109
- * most what it holds. A granted lease is the child's local allocation: its connection is the grant, and closing it
110
- * returns only that allocation. An absent endpoint grants nothing and refuses nothing; a connected endpoint's refusal
111
- * or protocol failure must fail admission rather than run the child beside its parent's count.
129
+ * Ask the immediate parent pool for `want` tokens, charged `memory` bytes: the task's last recorded peak, or null when
130
+ * it has none. The inherited count does not bound the ask: a pool grants at most what it holds. A granted lease is the
131
+ * child's local allocation: its connection is the grant, and closing it returns only that allocation. An absent
132
+ * endpoint grants nothing and refuses nothing; a connected endpoint's refusal or protocol failure must fail admission
133
+ * rather than run the child beside its parent's count.
112
134
  */
113
- export async function takeParentCpuTokens(parent, want) {
135
+ export async function takeParentCpuTokens(parent, want, memory) {
114
136
  if (!Number.isSafeInteger(want) || want < 1) {
115
137
  throw new RangeError(`a child asks its parent pool for a positive count, not ${want} (pool ${parent.tokens})`);
116
138
  }
139
+ if (memory !== null && (!Number.isSafeInteger(memory) || memory < 0)) {
140
+ throw new RangeError(`a child is charged a whole number of bytes, not ${memory}`);
141
+ }
117
142
  if (parent.socket.length === 0 || parent.socket.includes('\0')) {
118
143
  return {
119
144
  granted: false,
@@ -121,11 +146,12 @@ export async function takeParentCpuTokens(parent, want) {
121
146
  reason: `the parent CPU pool's endpoint ${JSON.stringify(parent.socket)} is not a socket path`,
122
147
  };
123
148
  }
124
- const lease = await holdLease(parent.socket, { op: 'cpu-pool', want }, 'the parent CPU pool', new CpuLeaseWait());
149
+ const request = memory === null ? { op: 'cpu-pool', want } : { op: 'cpu-pool', want, memory };
150
+ const lease = await holdLease(parent.socket, request, 'the parent CPU pool', new CpuLeaseWait());
125
151
  if (!lease.granted) {
126
152
  return lease;
127
153
  }
128
- const tokens = lease.answer.tokens;
154
+ const { tokens, oversized } = lease.answer;
129
155
  if (typeof tokens !== 'number' || !Number.isInteger(tokens) || tokens < 1 || tokens > want) {
130
156
  lease.release();
131
157
  return {
@@ -134,7 +160,15 @@ export async function takeParentCpuTokens(parent, want) {
134
160
  reason: `the parent CPU pool granted ${JSON.stringify(tokens)} tokens for ${want}`,
135
161
  };
136
162
  }
137
- return { granted: true, tokens, release: lease.release, closed: lease.closed };
163
+ if (oversized !== undefined && !isOversized(oversized)) {
164
+ lease.release();
165
+ return {
166
+ granted: false,
167
+ cause: 'other',
168
+ reason: `the parent CPU pool named its memory ${JSON.stringify(oversized)} in a grant, which is no byte count`,
169
+ };
170
+ }
171
+ return { granted: true, tokens, oversized: oversized ?? null, release: lease.release, closed: lease.closed };
138
172
  }
139
173
  /** A thrown value's message. */
140
174
  const describe = (error) => (error instanceof Error ? error.message : String(error));
@@ -269,10 +303,11 @@ function watchFifo(path, took, failed) {
269
303
  }
270
304
  /**
271
305
  * Make a pool of `tokens` that lives while `closed` does: when `closed` resolves the pool refuses
272
- * grants, ends its child connections, drains its jobserver fifo and removes its directory. Setup
273
- * failures are values; a non-positive or unsafe count is a programmer bug and throws.
306
+ * grants, ends its child connections, drains its jobserver fifo and removes its directory. A run's own
307
+ * pool charges its grants against `memory`, the run's memory in bytes; a sub-pool charges none (null).
308
+ * Setup failures are values; a non-positive or unsafe count is a programmer bug and throws.
274
309
  */
275
- export async function createCpuPool(tokens, closed) {
310
+ export async function createCpuPool(tokens, closed, memory) {
276
311
  if (!Number.isSafeInteger(tokens) || tokens < 1) {
277
312
  throw new RangeError(`a CPU pool holds a positive safe integer of tokens, not ${tokens}`);
278
313
  }
@@ -300,6 +335,8 @@ export async function createCpuPool(tokens, closed) {
300
335
  const scratch = Buffer.allocUnsafe(tokens);
301
336
  // The holder's implicit first token, while a socket child holds it.
302
337
  let slotLent = false;
338
+ // The bytes the children holding grants are charged, against `memory`.
339
+ let heldMemory = 0;
303
340
  // The readability wait while the queue's head finds no token, else undefined.
304
341
  let watch;
305
342
  let closing = false;
@@ -353,49 +390,55 @@ export async function createCpuPool(tokens, closed) {
353
390
  fail(`its jobserver fifo could not be watched for a token: ${watching.error}`);
354
391
  }
355
392
  };
356
- // FIFO: the head takes `min(want, available)` as one grant once any token is available, where available is the
357
- // fifo bytes it can read without blocking plus the implicit slot while no child holds it. `arrived` is bytes the
358
- // readability wait already took. A waiting child holds nothing, so no child waits while it holds tokens another
359
- // child needs. Whatever bytes are in hand when no head can use them go straight back to the fifo.
393
+ // FIFO (`admit`): the head takes `min(want, available)` as one grant once any token is available and, in a run's
394
+ // pool, its charge fits beside the holders'; available is the fifo bytes it can read without blocking plus the
395
+ // implicit slot while no child holds it. `arrived` is bytes the readability wait already took. A waiting child holds
396
+ // nothing, so no child waits while it holds tokens another child needs. Whatever bytes are in hand when no head can
397
+ // use them go straight back to the fifo. A head that waits for memory watches the fifo for nothing: only a holder's
398
+ // close frees memory, and that close drains again.
360
399
  function drain(arrived) {
400
+ if (closing) {
401
+ stopWatching();
402
+ return;
403
+ }
404
+ // A child that half-closed or failed while queued leaves the line. Its `close` finds it gone from the queue.
405
+ for (let at = queue.length - 1; at >= 0; at -= 1) {
406
+ if (queue[at]?.child.socket.writable === false)
407
+ queue.splice(at, 1);
408
+ }
361
409
  let inHand = arrived;
362
- while (!closing) {
363
- const waiter = queue[0];
364
- if (waiter === undefined) {
365
- break;
366
- }
367
- if (!waiter.child.socket.writable) {
368
- // A child that half-closed or failed while queued. Its `close` finds it gone from the queue.
369
- queue.shift();
370
- continue;
371
- }
372
- if (inHand < waiter.want) {
373
- try {
374
- inHand += readTokens(jobserver, scratch, waiter.want - inHand);
375
- }
376
- catch (error) {
377
- fail(`its jobserver fifo could not be read: ${describe(error)}`);
378
- return;
379
- }
410
+ const wanted = Math.min(queue.reduce((sum, waiter) => sum + waiter.want, 0), scratch.length);
411
+ if (inHand < wanted) {
412
+ try {
413
+ inHand += readTokens(jobserver, scratch, wanted - inHand);
380
414
  }
381
- const granted = Math.min(waiter.want, inHand + (slotLent ? 0 : 1));
382
- if (granted === 0) {
383
- watchForTokens();
415
+ catch (error) {
416
+ fail(`its jobserver fifo could not be read: ${describe(error)}`);
384
417
  return;
385
418
  }
386
- queue.shift();
419
+ }
420
+ const admission = admit(queue, inHand + (slotLent ? 0 : 1), memory === null ? null : { capacity: memory, held: heldMemory });
421
+ queue.splice(0, admission.grants.length);
422
+ for (const { request, tokens: granted, oversized } of admission.grants) {
387
423
  // Fifo bytes first, the implicit slot last.
388
424
  const bytes = Math.min(granted, inHand);
389
425
  inHand -= bytes;
390
426
  const slot = granted > bytes;
391
427
  if (slot)
392
428
  slotLent = true;
393
- waiter.child.phase = { kind: 'holding', bytes, slot };
394
- waiter.child.socket.write(frame({ ok: true, lease: 'granted', tokens: granted }));
429
+ heldMemory += request.memory;
430
+ request.child.phase = { kind: 'holding', bytes, slot, memory: request.memory };
431
+ request.child.socket.write(frame(oversized && memory !== null
432
+ ? { ok: true, lease: 'granted', tokens: granted, oversized: { memory } }
433
+ : { ok: true, lease: 'granted', tokens: granted }));
434
+ }
435
+ if (admission.waiting === 'cpu') {
436
+ watchForTokens();
437
+ }
438
+ else {
439
+ stopWatching();
395
440
  }
396
- stopWatching();
397
- if (!closing)
398
- returnTokens(inHand);
441
+ returnTokens(inHand);
399
442
  }
400
443
  const refuse = (child, error) => {
401
444
  child.phase = { kind: 'done' };
@@ -423,6 +466,7 @@ export async function createCpuPool(tokens, closed) {
423
466
  // A closing pool drains its fifo whole; until then the bytes go back for the next holder.
424
467
  if (child.phase.slot)
425
468
  slotLent = false;
469
+ heldMemory -= child.phase.memory;
426
470
  if (!closing)
427
471
  returnTokens(child.phase.bytes);
428
472
  }
@@ -479,12 +523,12 @@ export async function createCpuPool(tokens, closed) {
479
523
  parsed = undefined;
480
524
  }
481
525
  if (!isRequest(parsed)) {
482
- refuse(child, 'a request is {"op":"cpu-pool","want":<a whole number of tokens, at least 1>}');
526
+ refuse(child, 'a request is {"op":"cpu-pool","want":<a whole number of tokens, at least 1>,"memory"?:<bytes it is charged>}');
483
527
  return;
484
528
  }
485
529
  const request = parsed;
486
530
  child.phase = { kind: 'queued' };
487
- queue.push({ child, want: request.want });
531
+ queue.push({ child, want: request.want, memory: request.memory ?? 0 });
488
532
  socket.write(frame({ ok: true, lease: 'queued', server: process.pid }));
489
533
  drain(0);
490
534
  });
@@ -1 +1 @@
1
- {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/executor.ts"],"names":[],"mappings":"AA0BA,OAAO,EAIL,KAAK,gBAAgB,EAItB,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,sBAAsB,EAAmB,MAAM,uBAAuB,CAAC;AAYhF,OAAO,EAA4C,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAG5F,OAAO,EAOL,KAAK,YAAY,EAClB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EASL,aA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