@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.
- package/README.md +59 -30
- package/dist/.build-inputs.json +15 -8
- package/dist/executors/bounded-exec/cpu-pool-thread.d.ts +3 -2
- package/dist/executors/bounded-exec/cpu-pool-thread.d.ts.map +1 -1
- package/dist/executors/bounded-exec/cpu-pool-thread.js +1 -1
- package/dist/executors/bounded-exec/cpu-pool.d.ts +24 -10
- package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/cpu-pool.js +96 -52
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
- package/dist/executors/bounded-exec/executor.js +192 -82
- package/dist/executors/bounded-exec/host-memory.d.ts +47 -0
- package/dist/executors/bounded-exec/host-memory.d.ts.map +1 -0
- package/dist/executors/bounded-exec/host-memory.darwin.d.ts +3 -0
- package/dist/executors/bounded-exec/host-memory.darwin.d.ts.map +1 -0
- package/dist/executors/bounded-exec/host-memory.darwin.js +40 -0
- package/dist/executors/bounded-exec/host-memory.js +29 -0
- package/dist/executors/bounded-exec/host-memory.linux.d.ts +14 -0
- package/dist/executors/bounded-exec/host-memory.linux.d.ts.map +1 -0
- package/dist/executors/bounded-exec/host-memory.linux.js +104 -0
- package/dist/executors/bounded-exec/leaf-peak.d.ts +55 -0
- package/dist/executors/bounded-exec/leaf-peak.d.ts.map +1 -0
- package/dist/executors/bounded-exec/leaf-peak.js +146 -0
- package/dist/executors/bounded-exec/mbx-pool.d.ts +17 -9
- package/dist/executors/bounded-exec/mbx-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/mbx-pool.js +29 -11
- package/dist/executors/bounded-exec/mbx-reservations.d.ts +41 -0
- package/dist/executors/bounded-exec/mbx-reservations.d.ts.map +1 -0
- package/dist/executors/bounded-exec/mbx-reservations.js +372 -0
- package/dist/executors/bounded-exec/peak-waiter.d.ts +2 -0
- package/dist/executors/bounded-exec/peak-waiter.d.ts.map +1 -0
- package/dist/executors/bounded-exec/peak-waiter.js +53 -0
- package/dist/executors/bounded-exec/pool-admission.d.ts +38 -0
- package/dist/executors/bounded-exec/pool-admission.d.ts.map +1 -0
- package/dist/executors/bounded-exec/pool-admission.js +31 -0
- package/dist/executors/bounded-exec/run-cpu-pool.d.ts +6 -4
- package/dist/executors/bounded-exec/run-cpu-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/run-cpu-pool.js +20 -7
- package/dist/executors/bounded-exec/runner-sizing.d.ts +5 -5
- package/dist/executors/bounded-exec/runner-sizing.d.ts.map +1 -1
- package/dist/executors/bounded-exec/runner-sizing.js +6 -6
- package/dist/executors/bounded-exec/verdict.d.ts +21 -2
- package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
- package/dist/executors/bounded-exec/verdict.js +27 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/package.json +1 -1
- package/src/executors/bounded-exec/cpu-pool-thread.ts +4 -3
- package/src/executors/bounded-exec/cpu-pool.ts +111 -49
- package/src/executors/bounded-exec/executor.ts +202 -77
- package/src/executors/bounded-exec/host-memory.darwin.ts +44 -0
- package/src/executors/bounded-exec/host-memory.linux.ts +115 -0
- package/src/executors/bounded-exec/host-memory.ts +70 -0
- package/src/executors/bounded-exec/leaf-peak.ts +151 -0
- package/src/executors/bounded-exec/mbx-pool.ts +33 -13
- package/src/executors/bounded-exec/mbx-reservations.ts +300 -0
- package/src/executors/bounded-exec/peak-waiter.ts +82 -0
- package/src/executors/bounded-exec/pool-admission.ts +64 -0
- package/src/executors/bounded-exec/run-cpu-pool.ts +20 -6
- package/src/executors/bounded-exec/runner-sizing.ts +6 -6
- package/src/executors/bounded-exec/verdict.ts +40 -6
- package/src/index.ts +4 -1
- package/test-timings.json +134 -131
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { writeSync } from 'node:fs';
|
|
2
|
+
import { HOST_MEMORY } from './host-memory.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The waiter a leaf's command runs under (`leaf-peak.ts`; specs/cowshed/13_telemetry.md, "Job resource peaks"). Started
|
|
6
|
+
* on Bun as `bun --config=/dev/null peak-waiter.js <report fd> <fds> <file> [args…]`, it spawns `file args` with its
|
|
7
|
+
* own stdin, stdout and stderr and each descriptor `fds` names (comma-separated) at its own number, writes the
|
|
8
|
+
* command's pid to the report descriptor, waits for the command, writes its peak there, each as one JSON line, and
|
|
9
|
+
* ends as the command did: with its exit code, or with its signal raised on itself. Node, which runs the executor,
|
|
10
|
+
* reaps a child without its rusage; Bun's `Subprocess.resourceUsage()` reports it: `ru_maxrss`, the largest resident
|
|
11
|
+
* set any one process of the tree it waited on reached.
|
|
12
|
+
*
|
|
13
|
+
* The waiter leads the leaf's process group, so the executor's group signals reach the command directly: it ignores
|
|
14
|
+
* SIGINT, SIGTERM and SIGHUP and outlives the command to report it. A SIGKILL of the group ends it unreported. The
|
|
15
|
+
* command whose pid it names is the leaf's runner, which a hang snapshot samples (specs/cowshed/08_testing.md).
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
interface BunSubprocess {
|
|
19
|
+
readonly exited: Promise<number>;
|
|
20
|
+
readonly exitCode: number | null;
|
|
21
|
+
readonly signalCode: NodeJS.Signals | null;
|
|
22
|
+
readonly pid: number;
|
|
23
|
+
resourceUsage(): { readonly maxRSS: number } | undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The two Bun APIs the waiter uses. */
|
|
27
|
+
interface BunSpawner {
|
|
28
|
+
readonly version: string;
|
|
29
|
+
spawn(argv: string[], options: { stdio: (number | 'inherit' | 'ignore')[] }): BunSubprocess;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function isBunSpawner(runtime: unknown): runtime is BunSpawner {
|
|
33
|
+
return (
|
|
34
|
+
typeof runtime === 'object' &&
|
|
35
|
+
runtime !== null &&
|
|
36
|
+
'spawn' in runtime &&
|
|
37
|
+
typeof runtime.spawn === 'function' &&
|
|
38
|
+
'version' in runtime &&
|
|
39
|
+
typeof runtime.version === 'string'
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const IGNORED = ['SIGINT', 'SIGTERM', 'SIGHUP'] as const;
|
|
44
|
+
const bun: unknown = Reflect.get(globalThis, 'Bun');
|
|
45
|
+
const [reportFd, list, file, ...args] = process.argv.slice(2);
|
|
46
|
+
if (!isBunSpawner(bun) || HOST_MEMORY === null || reportFd === undefined || list === undefined || file === undefined) {
|
|
47
|
+
throw new Error('peak-waiter runs on Bun, on Linux or macOS, as `peak-waiter.js <report fd> <fds> <file> [args…]`');
|
|
48
|
+
}
|
|
49
|
+
const report = (line: { started: number } | { peakBytes: number } | { unmeasured: string }): void => {
|
|
50
|
+
try {
|
|
51
|
+
writeSync(Number(reportFd), `${JSON.stringify(line)}\n`);
|
|
52
|
+
} catch {
|
|
53
|
+
// The executor that would read the report is gone.
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const passed = list === '' ? [] : list.split(',').map(Number);
|
|
57
|
+
const stdio: (number | 'inherit' | 'ignore')[] = ['inherit', 'inherit', 'inherit'];
|
|
58
|
+
for (let fd = 3; fd <= Math.max(2, ...passed); fd += 1) stdio.push(passed.includes(fd) ? fd : 'ignore');
|
|
59
|
+
const ignore = (): void => {};
|
|
60
|
+
for (const signal of IGNORED) process.on(signal, ignore);
|
|
61
|
+
let child: BunSubprocess;
|
|
62
|
+
try {
|
|
63
|
+
child = bun.spawn([file, ...args], { stdio });
|
|
64
|
+
} catch (error) {
|
|
65
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
66
|
+
report({ unmeasured: `the command did not start: ${reason}` });
|
|
67
|
+
writeSync(2, `bounded-exec: could not start ${file}: ${reason}\n`);
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
report({ started: child.pid });
|
|
71
|
+
await child.exited;
|
|
72
|
+
const usage = child.resourceUsage();
|
|
73
|
+
report(
|
|
74
|
+
usage === undefined
|
|
75
|
+
? { unmeasured: 'Bun read no resource usage for the exited command' }
|
|
76
|
+
: { peakBytes: HOST_MEMORY.peakBytes(usage.maxRSS, bun.version) },
|
|
77
|
+
);
|
|
78
|
+
if (child.signalCode !== null) {
|
|
79
|
+
for (const signal of IGNORED) process.removeListener(signal, ignore);
|
|
80
|
+
process.kill(process.pid, child.signalCode);
|
|
81
|
+
}
|
|
82
|
+
process.exit(child.exitCode ?? 1);
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The admission decision of a CPU pool (`cpu-pool.ts`; specs/cowshed/05_gateway.md, "Without mbx, every Nx run budgets
|
|
3
|
+
* itself"): which queued requests a pool grants, in FIFO order, from the tokens it has free and, for a run's own pool,
|
|
4
|
+
* the run's memory. Pure: the pool reads its jobserver fifo for the free count and keeps the holders' charges, and this
|
|
5
|
+
* decides.
|
|
6
|
+
*
|
|
7
|
+
* Every grant needs both. The head takes `min(want, free)` tokens once one is free, and only while the charges of the
|
|
8
|
+
* leaves holding grants plus its own fit the run's memory; a head that cannot be granted holds up every request behind
|
|
9
|
+
* it, and no request holds part of a grant while it waits for the rest. A leaf is charged its task's last recorded
|
|
10
|
+
* memory peak, and nothing while its task has none. A leaf whose own charge alone exceeds the run's memory could never
|
|
11
|
+
* fit, so it is granted once nothing else holds memory, and the grant says so.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** What a queued request asks: whole tokens, at least one, and its charge in bytes (0 for a task with no peak). */
|
|
15
|
+
export interface PoolAsk {
|
|
16
|
+
readonly want: number;
|
|
17
|
+
readonly memory: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** The run's memory a pool charges against, and the bytes its holders are charged; null for a pool that charges none. */
|
|
21
|
+
export interface MemoryLedger {
|
|
22
|
+
readonly capacity: number;
|
|
23
|
+
readonly held: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** One request's grant: the request, its tokens, and whether its charge alone exceeds the run's memory. */
|
|
27
|
+
export interface PoolGrant<Ask extends PoolAsk> {
|
|
28
|
+
readonly request: Ask;
|
|
29
|
+
readonly tokens: number;
|
|
30
|
+
readonly oversized: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The grants of the queue's first requests, in its order, and what the first request left waiting waits for: free
|
|
35
|
+
* tokens (`cpu`) or the run's memory (`memory`). `waiting` is null when every request was granted.
|
|
36
|
+
*/
|
|
37
|
+
export interface Admission<Ask extends PoolAsk> {
|
|
38
|
+
readonly grants: readonly PoolGrant<Ask>[];
|
|
39
|
+
readonly waiting: 'cpu' | 'memory' | null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function admit<Ask extends PoolAsk>(
|
|
43
|
+
queue: readonly Ask[],
|
|
44
|
+
available: number,
|
|
45
|
+
memory: MemoryLedger | null,
|
|
46
|
+
): Admission<Ask> {
|
|
47
|
+
const grants: PoolGrant<Ask>[] = [];
|
|
48
|
+
let free = available;
|
|
49
|
+
let held = memory?.held ?? 0;
|
|
50
|
+
for (const request of queue) {
|
|
51
|
+
const oversized = memory !== null && request.memory > memory.capacity;
|
|
52
|
+
if (memory !== null && held + request.memory > memory.capacity && !(oversized && held === 0)) {
|
|
53
|
+
return { grants, waiting: 'memory' };
|
|
54
|
+
}
|
|
55
|
+
const tokens = Math.min(request.want, free);
|
|
56
|
+
if (tokens === 0) {
|
|
57
|
+
return { grants, waiting: 'cpu' };
|
|
58
|
+
}
|
|
59
|
+
free -= tokens;
|
|
60
|
+
held += request.memory;
|
|
61
|
+
grants.push({ request, tokens, oversized });
|
|
62
|
+
}
|
|
63
|
+
return { grants, waiting: null };
|
|
64
|
+
}
|
|
@@ -5,6 +5,7 @@ import { logger } from 'nx/src/devkit-exports.js';
|
|
|
5
5
|
import type { PostTasksExecutionContext, PreTasksExecutionContext } from 'nx/src/project-graph/plugins/public-api.js';
|
|
6
6
|
import { type CloseOutcome, type CpuPool, readInheritedCpuPool } from './cpu-pool.js';
|
|
7
7
|
import type { CpuPoolThreadData, CpuPoolThreadReport } from './cpu-pool-thread.js';
|
|
8
|
+
import { type RunMemoryReading, RunMemoryUnreadable, readRunMemory } from './host-memory.js';
|
|
8
9
|
import { mbxPool } from './mbx-pool.js';
|
|
9
10
|
import { CPU_TOKENS_ENV, parseInheritedTokens } from './runner-sizing.js';
|
|
10
11
|
|
|
@@ -23,6 +24,10 @@ import { CPU_TOKENS_ENV, parseInheritedTokens } from './runner-sizing.js';
|
|
|
23
24
|
* one token per core, or the inherited positive `BOUNDED_EXEC_CPU_TOKENS` when that is fewer: inside a cowshed job
|
|
24
25
|
* that count is the job's own, so the job's `--want` bounds the run.
|
|
25
26
|
*
|
|
27
|
+
* The pool also charges memory: each leaf is charged its task's last recorded peak, and granted only while the charges
|
|
28
|
+
* of the leaves holding grants and its own fit the run's memory (`host-memory.ts`: the cgroup's `memory.max` on Linux,
|
|
29
|
+
* else the host's). A run whose memory cannot be read does not start.
|
|
30
|
+
*
|
|
26
31
|
* The pool runs on a thread of its own (`cpu-pool-thread.ts`). The process that serves it, the Nx daemon when installed
|
|
27
32
|
* plugins load in it or the Nx CLI without one, hashes the run's tasks and builds its project graph in synchronous calls
|
|
28
33
|
* on its main thread. In a gate on 2026-10-28 one `hashPlans` ran for 14.2 s, and sixteen runners queued on a pool on
|
|
@@ -67,20 +72,26 @@ export function runPoolTokens(env: Readonly<NodeJS.ProcessEnv>, cores: number):
|
|
|
67
72
|
}
|
|
68
73
|
|
|
69
74
|
/**
|
|
70
|
-
* Serve `context`'s run a pool of `runPoolTokens
|
|
71
|
-
*
|
|
72
|
-
*
|
|
75
|
+
* Serve `context`'s run a pool of `runPoolTokens`, charged against the run's memory `readMemory` reads, and publish it
|
|
76
|
+
* in `env`, which every task inherits, unless the run is served none. A run whose memory cannot be read throws
|
|
77
|
+
* `RunMemoryUnreadable`, which fails the run before any task starts: it is not shown to have room. A pool that cannot
|
|
78
|
+
* be made is said, and the run's tasks are then sized only by the ceilings they inherit.
|
|
73
79
|
*/
|
|
74
80
|
export async function serveRunCpuPool(
|
|
75
81
|
context: Pick<PreTasksExecutionContext, 'id'>,
|
|
76
82
|
env: NodeJS.ProcessEnv = process.env,
|
|
77
83
|
cores: number = availableParallelism(),
|
|
84
|
+
readMemory: () => Promise<RunMemoryReading> = readRunMemory,
|
|
78
85
|
): Promise<void> {
|
|
79
86
|
const tokens = runPoolTokens(env, cores);
|
|
80
87
|
if (tokens === null) {
|
|
81
88
|
return;
|
|
82
89
|
}
|
|
83
|
-
const
|
|
90
|
+
const memory = await readMemory();
|
|
91
|
+
if (!memory.ok) {
|
|
92
|
+
throw new RunMemoryUnreadable(memory.error);
|
|
93
|
+
}
|
|
94
|
+
const served = await servePoolThread(tokens, memory.memory.bytes);
|
|
84
95
|
if (!served.ok) {
|
|
85
96
|
logger.warn(
|
|
86
97
|
`bounded-exec: this run's CPU pool failed (${served.error}); its tasks are sized only by the ceilings they inherit`,
|
|
@@ -99,8 +110,11 @@ export async function serveRunCpuPool(
|
|
|
99
110
|
* has said how its pool closed fails whichever wait is open, a later close returns that failure, and a thread lost while
|
|
100
111
|
* its pool serves is said at once.
|
|
101
112
|
*/
|
|
102
|
-
function servePoolThread(tokens: number): Promise<ServedPool> {
|
|
103
|
-
const thread = new Worker(THREAD_ENTRY, {
|
|
113
|
+
function servePoolThread(tokens: number, memory: number): Promise<ServedPool> {
|
|
114
|
+
const thread = new Worker(THREAD_ENTRY, {
|
|
115
|
+
workerData: { tokens, memory } satisfies CpuPoolThreadData,
|
|
116
|
+
...THREAD_PRELOAD,
|
|
117
|
+
});
|
|
104
118
|
return new Promise<ServedPool>((served) => {
|
|
105
119
|
let state: ThreadState = { kind: 'starting', served };
|
|
106
120
|
let closing: Promise<CloseOutcome> | undefined;
|
|
@@ -56,8 +56,9 @@ export type ReservedDemand = Extract<Demand, { kind: 'nextest' | 'bun-parallel'
|
|
|
56
56
|
export const CPU_TOKENS_ENV = 'BOUNDED_EXEC_CPU_TOKENS';
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
|
-
* The cores mbx granted the reservation a leaf runs under:
|
|
60
|
-
* as were free once one was
|
|
59
|
+
* The cores mbx granted the reservation a leaf runs under: its run's mbx reservation endpoint grants at most the N the
|
|
60
|
+
* leaf asks for, as many as were free once one was, and the leaf's shell reads that count into this variable
|
|
61
|
+
* (mbx-pool.ts, `reservation`), the one `mbx reserve --cpus N` names to its own command.
|
|
61
62
|
*/
|
|
62
63
|
export const GRANTED_CPUS_ENV = 'MBX_RESERVE_CPUS';
|
|
63
64
|
|
|
@@ -369,13 +370,12 @@ export function sizeRunner(
|
|
|
369
370
|
/**
|
|
370
371
|
* The shell statements that run first in a reserved leaf's reservation and size its runner to the grant, which only
|
|
371
372
|
* the command learns as it starts: `CPU_TOKENS_ENV` becomes the cores mbx granted (`GRANTED_CPUS_ENV`), never more
|
|
372
|
-
* than the leaf asked for (`WANT_ENV`, set before it reserved)
|
|
373
|
-
*
|
|
374
|
-
* ceilings, outranking the target's own as a numeric grant's do (`sizeRunner`).
|
|
373
|
+
* than the leaf asked for (`WANT_ENV`, set before it reserved). The test-thread variables a sizing sets follow from it,
|
|
374
|
+
* under their inherited ceilings, outranking the target's own as a numeric grant's do (`sizeRunner`).
|
|
375
375
|
*/
|
|
376
376
|
export function grantedSizing(demand: ReservedDemand): string {
|
|
377
377
|
const asked = `$${WANT_ENV}`;
|
|
378
|
-
const named =
|
|
378
|
+
const named = `$${GRANTED_CPUS_ENV}`;
|
|
379
379
|
const tokens = `$${CPU_TOKENS_ENV}`;
|
|
380
380
|
const atMost = (ceiling: number | null): string =>
|
|
381
381
|
ceiling === null ? `"${tokens}"` : `"$(( ${tokens} < ${ceiling} ? ${tokens} : ${ceiling} ))"`;
|
|
@@ -25,8 +25,9 @@ import { TEST_FAILURES_FILE, TEST_RESULTS_FILE } from './test-results.js';
|
|
|
25
25
|
* - `no-space`: the run failed and its output said a write found no space (ENOSPC). Whatever its tests then reported,
|
|
26
26
|
* they failed on the disk, not on their own: the verdict names the line that said so and, when the task held one,
|
|
27
27
|
* its RAM temp volume as it stood when that line arrived.
|
|
28
|
-
* - `queued`: the command failed before any admission after a live task PID was explicitly seen waiting in mbx
|
|
29
|
-
*
|
|
28
|
+
* - `queued`: the command failed before any admission after a live task PID was explicitly seen waiting in mbx, or
|
|
29
|
+
* while its reserved leaf's request waited on its run's mbx reservation endpoint. Its observed wait, and any public
|
|
30
|
+
* queue positions, describe admission pressure, never a wedged test.
|
|
30
31
|
* - `failed`: anything else that did not pass. That includes an assertion named in the report,
|
|
31
32
|
* or a non-zero exit with no report to say why.
|
|
32
33
|
*/
|
|
@@ -100,6 +101,13 @@ export interface BoundedExecRecord {
|
|
|
100
101
|
* expired; written for the reader of a refused run, never read back.
|
|
101
102
|
*/
|
|
102
103
|
readonly cpuWait?: CpuWaitRow;
|
|
104
|
+
/**
|
|
105
|
+
* The command's memory peak in bytes when it ended (specs/cowshed/13_telemetry.md, "Job resource peaks"): its rusage
|
|
106
|
+
* `ru_maxrss`, the largest resident set any one process of its tree reached, as its waiter read it (`leaf-peak.ts`).
|
|
107
|
+
* Null when it was not measured: the command never ran, the waiter ended before it, or no Bun waited on it; never
|
|
108
|
+
* zero for that. The task's next run is charged it in its run's pool (`readLastPeak`).
|
|
109
|
+
*/
|
|
110
|
+
readonly peakBytes: number | null;
|
|
103
111
|
}
|
|
104
112
|
|
|
105
113
|
/** The Nx task a run executes as. Nx gives an executor no task id, only its parts. */
|
|
@@ -487,6 +495,23 @@ export async function readRecord(directory: string): Promise<BoundedExecRecord |
|
|
|
487
495
|
return parseRecord(JSON.parse(text));
|
|
488
496
|
}
|
|
489
497
|
|
|
498
|
+
/**
|
|
499
|
+
* The peak the task's last record in `directory` names: its charge in its run's pool. Null when the task has no record
|
|
500
|
+
* or its record no peak; a record that cannot be read is an error naming it, never a charge of nothing.
|
|
501
|
+
*/
|
|
502
|
+
export async function readLastPeak(
|
|
503
|
+
directory: string,
|
|
504
|
+
): Promise<{ ok: true; peakBytes: number | null } | { ok: false; error: string }> {
|
|
505
|
+
try {
|
|
506
|
+
return { ok: true, peakBytes: (await readRecord(directory))?.peakBytes ?? null };
|
|
507
|
+
} catch (error) {
|
|
508
|
+
return {
|
|
509
|
+
ok: false,
|
|
510
|
+
error: `the task's last record ${join(directory, VERDICT_FILE)} cannot be read: ${error instanceof Error ? error.message : String(error)}`,
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
|
|
490
515
|
/** The JUnit report a command wrote into `directory`, or `null` when it wrote none. */
|
|
491
516
|
export async function readJunitReport(
|
|
492
517
|
directory: string,
|
|
@@ -510,7 +535,12 @@ function parseRecord(value: unknown): BoundedExecRecord {
|
|
|
510
535
|
if (!isObject(value) || typeof value.task !== 'string' || !(typeof value.hash === 'string' || value.hash === null)) {
|
|
511
536
|
throw new Error(`not a bounded-exec record: ${JSON.stringify(value)}`);
|
|
512
537
|
}
|
|
513
|
-
|
|
538
|
+
// A record written before peaks were recorded carries none.
|
|
539
|
+
const peakBytes = value.peakBytes ?? null;
|
|
540
|
+
if (!(peakBytes === null || (typeof peakBytes === 'number' && Number.isSafeInteger(peakBytes) && peakBytes >= 0))) {
|
|
541
|
+
throw new Error(`not a bounded-exec record: ${JSON.stringify(value)}`);
|
|
542
|
+
}
|
|
543
|
+
return { task: value.task, hash: value.hash, verdict: parseVerdict(value.verdict), peakBytes };
|
|
514
544
|
}
|
|
515
545
|
|
|
516
546
|
function parseVerdict(value: unknown): BoundedExecVerdict {
|
|
@@ -672,9 +702,13 @@ export async function failedTasksOfRun(runJson: unknown, workspaceData: string):
|
|
|
672
702
|
|
|
673
703
|
/** The same honest admission diagnostic in live output and a terminal verdict. */
|
|
674
704
|
export function describeAdmissionQueue(wait: AdmissionQueueWait): string {
|
|
675
|
-
|
|
676
|
-
.
|
|
677
|
-
|
|
705
|
+
const where =
|
|
706
|
+
wait.requests.length === 0
|
|
707
|
+
? "on its run's mbx reservation endpoint"
|
|
708
|
+
: `mbx ${wait.requests
|
|
709
|
+
.map((request) => `pid=${request.pid} ticket=${request.ticket} queue position=${request.queuePosition}`)
|
|
710
|
+
.join(', ')}`;
|
|
711
|
+
return `queued for admission ${(wait.waitedMs / 1_000).toFixed(1)} s; ${where}`;
|
|
678
712
|
}
|
|
679
713
|
export function describeVerdict(verdict: BoundedExecVerdict): string {
|
|
680
714
|
switch (verdict.outcome) {
|
package/src/index.ts
CHANGED
|
@@ -82,6 +82,7 @@ import {
|
|
|
82
82
|
type AllVerdictsOptions,
|
|
83
83
|
ESLINT_SOURCES_TOKEN,
|
|
84
84
|
} from './executors/all-verdicts/schema.js';
|
|
85
|
+
import { closeRunReservations, serveRunReservations } from './executors/bounded-exec/mbx-reservations.js';
|
|
85
86
|
import { closeRunCpuPool, serveRunCpuPool } from './executors/bounded-exec/run-cpu-pool.js';
|
|
86
87
|
import { ffiPathProblem } from './executors/scriptc-native/ffi-paths.js';
|
|
87
88
|
import type { ScriptcNativeFfi } from './executors/scriptc-native/schema.js';
|
|
@@ -1219,7 +1220,7 @@ function isBuildOutputPackageJson(packageJsonPath: string): boolean {
|
|
|
1219
1220
|
* hint and the opt-in producer completion receipts. Each sees the same options and run context; neither reads the
|
|
1220
1221
|
* other's output. The hint is recorded first so a producer-receipt bug cannot cost the controller its evidence. The
|
|
1221
1222
|
* pair also serves a run that inherits no CPU pool its own, which every task inherits (`run-cpu-pool.ts`), and closes
|
|
1222
|
-
* it when the run ends. Last, once every task has finished, the post hook starts the reclaim of the
|
|
1223
|
+
* 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
|
|
1223
1224
|
* superseded Cargo unit generations of each Cargo workspace the run built into, in a process of its own, never on
|
|
1224
1225
|
* Nx's thread (`@smoothbricks/cargo-retain`).
|
|
1225
1226
|
*/
|
|
@@ -1230,11 +1231,13 @@ export const preTasksExecution: PreTasksExecution<ProducerReceiptsOptions> = asy
|
|
|
1230
1231
|
preTaskResults(options, context);
|
|
1231
1232
|
await preProducerReceipts(options, context);
|
|
1232
1233
|
await serveRunCpuPool(context);
|
|
1234
|
+
await serveRunReservations(context);
|
|
1233
1235
|
};
|
|
1234
1236
|
export const postTasksExecution: PostTasksExecution<ProducerReceiptsOptions> = async (options, context) => {
|
|
1235
1237
|
await postTaskResults(options, context);
|
|
1236
1238
|
await postProducerReceipts(options, context);
|
|
1237
1239
|
await closeRunCpuPool(context);
|
|
1240
|
+
await closeRunReservations(context);
|
|
1238
1241
|
await postCargoRetention(options, context);
|
|
1239
1242
|
};
|
|
1240
1243
|
|