@smoothbricks/nx-plugin 0.7.6 → 0.7.8
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 +4 -1
- package/dist/.build-inputs.json +9 -9
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
- package/dist/executors/bounded-exec/executor.js +17 -17
- package/dist/executors/bounded-exec/host-memory.d.ts +7 -0
- package/dist/executors/bounded-exec/host-memory.d.ts.map +1 -1
- package/dist/executors/bounded-exec/host-memory.darwin.d.ts.map +1 -1
- package/dist/executors/bounded-exec/host-memory.darwin.js +76 -1
- package/dist/executors/bounded-exec/host-memory.linux.d.ts.map +1 -1
- package/dist/executors/bounded-exec/host-memory.linux.js +34 -1
- package/dist/executors/bounded-exec/leaf-peak.d.ts +5 -4
- package/dist/executors/bounded-exec/leaf-peak.d.ts.map +1 -1
- package/dist/executors/bounded-exec/leaf-peak.js +5 -4
- package/dist/executors/bounded-exec/mbx-reservations.d.ts +22 -0
- package/dist/executors/bounded-exec/mbx-reservations.d.ts.map +1 -1
- package/dist/executors/bounded-exec/mbx-reservations.js +22 -0
- package/dist/executors/bounded-exec/peak-waiter.js +27 -1
- package/dist/managed-files/ci-workflow.d.ts +7 -0
- package/dist/managed-files/ci-workflow.d.ts.map +1 -1
- package/dist/managed-files/ci-workflow.js +11 -4
- package/dist/managed-files/publish-workflow.d.ts.map +1 -1
- package/dist/managed-files/publish-workflow.js +13 -4
- package/managed/raw/patches/ttsc@0.34.1.patch +388 -0
- package/managed/templates/github/actions/setup-devenv/action.yml +69 -3
- package/package.json +3 -3
- package/src/executors/bounded-exec/executor.ts +18 -18
- package/src/executors/bounded-exec/host-memory.darwin.ts +104 -1
- package/src/executors/bounded-exec/host-memory.linux.ts +33 -1
- package/src/executors/bounded-exec/host-memory.ts +7 -0
- package/src/executors/bounded-exec/leaf-peak.ts +5 -4
- package/src/executors/bounded-exec/mbx-reservations.ts +30 -0
- package/src/executors/bounded-exec/peak-waiter.ts +37 -4
- package/src/managed-files/ci-workflow.ts +12 -4
- package/src/managed-files/publish-workflow.ts +15 -3
- package/test-timings.json +2 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ChildProcess, type IOType, spawn } from 'node:child_process';
|
|
2
2
|
import { accessSync, constants } from 'node:fs';
|
|
3
3
|
import { mkdtemp, rm } from 'node:fs/promises';
|
|
4
|
-
import { availableParallelism, userInfo } from 'node:os';
|
|
4
|
+
import { availableParallelism, constants as osConstants, userInfo } from 'node:os';
|
|
5
5
|
import { delimiter, isAbsolute, join, resolve as resolvePath } from 'node:path';
|
|
6
6
|
import { createInterface } from 'node:readline';
|
|
7
7
|
import { Duplex, Readable } from 'node:stream';
|
|
@@ -49,7 +49,7 @@ import {
|
|
|
49
49
|
withMbxLeaf,
|
|
50
50
|
} from './mbx-pool.js';
|
|
51
51
|
import { MBX_QUEUE_POLL_MS, type MbxQueuedRequest, snapshotMbxQueue } from './mbx-queue.js';
|
|
52
|
-
import { RESERVATIONS_ENV, type Reservation, reserveCores } from './mbx-reservations.js';
|
|
52
|
+
import { describeUnserved, RESERVATIONS_ENV, type Reservation, reserveCores, runEndpoint } from './mbx-reservations.js';
|
|
53
53
|
import { createNoSpaceWatch } from './no-space.js';
|
|
54
54
|
import {
|
|
55
55
|
COWSHED_EXECUTABLE_ENV,
|
|
@@ -105,12 +105,6 @@ type IdleDiagnosticResult =
|
|
|
105
105
|
| { kind: 'pending'; startedAtMs: number | null }
|
|
106
106
|
| { kind: 'captured'; snapshot: HangDiagnostics }
|
|
107
107
|
| { kind: 'failed'; detail: string };
|
|
108
|
-
const EXIT_CODE_BY_SIGNAL: Partial<Record<NodeJS.Signals, number>> = {
|
|
109
|
-
SIGHUP: 129,
|
|
110
|
-
SIGINT: 130,
|
|
111
|
-
SIGTERM: 143,
|
|
112
|
-
};
|
|
113
|
-
|
|
114
108
|
/** The pool descriptor: only a grant may give it, so neither the target's nor the inherited environment passes it on. */
|
|
115
109
|
const POOL_ENV = [CPU_TOKENS_ENV, CPU_POOL_ENV];
|
|
116
110
|
/**
|
|
@@ -715,13 +709,15 @@ export async function runBoundedExec(
|
|
|
715
709
|
return refuse(`cowshed: cpu-pool parent pool refused: ${parentRefusal}; refusing to run the command\n`);
|
|
716
710
|
}
|
|
717
711
|
// A reserved leaf takes its cores from its Nx run's mbx reservation endpoint (mbx-reservations.ts). A run that serves
|
|
718
|
-
// none said why in its own output
|
|
719
|
-
|
|
720
|
-
|
|
712
|
+
// none said why in its own output, which a gate's failures-only output never shows, so the refusal says it too; the
|
|
713
|
+
// leaf does not run beside the pool.
|
|
714
|
+
const endpoint = leaf?.kind === 'reserve' ? runEndpoint(process.env) : null;
|
|
715
|
+
if (endpoint !== null && endpoint.kind !== 'served') {
|
|
721
716
|
return refuse(
|
|
722
|
-
`cowshed: a reserved leaf takes its cores from its Nx run's mbx reservation endpoint, and ${RESERVATIONS_ENV} names none (
|
|
717
|
+
`cowshed: a reserved leaf takes its cores from its Nx run's mbx reservation endpoint, and ${RESERVATIONS_ENV} names none: ${describeUnserved(endpoint)}; refusing to run the command\n`,
|
|
723
718
|
);
|
|
724
719
|
}
|
|
720
|
+
const reserved = leaf?.kind === 'reserve' && endpoint?.kind === 'served' ? { leaf, endpoint: endpoint.socket } : null;
|
|
725
721
|
|
|
726
722
|
// A granted run serves a sub-pool of its own grant, so its descendants draw from that and never from above it.
|
|
727
723
|
// A pool that cannot be set up refuses the run: no granted command runs beside its grant.
|
|
@@ -1448,10 +1444,16 @@ export async function runBoundedExec(
|
|
|
1448
1444
|
|
|
1449
1445
|
const code = exitCode ?? signalToExitCode(exitSignal);
|
|
1450
1446
|
if (code !== 0 && state.expiry === null) {
|
|
1447
|
+
// No bound of this executor ended it, so a signal it died of came from outside (the kernel's OOM killer sends
|
|
1448
|
+
// SIGKILL): the signal is named, never folded into a bare status.
|
|
1449
|
+
const ended =
|
|
1450
|
+
exitCode === null && exitSignal !== null
|
|
1451
|
+
? `was killed by ${exitSignal} (status ${code})`
|
|
1452
|
+
: `exited with status ${code}`;
|
|
1451
1453
|
appendStderr(
|
|
1452
1454
|
fixture !== null && !mainStarted
|
|
1453
|
-
? `Fixture command
|
|
1454
|
-
: `Command
|
|
1455
|
+
? `Fixture command ${ended}: ${segment ?? fixture.command}\n`
|
|
1456
|
+
: `Command ${ended}: ${command}\n`,
|
|
1455
1457
|
);
|
|
1456
1458
|
}
|
|
1457
1459
|
|
|
@@ -1550,11 +1552,9 @@ function targetEnv(env: Record<string, string> | undefined, say: (text: string)
|
|
|
1550
1552
|
return kept;
|
|
1551
1553
|
}
|
|
1552
1554
|
|
|
1555
|
+
/** The status a shell gives a command a signal ended: 128 plus the signal's number (SIGKILL 137, SIGTERM 143). */
|
|
1553
1556
|
function signalToExitCode(signal: NodeJS.Signals | null): number {
|
|
1554
|
-
|
|
1555
|
-
return 1;
|
|
1556
|
-
}
|
|
1557
|
-
return EXIT_CODE_BY_SIGNAL[signal] ?? 1;
|
|
1557
|
+
return signal === null ? 1 : 128 + osConstants.signals[signal];
|
|
1558
1558
|
}
|
|
1559
1559
|
|
|
1560
1560
|
/** Resolves when `promise` settles or `ms` passes, whichever is first, leaving no timer behind. */
|
|
@@ -41,4 +41,107 @@ async function readRunMemory(): Promise<RunMemoryReading> {
|
|
|
41
41
|
return { ok: true, memory: { bytes, source: HW_MEMSIZE } };
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Bun's FFI, as the peak waiter reaches it. Node, which runs the executor, loads this module too and has no `bun:ffi`;
|
|
46
|
+
* only the waiter, on Bun, reads a tree's footprint, so the FFI loads on its first read, by a specifier the compiler
|
|
47
|
+
* does not resolve against Node's types.
|
|
48
|
+
*/
|
|
49
|
+
const BUN_FFI = 'bun:ffi';
|
|
50
|
+
const LIBPROC = '/usr/lib/libproc.dylib';
|
|
51
|
+
/** `proc_pid_rusage`'s oldest flavor, whose fields every later one starts with. */
|
|
52
|
+
const RUSAGE_INFO_V0 = 0;
|
|
53
|
+
/** `rusage_info_v0`: a 16-byte uuid, then ten u64 counters; `ri_phys_footprint` is the eighth, u64 index 9. */
|
|
54
|
+
const RUSAGE_INFO_V0_WORDS = 12;
|
|
55
|
+
const PHYS_FOOTPRINT = 9;
|
|
56
|
+
|
|
57
|
+
interface BunFfi {
|
|
58
|
+
dlopen(path: string, symbols: Record<string, { args: string[]; returns: string }>): { symbols: unknown };
|
|
59
|
+
ptr(view: ArrayBufferView): number;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** The two libproc calls a tree's footprint takes, each pointer a Bun FFI address. */
|
|
63
|
+
interface LibprocSymbols {
|
|
64
|
+
/** The pids whose parent is `pid`, written into `into` (`bytes` long): how many, or -1. */
|
|
65
|
+
proc_listchildpids(pid: number, into: number, bytes: number): number;
|
|
66
|
+
/** `pid`'s `rusage_info` of `flavor`, written into `into`: 0, or -1 once nothing it may read holds the pid. */
|
|
67
|
+
proc_pid_rusage(pid: number, flavor: number, into: number): number;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function isBunFfi(module: unknown): module is BunFfi {
|
|
71
|
+
return (
|
|
72
|
+
typeof module === 'object' &&
|
|
73
|
+
module !== null &&
|
|
74
|
+
'dlopen' in module &&
|
|
75
|
+
typeof module.dlopen === 'function' &&
|
|
76
|
+
'ptr' in module &&
|
|
77
|
+
typeof module.ptr === 'function'
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function isLibprocSymbols(symbols: unknown): symbols is LibprocSymbols {
|
|
82
|
+
return (
|
|
83
|
+
typeof symbols === 'object' &&
|
|
84
|
+
symbols !== null &&
|
|
85
|
+
'proc_listchildpids' in symbols &&
|
|
86
|
+
typeof symbols.proc_listchildpids === 'function' &&
|
|
87
|
+
'proc_pid_rusage' in symbols &&
|
|
88
|
+
typeof symbols.proc_pid_rusage === 'function'
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** One process's children and footprint, as libproc reads them. */
|
|
93
|
+
interface Footprints {
|
|
94
|
+
children(pid: number): number[];
|
|
95
|
+
/** What `pid` holds, or 0 once it is gone (or, a setuid program, unreadable to its owner's uid). */
|
|
96
|
+
footprint(pid: number): number;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
let footprints: Promise<Footprints> | undefined;
|
|
100
|
+
|
|
101
|
+
async function loadFootprints(): Promise<Footprints> {
|
|
102
|
+
const ffi: unknown = await import(BUN_FFI);
|
|
103
|
+
if (!isBunFfi(ffi)) {
|
|
104
|
+
throw new Error(`${BUN_FFI} names no dlopen and ptr: a tree's footprint is read on Bun, by the peak waiter`);
|
|
105
|
+
}
|
|
106
|
+
const { symbols } = ffi.dlopen(LIBPROC, {
|
|
107
|
+
proc_listchildpids: { args: ['i32', 'ptr', 'i32'], returns: 'i32' },
|
|
108
|
+
proc_pid_rusage: { args: ['i32', 'i32', 'ptr'], returns: 'i32' },
|
|
109
|
+
});
|
|
110
|
+
if (!isLibprocSymbols(symbols)) {
|
|
111
|
+
throw new Error(`${LIBPROC} opened without proc_listchildpids and proc_pid_rusage`);
|
|
112
|
+
}
|
|
113
|
+
const usage = new BigUint64Array(RUSAGE_INFO_V0_WORDS);
|
|
114
|
+
const usageAt = ffi.ptr(usage);
|
|
115
|
+
let pids = new Int32Array(256);
|
|
116
|
+
return {
|
|
117
|
+
children(pid) {
|
|
118
|
+
// A full buffer may have cut the list short: it is read again into one twice the size.
|
|
119
|
+
for (;;) {
|
|
120
|
+
const count = symbols.proc_listchildpids(pid, ffi.ptr(pids), pids.byteLength);
|
|
121
|
+
if (count < pids.length) return count <= 0 ? [] : Array.from(pids.subarray(0, count));
|
|
122
|
+
pids = new Int32Array(pids.length * 2);
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
footprint(pid) {
|
|
126
|
+
return symbols.proc_pid_rusage(pid, RUSAGE_INFO_V0, usageAt) === 0 ? Number(usage[PHYS_FOOTPRINT]) : 0;
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** What the tree rooted at `root` holds: each member's `ri_phys_footprint`, the tree walked by `proc_listchildpids`. */
|
|
132
|
+
async function treeResidentBytes(root: number): Promise<number> {
|
|
133
|
+
footprints ??= loadFootprints();
|
|
134
|
+
const proc = await footprints;
|
|
135
|
+
const seen = new Set<number>();
|
|
136
|
+
const pending = [root];
|
|
137
|
+
let total = 0;
|
|
138
|
+
for (let pid = pending.pop(); pid !== undefined; pid = pending.pop()) {
|
|
139
|
+
if (seen.has(pid)) continue;
|
|
140
|
+
seen.add(pid);
|
|
141
|
+
total += proc.footprint(pid);
|
|
142
|
+
pending.push(...proc.children(pid));
|
|
143
|
+
}
|
|
144
|
+
return total;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export const darwinMemory: HostMemory = { readRunMemory, peakBytes: (maxRss) => maxRss, treeResidentBytes };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
2
|
import { posix } from 'node:path';
|
|
3
|
+
import { childPids } from '../../process-children.linux.js';
|
|
3
4
|
import type { HostMemory, RunMemory, RunMemoryError, RunMemoryReading } from './host-memory.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -112,4 +113,35 @@ function peakBytes(maxRss: number, bunVersion: string): number {
|
|
|
112
113
|
return major < 1 || (major === 1 && minor < 4) ? maxRss * 1024 : maxRss;
|
|
113
114
|
}
|
|
114
115
|
|
|
115
|
-
|
|
116
|
+
/** What the tree rooted at `root` holds resident: each member's `VmRSS`, the tree walked by the kernel's child links. */
|
|
117
|
+
async function treeResidentBytes(root: number): Promise<number> {
|
|
118
|
+
const seen = new Set<number>();
|
|
119
|
+
let level = [root];
|
|
120
|
+
let total = 0;
|
|
121
|
+
while (level.length > 0) {
|
|
122
|
+
const members = level.filter((pid) => !seen.has(pid));
|
|
123
|
+
for (const pid of members) seen.add(pid);
|
|
124
|
+
const [resident, children] = await Promise.all([Promise.all(members.map(residentBytes)), childPids(members)]);
|
|
125
|
+
total += resident.reduce((sum, bytes) => sum + bytes, 0);
|
|
126
|
+
level = children;
|
|
127
|
+
}
|
|
128
|
+
return total;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* `VmRSS` from `/proc/<pid>/status`: what the process holds resident, anonymous, file-backed and shared memory together.
|
|
133
|
+
* A process that has exited (`ENOENT`, `ESRCH`) holds nothing, and so does a zombie, whose status names no `VmRSS`.
|
|
134
|
+
*/
|
|
135
|
+
async function residentBytes(pid: number): Promise<number> {
|
|
136
|
+
let status: string;
|
|
137
|
+
try {
|
|
138
|
+
status = await readFile(`/proc/${pid}/status`, 'utf8');
|
|
139
|
+
} catch (error) {
|
|
140
|
+
if (error instanceof Error && 'code' in error && (error.code === 'ENOENT' || error.code === 'ESRCH')) return 0;
|
|
141
|
+
throw error;
|
|
142
|
+
}
|
|
143
|
+
const kib = /^VmRSS:\s+(\d+) kB$/m.exec(status)?.[1];
|
|
144
|
+
return kib === undefined ? 0 : Number(kib) * 1024;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export const linuxMemory: HostMemory = { readRunMemory: () => linuxRunMemory(readText), peakBytes, treeResidentBytes };
|
|
@@ -14,6 +14,13 @@ export interface HostMemory {
|
|
|
14
14
|
* it: the exited leaf's `ru_maxrss`.
|
|
15
15
|
*/
|
|
16
16
|
peakBytes(maxRss: number, bunVersion: string): number;
|
|
17
|
+
/**
|
|
18
|
+
* What the process tree rooted at `root` holds resident at this instant: the sum over `root` and every descendant the
|
|
19
|
+
* kernel links to it, each process's footprint where the platform keeps one (macOS `ri_phys_footprint`, which counts
|
|
20
|
+
* its compressed pages) and its resident set where it does not (Linux `VmRSS`). A process that exits between the
|
|
21
|
+
* listing and its read adds nothing, and a root that has exited holds nothing.
|
|
22
|
+
*/
|
|
23
|
+
treeResidentBytes(root: number): Promise<number>;
|
|
17
24
|
}
|
|
18
25
|
|
|
19
26
|
/** The run's memory in bytes, and where it was read: the file or sysctl that holds it. */
|
|
@@ -7,10 +7,11 @@ import { resolveOnPath } from './runtime-pin.js';
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* A leaf's memory peak (specs/cowshed/05_gateway.md, "Without mbx, every Nx run budgets itself"; 13_telemetry.md, "Job
|
|
10
|
-
* resource peaks"): the exited command's
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
10
|
+
* resource peaks"): the largest sum of what the exited command's process tree held side by side, as its waiter
|
|
11
|
+
* (`peak-waiter.ts`) sampled it, never less than the command's rusage `ru_maxrss`, which the waiter also reads. The
|
|
12
|
+
* leaf runs no cgroup of its own, even under a cowshed supervisor, whose subtree of the command is an observed fold
|
|
13
|
+
* inside the job's cgroup (07_api.md, `JobSubtreeHandle`), so the peak is read from the leaf's own tree on Linux and
|
|
14
|
+
* macOS alike. The executor writes it into the task's record, and the task's next run is charged it in its run's pool.
|
|
14
15
|
*/
|
|
15
16
|
|
|
16
17
|
/** The descriptor the waiter reports on: past the lifecycle channel (3), the subtree admission (4) and mbx's grant (5). */
|
|
@@ -21,6 +21,34 @@ import { mbxPool } from './mbx-pool.js';
|
|
|
21
21
|
*/
|
|
22
22
|
export const RESERVATIONS_ENV = 'MBX_RESERVATIONS_SOCKET';
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Why the run serves its tasks no endpoint, published beside {@link RESERVATIONS_ENV} when its endpoint did not start.
|
|
26
|
+
* Every task inherits it, so each reserved leaf's refusal names the cause: a gate's failures-only output shows the
|
|
27
|
+
* leaves' refusals, never the run's own warning.
|
|
28
|
+
*/
|
|
29
|
+
export const RESERVATIONS_UNSERVED_ENV = 'BOUNDED_EXEC_RESERVATIONS_UNSERVED';
|
|
30
|
+
|
|
31
|
+
/** What a task's environment says of its run's reservation endpoint. */
|
|
32
|
+
export type RunEndpoint =
|
|
33
|
+
| { readonly kind: 'served'; readonly socket: string }
|
|
34
|
+
| { readonly kind: 'unserved'; readonly reason: string }
|
|
35
|
+
| { readonly kind: 'unpublished' };
|
|
36
|
+
|
|
37
|
+
/** The endpoint `env` names, else why its run serves none, else that its run published neither. */
|
|
38
|
+
export function runEndpoint(env: Readonly<NodeJS.ProcessEnv>): RunEndpoint {
|
|
39
|
+
const socket = env[RESERVATIONS_ENV] ?? '';
|
|
40
|
+
if (socket !== '') return { kind: 'served', socket };
|
|
41
|
+
const reason = env[RESERVATIONS_UNSERVED_ENV] ?? '';
|
|
42
|
+
return reason === '' ? { kind: 'unpublished' } : { kind: 'unserved', reason };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Why a task's run serves it no endpoint, as its reserved leaf's refusal says it. */
|
|
46
|
+
export function describeUnserved(endpoint: Exclude<RunEndpoint, { kind: 'served' }>): string {
|
|
47
|
+
return endpoint.kind === 'unserved'
|
|
48
|
+
? `the run's endpoint did not start (${endpoint.reason})`
|
|
49
|
+
: `the run published neither an endpoint nor why it has none (${RESERVATIONS_UNSERVED_ENV} is unset too), so its preTasksExecution never served this run or its environment never reached this task`;
|
|
50
|
+
}
|
|
51
|
+
|
|
24
52
|
const ENDPOINT_DIRECTORY = 'mbx-r-';
|
|
25
53
|
const ENDPOINT_SOCKET = 'r.sock';
|
|
26
54
|
/** What is kept of the endpoint's stderr to say why it ended: its last bytes. */
|
|
@@ -55,10 +83,12 @@ export async function serveRunReservations(
|
|
|
55
83
|
logger.warn(
|
|
56
84
|
`bounded-exec: this run's mbx reservation endpoint did not start (${started.error}); its reserved leaves refuse to run`,
|
|
57
85
|
);
|
|
86
|
+
env[RESERVATIONS_UNSERVED_ENV] = started.error;
|
|
58
87
|
return;
|
|
59
88
|
}
|
|
60
89
|
endpoints.set(context.id, started.endpoint);
|
|
61
90
|
env[RESERVATIONS_ENV] = started.socket;
|
|
91
|
+
delete env[RESERVATIONS_UNSERVED_ENV];
|
|
62
92
|
}
|
|
63
93
|
|
|
64
94
|
/** Close the endpoint `context`'s run was served, if it was served one: its standard input's end ends it. */
|
|
@@ -6,9 +6,14 @@ import { HOST_MEMORY } from './host-memory.js';
|
|
|
6
6
|
* on Bun as `bun --config=/dev/null peak-waiter.js <report fd> <fds> <file> [args…]`, it spawns `file args` with its
|
|
7
7
|
* own stdin, stdout and stderr and each descriptor `fds` names (comma-separated) at its own number, writes the
|
|
8
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.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* ends as the command did: with its exit code, or with its signal raised on itself.
|
|
10
|
+
*
|
|
11
|
+
* The peak is what the command's tree held side by side. Every {@link SAMPLE_MS} while the command runs, the waiter
|
|
12
|
+
* sums what the command and each descendant the kernel links to it hold (`HostMemory.treeResidentBytes`) and keeps the
|
|
13
|
+
* largest sum. At the exit it takes the larger of that and the command's `ru_maxrss`, the largest resident set any one
|
|
14
|
+
* process of the tree it waited on reached, which a spike between two samples still reaches: Node, which runs the
|
|
15
|
+
* executor, reaps a child without its rusage; Bun's `Subprocess.resourceUsage()` reports it. A tree it could not read
|
|
16
|
+
* is said on the command's stderr, and its peak is then the larger of what was read and `ru_maxrss`.
|
|
12
17
|
*
|
|
13
18
|
* The waiter leads the leaf's process group, so the executor's group signals reach the command directly: it ignores
|
|
14
19
|
* SIGINT, SIGTERM and SIGHUP and outlives the command to report it. A SIGKILL of the group ends it unreported. The
|
|
@@ -40,12 +45,15 @@ function isBunSpawner(runtime: unknown): runtime is BunSpawner {
|
|
|
40
45
|
);
|
|
41
46
|
}
|
|
42
47
|
|
|
48
|
+
/** How often, in ms, the waiter sums what its command's tree holds while the command runs. */
|
|
49
|
+
const SAMPLE_MS = 250;
|
|
43
50
|
const IGNORED = ['SIGINT', 'SIGTERM', 'SIGHUP'] as const;
|
|
44
51
|
const bun: unknown = Reflect.get(globalThis, 'Bun');
|
|
45
52
|
const [reportFd, list, file, ...args] = process.argv.slice(2);
|
|
46
53
|
if (!isBunSpawner(bun) || HOST_MEMORY === null || reportFd === undefined || list === undefined || file === undefined) {
|
|
47
54
|
throw new Error('peak-waiter runs on Bun, on Linux or macOS, as `peak-waiter.js <report fd> <fds> <file> [args…]`');
|
|
48
55
|
}
|
|
56
|
+
const memory = HOST_MEMORY;
|
|
49
57
|
const report = (line: { started: number } | { peakBytes: number } | { unmeasured: string }): void => {
|
|
50
58
|
try {
|
|
51
59
|
writeSync(Number(reportFd), `${JSON.stringify(line)}\n`);
|
|
@@ -68,12 +76,37 @@ try {
|
|
|
68
76
|
process.exit(1);
|
|
69
77
|
}
|
|
70
78
|
report({ started: child.pid });
|
|
79
|
+
const root = child.pid;
|
|
80
|
+
let treePeak = 0;
|
|
81
|
+
let unreadTree: string | null = null;
|
|
82
|
+
let reading: Promise<void> | null = null;
|
|
83
|
+
const sample = async (): Promise<void> => {
|
|
84
|
+
try {
|
|
85
|
+
treePeak = Math.max(treePeak, await memory.treeResidentBytes(root));
|
|
86
|
+
} catch (error) {
|
|
87
|
+
unreadTree ??= error instanceof Error ? error.message : String(error);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
// A read still running when the next period starts takes that period too: reads of one tree never overlap.
|
|
91
|
+
const sampler = setInterval(() => {
|
|
92
|
+
reading ??= sample().finally(() => {
|
|
93
|
+
reading = null;
|
|
94
|
+
});
|
|
95
|
+
}, SAMPLE_MS);
|
|
71
96
|
await child.exited;
|
|
97
|
+
clearInterval(sampler);
|
|
98
|
+
await reading;
|
|
99
|
+
if (unreadTree !== null) {
|
|
100
|
+
writeSync(
|
|
101
|
+
2,
|
|
102
|
+
`bounded-exec: the command tree's resident sum could not be read (${unreadTree}); its peak is the larger of what was read and its largest process's ru_maxrss\n`,
|
|
103
|
+
);
|
|
104
|
+
}
|
|
72
105
|
const usage = child.resourceUsage();
|
|
73
106
|
report(
|
|
74
107
|
usage === undefined
|
|
75
108
|
? { unmeasured: 'Bun read no resource usage for the exited command' }
|
|
76
|
-
: { peakBytes:
|
|
109
|
+
: { peakBytes: Math.max(treePeak, memory.peakBytes(usage.maxRSS, bun.version)) },
|
|
77
110
|
);
|
|
78
111
|
if (child.signalCode !== null) {
|
|
79
112
|
for (const signal of IGNORED) process.removeListener(signal, ignore);
|
|
@@ -254,6 +254,14 @@ export function defineCiWorkflow(options: CiWorkflowDefinitionOptions): CiWorkfl
|
|
|
254
254
|
*/
|
|
255
255
|
export const CI_CONCURRENCY_GROUP = 'CI-${{ github.event.pull_request.number || github.ref }}';
|
|
256
256
|
|
|
257
|
+
/**
|
|
258
|
+
* The CI workflow's name and its one job's id. A workflow whose tests are CI's (a release's) hands them to the
|
|
259
|
+
* setup-devenv action as `records-workflow` and `records-job`, so a task its Nx scope holds no record of is charged what
|
|
260
|
+
* CI's pushes last recorded of it (specs/cowshed/05_gateway.md, "Without mbx, every Nx run budgets itself").
|
|
261
|
+
*/
|
|
262
|
+
export const CI_WORKFLOW_NAME = 'CI';
|
|
263
|
+
export const CI_JOB_ID = 'main';
|
|
264
|
+
|
|
257
265
|
export function renderCiWorkflowYaml(options: CiWorkflowDefinitionOptions): string {
|
|
258
266
|
const steps = defineCiWorkflow(options);
|
|
259
267
|
return [
|
|
@@ -266,7 +274,7 @@ export function renderCiWorkflowYaml(options: CiWorkflowDefinitionOptions): stri
|
|
|
266
274
|
}
|
|
267
275
|
|
|
268
276
|
function renderCiWorkflowHeader(options: CiWorkflowDefinitionOptions): string {
|
|
269
|
-
return `name:
|
|
277
|
+
return `name: ${CI_WORKFLOW_NAME}
|
|
270
278
|
|
|
271
279
|
on:
|
|
272
280
|
push:
|
|
@@ -303,7 +311,7 @@ defaults:
|
|
|
303
311
|
working-directory: tooling/direnv
|
|
304
312
|
|
|
305
313
|
jobs:
|
|
306
|
-
|
|
314
|
+
${CI_JOB_ID}:
|
|
307
315
|
name: Validate
|
|
308
316
|
${renderRunsOnLine(options.runsOn)}
|
|
309
317
|
timeout-minutes: 45
|
|
@@ -867,8 +875,8 @@ export function cargoCredentialStepLines(step: CiWorkflowStep, config: PackageCa
|
|
|
867
875
|
const mirrorUrl = new URL(origin.internalMirror);
|
|
868
876
|
const mirrorBase = `${mirrorUrl.protocol}//${mirrorUrl.host}/`.replaceAll("'", "'\\''");
|
|
869
877
|
for (const prefix of mirrorRewritePrefixes(origin)) {
|
|
870
|
-
lines.push(
|
|
871
|
-
lines.push(
|
|
878
|
+
lines.push(` echo "GIT_CONFIG_KEY_\${idx}=url.${mirrorBase}.insteadOf"`);
|
|
879
|
+
lines.push(` echo "GIT_CONFIG_VALUE_\${idx}=${prefix.replaceAll("'", "'\\''")}"`);
|
|
872
880
|
lines.push(' idx=$((idx + 1))');
|
|
873
881
|
}
|
|
874
882
|
}
|
|
@@ -17,6 +17,8 @@ import type {
|
|
|
17
17
|
import { isSmoothBricksCodebasePackageName } from '../workspace-package-policy.js';
|
|
18
18
|
import {
|
|
19
19
|
artifactStepLines,
|
|
20
|
+
CI_JOB_ID,
|
|
21
|
+
CI_WORKFLOW_NAME,
|
|
20
22
|
CiWorkflowStepKind,
|
|
21
23
|
cargoCredentialJobEnvLines,
|
|
22
24
|
cargoCredentialStepLines,
|
|
@@ -578,6 +580,16 @@ function commentLinesForStep(step: PublishWorkflowStep): string[] {
|
|
|
578
580
|
return [` # Step ${step.number}`];
|
|
579
581
|
}
|
|
580
582
|
|
|
583
|
+
/** The setup-devenv step's `uses` and the scope its task records start from: a release's tests are CI's. */
|
|
584
|
+
function setupDevenvUsesLines(): string[] {
|
|
585
|
+
return [
|
|
586
|
+
' uses: ./.github/actions/setup-devenv',
|
|
587
|
+
' with:',
|
|
588
|
+
` records-workflow: ${CI_WORKFLOW_NAME}`,
|
|
589
|
+
` records-job: ${CI_JOB_ID}`,
|
|
590
|
+
];
|
|
591
|
+
}
|
|
592
|
+
|
|
581
593
|
function yamlLinesForStep(step: PublishWorkflowStep, options: PublishWorkflowDefinitionOptions): string[] {
|
|
582
594
|
switch (step.kind) {
|
|
583
595
|
case PublishWorkflowStepKind.Checkout:
|
|
@@ -598,7 +610,7 @@ function yamlLinesForStep(step: PublishWorkflowStep, options: PublishWorkflowDef
|
|
|
598
610
|
case PublishWorkflowStepKind.CargoCredentials:
|
|
599
611
|
return cargoCredentialsStepLines(options);
|
|
600
612
|
case PublishWorkflowStepKind.SetupDevenv:
|
|
601
|
-
return [` - name: ${step.name}`, ' id: setup',
|
|
613
|
+
return [` - name: ${step.name}`, ' id: setup', ...setupDevenvUsesLines()];
|
|
602
614
|
case PublishWorkflowStepKind.ConfigureReleaseAuthor:
|
|
603
615
|
return [
|
|
604
616
|
` - name: ${step.name}`,
|
|
@@ -1145,7 +1157,7 @@ function renderMacosPlatformSteps(options: PublishWorkflowDefinitionOptions): st
|
|
|
1145
1157
|
' # anchors; update these comments if top-level steps move.',
|
|
1146
1158
|
' - name: 🧱 Setup Nix/devenv',
|
|
1147
1159
|
' id: setup',
|
|
1148
|
-
|
|
1160
|
+
...setupDevenvUsesLines(),
|
|
1149
1161
|
);
|
|
1150
1162
|
if (isSmoothBricksCodebasePackageName(options.repoName)) {
|
|
1151
1163
|
lines.push(
|
|
@@ -1279,7 +1291,7 @@ function renderFinalLinuxPublishSteps(options: PublishWorkflowDefinitionOptions)
|
|
|
1279
1291
|
' # verified artifacts are restored, so this job still needs the full',
|
|
1280
1292
|
' # toolchain even though current release publishing is prebuilt-only.',
|
|
1281
1293
|
' id: setup',
|
|
1282
|
-
|
|
1294
|
+
...setupDevenvUsesLines(),
|
|
1283
1295
|
'',
|
|
1284
1296
|
` # Step ${stepNumber++}`,
|
|
1285
1297
|
...artifactStepLines(options.actionsProvider, '📥 Download candidate artifacts', 'download', [
|
package/test-timings.json
CHANGED
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"src/task-history-namespace.test.ts": 1786,
|
|
53
53
|
"src/managed-files/repo-path.test.ts": 1593,
|
|
54
54
|
"src/nx-cache-kept-outputs.test.ts": 1363,
|
|
55
|
+
"src/managed-files/setup-devenv-task-records.test.ts": 1330,
|
|
55
56
|
"src/nx-foreign-workspace-env.test.ts": 1255,
|
|
56
57
|
"src/managed-files/forgejo-artifact.test.ts": 1192,
|
|
57
58
|
"src/nx-plugin-load-errors.test.ts": 1180,
|
|
@@ -94,6 +95,7 @@
|
|
|
94
95
|
"src/release-config-policy.test.ts": 72,
|
|
95
96
|
"src/managed-files/cache-ttsc-plugins.test.ts": 62,
|
|
96
97
|
"src/workspace-config-policy.test.ts": 61,
|
|
98
|
+
"src/executors/bounded-exec/host-memory.test.ts": 59,
|
|
97
99
|
"src/generators/make-public/generator.test.ts": 52,
|
|
98
100
|
"src/executors/bounded-exec/mbx-pool.test.ts": 46,
|
|
99
101
|
"src/executors/scriptc-native/executor.test.ts": 44,
|